@@ -25,29 +25,56 @@ class KrakenPlugin extends Plugin {
25
25
.call (method: "listfunds" , params: params.toListFundsRequest ());
26
26
27
27
/// Make a call to listfunds like the prev one, and take only the channels
28
- return Future .value (
29
- {"listpays" : listPays, "channels" : listFunds["channels" ]});
28
+ /// The raw reason is the error message that core lightning return
29
+ return Future .value ({
30
+ "listpays" : listPays,
31
+ "channels" : listFunds["channels" ],
32
+ "raw_reason" : request["raw_reason" ] ?? "unknown"
33
+ });
30
34
} catch (ex, stacktrace) {
31
35
plugin.log (level: "broken" , message: "error received: ${ex .toString ()}" );
32
36
stderr.write (stacktrace);
33
37
rethrow ;
34
38
}
35
39
}
36
40
41
+ Future <String > handleBolt12 (Plugin plugin,
42
+ {required FetchInvoiceRequest offer}) async {
43
+ var fetchInvoice = await rpc!
44
+ .call <FetchInvoiceRequest , FetchInvoiceResponse >(
45
+ method: "fetchinvoice" , params: offer);
46
+ return fetchInvoice.invoice;
47
+ }
48
+
37
49
/// This is the Kraken pay RPC method. This method allows for
38
50
/// an alternate method to pay invoices in Core Lightning and
39
51
/// return payment failure analysis reports.
52
+ ///
53
+ /// For more info on what command we are wrapping, check the cln pay command
54
+ // https://lightning.readthedocs.io/lightning-pay.7.html
40
55
Future <Map <String , Object >> krakenPay (
41
56
Plugin plugin, Map <String , Object > request) async {
42
57
log (level: "info" , message: "This is the kraken pay output." );
43
58
try {
59
+ String invoice = request["bolt11" ]! as String ;
60
+ // The human-readable prefix for BOLT 12 offers is lno.
61
+ if (invoice.startsWith ("lno" )) {
62
+ // Modify request with the correct bolt 12!
63
+ // FIXME: we should remove the msatoshi amount from the request? or the pay command
64
+ // us smart enough to handle it?
65
+ request["bolt11" ] = await handleBolt12 (plugin,
66
+ offer: FetchInvoiceRequest (
67
+ offer: invoice, msamsatoshi: request["msatoshi" ] as String ? ));
68
+ }
44
69
// TODO: rpc should return an exception if any error occurs, and if we have the error returned run the doctor command
45
70
HashMap <String , Object > result =
46
71
await rpc! .call (method: "pay" , params: PayRequest .fromJson (request));
47
72
return Future .value (result);
48
73
} catch (ex, stacktrace) {
49
74
plugin.log (level: "broken" , message: "error received: ${ex .toString ()}" );
50
75
stderr.write (stacktrace);
76
+ // TODO run the doctor command, and put the CLN exception message inside the doctor request
77
+ // with identifier `raw_reason`
51
78
rethrow ;
52
79
}
53
80
}
0 commit comments