Struct bdk_chain::indexed_tx_graph::IndexedTxGraph

source ·
pub struct IndexedTxGraph<A, I> {
    pub index: I,
    /* private fields */
}
Expand description

The IndexedTxGraph combines a TxGraph and an Indexer implementation.

It ensures that TxGraph and Indexer are updated atomically.

Fields§

§index: I

Transaction index.

Implementations§

source§

impl<A, I> IndexedTxGraph<A, I>

source

pub fn new(index: I) -> Self

Construct a new IndexedTxGraph with a given index.

source

pub fn graph(&self) -> &TxGraph<A>

Get a reference of the internal transaction graph.

source§

impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>

source

pub fn apply_changeset(&mut self, changeset: ChangeSet<A, I::ChangeSet>)

Applies the ChangeSet to the IndexedTxGraph.

source

pub fn initial_changeset(&self) -> ChangeSet<A, I::ChangeSet>

Determines the ChangeSet between self and an empty IndexedTxGraph.

source§

impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
where I::ChangeSet: Default + Merge,

source

pub fn apply_update( &mut self, update: TxUpdate<A> ) -> ChangeSet<A, I::ChangeSet>

Available on crate feature std only.

Apply an update directly.

update is a tx_graph::TxUpdate<A> and the resultant changes is returned as ChangeSet.

source

pub fn apply_update_at( &mut self, update: TxUpdate<A>, seen_at: Option<u64> ) -> ChangeSet<A, I::ChangeSet>

Apply the given update with an optional seen_at timestamp.

seen_at represents when the update is seen (in unix seconds). It is used to determine the last_seens for all transactions in the update which have no corresponding anchor(s). The last_seen value is used internally to determine precedence of conflicting unconfirmed transactions (where the transaction with the lower last_seen value is omitted from the canonical history).

Not setting a seen_at value means unconfirmed transactions introduced by this update will not be part of the canonical history of transactions.

Use apply_update to have the seen_at value automatically set to the current time.

source

pub fn insert_txout( &mut self, outpoint: OutPoint, txout: TxOut ) -> ChangeSet<A, I::ChangeSet>

Insert a floating txout of given outpoint.

source

pub fn insert_tx<T: Into<Arc<Transaction>>>( &mut self, tx: T ) -> ChangeSet<A, I::ChangeSet>

Insert and index a transaction into the graph.

source

pub fn insert_anchor( &mut self, txid: Txid, anchor: A ) -> ChangeSet<A, I::ChangeSet>

Insert an anchor for a given transaction.

source

pub fn insert_seen_at( &mut self, txid: Txid, seen_at: u64 ) -> ChangeSet<A, I::ChangeSet>

Insert a unix timestamp of when a transaction is seen in the mempool.

This is used for transaction conflict resolution in TxGraph where the transaction with the later last-seen is prioritized.

source

pub fn batch_insert_relevant<T: Into<Arc<Transaction>>>( &mut self, txs: impl IntoIterator<Item = (T, impl IntoIterator<Item = A>)> ) -> ChangeSet<A, I::ChangeSet>

Batch insert transactions, filtering out those that are irrelevant.

Relevancy is determined by the Indexer::is_tx_relevant implementation of I. Irrelevant transactions in txs will be ignored. txs do not need to be in topological order.

source

pub fn batch_insert_relevant_unconfirmed<T: Into<Arc<Transaction>>>( &mut self, unconfirmed_txs: impl IntoIterator<Item = (T, u64)> ) -> ChangeSet<A, I::ChangeSet>

Batch insert unconfirmed transactions, filtering out those that are irrelevant.

Relevancy is determined by the internal Indexer::is_tx_relevant implementation of I. Irrelevant transactions in txs will be ignored.

Items of txs are tuples containing the transaction and a last seen timestamp. The last seen communicates when the transaction is last seen in the mempool which is used for conflict-resolution in TxGraph (refer to TxGraph::insert_seen_at for details).

source

pub fn batch_insert_unconfirmed<T: Into<Arc<Transaction>>>( &mut self, txs: impl IntoIterator<Item = (T, u64)> ) -> ChangeSet<A, I::ChangeSet>

Batch insert unconfirmed transactions.

Items of txs are tuples containing the transaction and a last seen timestamp. The last seen communicates when the transaction is last seen in the mempool which is used for conflict-resolution in TxGraph (refer to TxGraph::insert_seen_at for details).

To filter out irrelevant transactions, use batch_insert_relevant_unconfirmed instead.

source§

impl<A, I> IndexedTxGraph<A, I>
where I::ChangeSet: Default + Merge, for<'b> A: Anchor + From<TxPosInBlock<'b>>, I: Indexer,

Methods are available if the anchor (A) can be created from TxPosInBlock.

source

pub fn apply_block_relevant( &mut self, block: &Block, height: u32 ) -> ChangeSet<A, I::ChangeSet>

Batch insert all transactions of the given block of height, filtering out those that are irrelevant.

Each inserted transaction’s anchor will be constructed using TxPosInBlock.

Relevancy is determined by the internal Indexer::is_tx_relevant implementation of I. Irrelevant transactions in txs will be ignored.

source

pub fn apply_block( &mut self, block: Block, height: u32 ) -> ChangeSet<A, I::ChangeSet>

Batch insert all transactions of the given block of height.

Each inserted transaction’s anchor will be constructed using TxPosInBlock.

To only insert relevant transactions, use apply_block_relevant instead.

Trait Implementations§

source§

impl<A, I> AsRef<TxGraph<A>> for IndexedTxGraph<A, I>

source§

fn as_ref(&self) -> &TxGraph<A>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<A: Debug, I: Debug> Debug for IndexedTxGraph<A, I>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<A, I: Default> Default for IndexedTxGraph<A, I>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<A, I> Freeze for IndexedTxGraph<A, I>
where I: Freeze,

§

impl<A, I> RefUnwindSafe for IndexedTxGraph<A, I>

§

impl<A, I> Send for IndexedTxGraph<A, I>
where I: Send, A: Send,

§

impl<A, I> Sync for IndexedTxGraph<A, I>
where I: Sync, A: Sync,

§

impl<A, I> Unpin for IndexedTxGraph<A, I>
where I: Unpin,

§

impl<A, I> UnwindSafe for IndexedTxGraph<A, I>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V