Skip to content

Commit accf6a8

Browse files
committed
add payjoin scheduler
1 parent e1799ce commit accf6a8

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Diff for: src/payjoin_scheduler.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
use bitcoin::{secp256k1::PublicKey, ScriptBuf, TxOut};
1+
use bitcoin::{secp256k1::PublicKey, ScriptBuf, Transaction, TxOut};
22

33
#[derive(Clone)]
44
pub struct PayjoinScheduler {
55
channels: Vec<PayjoinChannel>,
6+
seen_txs: Vec<Transaction>,
67
}
78

89
impl PayjoinScheduler {
910
/// Create a new empty channel scheduler.
1011
pub fn new() -> Self {
11-
Self { channels: vec![] }
12+
Self { channels: vec![], seen_txs: vec![] }
1213
}
1314
/// Schedule a new channel.
1415
///
@@ -115,6 +116,29 @@ impl PayjoinScheduler {
115116
pub fn in_progress(&self) -> bool {
116117
self.channels.iter().any(|channel| !channel.is_channel_accepted())
117118
}
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+
118142
fn internal_find_by_tx_out(&self, txout: &TxOut) -> Option<PayjoinChannel> {
119143
let channel = self.channels.iter().find(|channel| {
120144
return Some(&txout.script_pubkey) == channel.output_script();

0 commit comments

Comments
 (0)