feat: expose get_tx method on wallet type
This commit is contained in:
parent
97a104fd5f
commit
806e29b93c
@ -104,6 +104,11 @@ interface DescriptorError {
|
|||||||
Hex(string e);
|
Hex(string e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[Error]
|
||||||
|
interface TxidParseError {
|
||||||
|
InvalidTxid(string txid);
|
||||||
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// bdk crate - types module
|
// bdk crate - types module
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -212,6 +217,9 @@ interface Wallet {
|
|||||||
|
|
||||||
sequence<CanonicalTx> transactions();
|
sequence<CanonicalTx> transactions();
|
||||||
|
|
||||||
|
[Throws=TxidParseError]
|
||||||
|
CanonicalTx? get_tx(string txid);
|
||||||
|
|
||||||
[Throws=CalculateFeeError]
|
[Throws=CalculateFeeError]
|
||||||
u64 calculate_fee([ByRef] Transaction tx);
|
u64 calculate_fee([ByRef] Transaction tx);
|
||||||
|
|
||||||
|
@ -109,6 +109,12 @@ pub enum FeeRateError {
|
|||||||
ArithmeticOverflow,
|
ArithmeticOverflow,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum TxidParseError {
|
||||||
|
#[error("invalid txid: {txid}")]
|
||||||
|
InvalidTxid { txid: String },
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum AddressError {
|
pub enum AddressError {
|
||||||
#[error("base58 address encoding error")]
|
#[error("base58 address encoding error")]
|
||||||
@ -318,12 +324,6 @@ impl From<std::io::Error> for PersistenceError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl From<DescriptorError> for Alpha3Error {
|
|
||||||
// fn from(_: DescriptorError) -> Self {
|
|
||||||
// Alpha3Error::Generic
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl From<AllowShrinkingError> for Alpha3Error {
|
impl From<AllowShrinkingError> for Alpha3Error {
|
||||||
fn from(_: AllowShrinkingError) -> Self {
|
fn from(_: AllowShrinkingError) -> Self {
|
||||||
Alpha3Error::Generic
|
Alpha3Error::Generic
|
||||||
|
@ -22,6 +22,7 @@ use crate::error::FeeRateError;
|
|||||||
use crate::error::PersistenceError;
|
use crate::error::PersistenceError;
|
||||||
use crate::error::PsbtParseError;
|
use crate::error::PsbtParseError;
|
||||||
use crate::error::TransactionError;
|
use crate::error::TransactionError;
|
||||||
|
use crate::error::TxidParseError;
|
||||||
use crate::error::WalletCreationError;
|
use crate::error::WalletCreationError;
|
||||||
use crate::esplora::EsploraClient;
|
use crate::esplora::EsploraClient;
|
||||||
use crate::keys::DerivationPath;
|
use crate::keys::DerivationPath;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Script, Transaction};
|
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, TxidParseError, WalletCreationError,
|
||||||
|
};
|
||||||
use crate::types::{AddressIndex, AddressInfo, Balance, CanonicalTx, FeeRate, ScriptAmount};
|
use crate::types::{AddressIndex, AddressInfo, Balance, CanonicalTx, FeeRate, ScriptAmount};
|
||||||
|
|
||||||
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
|
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
|
||||||
@ -108,6 +110,12 @@ impl Wallet {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_tx(&self, txid: String) -> Result<Option<CanonicalTx>, TxidParseError> {
|
||||||
|
let txid =
|
||||||
|
Txid::from_str(txid.as_str()).map_err(|_| TxidParseError::InvalidTxid { txid })?;
|
||||||
|
Ok(self.get_wallet().get_tx(txid).map(|tx| tx.into()))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn calculate_fee(&self, tx: &Transaction) -> Result<u64, CalculateFeeError> {
|
pub fn calculate_fee(&self, tx: &Transaction) -> Result<u64, CalculateFeeError> {
|
||||||
self.get_wallet()
|
self.get_wallet()
|
||||||
.calculate_fee(&tx.into())
|
.calculate_fee(&tx.into())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user