@@ -5,7 +5,7 @@ string in accordance with BOLT 11. After parsing the invoice, you'll need to
5
5
find a route from your node to the recipient and then make the payment using
6
6
` ChannelManager ` .
7
7
8
- <CodeSwitcher :languages =" {rust:'Rust', java:'Java', kotlin:'Kotlin', swift:'Swift'} " >
8
+ <CodeSwitcher :languages =" {rust:'Rust', kotlin:'Kotlin', swift:'Swift'} " >
9
9
<template v-slot:rust >
10
10
11
11
``` rust
@@ -39,113 +39,40 @@ channel_manager.send_payment(&route, payment_hash, &payment_secret)
39
39
```
40
40
41
41
</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 >
78
43
79
44
``` java
80
45
// 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
85
48
86
- val invoice = (parsedInvoice as Result_InvoiceParseOrSemanticErrorZ . Result_InvoiceParseOrSemanticErrorZ_OK ) . res
49
+ val res = UtilMethods . pay_invoice(invoice, Retry . attempts( 6 ), channelManager)
87
50
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
126
53
}
127
54
```
128
55
129
56
</template >
130
57
131
58
<template v-slot:swift >
132
59
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
147
73
}
148
- ```
74
+ }
75
+ ```
149
76
150
77
</template >
151
78
@@ -156,7 +83,7 @@ in a `PaymentSent` event with the preimage of the payment hash. Be sure to look
156
83
out for a ` PaymentFailed ` event, if the payment fails for some reason, and act
157
84
accordingly.
158
85
159
- <CodeSwitcher :languages =" {rust:'Rust', java:'Java ', swift:'Swift'} " >
86
+ <CodeSwitcher :languages =" {rust:'Rust', kotlin:'Kotlin ', swift:'Swift'} " >
160
87
<template v-slot:rust >
161
88
162
89
``` rust
@@ -173,17 +100,16 @@ match event {
173
100
```
174
101
175
102
</template >
176
- <template v-slot:java >
103
+ <template v-slot:kotlin >
177
104
178
105
``` 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
183
109
}
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
187
113
}
188
114
```
189
115
@@ -202,4 +128,4 @@ if let paymentSentEvent = event.getValueAsPaymentSent() {
202
128
203
129
</template >
204
130
205
- </CodeSwitcher >
131
+ </CodeSwitcher >
0 commit comments