|
14 | 14 | //! disconnections, transaction broadcasting, and feerate information requests.
|
15 | 15 |
|
16 | 16 | use bitcoin::blockdata::transaction::Transaction;
|
17 |
| -use bitcoin::blockdata::script::Script; |
18 |
| -use bitcoin::hash_types::Txid; |
19 |
| - |
20 |
| -use std::collections::HashSet; |
21 | 17 |
|
22 | 18 | /// An interface to send a transaction to the Bitcoin network.
|
23 | 19 | pub trait BroadcasterInterface: Sync + Send {
|
@@ -55,91 +51,3 @@ pub trait FeeEstimator: Sync + Send {
|
55 | 51 |
|
56 | 52 | /// Minimum relay fee as required by bitcoin network mempool policy.
|
57 | 53 | pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;
|
58 |
| - |
59 |
| -/// Utility for tracking registered txn/outpoints and checking for matches |
60 |
| -#[cfg_attr(test, derive(PartialEq))] |
61 |
| -pub struct ChainWatchedUtil { |
62 |
| - watch_all: bool, |
63 |
| - |
64 |
| - // We are more conservative in matching during testing to ensure everything matches *exactly*, |
65 |
| - // even though during normal runtime we take more optimized match approaches... |
66 |
| - #[cfg(test)] |
67 |
| - watched_txn: HashSet<(Txid, Script)>, |
68 |
| - #[cfg(not(test))] |
69 |
| - watched_txn: HashSet<Script>, |
70 |
| - |
71 |
| - watched_outpoints: HashSet<(Txid, u32)>, |
72 |
| -} |
73 |
| - |
74 |
| -impl ChainWatchedUtil { |
75 |
| - /// Constructs an empty (watches nothing) ChainWatchedUtil |
76 |
| - pub fn new() -> Self { |
77 |
| - Self { |
78 |
| - watch_all: false, |
79 |
| - watched_txn: HashSet::new(), |
80 |
| - watched_outpoints: HashSet::new(), |
81 |
| - } |
82 |
| - } |
83 |
| - |
84 |
| - /// Registers a tx for monitoring, returning true if it was a new tx and false if we'd already |
85 |
| - /// been watching for it. |
86 |
| - pub fn register_tx(&mut self, txid: &Txid, script_pub_key: &Script) -> bool { |
87 |
| - if self.watch_all { return false; } |
88 |
| - #[cfg(test)] |
89 |
| - { |
90 |
| - self.watched_txn.insert((txid.clone(), script_pub_key.clone())) |
91 |
| - } |
92 |
| - #[cfg(not(test))] |
93 |
| - { |
94 |
| - let _tx_unused = txid; // It's used in cfg(test), though |
95 |
| - self.watched_txn.insert(script_pub_key.clone()) |
96 |
| - } |
97 |
| - } |
98 |
| - |
99 |
| - /// Registers an outpoint for monitoring, returning true if it was a new outpoint and false if |
100 |
| - /// we'd already been watching for it |
101 |
| - pub fn register_outpoint(&mut self, outpoint: (Txid, u32), _script_pub_key: &Script) -> bool { |
102 |
| - if self.watch_all { return false; } |
103 |
| - self.watched_outpoints.insert(outpoint) |
104 |
| - } |
105 |
| - |
106 |
| - /// Sets us to match all transactions, returning true if this is a new setting and false if |
107 |
| - /// we'd already been set to match everything. |
108 |
| - pub fn watch_all(&mut self) -> bool { |
109 |
| - if self.watch_all { return false; } |
110 |
| - self.watch_all = true; |
111 |
| - true |
112 |
| - } |
113 |
| - |
114 |
| - /// Checks if a given transaction matches the current filter. |
115 |
| - pub fn does_match_tx(&self, tx: &Transaction) -> bool { |
116 |
| - if self.watch_all { |
117 |
| - return true; |
118 |
| - } |
119 |
| - for out in tx.output.iter() { |
120 |
| - #[cfg(test)] |
121 |
| - for &(ref txid, ref script) in self.watched_txn.iter() { |
122 |
| - if *script == out.script_pubkey { |
123 |
| - if tx.txid() == *txid { |
124 |
| - return true; |
125 |
| - } |
126 |
| - } |
127 |
| - } |
128 |
| - #[cfg(not(test))] |
129 |
| - for script in self.watched_txn.iter() { |
130 |
| - if *script == out.script_pubkey { |
131 |
| - return true; |
132 |
| - } |
133 |
| - } |
134 |
| - } |
135 |
| - for input in tx.input.iter() { |
136 |
| - for outpoint in self.watched_outpoints.iter() { |
137 |
| - let &(outpoint_hash, outpoint_index) = outpoint; |
138 |
| - if outpoint_hash == input.previous_output.txid && outpoint_index == input.previous_output.vout { |
139 |
| - return true; |
140 |
| - } |
141 |
| - } |
142 |
| - } |
143 |
| - false |
144 |
| - } |
145 |
| -} |
0 commit comments