Skip to content

src/primitives/common.hpp

Namespaces

Name
sgns
sgns::primitives
sgns::primitives::detail

Classes

Name
struct sgns::primitives::detail::BlockInfoT

Types

Name
using uint64_t BlocksRequestId
using uint64_t BlockNumber
using detail::BlockInfoT< struct BlockInfoTag > BlockInfo

Functions

Name
template <class Stream ,typename Tag ,typename =std::enable_if_t>
Stream &
operator<<(Stream & s, const BlockInfoT< Tag > & msg)
template <class Stream ,typename Tag ,typename =std::enable_if_t>
Stream &
operator>>(Stream & s, BlockInfoT< Tag > & msg)

Types Documentation

using BlocksRequestId

using sgns::primitives::BlocksRequestId = uint64_t;

using BlockNumber

using sgns::primitives::BlockNumber = uint64_t;

using BlockInfo

using sgns::primitives::BlockInfo = detail::BlockInfoT<struct BlockInfoTag>;

Functions Documentation

function operator<<

template <class Stream ,
typename Tag ,
typename  =std::enable_if_t<Stream::is_encoder_stream>>
Stream & operator<<(
    Stream & s,
    const BlockInfoT< Tag > & msg
)

function operator>>

template <class Stream ,
typename Tag ,
typename  =std::enable_if_t<Stream::is_decoder_stream>>
Stream & operator>>(
    Stream & s,
    BlockInfoT< Tag > & msg
)

Source code

#ifndef SUPERGENIUS_SRC_PRIMITIVES_COMMON_HPP
#define SUPERGENIUS_SRC_PRIMITIVES_COMMON_HPP

#include <cstdint>

#include <boost/operators.hpp>
#include "base/blob.hpp"

namespace sgns::primitives {
  using BlocksRequestId = uint64_t;

  using BlockNumber = uint64_t;
  using BlockHash = base::Hash256;

  namespace detail {
    // base data structure for the types describing block information
    // (BlockInfo, Prevote, Precommit, PrimaryPropose)
    template <typename Tag>
    struct BlockInfoT : public boost::equality_comparable<BlockInfoT<Tag>> {
      constexpr BlockInfoT() = default;

      constexpr BlockInfoT( BlockNumber n, BlockHash h ) : block_number( n ), block_hash( h )
      {
      }

      BlockNumber block_number{};
      BlockHash   block_hash;

      bool operator==(const BlockInfoT<Tag> &o) const {
        return block_number == o.block_number && block_hash == o.block_hash;
      }
    };

    template <class Stream,
              typename Tag,
              typename = std::enable_if_t<Stream::is_encoder_stream>>
    Stream &operator<<(Stream &s, const BlockInfoT<Tag> &msg) {
      return s << msg.block_hash << msg.block_number;
    }

    template <class Stream,
              typename Tag,
              typename = std::enable_if_t<Stream::is_decoder_stream>>
    Stream &operator>>(Stream &s, BlockInfoT<Tag> &msg) {
      return s >> msg.block_hash >> msg.block_number;
    }
  }  // namespace detail

  using BlockInfo = detail::BlockInfoT<struct BlockInfoTag>;

}  // namespace sgns::primitives

#endif  // SUPERGENIUS_SRC_PRIMITIVES_COMMON_HPP

Updated on 2026-03-04 at 13:10:44 -0800