X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Ftransaction.rs;h=0219ebbe8cad9631e1f2fef8c7b05600828e9f24;hb=28c9b56113ff1ebb1b505a2c979c55c1626aa06b;hp=c4917313f2988045a79c656945f76ddaffb75398;hpb=4395b92cc8bfe0cc803e70bba11f4db58d5d0dbf;p=rust-lightning diff --git a/lightning/src/chain/transaction.rs b/lightning/src/chain/transaction.rs index c4917313..0219ebbe 100644 --- a/lightning/src/chain/transaction.rs +++ b/lightning/src/chain/transaction.rs @@ -7,10 +7,41 @@ // You may not use this file except in accordance with one or both of these // licenses. -//! Contains simple structs describing parts of transactions on the chain. +//! Types describing on-chain transactions. use bitcoin::hash_types::Txid; use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint; +use bitcoin::blockdata::transaction::Transaction; + +/// Transaction data where each item consists of a transaction reference paired with the index of +/// the transaction within a block. +/// +/// Useful for passing enumerated transactions from a block, possibly filtered, in order to retain +/// the transaction index. +/// +/// ``` +/// extern crate bitcoin; +/// extern crate lightning; +/// +/// use bitcoin::blockdata::block::Block; +/// use bitcoin::blockdata::constants::genesis_block; +/// use bitcoin::network::constants::Network; +/// use lightning::chain::transaction::TransactionData; +/// +/// let block = genesis_block(Network::Bitcoin); +/// let txdata: Vec<_> = block.txdata.iter().enumerate().collect(); +/// check_block(&block, &txdata); +/// +/// fn check_block(block: &Block, txdata: &TransactionData) { +/// assert_eq!(block.txdata.len(), 1); +/// assert_eq!(txdata.len(), 1); +/// +/// let (index, tx) = txdata[0]; +/// assert_eq!(index, 0); +/// assert_eq!(tx, &block.txdata[0]); +/// } +/// ``` +pub type TransactionData<'a> = [(usize, &'a Transaction)]; /// A reference to a transaction output. /// @@ -35,6 +66,7 @@ impl OutPoint { } /// Converts this OutPoint into the OutPoint field as used by rust-bitcoin + /// (C-not exported) as the same type is used universally in the C bindings for all outpoints pub fn into_bitcoin_outpoint(self) -> BitcoinOutPoint { BitcoinOutPoint { txid: self.txid, @@ -43,7 +75,7 @@ impl OutPoint { } } -impl_writeable!(OutPoint, 0, { txid, index }); +impl_writeable!(OutPoint, { txid, index }); #[cfg(test)] mod tests {