// 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.
///
use ln::chan_utils::{CounterpartyCommitmentSecrets, HolderCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, PreCalculatedTxCreationKeys};
use ln::chan_utils;
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
-use chain::transaction::OutPoint;
+use chain::transaction::{OutPoint, TransactionData};
use chain::keysinterface::{ChannelKeys, KeysInterface};
use util::transaction_utils;
use util::ser::{Readable, Writeable, Writer};
///
/// May return some HTLCs (and their payment_hash) which have timed out and should be failed
/// back.
- pub fn block_connected(&mut self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) -> Result<(Option<msgs::FundingLocked>, Vec<(HTLCSource, PaymentHash)>), msgs::ErrorMessage> {
+ pub fn block_connected(&mut self, header: &BlockHeader, txdata: &TransactionData, height: u32) -> Result<(Option<msgs::FundingLocked>, Vec<(HTLCSource, PaymentHash)>), msgs::ErrorMessage> {
let mut timed_out_htlcs = Vec::new();
self.holding_cell_htlc_updates.retain(|htlc_update| {
match htlc_update {
use bitcoin::blockdata::block::BlockHeader;
use bitcoin::blockdata::constants::genesis_block;
-use bitcoin::blockdata::transaction::Transaction;
use bitcoin::network::constants::Network;
use bitcoin::hashes::{Hash, HashEngine};
use chain;
use chain::Watch;
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
-use chain::transaction::OutPoint;
+use chain::transaction::{OutPoint, TransactionData};
use ln::channel::{Channel, ChannelError};
use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent};
use ln::features::{InitFeatures, NodeFeatures};
L::Target: Logger,
{
/// Updates channel state based on transactions seen in a connected block.
- pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
+ pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
let header_hash = header.block_hash();
log_trace!(self.logger, "Block {} at height {} connected", header_hash, height);
let _ = self.total_consistency_lock.read().unwrap();
use chain;
use chain::Filter;
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
-use chain::transaction::OutPoint;
+use chain::transaction::{OutPoint, TransactionData};
use chain::keysinterface::{SpendableOutputDescriptor, ChannelKeys};
use util::logger::Logger;
use util::ser::{Readable, MaybeReadable, Writer, Writeable, U48};
/// [`ChannelMonitor::block_connected`]: struct.ChannelMonitor.html#method.block_connected
/// [`chain::Watch::release_pending_monitor_events`]: ../../chain/trait.Watch.html#tymethod.release_pending_monitor_events
/// [`chain::Filter`]: ../../chain/trait.Filter.html
- pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) -> bool {
+ pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) -> bool {
let mut has_new_outputs_to_watch = false;
{
let mut monitors = self.monitors.lock().unwrap();
/// [`get_outputs_to_watch`].
///
/// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
- pub fn block_connected<B: Deref, F: Deref, L: Deref>(&mut self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32, broadcaster: B, fee_estimator: F, logger: L)-> Vec<(Txid, Vec<TxOut>)>
+ pub fn block_connected<B: Deref, F: Deref, L: Deref>(&mut self, header: &BlockHeader, txdata: &TransactionData, height: u32, broadcaster: B, fee_estimator: F, logger: L)-> Vec<(Txid, Vec<TxOut>)>
where B::Target: BroadcasterInterface,
F::Target: FeeEstimator,
L::Target: Logger,
/// Filters a block's `txdata` for transactions spending watched outputs or for any child
/// transactions thereof.
- fn filter_block<'a>(&self, txdata: &[(usize, &'a Transaction)]) -> Vec<&'a Transaction> {
+ fn filter_block<'a>(&self, txdata: &TransactionData<'a>) -> Vec<&'a Transaction> {
let mut matched_txn = HashSet::new();
txdata.iter().filter(|&&(_, tx)| {
let mut matches = self.spends_watched_output(tx);