Skip to content

Commit b650336

Browse files
committed
ledger-rpc_api: Add check_transaction.
1 parent 0bf9d55 commit b650336

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/client/rpc_api.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ impl RpcApi for Client {
7575

7676
self.ledger.add_transaction_unconditionally(tx.clone());
7777

78+
if !self.ledger.check_transaction(tx.clone()) {
79+
return Err(bitcoincore_rpc::Error::Io(std::io::Error::other(
80+
"Transaction not valid.",
81+
)));
82+
}
83+
7884
Ok(tx.compute_txid())
7985
}
8086

@@ -140,8 +146,6 @@ impl RpcApi for Client {
140146

141147
let txid = self.send_raw_transaction(&tx)?;
142148

143-
self.ledger.add_transaction_unconditionally(tx);
144-
145149
Ok(txid)
146150
}
147151

src/ledger/transactions.rs

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ impl Ledger {
3636
pub fn get_transactions(&self) -> Vec<Transaction> {
3737
get_item!(self.transactions);
3838
}
39+
/// Checks if a transaction is OK or not.
40+
pub fn check_transaction(&self, transaction: Transaction) -> bool {
41+
println!("check tr");
42+
if let Ok(()) = self
43+
.database
44+
.lock()
45+
.unwrap()
46+
.verify_transaction(&transaction)
47+
{
48+
println!("check tr1");
49+
return true;
50+
};
51+
52+
println!("check tr2");
53+
false
54+
}
3955
}
4056

4157
#[cfg(test)]

0 commit comments

Comments
 (0)