Skip to main content

Beef

Struct Beef 

Source
pub struct Beef {
    pub version: u32,
    pub bumps: Vec<MerklePath>,
    pub txs: Vec<BeefTx>,
    pub atomic_txid: Option<String>,
}
Expand description

A BEEF (Background Evaluation Extended Format) container.

Contains a set of BUMPs (Merkle paths) and transactions that together form a validity proof chain for SPV verification.

Fields§

§version: u32

BEEF version (BEEF_V1 or BEEF_V2).

§bumps: Vec<MerklePath>

Merkle paths (BUMPs) proving transaction inclusion in blocks.

§txs: Vec<BeefTx>

Transactions with BEEF metadata.

§atomic_txid: Option<String>

For Atomic BEEF: the txid of the proven transaction.

Implementations§

Source§

impl Beef

Source

pub fn new(version: u32) -> Self

Create a new empty Beef with the given version.

Source

pub fn from_binary(reader: &mut impl Read) -> Result<Self, TransactionError>

Deserialize a Beef from binary format.

Source

pub fn to_binary(&self, writer: &mut impl Write) -> Result<(), TransactionError>

Serialize this Beef to binary format.

Source

pub fn from_hex(hex: &str) -> Result<Self, TransactionError>

Deserialize a Beef from a hex string.

Source

pub fn to_hex(&self) -> Result<String, TransactionError>

Serialize this Beef to a hex string.

Source

pub fn into_transaction(self) -> Result<Transaction, TransactionError>

Extract the subject transaction from this BEEF, consuming it.

If atomic_txid is set, returns the transaction matching that txid. Otherwise, returns the last transaction (the subject). Before returning, links source transactions from the BEEF for each input.

Source

pub fn sort_txs(&mut self)

Topologically sort transactions by dependency order.

Uses Kahn’s algorithm. Proven transactions (with bump_index) and those with no in-BEEF dependencies come first; dependent transactions follow.

Source

pub fn find_txid(&self, txid: &str) -> Option<&BeefTx>

Find a BeefTx by txid.

Source

pub fn merge_bump( &mut self, bump: &MerklePath, ) -> Result<usize, TransactionError>

Merge a MerklePath (BUMP) that is assumed to be fully valid.

If an identical bump (same block height, same computed root) already exists, combines them. Otherwise appends a new bump.

After merging, scans transactions to assign bump indices to any that match a leaf in the merged bump.

Returns the index of the merged bump.

Source

pub fn merge_raw_tx( &mut self, raw_tx: &[u8], bump_index: Option<usize>, ) -> Result<BeefTx, TransactionError>

Merge a raw serialized transaction into this BEEF.

Replaces any existing transaction with the same txid.

If bump_index is provided, it must be a valid index into self.bumps.

Source

pub fn merge_beef(&mut self, other: &Beef) -> Result<(), TransactionError>

Merge another Beef into this one.

All BUMPs from other are merged first (deduplicating by block height + root), then all transactions are merged (replacing any with matching txids).

Source

pub fn merge_beef_from_binary( &mut self, data: &[u8], ) -> Result<(), TransactionError>

Merge a Beef from binary data into this one.

Source

pub fn to_binary_atomic(&self, txid: &str) -> Result<Vec<u8>, TransactionError>

Serialize this Beef as Atomic BEEF (BRC-95) for a specific transaction.

The target txid must exist in this Beef. After sorting by dependency order, if the target transaction is not the last one, transactions after it are excluded.

The output format is: ATOMIC_BEEF(4 bytes) + txid(32 bytes LE) + BEEF binary.

Trait Implementations§

Source§

impl Clone for Beef

Source§

fn clone(&self) -> Beef

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Beef

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Beef

§

impl RefUnwindSafe for Beef

§

impl Send for Beef

§

impl Sync for Beef

§

impl Unpin for Beef

§

impl UnsafeUnpin for Beef

§

impl UnwindSafe for Beef

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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.