sgns::GeniusAccount¶
#include <GeniusAccount.hpp>
Inherits from std::enable_shared_from_this< GeniusAccount >
Public Types¶
| Name | |
|---|---|
| using std::pair< std::shared_ptr< ISecureStorage >, std::pair< KeyGenerator::ElGamal, ethereum::EthereumKeyGenerator > > | StorageWithAddress |
| using std::function< std::shared_ptr< ISecureStorage >(const std::string &identifier)> | SecureStorageFactory Factory function type for creating secure storage instances. |
Public Functions¶
| Name | |
|---|---|
| void | SetSecureStorageFactory(SecureStorageFactory factory) Sets the secure storage factory used by all GeniusAccount factory methods. |
| const SecureStorageFactory & | GetSecureStorageFactory() Returns the current secure storage factory (default if none set). |
| std::shared_ptr< GeniusAccount > | New(TokenID token_id, const char * eth_private_key, const boost::filesystem::path & base_path, bool full_node =false) Factory constructor of new GeniusAccount. |
| std::shared_ptr< GeniusAccount > | NewFromMnemonic(TokenID token_id, const std::string & mnemonic, const boost::filesystem::path & base_path, bool full_node =false) |
| std::shared_ptr< GeniusAccount > | NewFromPublicKey(TokenID token_id, std::string_view public_key, bool full_node =false) |
| std::shared_ptr< GeniusAccount > | New(TokenID token_id, const boost::filesystem::path & base_path, bool full_node =false) Factory constructor of new GeniusAccount. |
| std::vector< std::string > | GetAvailableAccounts(const boost::filesystem::path & base_path) |
| outcome::result< void > | DeleteAccount(std::string_view public_address, const boost::filesystem::path & base_path) |
| bool | VerifySignature(const std::string & address, std::string_view sig, const std::vector< uint8_t > & data) Verify a signature using the Genius account's public key. |
| outcome::result< StorageWithAddress > | GenerateGeniusAddress(const char * eth_private_key, const boost::filesystem::path & base_path) |
| outcome::result< StorageWithAddress > | GenerateGeniusAddress(const TW::PrivateKey & private_key, const boost::filesystem::path & base_path) |
| bool | InitMessenger(std::shared_ptr< ipfs_pubsub::GossipPubSub > pubsub) Initialize the messenger for the account. |
| bool | ConfigureDatabaseDependencies(std::shared_ptr< crdt::GlobalDB > global_db) Configures the block response handler. |
| void | DeconfigureDatabaseDependencies() Clears handlers and methods set by ConfigureDatabaseDependencies. |
| ~GeniusAccount() Destroy the Genius Account object. |
|
| std::string | GetAddress() const Get the Address object. |
| TokenID | GetToken() const Get the account's token. |
| std::string | GetNonce() const Get the confirmed nonce as a string. |
| std::vector< uint8_t > | Sign(const std::vector< uint8_t > & data) const Sign data using the Genius account's private key. |
| std::vector< InputUTXOInfo > | CreateInputsFromUTXOs(const std::vector< GeniusUTXO > & utxos) const Build signed transaction inputs from UTXOs. |
| void | SetPeerConfirmedNonce(uint64_t nonce, const std::string & address, const std::string & tx_hash ="") Set the confirmed nonce for an address. |
| void | RollBackPeerConfirmedNonce(uint64_t nonce, const std::string & address) Rollback the local confirmed nonce for a peer. |
| outcome::result< uint64_t > | GetPeerNonce(const std::string & address) const Get the confirmed nonce for a peer. |
| outcome::result< uint64_t > | GetLocalConfirmedNonce() const Get the local confirmed nonce. |
| outcome::result< std::string > | GetLocalConfirmedTxHash(uint64_t nonce) const Get a locally persisted confirmed transaction hash by nonce. |
| outcome::result< uint64_t > | GetConfirmedNonce(uint64_t timeout_ms) const Get confirmed nonce from the network. |
| outcome::result< std::optional< uint64_t > > | FetchNetworkNonce(uint64_t timeout_ms) const Fetch the latest nonce from the network without relying on cached values. |
| uint64_t | GetProposedNonce() const Get the next available nonce without reserving it. |
| uint64_t | ReserveNextNonce() Reserve the next available nonce. |
| void | ReleaseNonce(uint64_t nonce) Release a previously reserved nonce. |
| outcome::result< void > | RequestGenesis(uint64_t timeout_ms =8000, std::function< void(outcome::result< std::string >)> callback =nullptr) const |
| outcome::result< void > | RequestAccountCreation(uint64_t timeout_ms, std::function< void(outcome::result< std::string >)> callback) const |
| outcome::result< void > | RequestValidatorRegistry(uint64_t timeout_ms, std::function< void(outcome::result< std::string >)> callback) const |
| outcome::result< void > | RequestRegularBlock(uint64_t timeout_ms, const std::string & cid, std::function< void(outcome::result< std::string >)> callback =nullptr) const |
| outcome::result< void > | RequestTransaction(uint64_t timeout_ms, const std::string & tx_hash, std::function< void(outcome::result< std::string >)> callback =nullptr) const |
| outcome::result< std::unordered_set< std::string > > | RequestUTXOs(uint64_t timeout_ms, const std::string & address, uint64_t silent_time_ms =150) const Request UTXOs for a specific address and return the selected response. |
| outcome::result< void > | RequestHeads(const std::unordered_set< std::string > & topics) const Request heads broadcast for specific topics. |
| outcome::result< void > | SaveInSecureStorage(const std::string & key, const ISecureStorage::SecureBufferType & buffer) |
| outcome::result< ISecureStorage::SecureBufferType > | LoadFromSecureStorage(const std::string & key) |
| const UTXOManager & | GetUTXOManager() const |
| UTXOManager & | GetUTXOManager() |
Protected Functions¶
| Name | |
|---|---|
| void | SetGetBlockChainCIDMethod(std::function< outcome::result< std::string >(uint8_t, const std::string &)> method) |
| void | ClearGetBlockChainCIDMethod() |
| void | SetHasBlockCidMethod(std::function< outcome::result< bool >(const std::string &)> method) |
| void | ClearHasBlockCidMethod() |
| void | SetGetValidatorWeightMethod(std::function< outcome::result< std::optional< uint64_t > >(const std::string &)> method) |
| void | ClearGetValidatorWeightMethod() |
| void | SetGetTransactionCIDMethod(std::function< outcome::result< std::string >(const std::string &)> method) |
| void | ClearGetTransactionCIDMethod() |
| void | SetNonceStore(std::shared_ptr< storage::rocksdb > db) |
Public Attributes¶
| Name | |
|---|---|
| const std::array< uint8_t, 32 > | ELGAMAL_PUBKEY_PREDEFINED Predefined ElGamal public key. |
| int64_t | NONCE_CACHE_DURATION_MS Cache nonce results for 5 seconds. |
Friends¶
| Name | |
|---|---|
| class | Blockchain |
| class | TransactionManager |
Public Types Documentation¶
using StorageWithAddress¶
using sgns::GeniusAccount::StorageWithAddress = std::pair<std::shared_ptr<ISecureStorage>,
std::pair<KeyGenerator::ElGamal, ethereum::EthereumKeyGenerator>>;
using SecureStorageFactory¶
using sgns::GeniusAccount::SecureStorageFactory = std::function<std::shared_ptr<ISecureStorage>( const std::string &identifier )>;
Factory function type for creating secure storage instances.
Parameters:
- identifier Storage identifier (typically base58-encoded public key).
Return: Shared pointer to the created secure storage backend.
Public Functions Documentation¶
function SetSecureStorageFactory¶
Sets the secure storage factory used by all GeniusAccount factory methods.
Parameters:
- factory Factory function; pass nullptr to restore the default.
By default, the factory creates OS-specific secure storage (Apple Keychain, Linux secret service, etc.). Tests can override this to inject MemorySecureStorage, eliminating keychain prompts entirely.
function GetSecureStorageFactory¶
Returns the current secure storage factory (default if none set).
function New¶
static std::shared_ptr< GeniusAccount > New(
TokenID token_id,
const char * eth_private_key,
const boost::filesystem::path & base_path,
bool full_node =false
)
Factory constructor of new GeniusAccount.
Parameters:
- token_id Token ID of the account.
- eth_private_key Ethereum private key in hex format (0x...).
- base_path Base path to store/retrieve keys.
- full_node Whether to initialize as a full node.
Return: Valid pointer if succeeds, nullptr otherwise.
function NewFromMnemonic¶
static std::shared_ptr< GeniusAccount > NewFromMnemonic(
TokenID token_id,
const std::string & mnemonic,
const boost::filesystem::path & base_path,
bool full_node =false
)
function NewFromPublicKey¶
static std::shared_ptr< GeniusAccount > NewFromPublicKey(
TokenID token_id,
std::string_view public_key,
bool full_node =false
)
function New¶
static std::shared_ptr< GeniusAccount > New(
TokenID token_id,
const boost::filesystem::path & base_path,
bool full_node =false
)
Factory constructor of new GeniusAccount.
Parameters:
- token_id Token ID of the account
function GetAvailableAccounts¶
function DeleteAccount¶
static outcome::result< void > DeleteAccount(
std::string_view public_address,
const boost::filesystem::path & base_path
)
function VerifySignature¶
static bool VerifySignature(
const std::string & address,
std::string_view sig,
const std::vector< uint8_t > & data
)
Verify a signature using the Genius account's public key.
Parameters:
- address public address to verify the signature
- sig signature to be verified
- data data to be verified
Return: true if the signature is valid, false otherwise
function GenerateGeniusAddress¶
static outcome::result< StorageWithAddress > GenerateGeniusAddress(
const char * eth_private_key,
const boost::filesystem::path & base_path
)
function GenerateGeniusAddress¶
static outcome::result< StorageWithAddress > GenerateGeniusAddress(
const TW::PrivateKey & private_key,
const boost::filesystem::path & base_path
)
function InitMessenger¶
Initialize the messenger for the account.
Parameters:
- pubsub pubsub instance
Return: true if succeeds, false otherwise
function ConfigureDatabaseDependencies¶
Configures the block response handler.
Parameters:
- global_db GlobalDB instance used to store fetched block CIDs.
Return: true if successfully configured, false otherwise.
function DeconfigureDatabaseDependencies¶
Clears handlers and methods set by ConfigureDatabaseDependencies.
function ~GeniusAccount¶
Destroy the Genius Account object.
function GetAddress¶
Get the Address object.
Return: String representation of the address
function GetToken¶
Get the account's token.
Return: The token of the account
function GetNonce¶
Get the confirmed nonce as a string.
Return: The confirmed nonce in string format
function Sign¶
Sign data using the Genius account's private key.
Parameters:
- data data to be signed
Return: the signature as a vector of bytes
function CreateInputsFromUTXOs¶
Build signed transaction inputs from UTXOs.
Parameters:
- utxos UTXOs to turn into transaction inputs
Return: Signed input descriptors
function SetPeerConfirmedNonce¶
void SetPeerConfirmedNonce(
uint64_t nonce,
const std::string & address,
const std::string & tx_hash =""
)
Set the confirmed nonce for an address.
Parameters:
- nonce The nonce value to be set
- address The address whose nonce is being updated
- tx_hash The confirmed transaction hash. Persisted only for the local address
function RollBackPeerConfirmedNonce¶
Rollback the local confirmed nonce for a peer.
Parameters:
- nonce The nonce value to be rolled back to
- address The address of the peer
function GetPeerNonce¶
Get the confirmed nonce for a peer.
Parameters:
- address The address of the peer
Return: The confirmed nonce of the peer if exists, error otherwise
function GetLocalConfirmedNonce¶
Get the local confirmed nonce.
Return: The local confirmed nonce if exists, error otherwise
function GetLocalConfirmedTxHash¶
Get a locally persisted confirmed transaction hash by nonce.
Parameters:
- nonce The confirmed nonce to search for
Return: The confirmed transaction hash if it exists, error otherwise
function GetConfirmedNonce¶
Get confirmed nonce from the network.
Parameters:
- timeout_ms Timeout in miliseconds to get the confirmed nonce
Return: The confirmed nonce if success, error otherwise
function FetchNetworkNonce¶
Fetch the latest nonce from the network without relying on cached values.
Parameters:
- timeout_ms Timeout in miliseconds to get the confirmed nonce
Return: Error if no response received, optional nonce if success
function GetProposedNonce¶
Get the next available nonce without reserving it.
Return: The nonce that would be assigned to the next transaction
function ReserveNextNonce¶
Reserve the next available nonce.
Return: The reserved nonce value
function ReleaseNonce¶
Release a previously reserved nonce.
Parameters:
- nonce The nonce to release
function RequestGenesis¶
outcome::result< void > RequestGenesis(
uint64_t timeout_ms =8000,
std::function< void(outcome::result< std::string >)> callback =nullptr
) const
function RequestAccountCreation¶
outcome::result< void > RequestAccountCreation(
uint64_t timeout_ms,
std::function< void(outcome::result< std::string >)> callback
) const
function RequestValidatorRegistry¶
outcome::result< void > RequestValidatorRegistry(
uint64_t timeout_ms,
std::function< void(outcome::result< std::string >)> callback
) const
function RequestRegularBlock¶
outcome::result< void > RequestRegularBlock(
uint64_t timeout_ms,
const std::string & cid,
std::function< void(outcome::result< std::string >)> callback =nullptr
) const
function RequestTransaction¶
outcome::result< void > RequestTransaction(
uint64_t timeout_ms,
const std::string & tx_hash,
std::function< void(outcome::result< std::string >)> callback =nullptr
) const
function RequestUTXOs¶
outcome::result< std::unordered_set< std::string > > RequestUTXOs(
uint64_t timeout_ms,
const std::string & address,
uint64_t silent_time_ms =150
) const
Request UTXOs for a specific address and return the selected response.
Parameters:
- timeout_ms Total timeout in milliseconds to wait for responses
- address Address to request UTXOs for
- silent_time_ms Time to wait for subsequent responses after first one
Return: Set of UTXO strings based on selection criteria, or error otherwise
function RequestHeads¶
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
function SaveInSecureStorage¶
inline outcome::result< void > SaveInSecureStorage(
const std::string & key,
const ISecureStorage::SecureBufferType & buffer
)
function LoadFromSecureStorage¶
inline outcome::result< ISecureStorage::SecureBufferType > LoadFromSecureStorage(
const std::string & key
)
function GetUTXOManager¶
function GetUTXOManager¶
Protected Functions Documentation¶
function SetGetBlockChainCIDMethod¶
void SetGetBlockChainCIDMethod(
std::function< outcome::result< std::string >(uint8_t, const std::string &)> method
)
function ClearGetBlockChainCIDMethod¶
function SetHasBlockCidMethod¶
function ClearHasBlockCidMethod¶
function SetGetValidatorWeightMethod¶
void SetGetValidatorWeightMethod(
std::function< outcome::result< std::optional< uint64_t > >(const std::string &)> method
)
function ClearGetValidatorWeightMethod¶
function SetGetTransactionCIDMethod¶
void SetGetTransactionCIDMethod(
std::function< outcome::result< std::string >(const std::string &)> method
)
function ClearGetTransactionCIDMethod¶
function SetNonceStore¶
Public Attributes Documentation¶
variable ELGAMAL_PUBKEY_PREDEFINED¶
Predefined ElGamal public key.
variable NONCE_CACHE_DURATION_MS¶
Cache nonce results for 5 seconds.
Friends¶
friend Blockchain¶
friend TransactionManager¶
Updated on 2026-06-05 at 17:22:18 -0700