@@ -145,7 +145,7 @@ static struct command_result *sendpay_rpc_failure(struct command *cmd,
145
145
json_to_u32 (buffer , codetok , & errcode );
146
146
else
147
147
errcode = LIGHTNINGD ;
148
-
148
+ // FIXME: make this response more useful, maybe similar to waitsendpay
149
149
return command_fail (
150
150
cmd , errcode , "renesendpay failed to error in RPC: %.*s" ,
151
151
json_tok_full_len (toks ), json_tok_full (buffer , toks ));
@@ -297,6 +297,11 @@ static struct command_result *sendonion_done(struct command *cmd,
297
297
renesendpay -> total_amount );
298
298
json_add_string (response , "invoice" , renesendpay -> invoice );
299
299
300
+ const jsmntok_t * preimagetok =
301
+ json_get_member (buffer , toks , "payment_preimage" );
302
+ if (preimagetok )
303
+ json_add_tok (response , "payment_preimage" , preimagetok , buffer );
304
+
300
305
if (renesendpay -> label )
301
306
json_add_string (response , "label" , renesendpay -> label );
302
307
if (renesendpay -> description )
@@ -338,31 +343,55 @@ static struct command_result *waitblockheight_done(struct command *cmd,
338
343
const u8 * onion ;
339
344
struct out_req * req ;
340
345
341
- onion =
342
- create_onion (tmpctx , renesendpay , renesendpay -> route [0 ].node_id , 1 );
343
- req = jsonrpc_request_start (cmd , "sendonion" , sendonion_done ,
344
- sendpay_rpc_failure , renesendpay );
345
- json_add_hex_talarr (req -> js , "onion" , onion );
346
+ if (tal_count (renesendpay -> route ) > 0 ) {
347
+ onion = create_onion (tmpctx , renesendpay ,
348
+ renesendpay -> route [0 ].node_id , 1 );
349
+ req = jsonrpc_request_start (cmd , "sendonion" , sendonion_done ,
350
+ sendpay_rpc_failure , renesendpay );
351
+ json_add_hex_talarr (req -> js , "onion" , onion );
352
+
353
+ json_add_amount_msat (req -> js , "amount_msat" ,
354
+ renesendpay -> deliver_amount );
355
+
356
+ const struct route_hop * hop = & renesendpay -> route [0 ];
357
+ json_object_start (req -> js , "first_hop" );
358
+ json_add_amount_msat (req -> js , "amount_msat" , hop -> amount );
359
+ json_add_num (req -> js , "delay" ,
360
+ hop -> delay + renesendpay -> blockheight );
361
+ json_add_node_id (req -> js , "id" , & hop -> node_id );
362
+ json_add_short_channel_id (req -> js , "channel" , hop -> scid );
363
+ json_object_end (req -> js );
364
+
365
+ json_array_start (req -> js , "shared_secrets" );
366
+ for (size_t i = 0 ; i < tal_count (renesendpay -> shared_secrets );
367
+ i ++ ) {
368
+ json_add_secret (req -> js , NULL ,
369
+ & renesendpay -> shared_secrets [i ]);
370
+ }
371
+ json_array_end (req -> js );
372
+
373
+ json_add_node_id (req -> js , "destination" ,
374
+ & renesendpay -> destination );
375
+
376
+ } else {
377
+ /* self payment */
378
+ onion = NULL ;
379
+ req = jsonrpc_request_start (cmd , "sendpay" , sendonion_done ,
380
+ sendpay_rpc_failure , renesendpay );
381
+ json_array_start (req -> js , "route" );
382
+ json_array_end (req -> js );
383
+ json_add_amount_msat (req -> js , "amount_msat" ,
384
+ renesendpay -> total_amount );
385
+ if (renesendpay -> payment_secret )
386
+ json_add_secret (req -> js , "payment_secret" , renesendpay -> payment_secret );
387
+ else {
388
+ // FIXME: get payment_secret from blinded path
389
+ }
390
+ }
391
+
346
392
json_add_sha256 (req -> js , "payment_hash" , & renesendpay -> payment_hash );
347
393
json_add_u64 (req -> js , "partid" , renesendpay -> partid );
348
394
json_add_u64 (req -> js , "groupid" , renesendpay -> groupid );
349
- json_add_node_id (req -> js , "destination" , & renesendpay -> destination );
350
- json_add_amount_msat (req -> js , "amount_msat" , renesendpay -> deliver_amount );
351
-
352
- const struct route_hop * hop = & renesendpay -> route [0 ];
353
- json_object_start (req -> js , "first_hop" );
354
- json_add_amount_msat (req -> js , "amount_msat" , hop -> amount );
355
- json_add_num (req -> js , "delay" , hop -> delay + renesendpay -> blockheight );
356
- json_add_node_id (req -> js , "id" , & hop -> node_id );
357
- json_add_short_channel_id (req -> js , "channel" , hop -> scid );
358
- json_object_end (req -> js );
359
-
360
- json_array_start (req -> js , "shared_secrets" );
361
- for (size_t i = 0 ; i < tal_count (renesendpay -> shared_secrets ); i ++ ) {
362
- json_add_secret (req -> js , NULL , & renesendpay -> shared_secrets [i ]);
363
- }
364
- json_array_end (req -> js );
365
-
366
395
if (renesendpay -> label )
367
396
json_add_string (req -> js , "label" , renesendpay -> label );
368
397
if (renesendpay -> description )
@@ -431,7 +460,11 @@ struct command_result *json_renesendpay(struct command *cmd,
431
460
renesendpay -> partid = * partid ;
432
461
renesendpay -> groupid = * groupid ;
433
462
434
- renesendpay -> sent_amount = renesendpay -> route [0 ].amount ;
463
+ if (tal_count (renesendpay -> route ) > 0 )
464
+ renesendpay -> sent_amount = renesendpay -> route [0 ].amount ;
465
+ else /* this might be a self pay */
466
+ renesendpay -> sent_amount = * amount ;
467
+
435
468
renesendpay -> total_amount = * total_amount ;
436
469
renesendpay -> deliver_amount = * amount ;
437
470
renesendpay -> final_cltv = * final_cltv ;
0 commit comments