Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose unified list_balances interface method #250

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ class LibraryTest {
node1.syncWallets()
node2.syncWallets()

val spendableBalance1 = node1.spendableOnchainBalanceSats()
val spendableBalance2 = node2.spendableOnchainBalanceSats()
val totalBalance1 = node1.totalOnchainBalanceSats()
val totalBalance2 = node2.totalOnchainBalanceSats()
val spendableBalance1 = node1.listBalances().spendableOnchainBalanceSats
val spendableBalance2 = node2.listBalances().spendableOnchainBalanceSats
val totalBalance1 = node1.listBalances().totalOnchainBalanceSats
val totalBalance2 = node2.listBalances().totalOnchainBalanceSats
println("Spendable balance 1: $spendableBalance1")
println("Spendable balance 2: $spendableBalance1")
println("Total balance 1: $totalBalance1")
Expand Down Expand Up @@ -199,8 +199,8 @@ class LibraryTest {
node1.syncWallets()
node2.syncWallets()

val spendableBalance1AfterOpen = node1.spendableOnchainBalanceSats()
val spendableBalance2AfterOpen = node2.spendableOnchainBalanceSats()
val spendableBalance1AfterOpen = node1.listBalances().spendableOnchainBalanceSats
val spendableBalance2AfterOpen = node2.listBalances().spendableOnchainBalanceSats
println("Spendable balance 1 after open: $spendableBalance1AfterOpen")
println("Spendable balance 2 after open: $spendableBalance2AfterOpen")
assert(spendableBalance1AfterOpen > 49000u)
Expand Down Expand Up @@ -256,8 +256,8 @@ class LibraryTest {
node1.syncWallets()
node2.syncWallets()

val spendableBalance1AfterClose = node1.spendableOnchainBalanceSats()
val spendableBalance2AfterClose = node2.spendableOnchainBalanceSats()
val spendableBalance1AfterClose = node1.listBalances().spendableOnchainBalanceSats
val spendableBalance2AfterClose = node2.listBalances().spendableOnchainBalanceSats
println("Spendable balance 1 after close: $spendableBalance1AfterClose")
println("Spendable balance 2 after close: $spendableBalance2AfterClose")
assert(spendableBalance1AfterClose > 95000u)
Expand Down
34 changes: 29 additions & 5 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ interface LDKNode {
[Throws=NodeError]
Txid send_all_to_onchain_address([ByRef]Address address);
[Throws=NodeError]
u64 spendable_onchain_balance_sats();
[Throws=NodeError]
u64 total_onchain_balance_sats();
[Throws=NodeError]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
void disconnect(PublicKey node_id);
Expand Down Expand Up @@ -94,6 +90,7 @@ interface LDKNode {
PaymentDetails? payment([ByRef]PaymentHash payment_hash);
[Throws=NodeError]
void remove_payment([ByRef]PaymentHash payment_hash);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
sequence<PeerDetails> list_peers();
sequence<ChannelDetails> list_channels();
Expand Down Expand Up @@ -235,7 +232,6 @@ dictionary ChannelDetails {
u64? unspendable_punishment_reserve;
UserChannelId user_channel_id;
u32 feerate_sat_per_1000_weight;
u64 balance_msat;
u64 outbound_capacity_msat;
u64 inbound_capacity_msat;
u32? confirmations_required;
Expand Down Expand Up @@ -266,6 +262,31 @@ dictionary PeerDetails {
boolean is_connected;
};

[Enum]
interface LightningBalance {
ClaimableOnChannelClose ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis );
ClaimableAwaitingConfirmations ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 confirmation_height );
ContentiousClaimable ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 timeout_height, PaymentHash payment_hash, PaymentPreimage payment_preimage );
MaybeTimeoutClaimableHTLC ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 claimable_height, PaymentHash payment_hash);
MaybePreimageClaimableHTLC ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis, u32 expiry_height, PaymentHash payment_hash);
CounterpartyRevokedOutputClaimable ( ChannelId channel_id, PublicKey counterparty_node_id, u64 amount_satoshis );
};

[Enum]
interface PendingSweepBalance {
PendingBroadcast ( ChannelId? channel_id, u64 amount_satoshis );
BroadcastAwaitingConfirmation ( ChannelId? channel_id, u32 latest_broadcast_height, Txid latest_spending_txid, u64 amount_satoshis );
AwaitingThresholdConfirmations ( ChannelId? channel_id, Txid latest_spending_txid, BlockHash confirmation_hash, u32 confirmation_height, u64 amount_satoshis);
};

dictionary BalanceDetails {
u64 total_onchain_balance_sats;
u64 spendable_onchain_balance_sats;
u64 total_lightning_balance_sats;
sequence<LightningBalance> lightning_balances;
sequence<PendingSweepBalance> pending_balances_from_channel_closures;
};

interface ChannelConfig {
constructor();
u32 forwarding_fee_proportional_millionths();
Expand Down Expand Up @@ -294,6 +315,9 @@ enum LogLevel {
[Custom]
typedef string Txid;

[Custom]
typedef string BlockHash;

[Custom]
typedef string SocketAddress;

Expand Down
12 changes: 6 additions & 6 deletions bindings/python/src/ldk_node/test_ldk_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def test_channel_full_cycle(self):
node_1.sync_wallets()
node_2.sync_wallets()

spendable_balance_1 = node_1.spendable_onchain_balance_sats()
spendable_balance_2 = node_2.spendable_onchain_balance_sats()
total_balance_1 = node_1.total_onchain_balance_sats()
total_balance_2 = node_2.total_onchain_balance_sats()
spendable_balance_1 = node_1.list_balances().spendable_onchain_balance_sats
spendable_balance_2 = node_2.list_balances().spendable_onchain_balance_sats
total_balance_1 = node_1.list_balances().total_onchain_balance_sats
total_balance_2 = node_2.list_balances().total_onchain_balance_sats

print("SPENDABLE 1:", spendable_balance_1)
self.assertEqual(spendable_balance_1, 100000)
Expand Down Expand Up @@ -215,10 +215,10 @@ def test_channel_full_cycle(self):
node_1.sync_wallets()
node_2.sync_wallets()

spendable_balance_after_close_1 = node_1.spendable_onchain_balance_sats()
spendable_balance_after_close_1 = node_1.list_balances().spendable_onchain_balance_sats
assert spendable_balance_after_close_1 > 95000
assert spendable_balance_after_close_1 < 100000
spendable_balance_after_close_2 = node_2.spendable_onchain_balance_sats()
spendable_balance_after_close_2 = node_2.list_balances().spendable_onchain_balance_sats
self.assertEqual(spendable_balance_after_close_2, 102500)

# Stop nodes
Expand Down
Loading
Loading