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, UTXO_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.
void Stop()
Stop the request worker thread after draining pending tasks.
outcome::result< uint64_t > GetLatestNonce(std::chrono::milliseconds timeout, std::chrono::milliseconds silent_time =std::chrono::milliseconds(150))
Get the Latest Nonce from the network.
outcome::result< void > RequestGenesis(std::chrono::milliseconds timeout, std::function< void(outcome::result< std::string >)> callback =nullptr)
Request genesis block from the network (retries until timeout)
outcome::result< void > RequestAccountCreation(std::chrono::milliseconds timeout, std::function< void(outcome::result< std::string >)> callback)
Request account creation from the network and invoke callback with found CIDs.
outcome::result< void > RequestValidatorRegistry(std::chrono::milliseconds timeout, std::function< void(outcome::result< std::string >)> callback)
outcome::result< void > RequestRegularBlock(std::chrono::milliseconds timeout, std::string cid, std::function< void(outcome::result< std::string >)> callback =nullptr)
Request a block by CID from the network (retries until timeout)
outcome::result< void > RequestTransaction(std::chrono::milliseconds timeout, std::string tx_hash, std::function< void(outcome::result< std::string >)> callback =nullptr)
Request a transaction by hash from the network (retries until timeout)
outcome::result< std::unordered_set< std::string > > RequestUTXOs(std::chrono::milliseconds timeout, const std::string & address, std::chrono::milliseconds silent_time =std::chrono::milliseconds(150))
Request UTXOs for a specific address and return the selected response.
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.
UTXO_REQUEST_ERROR UTXO 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 Stop

void Stop()

Stop the request worker thread after draining pending tasks.

function GetLatestNonce

outcome::result< uint64_t > GetLatestNonce(
    std::chrono::milliseconds timeout,
    std::chrono::milliseconds silent_time =std::chrono::milliseconds(150)
)

Get the Latest Nonce from the network.

Parameters:

  • timeout How long to wait for the latest nonce
  • silent_time How long to wait for further nonce responses after the first

Return: Nonce value if success, error otherwise

function RequestGenesis

outcome::result< void > RequestGenesis(
    std::chrono::milliseconds timeout,
    std::function< void(outcome::result< std::string >)> callback =nullptr
)

Request genesis block from the network (retries until timeout)

Parameters:

  • timeout Total time 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(
    std::chrono::milliseconds timeout,
    std::function< void(outcome::result< std::string >)> callback
)

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

Parameters:

  • timeout Total time 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 RequestValidatorRegistry

outcome::result< void > RequestValidatorRegistry(
    std::chrono::milliseconds timeout,
    std::function< void(outcome::result< std::string >)> callback
)

function RequestRegularBlock

outcome::result< void > RequestRegularBlock(
    std::chrono::milliseconds timeout,
    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 Total time 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 RequestTransaction

outcome::result< void > RequestTransaction(
    std::chrono::milliseconds timeout,
    std::string tx_hash,
    std::function< void(outcome::result< std::string >)> callback =nullptr
)

Request a transaction by hash from the network (retries until timeout)

Parameters:

  • timeout Total time to wait for responses
  • tx_hash Transaction hash to request
  • callback Callback invoked with the CID result (or error)

Return: success on scheduled request, error otherwise

function RequestUTXOs

outcome::result< std::unordered_set< std::string > > RequestUTXOs(
    std::chrono::milliseconds timeout,
    const std::string & address,
    std::chrono::milliseconds silent_time =std::chrono::milliseconds(150)
)

Request UTXOs for a specific address and return the selected response.

Parameters:

  • timeout Total time to wait for responses
  • address Address to request UTXOs for
  • silent_time Time to wait for subsequent responses after the first one

Return: Set of UTXO strings based on selection criteria, or 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-08-28 at 01:08:42 +0000