OpenCBDC Transaction Processor
|
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. | |
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.
cbdc::transaction::wallet::wallet | ( | ) |
Constructor.
Initializes the randomization engine for key shuffling.
Definition at line 17 of file wallet.cpp.
References seed().
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.
Definition at line 288 of file wallet.cpp.
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.
credits | the inputs to add to the wallet's set of UTXOs. |
Definition at line 449 of file wallet.cpp.
void cbdc::transaction::wallet::confirm_transaction | ( | const full_tx & | tx | ) |
Confirms a transaction.
tx | the 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().
auto cbdc::transaction::wallet::count | ( | ) | const -> size_t |
Returns the number of UTXOs stored in this wallet.
Definition at line 298 of file wallet.cpp.
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.
seed_idx | the index in the seed set for which to generate the transaction. |
Definition at line 82 of file wallet.cpp.
References cbdc::transaction::full_tx::m_inputs, and cbdc::transaction::full_tx::m_outputs.
|
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.
send_tx | the send transaction generated by this wallet's send_to function. |
payee | the destination address of the transfer. |
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().
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.
output_count | number of outputs to send to the recipient. |
value | the amount to send per outputs in the base unit of the currency. |
payee | the destination address of the transfer. |
sign_tx | true if the wallet should sign this transaction. |
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.
auto cbdc::transaction::wallet::generate_key | ( | ) | -> pubkey_t |
Generates a new public key at which this wallet can receive payments via send_to.
Definition at line 124 of file wallet.cpp.
References cbdc::transaction::validation::get_p2pk_witness_commitment(), and cbdc::pubkey_from_privkey().
auto cbdc::transaction::wallet::is_spendable | ( | const input & | in | ) | const -> bool |
Checks if the input is spendable by the current wallet.
in | the input to check. |
Definition at line 536 of file wallet.cpp.
Referenced by cbdc::client::import_send_input().
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.
wallet_file | path to wallet file location. |
Definition at line 329 of file wallet.cpp.
References cbdc::transaction::validation::get_p2pk_witness_commitment().
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.
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 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.
void cbdc::transaction::wallet::save | ( | const std::string & | wallet_file | ) | const |
Save the state of the wallet to a binary data file.
wallet_file | path to wallet file location. |
values
Definition at line 307 of file wallet.cpp.
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.
privkey | the private key to use for the seeded outputs. |
value | the value of each seeded output. |
begin_seed | the start index to use for the seeded outputs. |
end_seed | the end index to use for the seeded outputs. |
Definition at line 236 of file wallet.cpp.
References cbdc::transaction::validation::get_p2pk_witness_commitment(), and cbdc::pubkey_from_privkey().
Referenced by wallet().
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.
witness_commitment | the witness commitment to use for the seeded outputs. |
value | the value to use for the seeded outputs. |
begin_seed | the start index to use for the seeded outputs. |
end_seed | the end index to use for the seeded outputs. |
Definition at line 260 of file wallet.cpp.
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.
input_count | number of inputs to include in the Tx. Must be >0. |
output_count | number of outputs to include in the Tx. Must be >0. |
payee | destination pubkey for the Tx outputs. |
sign_tx | true if the transaction should be signed. |
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.
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.
amount | the amount to send in the base unit of the currency. |
payee | the destination address of the transfer. |
sign_tx | true if the wallet should sign this transaction. |
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.
void cbdc::transaction::wallet::sign | ( | transaction::full_tx & | tx | ) | const |
Signs each of the transaction's inputs using Schnorr signatures.
tx | the 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().