Skip to content

Commit 1b52437

Browse files
committed
Add simplified methods to get total/spendable balance
1 parent 89eb89a commit 1b52437

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

bindings/ldk_node.udl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ interface Node {
3232
[Throws=NodeError]
3333
Txid send_all_to_onchain_address([ByRef]Address address);
3434
[Throws=NodeError]
35+
u64 spendable_onchain_balance_sats();
36+
[Throws=NodeError]
37+
u64 total_onchain_balance_sats();
38+
[Throws=NodeError]
3539
void connect(PublicKey node_id, SocketAddr address, boolean permanently);
3640
[Throws=NodeError]
3741
void disconnect([ByRef]PublicKey node_id);

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,16 @@ impl Node {
891891
self.wallet.send_to_address(address, None)
892892
}
893893

894+
/// Retrieve the currently spendable on-chain balance in satoshis.
895+
pub fn spendable_onchain_balance_sats(&self) -> Result<u64, Error> {
896+
Ok(self.wallet.get_balance().map(|bal| bal.get_spendable())?)
897+
}
898+
899+
/// Retrieve the current total on-chain balance in satoshis.
900+
pub fn total_onchain_balance_sats(&self) -> Result<u64, Error> {
901+
Ok(self.wallet.get_balance().map(|bal| bal.get_total())?)
902+
}
903+
894904
/// Retrieve a list of known channels.
895905
pub fn list_channels(&self) -> Vec<ChannelDetails> {
896906
self.channel_manager.list_channels()

0 commit comments

Comments
 (0)