Struct breez_sdk_core::bitcoin::util::merkleblock::MerkleBlock

pub struct MerkleBlock {
    pub header: BlockHeader,
    pub txn: PartialMerkleTree,
}
Expand description

Data structure that represents a block header paired to a partial merkle tree.

NOTE: This assumes that the given Block has at least 1 transaction. If the Block has 0 txs, it will hit an assertion.

Fields§

§header: BlockHeader

The block header

§txn: PartialMerkleTree

Transactions making up a partial merkle tree

Implementations§

§

impl MerkleBlock

pub fn from_block_with_predicate<F>( block: &Block, match_txids: F, ) -> MerkleBlock
where F: Fn(&Txid) -> bool,

Create a MerkleBlock from a block, that contains proofs for specific txids.

The block is a full block containing the header and transactions and match_txids is a function that returns true for the ids that should be included in the partial merkle tree.

§Examples
use bitcoin::hash_types::Txid;
use bitcoin::hashes::hex::FromHex;
use bitcoin::{Block, MerkleBlock};

// Block 80000
let block_bytes = Vec::from_hex("01000000ba8b9cda965dd8e536670f9ddec10e53aab14b20bacad2\
    7b9137190000000000190760b278fe7b8565fda3b968b918d5fd997f993b23674c0af3b6fde300b38f33\
    a5914ce6ed5b1b01e32f5702010000000100000000000000000000000000000000000000000000000000\
    00000000000000ffffffff0704e6ed5b1b014effffffff0100f2052a01000000434104b68a50eaa0287e\
    ff855189f949c1c6e5f58b37c88231373d8a59809cbae83059cc6469d65c665ccfd1cfeb75c6e8e19413\
    bba7fbff9bc762419a76d87b16086eac000000000100000001a6b97044d03da79c005b20ea9c0e1a6d9d\
    c12d9f7b91a5911c9030a439eed8f5000000004948304502206e21798a42fae0e854281abd38bacd1aee\
    d3ee3738d9e1446618c4571d1090db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d\
    5d6cc8d25c6b241501ffffffff0100f2052a010000001976a914404371705fa9bd789a2fcd52d2c580b6\
    5d35549d88ac00000000").unwrap();
let block: Block = bitcoin::consensus::deserialize(&block_bytes).unwrap();

// Create a merkle block containing a single transaction
let txid = Txid::from_hex(
    "5a4ebf66822b0b2d56bd9dc64ece0bc38ee7844a23ff1d7320a88c5fdb2ad3e2").unwrap();
let match_txids: Vec<Txid> = vec![txid].into_iter().collect();
let mb = MerkleBlock::from_block_with_predicate(&block, |t| match_txids.contains(t));

// Authenticate and extract matched transaction ids
let mut matches: Vec<Txid> = vec![];
let mut index: Vec<u32> = vec![];
assert!(mb.extract_matches(&mut matches, &mut index).is_ok());
assert_eq!(txid, matches[0]);

pub fn from_block(block: &Block, match_txids: &HashSet<Txid>) -> MerkleBlock

👎Deprecated since 0.26.2: use from_block_with_predicate

Create a MerkleBlock from a block, that contains proofs for specific txids.

pub fn from_header_txids_with_predicate<F>( header: &BlockHeader, block_txids: &[Txid], match_txids: F, ) -> MerkleBlock
where F: Fn(&Txid) -> bool,

Create a MerkleBlock from the block’s header and txids, that contain proofs for specific txids.

The header is the block header, block_txids is the full list of txids included in the block and match_txids is a function that returns true for the ids that should be included in the partial merkle tree.

pub fn from_header_txids( header: &BlockHeader, block_txids: &[Txid], match_txids: &HashSet<Txid>, ) -> MerkleBlock

👎Deprecated since 0.26.2: use from_header_txids_with_predicate

Create a MerkleBlock from the block’s header and txids, that should contain proofs for match_txids.

pub fn extract_matches( &self, matches: &mut Vec<Txid>, indexes: &mut Vec<u32>, ) -> Result<(), MerkleBlockError>

Extract the matching txid’s represented by this partial merkle tree and their respective indices within the partial tree. returns Ok(()) on success, or error in case of failure

Trait Implementations§

§

impl Clone for MerkleBlock

§

fn clone(&self) -> MerkleBlock

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for MerkleBlock

§

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

Formats the value using the given formatter. Read more
§

impl Decodable for MerkleBlock

§

fn consensus_decode<R>(r: &mut R) -> Result<MerkleBlock, Error>
where R: Read + ?Sized,

Decode an object with a well-defined format. Read more
§

fn consensus_decode_from_finite_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + ?Sized,

Decode Self from a size-limited reader. Read more
§

impl Encodable for MerkleBlock

§

fn consensus_encode<W>(&self, w: &mut W) -> Result<usize, Error>
where W: Write + ?Sized,

Encode an object with a well-defined format. Returns the number of bytes written on success. Read more
§

impl PartialEq for MerkleBlock

§

fn eq(&self, other: &MerkleBlock) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Eq for MerkleBlock

§

impl StructuralPartialEq for MerkleBlock

Auto Trait Implementations§

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
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

§

impl<T> AsAny for T
where T: Any,

§

fn as_any(&self) -> &(dyn Any + 'static)

§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

§

fn type_name(&self) -> &'static str

Gets the type name of self
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> Downcast for T
where T: AsAny + ?Sized,

§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

source§

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>,

source§

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

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DartSafe for T