|
1 |
| -use bitcoin::{secp256k1::PublicKey, ScriptBuf, TxOut}; |
| 1 | +use bitcoin::{secp256k1::PublicKey, ScriptBuf, Transaction, TxOut}; |
2 | 2 |
|
3 | 3 | #[derive(Clone)]
|
4 | 4 | pub struct PayjoinScheduler {
|
5 | 5 | channels: Vec<PayjoinChannel>,
|
| 6 | + seen_txs: Vec<Transaction>, |
6 | 7 | }
|
7 | 8 |
|
8 | 9 | impl PayjoinScheduler {
|
9 | 10 | /// Create a new empty channel scheduler.
|
10 | 11 | pub fn new() -> Self {
|
11 |
| - Self { channels: vec![] } |
| 12 | + Self { channels: vec![], seen_txs: vec![] } |
12 | 13 | }
|
13 | 14 | /// Schedule a new channel.
|
14 | 15 | ///
|
@@ -115,6 +116,29 @@ impl PayjoinScheduler {
|
115 | 116 | pub fn in_progress(&self) -> bool {
|
116 | 117 | self.channels.iter().any(|channel| !channel.is_channel_accepted())
|
117 | 118 | }
|
| 119 | + |
| 120 | + pub fn add_seen_tx(&mut self, tx: &Transaction) -> bool { |
| 121 | + for input in tx.input.iter() { |
| 122 | + for tx in self.seen_txs.clone() { |
| 123 | + if tx.input.contains(&input) { |
| 124 | + return false; |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + self.seen_txs.push(tx.clone()); |
| 129 | + return true; |
| 130 | + } |
| 131 | + |
| 132 | + // pub fn seen_outpoints(&self, tx: &bitcoin::Transaction) -> bool { |
| 133 | + // tx.input.iter().any(|input| self.seen_outpoints_internal(&input.previous_output)) |
| 134 | + // } |
| 135 | + |
| 136 | + // fn seen_outpoints_internal(&self, outpoint: &bitcoin::OutPoint) -> bool { |
| 137 | + // self.seen_txs |
| 138 | + // .iter() |
| 139 | + // .any(|seen_tx| seen_tx.input.iter().any(|input| &input.previous_output == outpoint)) |
| 140 | + // } |
| 141 | + |
118 | 142 | fn internal_find_by_tx_out(&self, txout: &TxOut) -> Option<PayjoinChannel> {
|
119 | 143 | let channel = self.channels.iter().find(|channel| {
|
120 | 144 | return Some(&txout.script_pubkey) == channel.output_script();
|
|
0 commit comments