feat: expose list_unspent and list_output methods on wallet

This commit is contained in:
thunderbiscuit 2024-04-10 13:15:27 -04:00
parent 806e29b93c
commit 54f3235254
No known key found for this signature in database
GPG Key ID: 88253696EB836462
2 changed files with 15 additions and 1 deletions

View File

@ -225,6 +225,10 @@ interface Wallet {
[Throws=CalculateFeeError] [Throws=CalculateFeeError]
FeeRate calculate_fee_rate([ByRef] Transaction tx); FeeRate calculate_fee_rate([ByRef] Transaction tx);
sequence<LocalOutput> list_unspent();
sequence<LocalOutput> list_output();
}; };
interface Update {}; interface Update {};

View File

@ -3,7 +3,9 @@ use crate::descriptor::Descriptor;
use crate::error::{ use crate::error::{
Alpha3Error, CalculateFeeError, PersistenceError, TxidParseError, WalletCreationError, Alpha3Error, CalculateFeeError, PersistenceError, TxidParseError, WalletCreationError,
}; };
use crate::types::{AddressIndex, AddressInfo, Balance, CanonicalTx, FeeRate, ScriptAmount}; use crate::types::{
AddressIndex, AddressInfo, Balance, CanonicalTx, FeeRate, LocalOutput, ScriptAmount,
};
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;
@ -128,6 +130,14 @@ impl Wallet {
.map(|bdk_fee_rate| Arc::new(FeeRate(bdk_fee_rate))) .map(|bdk_fee_rate| Arc::new(FeeRate(bdk_fee_rate)))
.map_err(|e| e.into()) .map_err(|e| e.into())
} }
pub fn list_unspent(&self) -> Vec<LocalOutput> {
self.get_wallet().list_unspent().map(|o| o.into()).collect()
}
pub fn list_output(&self) -> Vec<LocalOutput> {
self.get_wallet().list_output().map(|o| o.into()).collect()
}
} }
pub struct SentAndReceivedValues { pub struct SentAndReceivedValues {