]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Return optional Transaction from register_output
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 10 Mar 2021 17:13:21 +0000 (09:13 -0800)
committerJeffrey Czyz <jkczyz@gmail.com>
Sun, 21 Mar 2021 04:54:36 +0000 (00:54 -0400)
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.

lightning/src/chain/mod.rs
lightning/src/util/test_utils.rs

index 7d410b9b71dd116cbe22d2858e9664ec6bc14381..67ae5b347f9d94b029f93333fbb68dc6e23f9518 100644 (file)
@@ -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<T: Listen> Listen for std::ops::Deref<Target = T> {
index a0ccf4f816ea991e31a019351018d43a95633324..d2ba044e902e1ac943118aa16d137cc6da97d2c5 100644 (file)
@@ -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
        }
 }