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

Cryptographic wallet for digital currency assets and secrets. More...

#include <wallet.hpp>

Public Member Functions

 wallet ()
 Constructor.
 
auto mint_new_coins (size_t n_outputs, uint32_t output_val) -> full_tx
 Mints new spendable outputs.
 
auto send_to (uint32_t amount, const pubkey_t &payee, bool sign_tx) -> std::optional< full_tx >
 Generates a new send transaction with a set value.
 
auto send_to (size_t input_count, size_t output_count, const pubkey_t &payee, bool sign_tx) -> std::optional< full_tx >
 Generates a new send transaction with the specified number of inputs and outputs.
 
auto fan (size_t output_count, uint32_t value, const pubkey_t &payee, bool sign_tx) -> std::optional< transaction::full_tx >
 Generates a transaction sending multiple outputs of a set value.
 
auto generate_key () -> pubkey_t
 Generates a new public key at which this wallet can receive payments via send_to.
 
auto seed (const privkey_t &privkey, uint32_t value, size_t begin_seed, size_t end_seed) -> bool
 Marks the wallet as having pre-seeded outputs to spend.
 
void seed_readonly (const hash_t &witness_commitment, uint32_t value, size_t begin_seed, size_t end_seed)
 Marks the wallet as having read-only pre-seeded outputs to spend.
 
void confirm_transaction (const full_tx &tx)
 Confirms a transaction.
 
void sign (full_tx &tx) const
 Signs each of the transaction's inputs using Schnorr signatures.
 
auto is_spendable (const input &in) const -> bool
 Checks if the input is spendable by the current wallet.
 
auto balance () const -> uint64_t
 Returns the total balance of the wallet, e.g.
 
auto count () const -> size_t
 Returns the number of UTXOs stored in this wallet.
 
void save (const std::string &wallet_file) const
 Save the state of the wallet to a binary data file.
 
void load (const std::string &wallet_file)
 Overwrites the current state of the wallet with data loaded from a file saved via the Wallet::save function.
 
auto create_seeded_transaction (size_t seed_idx) -> std::optional< full_tx >
 Creates a new transaction from seeded outputs.
 
void confirm_inputs (const std::vector< input > &credits)
 Given a set of credit inputs, add the UTXOs and update the wallet's balance.
 

Static Public Member Functions

static auto export_send_inputs (const full_tx &send_tx, const pubkey_t &payee) -> std::vector< input >
 Extracts the transaction data that recipients need from senders to confirm pending transfers.
 

Detailed Description

Cryptographic wallet for digital currency assets and secrets.

Stores unspent transaction outputs (UTXOs), and public/private key pairs for Pay-to-Public-Key transaction attestations.

Definition at line 32 of file wallet.hpp.

Constructor & Destructor Documentation

◆ wallet()

cbdc::transaction::wallet::wallet ( )

Constructor.

Initializes the randomization engine for key shuffling.

Definition at line 17 of file wallet.cpp.

References seed().

Here is the call graph for this function:

Member Function Documentation

◆ balance()

auto cbdc::transaction::wallet::balance ( ) const -> uint64_t

Returns the total balance of the wallet, e.g.

the sum total value of all the UTXOs this wallet contains.

Returns
the wallet balance in the base unit of the currency.

Definition at line 288 of file wallet.cpp.

◆ confirm_inputs()

void cbdc::transaction::wallet::confirm_inputs ( const std::vector< input > & credits)

Given a set of credit inputs, add the UTXOs and update the wallet's balance.

Parameters
creditsthe inputs to add to the wallet's set of UTXOs.

Definition at line 449 of file wallet.cpp.

◆ confirm_transaction()

void cbdc::transaction::wallet::confirm_transaction ( const full_tx & tx)

Confirms a transaction.

  1. Adds new outputs. Adds to the total balance of this wallet the balance of each of the transaction's outputs with a witness program commitment matching one of this wallet's witness programs. Converts those outputs to inputs, and stores them in the wallet as spendable UTXOs.
  2. Subtracts the spent outputs. Subtracts the balance for each of the transaction's inputs that are UTXOs stored in this wallet, and drops those UTXOs from the wallet.
    Parameters
    txthe transaction to confirm.

Definition at line 271 of file wallet.cpp.

References cbdc::transaction::input_from_output(), cbdc::transaction::full_tx::m_inputs, cbdc::transaction::full_tx::m_outputs, and cbdc::transaction::tx_id().

