Clean up conversion between BDK TransactionDetails to ffi TransactionDetails
This commit is contained in:
parent
2f62377eec
commit
f003a6275e
@ -15,7 +15,7 @@ use crate::keys::{DescriptorPublicKey, DescriptorSecretKey, Mnemonic};
|
|||||||
use crate::psbt::PartiallySignedTransaction;
|
use crate::psbt::PartiallySignedTransaction;
|
||||||
use crate::wallet::{BumpFeeTxBuilder, TxBuilder, Wallet};
|
use crate::wallet::{BumpFeeTxBuilder, TxBuilder, Wallet};
|
||||||
use bdk::bitcoin::blockdata::script::Script as BdkScript;
|
use bdk::bitcoin::blockdata::script::Script as BdkScript;
|
||||||
use bdk::bitcoin::consensus::{serialize, Decodable};
|
use bdk::bitcoin::consensus::Decodable;
|
||||||
use bdk::bitcoin::psbt::serialize::Serialize;
|
use bdk::bitcoin::psbt::serialize::Serialize;
|
||||||
use bdk::bitcoin::{
|
use bdk::bitcoin::{
|
||||||
Address as BdkAddress, Network, OutPoint as BdkOutPoint, Transaction as BdkTransaction, Txid,
|
Address as BdkAddress, Network, OutPoint as BdkOutPoint, Transaction as BdkTransaction, Txid,
|
||||||
@ -117,23 +117,18 @@ pub struct TransactionDetails {
|
|||||||
pub confirmation_time: Option<BlockTime>,
|
pub confirmation_time: Option<BlockTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&bdk::TransactionDetails> for TransactionDetails {
|
impl From<bdk::TransactionDetails> for TransactionDetails {
|
||||||
fn from(x: &bdk::TransactionDetails) -> TransactionDetails {
|
fn from(tx_details: bdk::TransactionDetails) -> Self {
|
||||||
let potential_tx: Option<Arc<Transaction>> = match &x.transaction {
|
let optional_tx: Option<Arc<Transaction>> =
|
||||||
Some(tx) => {
|
tx_details.transaction.map(|tx| Arc::new(tx.into()));
|
||||||
let buffer: Vec<u8> = serialize(tx);
|
|
||||||
Some(Arc::new(Transaction::new(buffer).unwrap()))
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
TransactionDetails {
|
TransactionDetails {
|
||||||
transaction: potential_tx,
|
transaction: optional_tx,
|
||||||
fee: x.fee,
|
fee: tx_details.fee,
|
||||||
txid: x.txid.to_string(),
|
txid: tx_details.txid.to_string(),
|
||||||
received: x.received,
|
received: tx_details.received,
|
||||||
sent: x.sent,
|
sent: tx_details.sent,
|
||||||
confirmation_time: x.confirmation_time.clone(),
|
confirmation_time: tx_details.confirmation_time,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,6 +335,12 @@ impl Transaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<bdk::bitcoin::Transaction> for Transaction {
|
||||||
|
fn from(tx: bdk::bitcoin::Transaction) -> Self {
|
||||||
|
Transaction { internal: tx }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A Bitcoin address.
|
/// A Bitcoin address.
|
||||||
struct Address {
|
struct Address {
|
||||||
address: BdkAddress,
|
address: BdkAddress,
|
||||||
|
@ -126,7 +126,7 @@ impl Wallet {
|
|||||||
) -> Result<Vec<TransactionDetails>, BdkError> {
|
) -> Result<Vec<TransactionDetails>, BdkError> {
|
||||||
let transaction_details = self.get_wallet().list_transactions(include_raw)?;
|
let transaction_details = self.get_wallet().list_transactions(include_raw)?;
|
||||||
Ok(transaction_details
|
Ok(transaction_details
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(TransactionDetails::from)
|
.map(TransactionDetails::from)
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
@ -376,7 +376,7 @@ impl TxBuilder {
|
|||||||
psbt: Arc::new(PartiallySignedTransaction {
|
psbt: Arc::new(PartiallySignedTransaction {
|
||||||
internal: Mutex::new(psbt),
|
internal: Mutex::new(psbt),
|
||||||
}),
|
}),
|
||||||
transaction_details: TransactionDetails::from(&tx_details),
|
transaction_details: TransactionDetails::from(tx_details),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user