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: u32BEEF 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
impl Beef
Sourcepub fn from_binary(reader: &mut impl Read) -> Result<Self, TransactionError>
pub fn from_binary(reader: &mut impl Read) -> Result<Self, TransactionError>
Deserialize a Beef from binary format.
Sourcepub fn to_binary(&self, writer: &mut impl Write) -> Result<(), TransactionError>
pub fn to_binary(&self, writer: &mut impl Write) -> Result<(), TransactionError>
Serialize this Beef to binary format.
Sourcepub fn from_hex(hex: &str) -> Result<Self, TransactionError>
pub fn from_hex(hex: &str) -> Result<Self, TransactionError>
Deserialize a Beef from a hex string.
Sourcepub fn to_hex(&self) -> Result<String, TransactionError>
pub fn to_hex(&self) -> Result<String, TransactionError>
Serialize this Beef to a hex string.
Sourcepub fn into_transaction(self) -> Result<Transaction, TransactionError>
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.
Sourcepub fn sort_txs(&mut self)
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.
Sourcepub fn merge_bump(
&mut self,
bump: &MerklePath,
) -> Result<usize, TransactionError>
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.
Sourcepub fn merge_raw_tx(
&mut self,
raw_tx: &[u8],
bump_index: Option<usize>,
) -> Result<BeefTx, TransactionError>
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.
Sourcepub fn merge_beef(&mut self, other: &Beef) -> Result<(), TransactionError>
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).
Sourcepub fn merge_beef_from_binary(
&mut self,
data: &[u8],
) -> Result<(), TransactionError>
pub fn merge_beef_from_binary( &mut self, data: &[u8], ) -> Result<(), TransactionError>
Merge a Beef from binary data into this one.
Sourcepub fn to_binary_atomic(&self, txid: &str) -> Result<Vec<u8>, TransactionError>
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.