Use From trait for conversion

This commit is contained in:
Sudarsan Balaji 2021-11-05 01:08:50 +05:30
parent 358cc35b60
commit c6c4446092

View File

@ -82,7 +82,8 @@ pub enum Transaction {
}, },
} }
fn to_transaction(x: &bdk::TransactionDetails) -> Transaction { impl From<&bdk::TransactionDetails> for Transaction {
fn from(x: &bdk::TransactionDetails) -> Transaction {
let details = TransactionDetails { let details = TransactionDetails {
fees: x.fee, fees: x.fee,
id: x.txid.to_string(), id: x.txid.to_string(),
@ -97,6 +98,7 @@ fn to_transaction(x: &bdk::TransactionDetails) -> Transaction {
None => Transaction::Unconfirmed { details }, None => Transaction::Unconfirmed { details },
} }
} }
}
trait OfflineWalletOperations<B>: WalletHolder<B> { trait OfflineWalletOperations<B>: WalletHolder<B> {
fn get_new_address(&self) -> String { fn get_new_address(&self) -> String {
@ -133,7 +135,7 @@ trait OfflineWalletOperations<B>: WalletHolder<B> {
fn get_transactions(&self) -> Result<Vec<Transaction>, Error> { fn get_transactions(&self) -> Result<Vec<Transaction>, Error> {
let transactions = self.get_wallet().list_transactions(true)?; let transactions = self.get_wallet().list_transactions(true)?;
Ok(transactions.iter().map(to_transaction).collect()) Ok(transactions.iter().map(Transaction::from).collect())
} }
} }
@ -275,7 +277,7 @@ impl OnlineWallet {
) -> Result<Transaction, Error> { ) -> Result<Transaction, Error> {
let tx = psbt.internal.lock().unwrap().clone().extract_tx(); let tx = psbt.internal.lock().unwrap().clone().extract_tx();
self.get_wallet().broadcast(tx)?; self.get_wallet().broadcast(tx)?;
Ok(to_transaction(&psbt.details)) Ok(Transaction::from(&psbt.details))
} }
} }