Skip to content

Commit d6aa27c

Browse files
authored
Merge pull request #250 from tnull/2024-02-unified-balance-interface
Expose unified `list_balances` interface method
2 parents 73fd07e + e809b23 commit d6aa27c

File tree

10 files changed

+456
-69
lines changed

10 files changed

+456
-69
lines changed

bindings/kotlin/ldk-node-jvm/lib/src/test/kotlin/org/lightningdevkit/ldknode/LibraryTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ class LibraryTest {
162162
node1.syncWallets()
163163
node2.syncWallets()
164164

165-
val spendableBalance1 = node1.spendableOnchainBalanceSats()
166-
val spendableBalance2 = node2.spendableOnchainBalanceSats()
167-
val totalBalance1 = node1.totalOnchainBalanceSats()
168-
val totalBalance2 = node2.totalOnchainBalanceSats()
165+
val spendableBalance1 = node1.listBalances().spendableOnchainBalanceSats
166+
val spendableBalance2 = node2.listBalances().spendableOnchainBalanceSats
167+
val totalBalance1 = node1.listBalances().totalOnchainBalanceSats
168+
val totalBalance2 = node2.listBalances().totalOnchainBalanceSats
169169
println("Spendable balance 1: $spendableBalance1")
170170
println("Spendable balance 2: $spendableBalance1")
171171
println("Total balance 1: $totalBalance1")
@@ -199,8 +199,8 @@ class LibraryTest {
199199
node1.syncWallets()
200200
node2.syncWallets()
201201

202-
val spendableBalance1AfterOpen = node1.spendableOnchainBalanceSats()
203-
val spendableBalance2AfterOpen = node2.spendableOnchainBalanceSats()
202+
val spendableBalance1AfterOpen = node1.listBalances().spendableOnchainBalanceSats
203+
val spendableBalance2AfterOpen = node2.listBalances().spendableOnchainBalanceSats
204204
println("Spendable balance 1 after open: $spendableBalance1AfterOpen")
205205
println("Spendable balance 2 after open: $spendableBalance2AfterOpen")
206206
assert(spendableBalance1AfterOpen > 49000u)
@@ -256,8 +256,8 @@ class LibraryTest {
256256
node1.syncWallets()
257257
node2.syncWallets()
258258

259-
val spendableBalance1AfterClose = node1.spendableOnchainBalanceSats()
260-
val spendableBalance2AfterClose = node2.spendableOnchainBalanceSats()
259+
val spendableBalance1AfterClose = node1.listBalances().spendableOnchainBalanceSats
260+
val spendableBalance2AfterClose = node2.listBalances().spendableOnchainBalanceSats
261261
println("Spendable balance 1 after close: $spendableBalance1AfterClose")
262262
println("Spendable balance 2 after close: $spendableBalance2AfterClose")
263263
assert(spendableBalance1AfterClose > 95000u)

bindings/ldk_node.udl

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ interface LDKNode {
5656
[Throws=NodeError]
5757
Txid send_all_to_onchain_address([ByRef]Address address);
5858
[Throws=NodeError]
59-
u64 spendable_onchain_balance_sats();
60-
[Throws=NodeError]
61-
u64 total_onchain_balance_sats();
62-
[Throws=NodeError]
6359
void connect(PublicKey node_id, SocketAddress address, boolean persist);
6460
[Throws=NodeError]
6561
void disconnect(PublicKey node_id);
@@ -94,6 +90,7 @@ interface LDKNode {
9490
PaymentDetails? payment([ByRef]PaymentHash payment_hash);
9591
[Throws=NodeError]
9692
void remove_payment([ByRef]PaymentHash payment_hash);
93+
BalanceDetails list_balances();
9794
sequence<PaymentDetails> list_payments();
9895
sequence<PeerDetails> list_peers();
9996
sequence<ChannelDetails> list_channels();
@@ -235,7 +232,6 @@ dictionary ChannelDetails {
235232
u64? unspendable_punishment_reserve;
236233
UserChannelId user_channel_id;
237234
u32 feerate_sat_per_1000_weight;
238-
u64 balance_msat;
239235
u64 outbound_capacity_msat;
240236
u64 inbound_capacity_msat;
241237
u32? confirmations_required;
@@ -266,6 +262,31 @@ dictionary PeerDetails {
266262
boolean is_connected;
267263
};
268264

265+
[Enum]
266+
interface LightningBalance {
267+
ClaimableOnChannelClose ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis );
268+
ClaimableAwaitingConfirmations ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 confirmation_height );
269+
ContentiousClaimable ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 timeout_height, PaymentHash payment_hash, PaymentPreimage payment_preimage );
270+
MaybeTimeoutClaimableHTLC ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 claimable_height, PaymentHash payment_hash);
271+
MaybePreimageClaimableHTLC ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 expiry_height, PaymentHash payment_hash);
272+
CounterpartyRevokedOutputClaimable ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis );
273+
};
274+
275+
[Enum]
276+
interface PendingSweepBalance {
277+
PendingBroadcast ( ChannelId? channel_id, u64 amount_satoshis );
278+
BroadcastAwaitingConfirmation ( ChannelId? channel_id, u32 latest_broadcast_height, Txid latest_spending_txid, u64 amount_satoshis );
279+
AwaitingThresholdConfirmations ( ChannelId? channel_id, Txid latest_spending_txid, BlockHash confirmation_hash, u32 confirmation_height, u64 amount_satoshis);
280+
};
281+
282+
dictionary BalanceDetails {
283+
u64 total_onchain_balance_sats;
284+
u64 spendable_onchain_balance_sats;
285+
u64 total_lightning_balance_sats;
286+
sequence<LightningBalance> lightning_balances;
287+
sequence<PendingSweepBalance> pending_balances_from_channel_closures;
288+
};
289+
269290
interface ChannelConfig {
270291
constructor();
271292
u32 forwarding_fee_proportional_millionths();
@@ -294,6 +315,9 @@ enum LogLevel {
294315
[Custom]
295316
typedef string Txid;
296317

318+
[Custom]
319+
typedef string BlockHash;
320+
297321
[Custom]
298322
typedef string SocketAddress;
299323

bindings/python/src/ldk_node/test_ldk_node.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ def test_channel_full_cycle(self):
138138
node_1.sync_wallets()
139139
node_2.sync_wallets()
140140

141-
spendable_balance_1 = node_1.spendable_onchain_balance_sats()
142-
spendable_balance_2 = node_2.spendable_onchain_balance_sats()
143-
total_balance_1 = node_1.total_onchain_balance_sats()
144-
total_balance_2 = node_2.total_onchain_balance_sats()
141+
spendable_balance_1 = node_1.list_balances().spendable_onchain_balance_sats
142+
spendable_balance_2 = node_2.list_balances().spendable_onchain_balance_sats
143+
total_balance_1 = node_1.list_balances().total_onchain_balance_sats
144+
total_balance_2 = node_2.list_balances().total_onchain_balance_sats
145145

146146
print("SPENDABLE 1:", spendable_balance_1)
147147
self.assertEqual(spendable_balance_1, 100000)
@@ -215,10 +215,10 @@ def test_channel_full_cycle(self):
215215
node_1.sync_wallets()
216216
node_2.sync_wallets()
217217

218-
spendable_balance_after_close_1 = node_1.spendable_onchain_balance_sats()
218+
spendable_balance_after_close_1 = node_1.list_balances().spendable_onchain_balance_sats
219219
assert spendable_balance_after_close_1 > 95000
220220
assert spendable_balance_after_close_1 < 100000
221-
spendable_balance_after_close_2 = node_2.spendable_onchain_balance_sats()
221+
spendable_balance_after_close_2 = node_2.list_balances().spendable_onchain_balance_sats
222222
self.assertEqual(spendable_balance_after_close_2, 102500)
223223

224224
# Stop nodes

0 commit comments

Comments
 (0)