OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::twophase_client Class Reference

Client for interacting with the 2PC architecture. More...

#include <twophase_client.hpp>

Inheritance diagram for cbdc::twophase_client:
Collaboration diagram for cbdc::twophase_client:

Public Member Functions

 twophase_client (const cbdc::config::options &opts, const std::shared_ptr< logging::log > &logger, const std::string &wallet_file, const std::string &client_file)
 Constructor.
 
 ~twophase_client () override=default
 
 twophase_client ()=delete
 
 twophase_client (const twophase_client &)=delete
 
auto operator= (const twophase_client &) -> twophase_client &=delete
 
 twophase_client (twophase_client &&)=delete
 
auto operator= (twophase_client &&) -> twophase_client &=delete
 
auto sync () -> bool override
 Update the client with the latest state from the shard network.
 
auto check_tx_id (const hash_t &tx_id) -> std::optional< bool >
 Checks the shard network for the status of a specific transaction.
 
auto check_unspent (const hash_t &uhs_id) -> std::optional< bool >
 Checks the shard network for the status of a specific UHS ID.
 
- Public Member Functions inherited from cbdc::client
 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.
 
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.
 

Protected Member Functions

auto init_derived () -> bool override
 Initializes the 2PC architecture client.
 
auto send_mint_tx (const transaction::full_tx &mint_tx) -> bool override
 Sends the given mint transaction directly to a coordinator cluster.
 
- Protected Member Functions inherited from cbdc::client
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.
 

Additional Inherited Members

- Public Types inherited from cbdc::client
enum class  address_type : uint8_t { public_key = 0 }
 Client address type signifier. More...
 
- Static Public Member Functions inherited from cbdc::client
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.
 

Detailed Description

Client for interacting with the 2PC architecture.

Definition at line 15 of file twophase_client.hpp.

Constructor & Destructor Documentation

◆ twophase_client() [1/4]

cbdc::twophase_client::twophase_client ( const cbdc::config::options & opts,
const std::shared_ptr< logging::log > & logger,
const std::string & wallet_file,
const std::string & client_file )

Constructor.

Parameters
optsconfiguration options.
loggerpointer to shared logger.
wallet_filename of .dat file in which to store the wallet data.
client_filename of .dat file in which to store the internal state data.

Definition at line 11 of file twophase_client.cpp.

◆ ~twophase_client()

cbdc::twophase_client::~twophase_client ( )
overridedefault

◆ twophase_client() [2/4]

cbdc::twophase_client::twophase_client ( )
delete

◆ twophase_client() [3/4]

cbdc::twophase_client::twophase_client ( const twophase_client & )
delete

◆ twophase_client() [4/4]

cbdc::twophase_client::twophase_client ( twophase_client && )
delete

Member Function Documentation

◆ check_tx_id()

auto cbdc::twophase_client::check_tx_id ( const hash_t & tx_id) -> std::optional<bool>

Checks the shard network for the status of a specific transaction.

Queries the shards' read-only endpoints to determine whether the transaction processing system has confirmed a specific transaction.

Returns
true if the shards have confirmed the given transaction, false if the transaction is unknown to the shards.

Definition at line 66 of file twophase_client.cpp.

◆ check_unspent()

auto cbdc::twophase_client::check_unspent ( const hash_t & uhs_id) -> std::optional<bool>

Checks the shard network for the status of a specific UHS ID.

Queries the shards' read-only endpoints to determine whether a specific UHS ID is unspent.

Returns
true if the shards confirm the given UHS ID is unspent.

Definition at line 71 of file twophase_client.cpp.

◆ init_derived()

auto cbdc::twophase_client::init_derived ( ) -> bool
overrideprotectedvirtual

Initializes the 2PC architecture client.

Connects to the coordinator network to allow this client to directly submit minting transactions. Initializes the locking shard read-only client to allow this client to confirm transactions and imported inputs.

Returns
true if the initialization succeeded.

Implements cbdc::client.

Definition at line 24 of file twophase_client.cpp.

◆ operator=() [1/2]

auto cbdc::twophase_client::operator= ( const twophase_client & ) -> twophase_client &=delete
delete

◆ operator=() [2/2]

auto cbdc::twophase_client::operator= ( twophase_client && ) -> twophase_client &=delete
delete

◆ send_mint_tx()

auto cbdc::twophase_client::send_mint_tx ( const transaction::full_tx & mint_tx) -> bool
overrideprotectedvirtual

Sends the given mint transaction directly to a coordinator cluster.

Parameters
mint_txtransaction to send.
Returns
true if the transaction was sent successfully.

Implements cbdc::client.

Definition at line 76 of file twophase_client.cpp.

◆ sync()

auto cbdc::twophase_client::sync ( ) -> bool
overridevirtual

Update the client with the latest state from the shard network.

Queries the shards' read-only endpoints to determine whether the transaction processing system has confirmed any of this client's pending transactions or inputs.

Returns
true if querying the shards was successful.

Implements cbdc::client.

Definition at line 36 of file twophase_client.cpp.

References cbdc::to_string().

Here is the call graph for this function:

The documentation for this class was generated from the following files: