Add optional transaction field on the TransactionDetails type
This commit is contained in:
parent
40ca62086c
commit
7557e214c8
@ -94,6 +94,7 @@ interface DatabaseConfig {
|
|||||||
};
|
};
|
||||||
|
|
||||||
dictionary TransactionDetails {
|
dictionary TransactionDetails {
|
||||||
|
Transaction? transaction;
|
||||||
u64? fee;
|
u64? fee;
|
||||||
u64 received;
|
u64 received;
|
||||||
u64 sent;
|
u64 sent;
|
||||||
@ -186,6 +187,13 @@ dictionary OutPoint {
|
|||||||
u32 vout;
|
u32 vout;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary TxIn {
|
||||||
|
OutPoint previous_output;
|
||||||
|
Script script_sig;
|
||||||
|
u32 sequence;
|
||||||
|
sequence<sequence<u8>> witness;
|
||||||
|
};
|
||||||
|
|
||||||
dictionary TxOut {
|
dictionary TxOut {
|
||||||
u64 value;
|
u64 value;
|
||||||
Script script_pubkey;
|
Script script_pubkey;
|
||||||
@ -262,6 +270,14 @@ interface Transaction {
|
|||||||
boolean is_explicitly_rbf();
|
boolean is_explicitly_rbf();
|
||||||
|
|
||||||
boolean is_lock_time_enabled();
|
boolean is_lock_time_enabled();
|
||||||
|
|
||||||
|
i32 version();
|
||||||
|
|
||||||
|
u32 lock_time();
|
||||||
|
|
||||||
|
sequence<TxIn> inputs();
|
||||||
|
|
||||||
|
sequence<TxOut> outputs();
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PartiallySignedTransaction {
|
interface PartiallySignedTransaction {
|
||||||
|
@ -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::Decodable;
|
use bdk::bitcoin::consensus::{Decodable, serialize};
|
||||||
use bdk::bitcoin::psbt::serialize::Serialize;
|
use bdk::bitcoin::psbt::serialize::Serialize;
|
||||||
use bdk::bitcoin::{Address as BdkAddress, Network, OutPoint as BdkOutPoint, Transaction as BdkTransaction, Txid};
|
use bdk::bitcoin::{Address as BdkAddress, Network, OutPoint as BdkOutPoint, Transaction as BdkTransaction, Txid};
|
||||||
use bdk::blockchain::Progress as BdkProgress;
|
use bdk::blockchain::Progress as BdkProgress;
|
||||||
@ -94,8 +94,9 @@ impl From<AddressIndex> for BdkAddressIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A wallet transaction
|
/// A wallet transaction
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct TransactionDetails {
|
pub struct TransactionDetails {
|
||||||
|
pub transaction: Option<Arc<Transaction>>,
|
||||||
/// Transaction id.
|
/// Transaction id.
|
||||||
pub txid: String,
|
pub txid: String,
|
||||||
/// Received value (sats)
|
/// Received value (sats)
|
||||||
@ -116,7 +117,16 @@ pub struct TransactionDetails {
|
|||||||
|
|
||||||
impl From<&bdk::TransactionDetails> for TransactionDetails {
|
impl From<&bdk::TransactionDetails> for TransactionDetails {
|
||||||
fn from(x: &bdk::TransactionDetails) -> TransactionDetails {
|
fn from(x: &bdk::TransactionDetails) -> TransactionDetails {
|
||||||
|
let potential_tx: Option<Arc<Transaction>> = match &x.transaction {
|
||||||
|
Some(tx) => {
|
||||||
|
let buffer: Vec<u8> = serialize(tx);
|
||||||
|
Some(Arc::new(Transaction::new(buffer).unwrap()))
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
TransactionDetails {
|
TransactionDetails {
|
||||||
|
transaction: potential_tx,
|
||||||
fee: x.fee,
|
fee: x.fee,
|
||||||
txid: x.txid.to_string(),
|
txid: x.txid.to_string(),
|
||||||
received: x.received,
|
received: x.received,
|
||||||
@ -173,7 +183,7 @@ impl From<BdkBalance> for Balance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A transaction output, which defines new coins to be created from old ones.
|
/// A transaction output, which defines new coins to be created from old ones.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TxOut {
|
pub struct TxOut {
|
||||||
/// The value of the output, in satoshis.
|
/// The value of the output, in satoshis.
|
||||||
value: u64,
|
value: u64,
|
||||||
@ -233,16 +243,16 @@ impl fmt::Debug for ProgressHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TxIn {
|
pub struct TxIn {
|
||||||
pub previous_output: OutPoint,
|
pub previous_output: OutPoint,
|
||||||
pub script_sig: Script,
|
pub script_sig: Arc<Script>,
|
||||||
pub sequence: u32,
|
pub sequence: u32,
|
||||||
pub witness: Vec<Vec<u8>>,
|
pub witness: Vec<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Bitcoin transaction.
|
/// A Bitcoin transaction.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Transaction {
|
pub struct Transaction {
|
||||||
internal: BdkTransaction,
|
internal: BdkTransaction,
|
||||||
pub version: i32,
|
pub version: i32,
|
||||||
@ -260,7 +270,7 @@ impl Transaction {
|
|||||||
txid: input.previous_output.txid.to_string(),
|
txid: input.previous_output.txid.to_string(),
|
||||||
vout: input.previous_output.vout,
|
vout: input.previous_output.vout,
|
||||||
},
|
},
|
||||||
script_sig: Script::from(input.script_sig.clone()),
|
script_sig: Arc::new(Script::from(input.script_sig.clone())),
|
||||||
sequence: input.sequence.0,
|
sequence: input.sequence.0,
|
||||||
witness: input.witness.to_vec(),
|
witness: input.witness.to_vec(),
|
||||||
}).collect();
|
}).collect();
|
||||||
@ -309,6 +319,22 @@ impl Transaction {
|
|||||||
fn is_lock_time_enabled(&self) -> bool {
|
fn is_lock_time_enabled(&self) -> bool {
|
||||||
self.internal.is_lock_time_enabled()
|
self.internal.is_lock_time_enabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn version(&self) -> i32 {
|
||||||
|
self.version
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lock_time(&self) -> u32 {
|
||||||
|
self.lock_time
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inputs(&self) -> Vec<TxIn> {
|
||||||
|
self.inputs.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn outputs(&self) -> Vec<TxOut> {
|
||||||
|
self.outputs.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Bitcoin address.
|
/// A Bitcoin address.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user