Here is the call graph for this function:

◆ count()

auto cbdc::transaction::wallet::count ( ) const -> size_t

Returns the number of UTXOs stored in this wallet.

Returns
number of UTXOs.

Definition at line 298 of file wallet.cpp.

◆ create_seeded_transaction()

auto cbdc::transaction::wallet::create_seeded_transaction ( size_t seed_idx) -> std::optional<full_tx>

Creates a new transaction from seeded outputs.

Creates a new transaction that receives a spendable input from the seed set based on the parameters passed in a preceding call to the seed function. Used from the shard-seeder tool to consolidate this logic in one place.

Parameters
seed_idxthe index in the seed set for which to generate the transaction.
Returns
the generated transaction.

Definition at line 82 of file wallet.cpp.

References cbdc::transaction::full_tx::m_inputs, and cbdc::transaction::full_tx::m_outputs.

◆ export_send_inputs()

auto cbdc::transaction::wallet::export_send_inputs ( const full_tx & send_tx,
const pubkey_t & payee ) -> std::vector<input>
static

Extracts the transaction data that recipients need from senders to confirm pending transfers.

Returns the output of the send transaction intended for the target recipient, converted to an input. Senders transmit this data to recipients so that they can confirm the transaction on their end and spend the outputs.

Parameters
send_txthe send transaction generated by this wallet's send_to function.
payeethe destination address of the transfer.
Returns
inputs to transmit to the send transaction recipient, or empty vector if there is no transaction output with the corresponding payee information.

Definition at line 109 of file wallet.cpp.

References cbdc::transaction::validation::get_p2pk_witness_commitment(), and cbdc::transaction::input_from_output().

Referenced by cbdc::client::export_send_inputs().

Here is the call graph for this function:

◆ fan()

auto cbdc::transaction::wallet::fan ( size_t output_count,
uint32_t value,
const pubkey_t & payee,
bool sign_tx ) -> std::optional<transaction::full_tx>

Generates a transaction sending multiple outputs of a set value.

Generates a transaction to transfer a specified number of outputs with a fixed amount from this wallet to a recipient's target address. Returns the transaction for wallet clients to submit to the processing system and syndicate to recipients.

Parameters
output_countnumber of outputs to send to the recipient.
valuethe amount to send per outputs in the base unit of the currency.
payeethe destination address of the transfer.
sign_txtrue if the wallet should sign this transaction.
Returns
the completed transaction.
See also
export_send_inputs

Definition at line 454 of file wallet.cpp.

References cbdc::transaction::validation::get_p2pk_witness_commitment(), cbdc::transaction::output::m_value, and cbdc::transaction::output::m_witness_program_commitment.

Here is the call graph for this function:

◆ generate_key()

auto cbdc::transaction::wallet::generate_key ( ) -> pubkey_t

Generates a new public key at which this wallet can receive payments via send_to.

Returns
a new public key.

Definition at line 124 of file wallet.cpp.

References cbdc::transaction::validation::get_p2pk_witness_commitment(), and cbdc::pubkey_from_privkey().

Here is the call graph for this function:

◆ is_spendable()

auto cbdc::transaction::wallet::is_spendable ( const input & in) const -> bool

Checks if the input is spendable by the current wallet.

Parameters
inthe input to check.

Definition at line 536 of file wallet.cpp.

Referenced by cbdc::client::import_send_input().

◆ load()

void cbdc::transaction::wallet::load ( const std::string & wallet_file)

Overwrites the current state of the wallet with data loaded from a file saved via the Wallet::save function.

Parameters
wallet_filepath to wallet file location.

Definition at line 329 of file wallet.cpp.

References cbdc::transaction::validation::get_p2pk_witness_commitment().

Here is the call graph for this function:

◆ mint_new_coins()

auto cbdc::transaction::wallet::mint_new_coins ( size_t n_outputs,
uint32_t output_val ) -> full_tx

Mints new spendable outputs.

Generates the specified number spendable outputs, each with the specified value, and returns a transaction with the result to submit to the transaction processing system.

Parameters
n_outputsnumber of new spendable outputs to create.
output_valvalue of the amount to associate with each output in the base unit of the currency.
Returns
the transaction which mints the new coins.

Definition at line 25 of file wallet.cpp.

References cbdc::transaction::validation::get_p2pk_witness_commitment(), cbdc::transaction::full_tx::m_outputs, cbdc::transaction::output::m_value, and cbdc::transaction::output::m_witness_program_commitment.

