Skip to content

sgns::AccountMessenger

#include <AccountMessenger.hpp>

Inherits from std::enable_shared_from_this< AccountMessenger >

Public Classes

Name
struct InterfaceMethods
Interface methods the user needs to define.

Public Types

Name
enum class Error { PROTO_DESERIALIZATION = 0, PROTO_SERIALIZATION, NONCE_REQUEST_IN_PROGRESS, NONCE_GET_ERROR, NO_RESPONSE_RECEIVED, RESPONSE_WITHOUT_NONCE, GENESIS_REQUEST_ERROR}
Account Messenger errors.
using std::function< bool(const std::string &cid, const std::string &peer_id, const std::string &address)> BlockResponseHandler
using std::function< void(const std::set< std::string > &topics)> HeadRequestHandler

Public Functions

Name
std::shared_ptr< AccountMessenger > New(std::string address, std::shared_ptr< ipfs_pubsub::GossipPubSub > pubsub, InterfaceMethods methods)
Factory constructor of new AccountMessenger.
~AccountMessenger()
Destroy the Account Messenger object.
outcome::result< uint64_t > GetLatestNonce(uint64_t timeout_ms, uint64_t silent_time_ms =150)
Get the Latest Nonce from the network.
outcome::result< void > RequestGenesis(uint64_t timeout_ms, std::function< void(outcome::result< std::string >)> callback =nullptr)
Request genesis block from the network (retries until timeout).
outcome::result< void > RequestAccountCreation(uint64_t timeout_ms, std::function< void(outcome::result< std::string >)> callback)
Request account creation from the network and invoke callback with found CIDs.
outcome::result< void > RequestRegularBlock(uint64_t timeout_ms, std::string cid, std::function< void(outcome::result< std::string >)> callback =nullptr)
Request a block by CID from the network (retries until timeout).
void RegisterBlockResponseHandler(BlockResponseHandler handler)
Register global block response handler.
void ClearBlockResponseHandler()
Clears the block response handler.
void RegisterHeadRequestHandler(HeadRequestHandler handler)
Register handler for incoming head requests.
void ClearHeadRequestHandler()
Clears the head request handler.
outcome::result< void > RequestHeads(const std::unordered_set< std::string > & topics)
Request heads broadcast for specific topics.

Public Types Documentation

enum Error

Enumerator Value Description
PROTO_DESERIALIZATION 0 Error in protobuf data deserialization.
PROTO_SERIALIZATION Error in protobuf data serialization.
NONCE_REQUEST_IN_PROGRESS Nonce request already in progress.
NONCE_GET_ERROR Nonce couldn't be fetched.
NO_RESPONSE_RECEIVED No response received from network.
RESPONSE_WITHOUT_NONCE Response received but without nonce data.
GENESIS_REQUEST_ERROR Genesis request failed.

Account Messenger errors.

using BlockResponseHandler

using sgns::AccountMessenger::BlockResponseHandler = 
std::function<bool( const std::string &cid, const std::string &peer_id, const std::string &address )>;

using HeadRequestHandler

using sgns::AccountMessenger::HeadRequestHandler = std::function<void( const std::set<std::string> &topics )>;

Public Functions Documentation

function New

static std::shared_ptr< AccountMessenger > New(
    std::string address,
    std::shared_ptr< ipfs_pubsub::GossipPubSub > pubsub,
    InterfaceMethods methods
)

Factory constructor of new AccountMessenger.

Parameters:

  • address Own address
  • pubsub pubsub instance
  • methods interface methods InterfaceMethods

Return: Valid pointer if succeeds, nullptr otherwise

function ~AccountMessenger

~AccountMessenger()

Destroy the Account Messenger object.

function GetLatestNonce

outcome::result< uint64_t > GetLatestNonce(
    uint64_t timeout_ms,
    uint64_t silent_time_ms =150
)

Get the Latest Nonce from the network.

Parameters:

  • timeout_ms Timeout in miliseconds to get the latest nonce
  • silent_time_ms Time tyo wait for subsequential nonce responses after first was received

Return: Nonce value if success, error otherwise

function RequestGenesis

outcome::result< void > RequestGenesis(
    uint64_t timeout_ms,
    std::function< void(outcome::result< std::string >)> callback =nullptr
)

Request genesis block from the network (retries until timeout).

Parameters:

  • timeout_ms Total timeout in milliseconds to wait for responses
  • callback Function to be called for each CID found (empty string if none)

Return: success if at least one response arrives before timeout, error otherwise

function RequestAccountCreation

outcome::result< void > RequestAccountCreation(
    uint64_t timeout_ms,
    std::function< void(outcome::result< std::string >)> callback
)

Request account creation from the network and invoke callback with found CIDs.

Parameters:

  • timeout_ms Total timeout in milliseconds to wait for responses
  • callback Function to be called for each CID found (signature: void(std::string))

Return: success on scheduled request, error otherwise

function RequestRegularBlock

outcome::result< void > RequestRegularBlock(
    uint64_t timeout_ms,
    std::string cid,
    std::function< void(outcome::result< std::string >)> callback =nullptr
)

Request a block by CID from the network (retries until timeout).

Parameters:

  • timeout_ms Total timeout in milliseconds to wait for responses
  • cid CID to request
  • callback Callback invoked with the CID result (or error)

Return: success on scheduled request, error otherwise

function RegisterBlockResponseHandler

void RegisterBlockResponseHandler(
    BlockResponseHandler handler
)

Register global block response handler.

Parameters:

  • handler Function to call for all block responses

function ClearBlockResponseHandler

void ClearBlockResponseHandler()

Clears the block response handler.

function RegisterHeadRequestHandler

void RegisterHeadRequestHandler(
    HeadRequestHandler handler
)

Register handler for incoming head requests.

Parameters:

  • handler Function to call when head request is received with topic list

function ClearHeadRequestHandler

void ClearHeadRequestHandler()

Clears the head request handler.

function RequestHeads

outcome::result< void > RequestHeads(
    const std::unordered_set< std::string > & topics
)

Request heads broadcast for specific topics.

Parameters:

  • topics Vector of topic names to request heads for

Return: outcome::success if request was sent, error otherwise


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