Trait bdk::blockchain::Blockchain [−][src]
pub trait Blockchain {
fn get_capabilities(&self) -> HashSet<Capability>;
fn setup<D: BatchDatabase, P: 'static + Progress>(
&self,
database: &mut D,
progress_update: P
) -> Result<(), Error>;
fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error>;
fn broadcast(&self, tx: &Transaction) -> Result<(), Error>;
fn get_height(&self) -> Result<u32, Error>;
fn estimate_fee(&self, target: usize) -> Result<FeeRate, Error>;
fn sync<D: BatchDatabase, P: 'static + Progress>(
&self,
database: &mut D,
progress_update: P
) -> Result<(), Error> { ... }
}
Expand description
Trait that defines the actions that must be supported by a blockchain backend
Required methods
fn get_capabilities(&self) -> HashSet<Capability>
fn get_capabilities(&self) -> HashSet<Capability>
Return the set of Capability
supported by this backend
Setup the backend and populate the internal database for the first time
This method is the equivalent of Blockchain::sync
, but it’s guaranteed to only be
called once, at the first Wallet::sync
.
The rationale behind the distinction between sync
and setup
is that some custom backends
might need to perform specific actions only the first time they are synced.
For types that do not have that distinction, only this method can be implemented, since
Blockchain::sync
defaults to calling this internally if not overridden.
Fetch a transaction from the blockchain given its txid
fn get_height(&self) -> Result<u32, Error>
fn get_height(&self) -> Result<u32, Error>
Return the current height
Provided methods
Populate the internal database with transactions and UTXOs
If not overridden, it defaults to calling Blockchain::setup
internally.
This method should implement the logic required to iterate over the list of the wallet’s
script_pubkeys using Database::iter_script_pubkeys
and look for relevant transactions
in the blockchain to populate the database with BatchOperations::set_tx
and
BatchOperations::set_utxo
.
This method should also take care of removing UTXOs that are seen as spent in the
blockchain, using BatchOperations::del_utxo
.
The progress_update
object can be used to give the caller updates about the progress by using
Progress::update
.
Implementations on Foreign Types
Implementors
impl Blockchain for CompactFiltersBlockchain
compact_filters
only.