Skip to content

Commit

Permalink
Move BOLT11 payments API to Bolt11PaymentsHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Mar 5, 2024
1 parent 4b1bfe8 commit 0d2ea71
Show file tree
Hide file tree
Showing 11 changed files with 609 additions and 521 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A ready-to-go Lightning node library built using [LDK][ldk] and [BDK][bdk].
LDK Node is a self-custodial Lightning node in library form. Its central goal is to provide a small, simple, and straightforward interface that enables users to easily set up and run a Lightning node with an integrated on-chain wallet. While minimalism is at its core, LDK Node aims to be sufficiently modular and configurable to be useful for a variety of use cases.

## Getting Started
The primary abstraction of the library is the [`Node`][api_docs_node], which can be retrieved by setting up and configuring a [`Builder`][api_docs_builder] to your liking and calling one of the `build` methods. `Node` can then be controlled via commands such as `start`, `stop`, `connect_open_channel`, `send_payment`, etc.
The primary abstraction of the library is the [`Node`][api_docs_node], which can be retrieved by setting up and configuring a [`Builder`][api_docs_builder] to your liking and calling one of the `build` methods. `Node` can then be controlled via commands such as `start`, `stop`, `connect_open_channel`, `send`, etc.

```rust
use ldk_node::Builder;
Expand Down Expand Up @@ -44,7 +44,7 @@ fn main() {
node.event_handled();

let invoice = Bolt11Invoice::from_str("INVOICE_STR").unwrap();
node.send_payment(&invoice).unwrap();
node.bolt11_payment().send(&invoice).unwrap();

node.stop().unwrap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ class LibraryTest {
else -> return
}

val invoice = node2.receivePayment(2500000u, "asdf", 9217u)
val invoice = node2.bolt11_payment().receive(2500000u, "asdf", 9217u)

node1.sendPayment(invoice)
node1.bolt11_payment().send(invoice)

val paymentSuccessfulEvent = node1.waitNextEvent()
println("Got event: $paymentSuccessfulEvent")
Expand Down
36 changes: 20 additions & 16 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface Node {
void event_handled();
PublicKey node_id();
sequence<SocketAddress>? listening_addresses();
Bolt11PaymentsHandler bolt11_payment();
[Throws=NodeError]
Address new_onchain_address();
[Throws=NodeError]
Expand All @@ -70,25 +71,9 @@ interface Node {
[Throws=NodeError]
void sync_wallets();
[Throws=NodeError]
PaymentHash send_payment([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
PaymentHash send_payment_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
[Throws=NodeError]
PaymentHash send_spontaneous_payment(u64 amount_msat, PublicKey node_id);
[Throws=NodeError]
void send_payment_probes([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
void send_spontaneous_payment_probes(u64 amount_msat, PublicKey node_id);
[Throws=NodeError]
void send_payment_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
[Throws=NodeError]
Bolt11Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
[Throws=NodeError]
Bolt11Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);
[Throws=NodeError]
Bolt11Invoice receive_payment_via_jit_channel(u64 amount_msat, [ByRef]string description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
Bolt11Invoice receive_variable_amount_payment_via_jit_channel([ByRef]string description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
PaymentDetails? payment([ByRef]PaymentHash payment_hash);
[Throws=NodeError]
void remove_payment([ByRef]PaymentHash payment_hash);
Expand All @@ -102,6 +87,25 @@ interface Node {
boolean is_running();
};

interface Bolt11PaymentsHandler {
[Throws=NodeError]
PaymentHash send([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
PaymentHash send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
[Throws=NodeError]
Bolt11Invoice receive(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
[Throws=NodeError]
Bolt11Invoice receive_variable_amount([ByRef]string description, u32 expiry_secs);
[Throws=NodeError]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]string description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]string description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
};

[Error]
enum NodeError {
"AlreadyRunning",
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/src/ldk_node/test_ldk_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def test_channel_full_cycle(self):
print("EVENT:", channel_ready_event_2)
node_2.event_handled()

invoice = node_2.receive_payment(2500000, "asdf", 9217)
node_1.send_payment(invoice)
invoice = node_2.bolt11_payment().receive(2500000, "asdf", 9217)
node_1.bolt11_payment().send(invoice)

payment_successful_event_1 = node_1.wait_next_event()
assert isinstance(payment_successful_event_1, Event.PAYMENT_SUCCESSFUL)
Expand Down
Loading

0 comments on commit 0d2ea71

Please sign in to comment.