6#ifndef OPENCBDC_TX_SRC_CLIENT_CLIENT_H_
7#define OPENCBDC_TX_SRC_CLIENT_CLIENT_H_
15 static constexpr auto bits_per_byte = 8;
16 static constexpr auto bech32_bits_per_symbol = 5;
18 auto decode(
const std::string& addr_str)
19 -> std::optional<cbdc::hash_t>;
33 std::shared_ptr<logging::log> logger,
34 std::string wallet_file,
35 std::string client_file);
69 auto mint(
size_t n_outputs, uint32_t output_val)
83 -> std::pair<std::optional<transaction::full_tx>,
84 std::optional<cbdc::sentinel::execute_response>>;
98 auto fan(uint32_t count, uint32_t value,
const pubkey_t& payee)
99 -> std::pair<std::optional<transaction::full_tx>,
100 std::optional<cbdc::sentinel::execute_response>>;
116 -> std::vector<transaction::input>;
134 virtual auto sync() ->
bool = 0;
189 -> std::optional<transaction::full_tx>;
199 -> std::optional<cbdc::sentinel::execute_response>;
262 -> std::unordered_map<
hash_t, transaction::full_tx, hashing::null>;
271 -> std::unordered_map<
hash_t, transaction::input, hashing::null>;
274 cbdc::config::options m_opts;
275 std::shared_ptr<logging::log> m_logger;
277 cbdc::sentinel::rpc::
client m_sentinel_client;
281 std::unordered_map<
hash_t, transaction::full_tx, hashing::null>
287 std::unordered_map<
hash_t, transaction::input, hashing::null>
292 std::unordered_map<
hash_t, transaction::input, hashing::null>
295 transaction::wallet m_wallet{};
297 std::string m_client_file;
298 std::string m_wallet_file;
305 void load_client_state();
306 void save_client_state();
External client for sending new transactions to the system.
auto pending_inputs() const -> std::unordered_map< hash_t, transaction::input, hashing::null >
Returns the set of imported inputs from senders.
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.
auto init() -> bool
Initializes the client.
virtual auto sync() -> bool=0
Checks the status of pending transactions and updates the wallet's balance with the result.
auto pending_tx_count() -> size_t
Returns the number of unconfirmed transactions.
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 confirm_transaction(const hash_t &tx_id) -> bool
Confirms the transaction with the given ID.
client(cbdc::config::options opts, std::shared_ptr< logging::log > logger, std::string wallet_file, std::string client_file)
Constructor.
auto balance() -> uint64_t
Returns the balance in this client's wallet.
auto new_address() -> pubkey_t
Generates a new wallet address that other clients can use to send money to this client using send.
auto abandon_transaction(const hash_t &tx_id) -> bool
Abandons a transaction currently awaiting confirmation.
void sign_transaction(transaction::full_tx &tx)
Signs the given transaction for as far as client's wallet contains the transaction's keys.
auto pending_txs() const -> std::unordered_map< hash_t, transaction::full_tx, hashing::null >
Returns the set of transactions pending confirmation.
virtual auto init_derived() -> bool=0
Initializes the derived class.
virtual ~client()=default
void import_send_input(const transaction::input &in)
Imports transaction data from a sender.
auto send_transaction(const transaction::full_tx &tx) -> std::optional< cbdc::sentinel::execute_response >
Send the given transaction to the sentinel.
auto operator=(const client &) -> client &=delete
auto operator=(client &&) -> client &=delete
auto create_transaction(uint32_t value, const pubkey_t &payee) -> std::optional< transaction::full_tx >
Create a new transaction.
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.
auto utxo_count() -> size_t
Returns the number of UTXOs in this client's wallet.
address_type
Client address type signifier.
@ public_key
Pay-to-Public-Key (P2PK) address data.
auto check_pending(const transaction::input &inp) -> bool
Checks the client's pending transaction set for the specified transaction.
client(const client &)=delete
auto pending_input_count() -> size_t
Returns the number of pending received inputs.
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 mint(size_t n_outputs, uint32_t output_val) -> transaction::full_tx
Creates the specified number spendable outputs each with the specified value.
static auto print_amount(uint64_t val) -> std::string
Format a value given in currency base units as USD.
auto decode(const std::string &addr_str) -> std::optional< cbdc::hash_t >
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
std::array< unsigned char, pubkey_len > pubkey_t
A public key of a public/private keypair.
Project-wide configuration options.