Skip to main content

QueryablePayload

Trait QueryablePayload 

pub trait QueryablePayload<Types>: BlockPayload<Types>
where Types: NodeType, <Types as NodeType>::BlockHeader: QueryableHeader<Types>,
{ type Iter<'a>: Iterator<Item = TransactionIndex<Types>> where Self: 'a; type InclusionProof: VerifiableInclusion<Types>; // Required methods fn len(&self, meta: &Self::Metadata) -> usize; fn iter<'a>(&'a self, meta: &'a Self::Metadata) -> Self::Iter<'a>; fn transaction( &self, meta: &Self::Metadata, index: &TransactionIndex<Types>, ) -> Option<Self::Transaction>; fn transaction_proof( &self, meta: &Self::Metadata, vid: &VidCommonQueryData<Types>, index: &TransactionIndex<Types>, ) -> Option<Self::InclusionProof>; // Provided methods fn is_empty(&self, meta: &Self::Metadata) -> bool { ... } fn enumerate<'a>( &'a self, meta: &'a Self::Metadata, ) -> Box<dyn Iterator<Item = (TransactionIndex<Types>, Self::Transaction)> + 'a> { ... } fn nth( &self, meta: &Self::Metadata, n: usize, ) -> Option<TransactionIndex<Types>> { ... } fn nth_transaction( &self, meta: &Self::Metadata, n: usize, ) -> Option<Self::Transaction> { ... } fn by_hash( &self, meta: &Self::Metadata, hash: Commitment<Self::Transaction>, ) -> Option<TransactionIndex<Types>> { ... } fn transaction_by_hash( &self, meta: &Self::Metadata, hash: Commitment<Self::Transaction>, ) -> Option<Self::Transaction> { ... } }
Expand description

A block payload whose contents (e.g. individual transactions) can be examined.

Note to implementers: this trait has only a few required methods. The provided methods, for querying transactions in various ways, are implemented in terms of the required iter and transaction_proof methods, and the default implementations may be inefficient (e.g. performing an O(n) search, or computing an unnecessary inclusion proof). It is good practice to override these default implementations if your block type supports more efficient implementations (e.g. sublinear indexing by hash).

Required Associated Types§

type Iter<'a>: Iterator<Item = TransactionIndex<Types>> where Self: 'a

Enumerate the transactions in this block.

type InclusionProof: VerifiableInclusion<Types>

A proof that a certain transaction exists in the block.

Required Methods§

fn len(&self, meta: &Self::Metadata) -> usize

The number of transactions in the block.

fn iter<'a>(&'a self, meta: &'a Self::Metadata) -> Self::Iter<'a>

List the transaction indices in the block.

fn transaction( &self, meta: &Self::Metadata, index: &TransactionIndex<Types>, ) -> Option<Self::Transaction>

Get a transaction by its block-specific index.

fn transaction_proof( &self, meta: &Self::Metadata, vid: &VidCommonQueryData<Types>, index: &TransactionIndex<Types>, ) -> Option<Self::InclusionProof>

Get an inclusion proof for the given transaction.

This function may be slow and computationally intensive, especially for large transactions.

Provided Methods§

fn is_empty(&self, meta: &Self::Metadata) -> bool

Whether this block is empty of transactions.

fn enumerate<'a>( &'a self, meta: &'a Self::Metadata, ) -> Box<dyn Iterator<Item = (TransactionIndex<Types>, Self::Transaction)> + 'a>

Enumerate the transactions in the block with their indices.

fn nth( &self, meta: &Self::Metadata, n: usize, ) -> Option<TransactionIndex<Types>>

Get the index of the nth transaction.

fn nth_transaction( &self, meta: &Self::Metadata, n: usize, ) -> Option<Self::Transaction>

Get the nth transaction.

fn by_hash( &self, meta: &Self::Metadata, hash: Commitment<Self::Transaction>, ) -> Option<TransactionIndex<Types>>

Get the index of the transaction with a given hash, if it is in the block.

fn transaction_by_hash( &self, meta: &Self::Metadata, hash: Commitment<Self::Transaction>, ) -> Option<Self::Transaction>

Get the transaction with a given hash, if it is in the block.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§