6#ifndef OPENCBDC_TX_SRC_TRANSACTION_WALLET_H_
7#define OPENCBDC_TX_SRC_TRANSACTION_WALLET_H_
23#include <shared_mutex>
24#include <unordered_map>
25#include <unordered_set>
62 -> std::optional<full_tx>;
79 auto send_to(
size_t input_count,
82 bool sign_tx) -> std::optional<full_tx>;
98 auto fan(
size_t output_count,
101 bool sign_tx) -> std::optional<transaction::full_tx>;
118 -> std::vector<input>;
137 size_t end_seed) -> bool;
182 auto balance()
const -> uint64_t;
186 auto count()
const -> size_t;
190 void save(
const std::string& wallet_file)
const;
195 void load(
const std::string& wallet_file);
207 -> std::optional<full_tx>;
216 auto operator()(
const input& lhs,
const input& rhs)
const ->
bool {
225 mutable std::shared_mutex m_utxos_mut;
226 uint64_t m_balance{0};
228 std::set<input, cmp_input> m_utxos_set;
229 size_t m_seed_from{0};
231 uint32_t m_seed_value{0};
232 hash_t m_seed_witness_commitment{0};
234 std::list<input> m_spend_queue;
239 mutable std::shared_mutex m_keys_mut;
244 std::vector<pubkey_t> m_pubkeys;
245 std::default_random_engine m_shuffle;
249 std::unordered_map<hash_t, pubkey_t, hashing::const_sip_hash<hash_t>>
257 auto create_seeded_input(
size_t seed_idx) -> std::optional<input>;
259 static const inline auto m_secp
261 decltype(&secp256k1_context_destroy)>(
262 secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
263 &secp256k1_context_destroy);
265 static const inline auto m_random_source
266 = std::make_unique<random_source>(config::random_source);
272 void update_balance(
const std::vector<input>& credits,
273 const std::vector<input>& debits);
275 auto accumulate_inputs(uint64_t amount)
276 -> std::optional<std::pair<full_tx, uint64_t>>;
Cryptographic wallet for digital currency assets and secrets.
void confirm_inputs(const std::vector< input > &credits)
Given a set of credit inputs, add the UTXOs and update the wallet's balance.
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.
auto generate_key() -> pubkey_t
Generates a new public key at which this wallet can receive payments via send_to.
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 fu...
void confirm_transaction(const full_tx &tx)
Confirms a transaction.
auto mint_new_coins(size_t n_outputs, uint32_t output_val) -> full_tx
Mints new spendable outputs.
auto count() const -> size_t
Returns the number of UTXOs stored in this wallet.
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.
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.
void sign(full_tx &tx) const
Signs each of the transaction's inputs using Schnorr signatures.
void save(const std::string &wallet_file) const
Save the state of the wallet to a binary data file.
auto is_spendable(const input &in) const -> bool
Checks if the input is spendable by the current wallet.
auto create_seeded_transaction(size_t seed_idx) -> std::optional< full_tx >
Creates a new transaction from seeded 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 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.
auto balance() const -> uint64_t
Returns the total balance of the wallet, e.g.
Tools for reading options from a configuration file and building application-specific parameter sets ...
struct secp256k1_context_struct secp256k1_context
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
std::array< unsigned char, pubkey_len > privkey_t
A private key of a public/private keypair.
std::array< unsigned char, pubkey_len > pubkey_t
A public key of a public/private keypair.
Pseudorandom number generator (PRNG) for generating random data from a given entropy source.
SipHash function to generate STL data structure hash keys for system IDs.
hash_t m_tx_id
The hash of the transaction which created the out_point.
uint64_t m_index
The index of the output in the transaction's output list.