Skip to content

src/primitives/authority.hpp

Namespaces

Name
sgns
sgns::primitives

Classes

Name
struct sgns::primitives::AuthorityId
struct sgns::primitives::Authority
struct sgns::primitives::AuthorityList
Special type for vector of authorities.

Types

Name
using uint64_t AuthorityWeight
using uint64_t AuthorityIndex

Functions

Name
bool operator<(const AuthorityId & lhs, const AuthorityId & rhs)
template <class Stream ,typename =std::enable_if_t>
Stream &
operator<<(Stream & s, const AuthorityId & a)
outputs object of type AuthorityId to stream
template <class Stream ,typename =std::enable_if_t>
Stream &
operator>>(Stream & s, AuthorityId & a)
decodes object of type AuthorityId from stream
template <class Stream ,typename =std::enable_if_t>
Stream &
operator<<(Stream & s, const Authority & a)
outputs object of type Authority to stream
template <class Stream ,typename =std::enable_if_t>
Stream &
operator>>(Stream & s, Authority & a)
decodes object of type Authority from stream

Types Documentation

using AuthorityWeight

using sgns::primitives::AuthorityWeight = uint64_t;

using AuthorityIndex

using sgns::primitives::AuthorityIndex = uint64_t;

Authority index

Functions Documentation

function operator<

inline bool operator<(
    const AuthorityId & lhs,
    const AuthorityId & rhs
)

function operator<<

template <class Stream ,
typename  =std::enable_if_t<Stream::is_encoder_stream>>
Stream & operator<<(
    Stream & s,
    const AuthorityId & a
)

outputs object of type AuthorityId to stream

Parameters:

  • s stream reference
  • a value to output

Template Parameters:

  • Stream output stream type

Return: reference to stream

function operator>>

template <class Stream ,
typename  =std::enable_if_t<Stream::is_decoder_stream>>
Stream & operator>>(
    Stream & s,
    AuthorityId & a
)

decodes object of type AuthorityId from stream

Parameters:

  • s stream reference
  • a value to decode

Template Parameters:

  • Stream input stream type

Return: reference to stream

function operator<<

template <class Stream ,
typename  =std::enable_if_t<Stream::is_encoder_stream>>
Stream & operator<<(
    Stream & s,
    const Authority & a
)

outputs object of type Authority to stream

Parameters:

  • s stream reference
  • a value to output

Template Parameters:

  • Stream output stream type

Return: reference to stream

function operator>>

template <class Stream ,
typename  =std::enable_if_t<Stream::is_decoder_stream>>
Stream & operator>>(
    Stream & s,
    Authority & a
)

decodes object of type Authority from stream

Parameters:

  • s stream reference
  • a value to decode

Template Parameters:

  • Stream input stream type

Return: reference to stream

Source code

#ifndef SUPERGENIUS_AUTHORITY_HPP
#define SUPERGENIUS_AUTHORITY_HPP

#include <cstdint>
#include "primitives/session_key.hpp"

namespace sgns::primitives {
  using AuthorityWeight = uint64_t;

  struct AuthorityId {
    // TODO(kamilsa): id types should be different for Production and Finality
    // Authority Ids
    SessionKey id;

    bool operator==(const AuthorityId &other) const {
      return id == other.id;
    }
    bool operator!=(const AuthorityId &other) const {
      return !(*this == other);
    }
    //added by Jin to fix link error in test
    friend std::ostream &operator<<(std::ostream &out, const AuthorityId &a)
    {
      return out << a.id; 
    }
    //end
  };

  inline bool operator<(const AuthorityId &lhs, const AuthorityId &rhs) {
    return lhs.id < rhs.id;
  }

  using AuthorityIndex = uint64_t;

  struct Authority {
    AuthorityId id;
    AuthorityWeight weight{};

    bool operator==(const Authority &other) const {
      return id == other.id && weight == other.weight;
    }
    bool operator!=(const Authority &other) const {
      return !(*this == other);
    }
    //added to fix link errors
    friend std::ostream &operator<<(std::ostream &out, const Authority &test_struct)
    {
        return out << test_struct.id;
    }
    //end
  };

  template <class Stream,
            typename = std::enable_if_t<Stream::is_encoder_stream>>
  Stream &operator<<(Stream &s, const AuthorityId &a) {
    return s << a.id;
  }

  template <class Stream,
            typename = std::enable_if_t<Stream::is_decoder_stream>>
  Stream &operator>>(Stream &s, AuthorityId &a) {
    return s >> a.id;
  }

  template <class Stream,
            typename = std::enable_if_t<Stream::is_encoder_stream>>
  Stream &operator<<(Stream &s, const Authority &a) {
    return s << a.id << a.weight;
  }

  template <class Stream,
            typename = std::enable_if_t<Stream::is_decoder_stream>>
  Stream &operator>>(Stream &s, Authority &a) {
    return s >> a.id >> a.weight;
  }

  struct AuthorityList : public std::vector<Authority> {
    // Attention: When adding a member, we need to ensure correct
    // destruction to avoid memory leaks or any other problem
    using std::vector<Authority>::vector;
  };
}  // namespace sgns::primitives

#endif  // SUPERGENIUS_AUTHORITY_HPP

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