feat: use bdk names for CanonicalTx and ChainPosition exposed structures
This commit is contained in:
parent
ab9763bb58
commit
f698d46392
@ -100,6 +100,17 @@ dictionary TxOut {
|
|||||||
Script script_pubkey;
|
Script script_pubkey;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[Enum]
|
||||||
|
interface ChainPosition {
|
||||||
|
Confirmed(u32 height, u64 timestamp);
|
||||||
|
Unconfirmed(u64 timestamp);
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary CanonicalTx {
|
||||||
|
Transaction transaction;
|
||||||
|
ChainPosition chain_position;
|
||||||
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// bdk crate - wallet module
|
// bdk crate - wallet module
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -147,7 +158,7 @@ interface Wallet {
|
|||||||
|
|
||||||
SentAndReceivedValues sent_and_received([ByRef] Transaction tx);
|
SentAndReceivedValues sent_and_received([ByRef] Transaction tx);
|
||||||
|
|
||||||
sequence<TransactionDetails> transactions();
|
sequence<CanonicalTx> transactions();
|
||||||
|
|
||||||
[Throws=CalculateFeeError]
|
[Throws=CalculateFeeError]
|
||||||
u64 calculate_fee([ByRef] Transaction tx);
|
u64 calculate_fee([ByRef] Transaction tx);
|
||||||
@ -363,17 +374,6 @@ interface Address {
|
|||||||
boolean is_valid_for_network(Network network);
|
boolean is_valid_for_network(Network network);
|
||||||
};
|
};
|
||||||
|
|
||||||
[Enum]
|
|
||||||
interface ConfirmationDetails {
|
|
||||||
Confirmed(u32 height, u64 timestamp);
|
|
||||||
Unconfirmed(u64 timestamp);
|
|
||||||
};
|
|
||||||
|
|
||||||
dictionary TransactionDetails {
|
|
||||||
Transaction transaction;
|
|
||||||
ConfirmationDetails confirmation;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface Transaction {
|
interface Transaction {
|
||||||
[Throws=Alpha3Error]
|
[Throws=Alpha3Error]
|
||||||
constructor(sequence<u8> transaction_bytes);
|
constructor(sequence<u8> transaction_bytes);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use crate::error::Alpha3Error;
|
||||||
|
|
||||||
use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked};
|
use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked};
|
||||||
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
|
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
|
||||||
use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut;
|
use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut;
|
||||||
@ -8,10 +10,7 @@ use bdk::bitcoin::Network;
|
|||||||
use bdk::bitcoin::OutPoint as BdkOutPoint;
|
use bdk::bitcoin::OutPoint as BdkOutPoint;
|
||||||
use bdk::bitcoin::Transaction as BdkTransaction;
|
use bdk::bitcoin::Transaction as BdkTransaction;
|
||||||
use bdk::bitcoin::Txid;
|
use bdk::bitcoin::Txid;
|
||||||
use bdk::chain::tx_graph::CanonicalTx as BdkCanonicalTx;
|
|
||||||
|
|
||||||
use crate::error::Alpha3Error;
|
|
||||||
use bdk::chain::{ChainPosition, ConfirmationTimeHeightAnchor};
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@ -116,36 +115,6 @@ impl From<BdkAddress> for Address {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub enum ConfirmationDetails {
|
|
||||||
Confirmed { height: u32, timestamp: u64 },
|
|
||||||
Unconfirmed { timestamp: u64 },
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TransactionDetails {
|
|
||||||
pub transaction: Arc<Transaction>,
|
|
||||||
pub confirmation: ConfirmationDetails,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<BdkCanonicalTx<'a, BdkTransaction, ConfirmationTimeHeightAnchor>>
|
|
||||||
for TransactionDetails
|
|
||||||
{
|
|
||||||
fn from(tx: BdkCanonicalTx<'a, BdkTransaction, ConfirmationTimeHeightAnchor>) -> Self {
|
|
||||||
let confirmation = match tx.chain_position {
|
|
||||||
ChainPosition::Confirmed(anchor) => ConfirmationDetails::Confirmed {
|
|
||||||
height: anchor.confirmation_height,
|
|
||||||
timestamp: anchor.confirmation_time,
|
|
||||||
},
|
|
||||||
ChainPosition::Unconfirmed(timestamp) => ConfirmationDetails::Unconfirmed { timestamp },
|
|
||||||
};
|
|
||||||
|
|
||||||
TransactionDetails {
|
|
||||||
transaction: Arc::new(Transaction::from(tx.tx_node.tx)),
|
|
||||||
confirmation,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Transaction {
|
pub struct Transaction {
|
||||||
inner: BdkTransaction,
|
inner: BdkTransaction,
|
||||||
|
@ -17,6 +17,8 @@ use crate::error::Alpha3Error;
|
|||||||
use crate::error::CalculateFeeError;
|
use crate::error::CalculateFeeError;
|
||||||
use crate::error::EsploraError;
|
use crate::error::EsploraError;
|
||||||
use crate::error::FeeRateError;
|
use crate::error::FeeRateError;
|
||||||
|
use crate::error::PersistenceError;
|
||||||
|
use crate::error::WalletCreationError;
|
||||||
use crate::esplora::EsploraClient;
|
use crate::esplora::EsploraClient;
|
||||||
use crate::keys::DerivationPath;
|
use crate::keys::DerivationPath;
|
||||||
use crate::keys::DescriptorPublicKey;
|
use crate::keys::DescriptorPublicKey;
|
||||||
@ -25,6 +27,8 @@ use crate::keys::Mnemonic;
|
|||||||
use crate::types::AddressIndex;
|
use crate::types::AddressIndex;
|
||||||
use crate::types::AddressInfo;
|
use crate::types::AddressInfo;
|
||||||
use crate::types::Balance;
|
use crate::types::Balance;
|
||||||
|
use crate::types::CanonicalTx;
|
||||||
|
use crate::types::ChainPosition;
|
||||||
use crate::types::FeeRate;
|
use crate::types::FeeRate;
|
||||||
use crate::types::LocalOutput;
|
use crate::types::LocalOutput;
|
||||||
use crate::types::ScriptAmount;
|
use crate::types::ScriptAmount;
|
||||||
@ -34,11 +38,6 @@ use crate::wallet::TxBuilder;
|
|||||||
use crate::wallet::Update;
|
use crate::wallet::Update;
|
||||||
use crate::wallet::Wallet;
|
use crate::wallet::Wallet;
|
||||||
|
|
||||||
use crate::bitcoin::ConfirmationDetails;
|
|
||||||
use crate::bitcoin::TransactionDetails;
|
|
||||||
|
|
||||||
use crate::error::PersistenceError;
|
|
||||||
use crate::error::WalletCreationError;
|
|
||||||
use bdk::bitcoin::Network;
|
use bdk::bitcoin::Network;
|
||||||
use bdk::keys::bip39::WordCount;
|
use bdk::keys::bip39::WordCount;
|
||||||
use bdk::wallet::tx_builder::ChangeSpendPolicy;
|
use bdk::wallet::tx_builder::ChangeSpendPolicy;
|
||||||
|
@ -1,16 +1,46 @@
|
|||||||
use crate::bitcoin::{Address, OutPoint, Script, TxOut};
|
use crate::bitcoin::{Address, OutPoint, Script, Transaction, TxOut};
|
||||||
|
use crate::error::FeeRateError;
|
||||||
|
|
||||||
|
use bdk::bitcoin::FeeRate as BdkFeeRate;
|
||||||
|
use bdk::bitcoin::Transaction as BdkTransaction;
|
||||||
|
use bdk::chain::tx_graph::CanonicalTx as BdkCanonicalTx;
|
||||||
|
use bdk::chain::{ChainPosition as BdkChainPosition, ConfirmationTimeHeightAnchor};
|
||||||
use bdk::wallet::AddressIndex as BdkAddressIndex;
|
use bdk::wallet::AddressIndex as BdkAddressIndex;
|
||||||
use bdk::wallet::AddressInfo as BdkAddressInfo;
|
use bdk::wallet::AddressInfo as BdkAddressInfo;
|
||||||
use bdk::wallet::Balance as BdkBalance;
|
use bdk::wallet::Balance as BdkBalance;
|
||||||
use bdk::KeychainKind;
|
use bdk::KeychainKind;
|
||||||
use bdk::LocalOutput as BdkLocalOutput;
|
use bdk::LocalOutput as BdkLocalOutput;
|
||||||
|
|
||||||
use bdk::bitcoin::FeeRate as BdkFeeRate;
|
|
||||||
|
|
||||||
use crate::error::FeeRateError;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum ChainPosition {
|
||||||
|
Confirmed { height: u32, timestamp: u64 },
|
||||||
|
Unconfirmed { timestamp: u64 },
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CanonicalTx {
|
||||||
|
pub transaction: Arc<Transaction>,
|
||||||
|
pub chain_position: ChainPosition,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<BdkCanonicalTx<'_, BdkTransaction, ConfirmationTimeHeightAnchor>> for CanonicalTx {
|
||||||
|
fn from(tx: BdkCanonicalTx<'_, BdkTransaction, ConfirmationTimeHeightAnchor>) -> Self {
|
||||||
|
let chain_position = match tx.chain_position {
|
||||||
|
BdkChainPosition::Confirmed(anchor) => ChainPosition::Confirmed {
|
||||||
|
height: anchor.confirmation_height,
|
||||||
|
timestamp: anchor.confirmation_time,
|
||||||
|
},
|
||||||
|
BdkChainPosition::Unconfirmed(timestamp) => ChainPosition::Unconfirmed { timestamp },
|
||||||
|
};
|
||||||
|
|
||||||
|
CanonicalTx {
|
||||||
|
transaction: Arc::new(Transaction::from(tx.tx_node.tx)),
|
||||||
|
chain_position,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct FeeRate(pub BdkFeeRate);
|
pub struct FeeRate(pub BdkFeeRate);
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Transaction, TransactionDetails};
|
use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Script, Transaction};
|
||||||
use crate::descriptor::Descriptor;
|
use crate::descriptor::Descriptor;
|
||||||
use crate::error::{Alpha3Error, CalculateFeeError, PersistenceError, WalletCreationError};
|
use crate::error::{Alpha3Error, CalculateFeeError, PersistenceError, WalletCreationError};
|
||||||
use crate::types::ScriptAmount;
|
use crate::types::{AddressIndex, AddressInfo, Balance, CanonicalTx, FeeRate, ScriptAmount};
|
||||||
use crate::types::{Balance, FeeRate};
|
|
||||||
use crate::Script;
|
|
||||||
use crate::{AddressIndex, AddressInfo};
|
|
||||||
|
|
||||||
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
|
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
|
||||||
use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransaction;
|
use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransaction;
|
||||||
@ -104,7 +101,7 @@ impl Wallet {
|
|||||||
SentAndReceivedValues { sent, received }
|
SentAndReceivedValues { sent, received }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transactions(&self) -> Vec<TransactionDetails> {
|
pub fn transactions(&self) -> Vec<CanonicalTx> {
|
||||||
self.get_wallet()
|
self.get_wallet()
|
||||||
.transactions()
|
.transactions()
|
||||||
.map(|tx| tx.into())
|
.map(|tx| tx.into())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user