External client for sending new transactions to the system. More...
#include <client.hpp>
Public Types | |
enum class | address_type : uint8_t { public_key = 0 } |
Client address type signifier. More... | |
Public Member Functions | |
client (cbdc::config::options opts, std::shared_ptr< logging::log > logger, std::string wallet_file, std::string client_file) | |
Constructor. | |
virtual | ~client ()=default |
client (const client &)=delete | |
auto | operator= (const client &) -> client &=delete |
client (client &&)=delete | |
auto | operator= (client &&) -> client &=delete |
auto | init () -> bool |
Initializes the client. | |
auto | mint (size_t n_outputs, uint32_t output_val) -> transaction::full_tx |
Creates the specified number spendable outputs each with the specified value. | |
auto | send (uint32_t value, const pubkey_t &payee) -> std::pair< std::optional< transaction::full_tx >, std::optional< cbdc::sentinel::execute_response > > |
Send a specified amount from this client's wallet to a target address. | |
auto | fan (uint32_t count, uint32_t value, const pubkey_t &payee) -> std::pair< std::optional< transaction::full_tx >, std::optional< cbdc::sentinel::execute_response > > |
Send a specified number of fixed-value outputs from this client's wallet to a target address. | |
void | import_send_input (const transaction::input &in) |
Imports transaction data from a sender. | |
virtual auto | sync () -> bool=0 |
Checks the status of pending transactions and updates the wallet's balance with the result. | |
auto | new_address () -> pubkey_t |
Generates a new wallet address that other clients can use to send money to this client using send. | |
auto | balance () -> uint64_t |
Returns the balance in this client's wallet. | |
auto | utxo_count () -> size_t |
Returns the number of UTXOs in this client's wallet. | |
auto | pending_tx_count () -> size_t |
Returns the number of unconfirmed transactions. | |
auto | pending_input_count () -> size_t |
Returns the number of pending received inputs. | |
auto | confirm_transaction (const hash_t &tx_id) -> bool |
Confirms the transaction with the given ID. | |
auto | create_transaction (uint32_t value, const pubkey_t &payee) -> std::optional< transaction::full_tx > |
Create a new transaction. | |
auto | send_transaction (const transaction::full_tx &tx) -> std::optional< cbdc::sentinel::execute_response > |
Send the given transaction to the sentinel. | |
auto | abandon_transaction (const hash_t &tx_id) -> bool |
Abandons a transaction currently awaiting confirmation. | |
auto | check_pending (const transaction::input &inp) -> bool |
Checks the client's pending transaction set for the specified transaction. | |
void | sign_transaction (transaction::full_tx &tx) |
Signs the given transaction for as far as client's wallet contains the transaction's keys. | |
Static Public Member Functions | |
static auto | print_amount (uint64_t val) -> std::string |
Format a value given in currency base units as USD. | |
static auto | export_send_inputs (const transaction::full_tx &send_tx, const pubkey_t &payee) -> std::vector< transaction::input > |
Extracts the transaction data that recipients need from senders to confirm pending transfers. | |
Protected Member Functions | |
virtual auto | init_derived () -> bool=0 |
Initializes the derived class. | |
virtual auto | send_mint_tx (const transaction::full_tx &mint_tx) -> bool=0 |
Sends the given minting transaction to a service that will accept and process it. | |
auto | pending_txs () const -> std::unordered_map< hash_t, transaction::full_tx, hashing::null > |
Returns the set of transactions pending confirmation. | |
auto | pending_inputs () const -> std::unordered_map< hash_t, transaction::input, hashing::null > |
Returns the set of imported inputs from senders. | |
External client for sending new transactions to the system.
Definition at line 23 of file uhs/client/client.hpp.
|
strong |
Client address type signifier.
Prefixes client address data, indicating which addressing regime clients should use to transact with the address.
Enumerator | |
---|---|
public_key | Pay-to-Public-Key (P2PK) address data. |
Definition at line 232 of file uhs/client/client.hpp.
cbdc::client::client | ( | cbdc::config::options | opts, |
std::shared_ptr< logging::log > | logger, | ||
std::string | wallet_file, | ||
std::string | client_file ) |
Constructor.
opts | configuration options. |
logger | pointer shared logger. |
wallet_file | name of .dat file in which to store the wallet data. |
client_file | name of .dat file in which to store the internal state data. |
Definition at line 61 of file uhs/client/client.cpp.
|
virtualdefault |
|
delete |
|
delete |
auto cbdc::client::abandon_transaction | ( | const hash_t & | tx_id | ) | -> bool |
Abandons a transaction currently awaiting confirmation.
Releases the lock on the transactions input UTXOs so the client can attempt to use them again in a subsequent transaction.
tx_id | ID of the transaction to abandon. |
Definition at line 253 of file uhs/client/client.cpp.
References cbdc::transaction::full_tx::m_inputs.
auto cbdc::client::balance | ( | ) | -> uint64_t |
Returns the balance in this client's wallet.
Definition at line 218 of file uhs/client/client.cpp.
auto cbdc::client::check_pending | ( | const transaction::input & | inp | ) | -> bool |
Checks the client's pending transaction set for the specified transaction.
Searches the client's pending transaction set and returns true if there is a transaction that contains the passed input as one of its inputs
inp | the input to look for. |
Definition at line 239 of file uhs/client/client.cpp.
auto cbdc::client::confirm_transaction | ( | const hash_t & | tx_id | ) | -> bool |
Confirms the transaction with the given ID.
Searches the client's pending transactions and pending input sets for the specified transaction ID and confirms it. Erases spent outputs and adds confirmed inputs to the wallet and makes them available to spend.
tx_id | the ID of the transaction to confirm. |
Definition at line 280 of file uhs/client/client.cpp.
auto cbdc::client::create_transaction | ( | uint32_t | value, |
const pubkey_t & | payee ) -> std::optional<transaction::full_tx> |
Create a new transaction.
Creates a signed transaction that constitutes sending a specified amount from this client's wallet to a target address. Selects a set of UTXOs to spend as transaction inputs, and locks them so they will not be used in further calls to this function.
value | the amount to send in the base unit of the currency. |
payee | the destination address of the transfer. |
Definition at line 121 of file uhs/client/client.cpp.
|
static |
Extracts the transaction data that recipients need from senders to confirm pending transfers.
Returns the outputs of the send transaction intended for the target recipient, converted to inputs. Senders transmit this data to recipients, who then call import_send_input to receive the transfer.
send_tx | the send transaction generated by send. |
payee | the destination address of the transfer. |
Definition at line 197 of file uhs/client/client.cpp.
References cbdc::transaction::wallet::export_send_inputs().
Referenced by print_tx_result().
auto cbdc::client::fan | ( | uint32_t | count, |
uint32_t | value, | ||
const pubkey_t & | payee ) -> std::pair<std::optional<transaction::full_tx>, std::optional<cbdc::sentinel::execute_response>> |
Send a specified number of fixed-value outputs from this client's wallet to a target address.
Generates, transmits, and, if possible, confirms a full transaction. Returns the transaction and system response data.
count | number of outputs to generate. |
value | the amount to send per output, in the base unit of the currency. |
payee | the destination address of the transfer. |
Definition at line 153 of file uhs/client/client.cpp.
void cbdc::client::import_send_input | ( | const transaction::input & | in | ) |
Imports transaction data from a sender.
Expects data generated by a sender's export_send_inputs. Stores the provided input as a credit awaiting confirmation from the transaction processing system using sync or a call to confirm_transaction.
in | a spendable input generated by a sender. |
Definition at line 203 of file uhs/client/client.cpp.
References cbdc::transaction::wallet::is_spendable(), cbdc::transaction::input::m_prevout, and cbdc::transaction::out_point::m_tx_id.
auto cbdc::client::init | ( | ) | -> bool |
Initializes the client.
Attempts to load the data files and establish connections to the system components.
Definition at line 71 of file uhs/client/client.cpp.
Referenced by cbdc::sentinel::controller::init(), and cbdc::sentinel_2pc::controller::init().
|
protectedpure virtual |
Initializes the derived class.
Called at the end of init. Subclasses should define custom initialization logic here.
Implemented in cbdc::atomizer_client, and cbdc::twophase_client.
auto cbdc::client::mint | ( | size_t | n_outputs, |
uint32_t | output_val ) -> transaction::full_tx |
Creates the specified number spendable outputs each with the specified value.
Generates a transaction with the specified outputs and no inputs. Saves the transaction in the client's internal state. Submits the transaction to the system via send_mint_tx.
n_outputs | number of new spendable outputs to create. |
output_val | value of the amount to associate with each output in the base unit of the currency. |
Definition at line 95 of file uhs/client/client.cpp.
auto cbdc::client::new_address | ( | ) | -> pubkey_t |
Generates a new wallet address that other clients can use to send money to this client using send.
Definition at line 212 of file uhs/client/client.cpp.
Referenced by newaddress_command().
auto cbdc::client::pending_input_count | ( | ) | -> size_t |
Returns the number of pending received inputs.
Returns the number of inputs received from senders for which this client is awaiting confirmation from the transaction processing system.
Definition at line 230 of file uhs/client/client.cpp.
|
nodiscardprotected |
Returns the set of imported inputs from senders.
Returns the current set of pending inputs imported into this client via the import_send_input method which the system has yet to confirm.
Definition at line 346 of file uhs/client/client.cpp.
auto cbdc::client::pending_tx_count | ( | ) | -> size_t |
Returns the number of unconfirmed transactions.
Definition at line 226 of file uhs/client/client.cpp.
|
nodiscardprotected |
Returns the set of transactions pending confirmation.
Returns the set of pending transactions sent to the transaction processing system via the send or mint methods which the system has yet to confirm.
Definition at line 341 of file uhs/client/client.cpp.
|
static |
Format a value given in currency base units as USD.
Assumes the atomic (base) unit of the currency is equivalent to $0.01 (one USD cent). Ex. 10000 <=> $100.00.
val | value in currency base units. |
Definition at line 88 of file uhs/client/client.cpp.
Referenced by confirmtx_command(), and main().
auto cbdc::client::send | ( | uint32_t | value, |
const pubkey_t & | payee ) -> std::pair<std::optional<transaction::full_tx>, std::optional<cbdc::sentinel::execute_response>> |
Send a specified amount from this client's wallet to a target address.
Generates, transmits, and, if possible, confirms a full transaction. Returns the transaction and system response data.
value | the amount to send, in the base unit of the currency. |
payee | the destination address of the transfer. |
Definition at line 133 of file uhs/client/client.cpp.
|
protectedpure virtual |
Sends the given minting transaction to a service that will accept and process it.
Called by mint to send the resulting transaction. Subclasses should define custom transmission logic here.
mint_tx | invalid transaction that mints new coins. |
Implemented in cbdc::atomizer_client, and cbdc::twophase_client.
auto cbdc::client::send_transaction | ( | const transaction::full_tx & | tx | ) | -> std::optional<cbdc::sentinel::execute_response> |
Send the given transaction to the sentinel.
tx | the transaction to send. |
Definition at line 175 of file uhs/client/client.cpp.
References cbdc::sentinel::confirmed, cbdc::sentinel::to_string(), cbdc::to_string(), and cbdc::transaction::tx_id().
void cbdc::client::sign_transaction | ( | transaction::full_tx & | tx | ) |
Signs the given transaction for as far as client's wallet contains the transaction's keys.
tx | the transaction to sign. |
Definition at line 108 of file uhs/client/client.cpp.
References cbdc::transaction::wallet::sign().
|
pure virtual |
Checks the status of pending transactions and updates the wallet's balance with the result.
Implementations should combine their own system querying logic with the confirm_transaction abandon_transaction functions to update the client and wallet state.
Implemented in cbdc::atomizer_client, and cbdc::twophase_client.
auto cbdc::client::utxo_count | ( | ) | -> size_t |
Returns the number of UTXOs in this client's wallet.
Does not include those locked in pending transactions.
Definition at line 222 of file uhs/client/client.cpp.