Allow listing confirmed transactions
This commit is contained in:
parent
38b8589526
commit
25b8a8841d
13
src/bdk.udl
13
src/bdk.udl
@ -63,6 +63,15 @@ interface DatabaseConfig {
|
|||||||
Sled(SledDbConfiguration config);
|
Sled(SledDbConfiguration config);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary ConfirmedTransaction {
|
||||||
|
u64? fees;
|
||||||
|
u32 height;
|
||||||
|
u64 timestamp;
|
||||||
|
u64 received;
|
||||||
|
u64 sent;
|
||||||
|
string id;
|
||||||
|
};
|
||||||
|
|
||||||
interface OfflineWallet {
|
interface OfflineWallet {
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
constructor(string descriptor, Network network, DatabaseConfig database_config);
|
constructor(string descriptor, Network network, DatabaseConfig database_config);
|
||||||
@ -73,6 +82,8 @@ interface OfflineWallet {
|
|||||||
u64 get_balance();
|
u64 get_balance();
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
void sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
void sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
||||||
|
[Throws=BdkError]
|
||||||
|
sequence<ConfirmedTransaction> get_transactions();
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary ElectrumConfig {
|
dictionary ElectrumConfig {
|
||||||
@ -111,6 +122,8 @@ interface OnlineWallet {
|
|||||||
u64 get_balance();
|
u64 get_balance();
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
void sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
void sign([ByRef] PartiallySignedBitcoinTransaction psbt);
|
||||||
|
[Throws=BdkError]
|
||||||
|
sequence<ConfirmedTransaction> get_transactions();
|
||||||
|
|
||||||
// OnlineWalletInterface
|
// OnlineWalletInterface
|
||||||
Network get_network();
|
Network get_network();
|
||||||
|
25
src/lib.rs
25
src/lib.rs
@ -57,6 +57,16 @@ impl WalletHolder<()> for OfflineWallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||||
|
pub struct ConfirmedTransaction {
|
||||||
|
pub fees: Option<u64>,
|
||||||
|
pub height: u32,
|
||||||
|
pub timestamp: u64,
|
||||||
|
pub received: u64,
|
||||||
|
pub sent: u64,
|
||||||
|
pub id: String,
|
||||||
|
}
|
||||||
|
|
||||||
trait OfflineWalletOperations<B>: WalletHolder<B> {
|
trait OfflineWalletOperations<B>: WalletHolder<B> {
|
||||||
fn get_new_address(&self) -> String {
|
fn get_new_address(&self) -> String {
|
||||||
self.get_wallet()
|
self.get_wallet()
|
||||||
@ -81,6 +91,21 @@ trait OfflineWalletOperations<B>: WalletHolder<B> {
|
|||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_transactions(&self) -> Result<Vec<ConfirmedTransaction>, Error> {
|
||||||
|
let transactions = self.get_wallet().list_transactions(true)?;
|
||||||
|
Ok(transactions
|
||||||
|
.iter()
|
||||||
|
.map(|x| ConfirmedTransaction {
|
||||||
|
fees: x.fee,
|
||||||
|
height: x.confirmation_time.clone().map_or(0, |c| c.height),
|
||||||
|
timestamp: x.confirmation_time.clone().map_or(0, |c| c.timestamp),
|
||||||
|
id: x.txid.to_string(),
|
||||||
|
received: x.received,
|
||||||
|
sent: x.sent,
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OfflineWallet {
|
impl OfflineWallet {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user