X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Fchain%2Ftransaction.rs;h=502eb895b2683e4ad3b7fa5bc34f367111781ede;hb=e84f5edbc5b959c7bbad17b5968f2c9e32df68df;hp=d490797bc8e74cc541d1c4db4269d876991c9324;hpb=2087032e7a823f6c63a64dac951e0f4843bc4667;p=rust-lightning diff --git a/lightning/src/chain/transaction.rs b/lightning/src/chain/transaction.rs index d490797b..502eb895 100644 --- a/lightning/src/chain/transaction.rs +++ b/lightning/src/chain/transaction.rs @@ -1,7 +1,47 @@ -//! Contains simple structs describing parts of transactions on the chain. +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + +//! 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. /// @@ -26,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,