Here is the call graph for this function:

◆ save()

void cbdc::transaction::wallet::save ( const std::string & wallet_file) const

Save the state of the wallet to a binary data file.

Parameters
wallet_filepath to wallet file location.

values

Definition at line 307 of file wallet.cpp.

◆ seed()

auto cbdc::transaction::wallet::seed ( const privkey_t & privkey,
uint32_t value,
size_t begin_seed,
size_t end_seed ) -> bool

Marks the wallet as having pre-seeded outputs to spend.

Given that the outputs are deterministic, the wallet will create them on-the-fly while spending them.

Parameters
privkeythe private key to use for the seeded outputs.
valuethe value of each seeded output.
begin_seedthe start index to use for the seeded outputs.
end_seedthe end index to use for the seeded outputs.
Returns
true if setting the seed parameters succeeded.

Definition at line 236 of file wallet.cpp.

References cbdc::transaction::validation::get_p2pk_witness_commitment(), and cbdc::pubkey_from_privkey().

Referenced by wallet().

Here is the call graph for this function:

◆ seed_readonly()

void cbdc::transaction::wallet::seed_readonly ( const hash_t & witness_commitment,
uint32_t value,
size_t begin_seed,
size_t end_seed )

Marks the wallet as having read-only pre-seeded outputs to spend.

This method marks the wallet as having pre-seeded outputs which can only generate unsigned transactions. It is called from seed – where seed also provides the wallet with the private key and makes the outputs spendable. The shard seeder to uses this read-only variant to allow for calls to create_seeded_transaction.

Parameters
witness_commitmentthe witness commitment to use for the seeded outputs.
valuethe value to use for the seeded outputs.
begin_seedthe start index to use for the seeded outputs.
end_seedthe end index to use for the seeded outputs.

Definition at line 260 of file wallet.cpp.

◆ send_to() [1/2]

auto cbdc::transaction::wallet::send_to ( size_t input_count,
size_t output_count,
const pubkey_t & payee,
bool sign_tx ) -> std::optional<full_tx>

Generates a new send transaction with the specified number of inputs and outputs.

This method is best-effort: it will return an empty optional if the method cannot use the specified number of inputs to create the specified number of outputs. Likewise, the method will return an empty optional if the wallet contains fewer UTXOs than the specified input count.

Parameters
input_countnumber of inputs to include in the Tx. Must be >0.
output_countnumber of outputs to include in the Tx. Must be >0.
payeedestination pubkey for the Tx outputs.
sign_txtrue if the transaction should be signed.
Returns
the completed transaction.

Definition at line 366 of file wallet.cpp.

References cbdc::transaction::validation::get_p2pk_witness_commitment(), cbdc::transaction::full_tx::m_inputs, cbdc::transaction::full_tx::m_outputs, cbdc::transaction::output::m_value, cbdc::transaction::full_tx::m_witness, and cbdc::transaction::output::m_witness_program_commitment.

Here is the call graph for this function:

◆ send_to() [2/2]

auto cbdc::transaction::wallet::send_to ( uint32_t amount,
const pubkey_t & payee,
bool sign_tx ) -> std::optional<full_tx>

Generates a new send transaction with a set value.

Generates a transaction to transfer a specified amount from this wallet to a recipient's target address. Returns the transaction for wallet clients to submit to the processing system and syndicate to recipients.

Parameters
amountthe amount to send in the base unit of the currency.
payeethe destination address of the transfer.
sign_txtrue if the wallet should sign this transaction.
Returns
the completed transaction.
See also
export_send_inputs

Definition at line 46 of file wallet.cpp.

References cbdc::transaction::validation::get_p2pk_witness_commitment(), cbdc::transaction::output::m_value, and cbdc::transaction::output::m_witness_program_commitment.

Here is the call graph for this function:

◆ sign()

void cbdc::transaction::wallet::sign ( transaction::full_tx & tx) const

Signs each of the transaction's inputs using Schnorr signatures.

Parameters
txthe transaction whose inputs to sign.

Definition at line 158 of file wallet.cpp.

References cbdc::transaction::full_tx::m_inputs, cbdc::transaction::full_tx::m_witness, cbdc::transaction::validation::p2pk, and cbdc::transaction::tx_id().

Referenced by cbdc::client::sign_transaction().

Here is the call graph for this function:

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