From: Jeffrey Czyz Date: Wed, 10 Mar 2021 17:13:21 +0000 (-0800) Subject: Return optional Transaction from register_output X-Git-Tag: v0.0.14~42^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d70fdd3a5c7bb2f240ef9de0fa075494b3923fe5;p=rust-lightning Return optional Transaction from register_output Electrum clients primarily operate by subscribing to notifications of transactions by script pubkeys. Therefore, they will send filtered transaction data without including dependent transactions. Outputs for such transactions must be explicitly registered with these clients. Therefore, upon block_connected, provide a mechanism for an Electrum- backed chain::Filter to return new transaction data to scan. --- diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index 7d410b9b7..67ae5b347 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -11,7 +11,7 @@ use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::script::Script; -use bitcoin::blockdata::transaction::TxOut; +use bitcoin::blockdata::transaction::{Transaction, TxOut}; use bitcoin::hash_types::{BlockHash, Txid}; use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent}; @@ -131,7 +131,10 @@ pub trait Filter: Send + Sync { /// Registers interest in spends of a transaction output identified by `outpoint` having /// `script_pubkey` as the spending condition. - fn register_output(&self, outpoint: &OutPoint, script_pubkey: &Script); + /// + /// Optionally, returns any transaction dependent on the output. This is useful for Electrum + /// clients to facilitate registering in-block descendants. + fn register_output(&self, outpoint: &OutPoint, script_pubkey: &Script) -> Option<(usize, Transaction)>; } impl Listen for std::ops::Deref { diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index a0ccf4f81..d2ba044e9 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -546,7 +546,8 @@ impl chain::Filter for TestChainSource { self.watched_txn.lock().unwrap().insert((*txid, script_pubkey.clone())); } - fn register_output(&self, outpoint: &OutPoint, script_pubkey: &Script) { + fn register_output(&self, outpoint: &OutPoint, script_pubkey: &Script) -> Option<(usize, Transaction)> { self.watched_outputs.lock().unwrap().insert((*outpoint, script_pubkey.clone())); + None } }