Module tuxedo_template_wallet::sync
source · Expand description
This module is responsible for maintaining the wallet’s local database of blocks and owned UTXOs to the canonical database reported by the node.
It is backed by a sled database
§Schema
There are 4 tables in the database BlockHashes block_number:u32 => block_hash:H256 Blocks block_hash:H256 => block:Block UnspentOutputs output_ref => (owner_pubkey, amount) SpentOutputs output_ref => (owner_pubkey, amount)
Constants§
- BLOCKS 🔒The identifier for the blocks tree in the db.
- The identifier for the block_hashes tree in the db.
- SPENT 🔒The identifier for the spent tree in the db.
- UNSPENT 🔒The identifier for the unspent tree in the db.
Functions§
- Add a new output to the database updating all tables.
- Apply a block to the local database
- Apply a single transaction to the local database The owner-specific tables are mappings from output_refs to coin amounts
- Picks an arbitrary set of unspent outputs from the database for spending. The set’s token values must add up to at least the specified target value.
- Iterate the entire unspent set summing the values of the coins on a per-address basis.
- Gets the block from the local database given a block hash. Similar to the Node’s RPC.
- Gets the block hash from the local database given a block height. Similar the Node’s RPC.
- Gets the owner and amount associated with an output ref from the unspent table
- height 🔒Get the block height that the wallet is currently synced to
- open_db 🔒Open a database at the given location intended for the given genesis block.
- Debugging use. Print out the entire block_hashes tree.
- Debugging use. Print the entire unspent outputs tree.
- Remove an output from the database updating all tables.
- Mark an existing output as spent. This does not purge all record of the output from the db. It just moves the record from the unspent table to the spent table
- Synchronize the local database to the database of the running node. The wallet entirely trusts the data the node feeds it. In the bigger picture, that means run your own (light) node.
- Unapply the best block that the wallet currently knows about
- Run a transaction backwards against a database. Mark all of the Inputs as unspent, and drop all of the outputs.
- Mark an output that was previously spent back as unspent.