diff --git a/src/client/rpc_api.rs b/src/client/rpc_api.rs index ad17ef0..e241736 100644 --- a/src/client/rpc_api.rs +++ b/src/client/rpc_api.rs @@ -43,12 +43,7 @@ impl RpcApi for Client { txid: &bitcoin::Txid, _block_hash: Option<&bitcoin::BlockHash>, ) -> bitcoincore_rpc::Result { - Ok(self - .database - .lock() - .unwrap() - .get_transaction(&txid.to_string()) - .unwrap()) + Ok(self.ledger.get_transaction(*txid)) } fn send_raw_transaction( @@ -57,11 +52,7 @@ impl RpcApi for Client { ) -> bitcoincore_rpc::Result { let tx: Transaction = encode::deserialize_hex(&tx.raw_hex()).unwrap(); - self.database - .lock() - .unwrap() - .insert_transaction_unconditionally(&tx) - .unwrap(); + self.ledger.add_transaction_unconditionally(tx.clone()); Ok(tx.compute_txid()) } @@ -191,11 +182,7 @@ impl RpcApi for Client { output: vec![txout], }; - self.database - .lock() - .unwrap() - .insert_transaction_unconditionally(&tx) - .unwrap(); + self.ledger.add_transaction_unconditionally(tx.clone()); for output in tx.output { self.ledger.add_utxo(output); diff --git a/src/ledger/transactions.rs b/src/ledger/transactions.rs index 783ee1a..950f4fe 100644 --- a/src/ledger/transactions.rs +++ b/src/ledger/transactions.rs @@ -2,7 +2,7 @@ use super::Ledger; use crate::{add_item, get_item}; -use bitcoin::{Transaction, TxOut}; +use bitcoin::{Transaction, TxOut, Txid}; impl Ledger { /// Adds a new UTXO to user's UTXO's. @@ -25,6 +25,14 @@ impl Ledger { add_item!(self.transactions, transaction); } /// Returns user's list of transactions. + pub fn get_transaction(&self, txid: Txid) -> Transaction { + self.database + .lock() + .unwrap() + .get_transaction(&txid.to_string()) + .unwrap() + } + /// Returns user's list of transactions. pub fn get_transactions(&self) -> Vec { get_item!(self.transactions); }