Expand description
§Utilities for Zcash wallet construction
This module defines a set of APIs for wallet data persistence, and provides a suite of methods
based upon these APIs that can be used to implement a fully functional Zcash wallet. At
present, the interfaces provided here are built primarily around the use of a source of
CompactBlock
data such as the Zcash Light Client Protocol as defined in
ZIP 307 but they may be generalized to full-block use cases in
the future.
§Important Concepts
There are several important operations that a Zcash wallet must perform that distinguish Zcash wallet design from wallets for other cryptocurrencies.
- Viewing Keys: Wallets based upon this module are built around the capabilities of Zcash
UnifiedFullViewingKey
s; the wallet backend provides no facilities for the storage of spending keys, and spending keys must be provided by the caller in order to perform transaction creation operations. - Blockchain Scanning: A Zcash wallet must download and trial-decrypt each transaction on the
Zcash blockchain using one or more Viewing Keys in order to find new shielded transaction
outputs (generally termed “notes”) belonging to the wallet. The primary entrypoint for this
functionality is the
scan_cached_blocks
method. See thechain
module for additional details. - Witness Updates: In order to spend a shielded note, the wallet must be able to compute the
Merkle path to that note in the global note commitment tree. When
scan_cached_blocks
is used to process a range of blocks, the note commitment tree is updated with the note commitments for the blocks in that range. - Transaction Construction: The
wallet
module provides functions for creating Zcash transactions that spend funds belonging to the wallet.
§Core Traits
The utility functions described above depend upon four important traits defined in this
module, which between them encompass the data storage requirements of a light wallet.
The relevant traits are InputSource
, WalletRead
, WalletWrite
, and
WalletCommitmentTrees
. A complete implementation of the data storage layer for a wallet
will include an implementation of all four of these traits. See the zcash_client_sqlite
crate for a complete example of the implementation of these traits.
§Accounts
The operation of the InputSource
, WalletRead
and WalletWrite
traits is built around
the concept of a wallet having one or more accounts, with a unique AccountId
for each
account.
An account identifier corresponds to at most a single UnifiedSpendingKey
’s worth of spend
authority, with the received and spent notes of that account tracked via the corresponding
UnifiedFullViewingKey
. Both received notes and change spendable by that spending authority
(both the external and internal parts of that key, as defined by
ZIP 316) will be interpreted as belonging to that account.
Modules§
- chain
- Tools for blockchain validation & scanning
- error
- Types for wallet error handling.
- scanning
- Common types used for managing a queue of scanning ranges.
- testing
test-dependencies
- Utilities for testing wallets based upon the
crate::data_api
traits. - wallet
- Functions for creating Zcash transactions that spend funds belonging to the wallet
Macros§
- ambassador_
impl_ Input Source - A macro to be used by [
ambassador::Delegate
] to delegateInputSource
- ambassador_
impl_ Wallet Commitment Trees - A macro to be used by [
ambassador::Delegate
] to delegateWalletCommitmentTrees
- ambassador_
impl_ Wallet Read - A macro to be used by [
ambassador::Delegate
] to delegateWalletRead
- ambassador_
impl_ Wallet Test - A macro to be used by [
ambassador::Delegate
] to delegateWalletTest
- ambassador_
impl_ Wallet Write - A macro to be used by [
ambassador::Delegate
] to delegateWalletWrite
Structs§
- Account
Balance - Balance information for a single account. The sum of this struct’s fields is the total balance of the wallet.
- Account
Birthday - A data structure used to set the birthday height for an account, and ensure that the initial note commitment tree state is recorded at that height.
- Account
Meta - Metadata about the structure of the wallet for a particular account.
- Address
Info - Information about an address in the wallet.
- Balance
- Balance information for a value within a single pool in an account.
- Block
Metadata - Metadata describing the sizes of the zcash note commitment trees as of a particular block.
- Bounded
U8 - A
u8
value in the range 0..=MAX - Decrypted
Transaction - A transaction that was detected during scanning of the blockchain, including its decrypted Sapling and/or Orchard outputs.
- Output
OfSent Tx test-dependencies
- The output of a transaction sent by the wallet.
- Pool
Meta - Metadata about the structure of unspent outputs in a single pool within a wallet account.
- Progress
- A type representing the progress the wallet has made toward detecting all of the funds belonging to the wallet.
- Ratio
- A polymorphic ratio type, usually used for rational numbers.
- Scanned
Block - The subset of information that is relevant to this wallet that has been
decrypted and extracted from a
CompactBlock
. - Scanned
Block Commitments - A struct used to return the vectors of note commitments for a
ScannedBlock
as owned values. - Scanned
Bundles - The protocol-specific note commitment and nullifier data extracted from the per-transaction
shielded bundles in
CompactBlock
, used by the wallet for note commitment tree maintenance and spend detection. - Sent
Transaction - A transaction that was constructed and sent by the wallet.
- Sent
Transaction Output - An output of a transaction generated by the wallet.
- Spendable
Notes - Spendable shielded outputs controlled by the wallet.
- Wallet
Summary - A type representing the potentially-spendable value of unspent outputs in the wallet.
- Zip32
Derivation - Source metadata for a ZIP 32-derived key.
Enums§
- Account
Purpose - An enumeration used to control what information is tracked by the wallet for notes received by a given account.
- Account
Source - The kinds of accounts supported by
zcash_client_backend
. - Birthday
Error - Errors that can occur in the construction of an
AccountBirthday
from aTreeState
. - Note
Filter - A small query language for filtering notes belonging to an account.
- Nullifier
Query - An enumeration of constraints that can be applied when querying for nullifiers for notes belonging to the wallet.
- Output
Status Filter transparent-inputs
- A type used to filter transactions to be returned in response to a
TransactionDataRequest
, in terms of the spentness of the transaction’s transparent outputs. - Seed
Relevance - The relevance of a seed to a given wallet.
- Transaction
Data Request - A request for transaction data enhancement, spentness check, or discovery of spends from a given transparent address within a specific block range.
- Transaction
Status - Metadata about the status of a transaction obtained by inspecting the chain state.
- Transaction
Status Filter transparent-inputs
- A type describing the mined-ness of transactions that should be returned in response to a
TransactionDataRequest
.
Constants§
- ORCHARD_
SHARD_ HEIGHT orchard
- The height of subtree roots in the Orchard note commitment tree.
- SAPLING_
SHARD_ HEIGHT - The height of subtree roots in the Sapling note commitment tree.
Traits§
- Account
- A set of capabilities that a client account must provide.
- Input
Source - A trait representing the capability to query a data store for unspent transaction outputs belonging to a account.
- Note
Retention - A predicate that can be used to choose whether or not a particular note is retained in note selection.
- Wallet
Commitment Trees - This trait describes a capability for manipulating wallet note commitment trees.
- Wallet
Read - Read-only operations required for light wallet functions.
- Wallet
Test - Read-only operations required for testing light wallet functions.
- Wallet
Write - This trait encapsulates the write capabilities required to update stored wallet data.