pub(crate) struct AddressCacheInner<D: AddressCacheDatabase> {
pub(crate) database: D,
pub(crate) address_map: HashMap<Hash, CachedAddress>,
pub(crate) script_set: HashSet<Hash>,
pub(crate) utxo_index: HashMap<OutPoint, Hash>,
}Fields§
§database: DA database that will be used to persist all needed to get our address history
address_map: HashMap<Hash, CachedAddress>Maps a hash to a cached address struct, this is basically an in-memory version of our database, used for speeding up processing a block. This hash is the electrum’s script hash
script_set: HashSet<Hash>Holds all scripts we are interested in
utxo_index: HashMap<OutPoint, Hash>Keeps track of all utxos we own, and the script hash they belong to
Implementations§
Source§impl<D: AddressCacheDatabase> AddressCacheInner<D>
impl<D: AddressCacheDatabase> AddressCacheInner<D>
Sourcepub(crate) fn block_process(
&mut self,
block: &Block,
height: u32,
) -> Vec<(Transaction, TxOut)>
pub(crate) fn block_process( &mut self, block: &Block, height: u32, ) -> Vec<(Transaction, TxOut)>
Iterates through a block, finds transactions destined to ourselves. Returns all transactions we found.
pub(crate) fn new(database: D) -> AddressCacheInner<D>
pub(crate) fn get_address_utxos( &self, script_hash: &Hash, ) -> Option<Vec<(TxOut, OutPoint)>>
pub(crate) fn get_transaction(&self, txid: &Txid) -> Option<CachedTransaction>
Sourcepub(crate) fn get_address_history(
&self,
script_hash: &Hash,
) -> Option<Vec<CachedTransaction>>
pub(crate) fn get_address_history( &self, script_hash: &Hash, ) -> Option<Vec<CachedTransaction>>
Returns all transactions this address has, both input and outputs
Sourcepub(crate) fn get_merkle_proof(&self, txid: &Txid) -> Option<MerkleProof>
pub(crate) fn get_merkle_proof(&self, txid: &Txid) -> Option<MerkleProof>
Get Merkle Proof
Returns none if a given Txid is an unconfirmed transaction or unrelated with your wallet, defined by the xpubs, descriptors and addresses in your config.toml.
Sourcepub(crate) fn cache_address(&mut self, script_pk: ScriptBuf)
pub(crate) fn cache_address(&mut self, script_pk: ScriptBuf)
Adds a new address to track, should be called at wallet setup and every once in a while to cache new addresses, as we use the first ones. Only requires a script to cache.
Sourcepub(crate) fn setup(&self) -> Result<(), WatchOnlyError<D::Error>>
pub(crate) fn setup(&self) -> Result<(), WatchOnlyError<D::Error>>
Setup is the first command that should be executed. In a new cache. It sets our wallet’s state, like the height we should start scanning and the wallet’s descriptor.
pub(crate) fn derive_addresses( &mut self, ) -> Result<(), WatchOnlyError<D::Error>>
pub(crate) fn maybe_derive_addresses(&mut self)
pub(crate) fn find_unconfirmed( &self, ) -> Result<Vec<Transaction>, WatchOnlyError<D::Error>>
pub(crate) fn find_spend( &self, transaction: &Transaction, ) -> Vec<(usize, TxOut)>
pub(crate) fn cache_mempool_transaction( &mut self, transaction: &Transaction, ) -> Vec<TxOut>
pub(crate) fn save_mempool_tx( &mut self, hash: Hash, transaction_to_cache: CachedTransaction, )
pub(crate) fn save_non_mempool_tx( &mut self, transaction: &Transaction, is_spend: bool, value: u64, index: usize, hash: Hash, transaction_to_cache: CachedTransaction, )
Sourcepub(crate) fn cache_transaction(
&mut self,
transaction: &Transaction,
height: u32,
value: u64,
merkle_block: MerkleProof,
position: u32,
index: usize,
is_spend: bool,
hash: Hash,
)
pub(crate) fn cache_transaction( &mut self, transaction: &Transaction, height: u32, value: u64, merkle_block: MerkleProof, position: u32, index: usize, is_spend: bool, hash: Hash, )
Caches a new transaction. This method may be called for addresses we don’t follow yet, this automatically makes we follow this address.