@@ -5,7 +5,7 @@ string in accordance with BOLT 11. After parsing the invoice, you'll need to
55find a route from your node to the recipient and then make the payment using
66` ChannelManager ` .
77
8- <CodeSwitcher :languages =" {rust:'Rust', java:'Java', kotlin:'Kotlin', swift:'Swift'} " >
8+ <CodeSwitcher :languages =" {rust:'Rust', kotlin:'Kotlin', swift:'Swift'} " >
99 <template v-slot:rust >
1010
1111``` rust
@@ -39,113 +39,40 @@ channel_manager.send_payment(&route, payment_hash, &payment_secret)
3939```
4040
4141 </template >
42- <template v-slot:java >
43-
44- ``` java
45- String invoice_str = // get an invoice from the payee
46- Result_InvoiceNoneZ parsed_invoice = Invoice . from_str(invoice_str);
47-
48- if (parsed_invoice instanceof Result_InvoiceNoneZ . Result_InvoiceNoneZ_OK ) {
49- Invoice invoice = ((Result_InvoiceNoneZ . Result_InvoiceNoneZ_OK ) parsed_invoice). res;
50- long amt_msat = 0 ;
51- if (invoice. amount_pico_btc() instanceof Option_u64Z . Some ) {
52- amt_msat = ((Option_u64Z . Some )invoice. amount_pico_btc()). some / 10 ;
53- }
54- if (amt_msat == 0 ) {
55- // <Handle a zero-value invoice>
56- }
57-
58- Route route;
59- try (LockedNetworkGraph netgraph = router. read_locked_graph()) {
60- NetworkGraph graph = netgraph. graph();
61- Result_RouteLightningErrorZ route_res = UtilMethods . get_route(
62- channel_manager. get_our_node_id(),
63- graph, invoice. recover_payee_pub_key(), invoice. features(),
64- channel_manager. list_usable_channels(), invoice. route_hints(),
65- amt_msat, invoice. min_final_cltv_expiry(), logger);
66- assert route_res instanceof Result_RouteLightningErrorZ . Result_RouteLightningErrorZ_OK ;
67- route = ((Result_RouteLightningErrorZ . Result_RouteLightningErrorZ_OK ) route_res). res;
68- }
69-
70- Result_NonePaymentSendFailureZ payment_res = channel_manager. send_payment(
71- route, invoice. payment_hash(), invoice. payment_secret());
72- assert payment_res instanceof Result_NonePaymentSendFailureZ . Result_NonePaymentSendFailureZ_OK ;
73- }
74- ```
75-
76- </template >
77- <template v-slot:kotlin>
42+ <template v-slot:kotlin >
7843
7944``` java
8045// Get an invoice from the recipient/payee
81- val parsedInvoice = Invoice . from_str(recipientInvoice)
82- if (! parsedInvoice. is_ok) {
83- // Unable to parse invoice
84- }
46+ val parsedInvoice = Bolt11Invoice . from_str(recipientInvoice)
47+ val invoiceVal = (parsedInvoice as Result_Bolt11InvoiceSignOrCreationErrorZ . Result_Bolt11InvoiceSignOrCreationErrorZ_OK ). res
8548
86- val invoice = (parsedInvoice as Result_InvoiceParseOrSemanticErrorZ . Result_InvoiceParseOrSemanticErrorZ_OK ) . res
49+ val res = UtilMethods . pay_invoice(invoice, Retry . attempts( 6 ), channelManager)
8750
88- var amountSats: Long = 0
89- if (invoice. amount_milli_satoshis() is Option_u64Z . Some ) {
90- amountSats = (invoice. amount_milli_satoshis() as Option_u64Z . Some ). some * 1000
91- }
92-
93- if (amountSats == 0L ) {
94- // Handle a zero-value invoice
95- }
96-
97- val res = channelManagerConstructor. payer. pay_invoice(invoice)
98-
99-
100-
101- if (parsed_invoice instanceof Result_InvoiceNoneZ . Result_InvoiceNoneZ_OK ) {
102- Invoice invoice = ((Result_InvoiceNoneZ . Result_InvoiceNoneZ_OK ) parsed_invoice). res;
103- long amt_msat = 0 ;
104- if (invoice. amount_pico_btc() instanceof Option_u64Z . Some ) {
105- amt_msat = ((Option_u64Z . Some )invoice. amount_pico_btc()). some / 10 ;
106- }
107- if (amt_msat == 0 ) {
108- // <Handle a zero-value invoice>
109- }
110-
111- Route route;
112- try (LockedNetworkGraph netgraph = router. read_locked_graph()) {
113- NetworkGraph graph = netgraph. graph();
114- Result_RouteLightningErrorZ route_res = UtilMethods . get_route(
115- channel_manager. get_our_node_id(),
116- graph, invoice. recover_payee_pub_key(), invoice. features(),
117- channel_manager. list_usable_channels(), invoice. route_hints(),
118- amt_msat, invoice. min_final_cltv_expiry(), logger);
119- assert route_res instanceof Result_RouteLightningErrorZ . Result_RouteLightningErrorZ_OK ;
120- route = ((Result_RouteLightningErrorZ . Result_RouteLightningErrorZ_OK ) route_res). res;
121- }
122-
123- Result_NonePaymentSendFailureZ payment_res = channel_manager. send_payment(
124- route, invoice. payment_hash(), invoice. payment_secret());
125- assert payment_res instanceof Result_NonePaymentSendFailureZ . Result_NonePaymentSendFailureZ_OK ;
51+ if (res. is_ok) {
52+ // Payment success
12653}
12754```
12855
12956 </template >
13057
13158 <template v-slot:swift >
13259
133- ``` Swift
134- let invoiceStr = // get an invoice from the payee
135- let parsedInvoice = Bolt11Invoice.fromStr (s : invoiceStr)
136-
137- if let invoiceVal = parsedInvoice.getValue () {
138- let invoicePaymentResult = Bindings.payInvoice (
139- invoice : invoiceVal,
140- retryStrategy : Bindings.Retry .initWithTimeout (a : 15 ),
141- channelmanager : channelManager
142- )
143-
144- if invoicePaymentResult.isOk () {
145- // Payment Sent
146- }
60+ ``` Swift
61+ let invoiceStr = // get an invoice from the payee
62+ let parsedInvoice = Bolt11Invoice.fromStr (s : invoiceStr)
63+
64+ if let invoiceVal = parsedInvoice.getValue () {
65+ let invoicePaymentResult = Bindings.payInvoice (
66+ invoice : invoiceVal,
67+ retryStrategy : Bindings.Retry .initWithTimeout (a : 15 ),
68+ channelmanager : channelManager
69+ )
70+
71+ if invoicePaymentResult.isOk () {
72+ // Payment Sent
14773 }
148- ```
74+ }
75+ ```
14976
15077 </template >
15178
@@ -156,7 +83,7 @@ in a `PaymentSent` event with the preimage of the payment hash. Be sure to look
15683out for a ` PaymentFailed ` event, if the payment fails for some reason, and act
15784accordingly.
15885
159- <CodeSwitcher :languages =" {rust:'Rust', java:'Java ', swift:'Swift'} " >
86+ <CodeSwitcher :languages =" {rust:'Rust', kotlin:'Kotlin ', swift:'Swift'} " >
16087 <template v-slot:rust >
16188
16289``` rust
@@ -173,17 +100,16 @@ match event {
173100```
174101
175102 </template >
176- <template v-slot:java >
103+ <template v-slot:kotlin >
177104
178105``` java
179- // In the `handle_event` method of ChannelManagerPersister implementation
180- else if (e instanceof Event . PaymentSent ) {
181- // Handle successful payment
182- Event . PaymentSent event = ((Event . PaymentSent ) e);
106+ // In the `handleEvent` method of ChannelManagerPersister implementation
107+ if (event is Event . PaymentSent ) {
108+ // Handle successful payment
183109}
184- else if (e instanceof Event . PaymentFailed ) {
185- // Handle failed payment
186- Event . PaymentFailed event = (( Event . PaymentFailed ) e);
110+
111+ if (event is Event . PaymentFailed ) {
112+ // Handle failed payment
187113}
188114```
189115
@@ -202,4 +128,4 @@ if let paymentSentEvent = event.getValueAsPaymentSent() {
202128
203129 </template >
204130
205- </CodeSwitcher >
131+ </CodeSwitcher >
0 commit comments