@@ -261,11 +261,42 @@ static const u8 *create_onion(const tal_t *ctx,
261
261
return onion ;
262
262
}
263
263
264
- static struct command_result * sendonion_done (struct command * cmd ,
265
- const char * method UNUSED ,
266
- const char * buffer ,
267
- const jsmntok_t * toks ,
268
- struct renesendpay * renesendpay )
264
+ static struct command_result * sendpay_fail (struct command * cmd ,
265
+ const char * method UNUSED ,
266
+ const char * buffer ,
267
+ const jsmntok_t * toks ,
268
+ struct renesendpay * renesendpay )
269
+ {
270
+ plugin_log (cmd -> plugin , LOG_UNUSUAL ,
271
+ "renesendpay failed calling sendpay: %.*s" ,
272
+ json_tok_full_len (toks ), json_tok_full (buffer , toks ));
273
+ const jsmntok_t * codetok = json_get_member (buffer , toks , "code" );
274
+ const jsmntok_t * msgtok = json_get_member (buffer , toks , "message" );
275
+ const char * msg = NULL ;
276
+ if (msgtok )
277
+ msg = json_strdup (tmpctx , buffer , msgtok );
278
+ u32 errcode ;
279
+ if (codetok != NULL )
280
+ json_to_u32 (buffer , codetok , & errcode );
281
+ else
282
+ errcode = PLUGIN_ERROR ;
283
+ struct json_stream * response = jsonrpc_stream_fail (
284
+ cmd , errcode ,
285
+ tal_fmt (tmpctx , "sendpay failed: %s" , msg ? msg : "\"\"" ));
286
+ json_object_start (response , "data" );
287
+ json_add_sha256 (response , "payment_hash" , & renesendpay -> payment_hash );
288
+ json_add_string (response , "status" , "failed" );
289
+ json_add_amount_msat (response , "amount_sent_msat" ,
290
+ renesendpay -> sent_amount );
291
+ json_object_end (response );
292
+ return command_finished (cmd , response );
293
+ }
294
+
295
+ static struct command_result * renesendpay_done (struct command * cmd ,
296
+ const char * method UNUSED ,
297
+ const char * buffer ,
298
+ const jsmntok_t * toks ,
299
+ struct renesendpay * renesendpay )
269
300
{
270
301
const char * err ;
271
302
u64 created_index ;
@@ -296,6 +327,7 @@ static struct command_result *sendonion_done(struct command *cmd,
296
327
json_add_amount_msat (response , "amount_total_msat" ,
297
328
renesendpay -> total_amount );
298
329
json_add_string (response , "invoice" , renesendpay -> invoice );
330
+ json_add_string (response , "status" , "pending" );
299
331
300
332
const jsmntok_t * preimagetok =
301
333
json_get_member (buffer , toks , "payment_preimage" );
@@ -325,6 +357,39 @@ static struct command_result *sendonion_done(struct command *cmd,
325
357
return command_finished (cmd , response );
326
358
}
327
359
360
+ static struct command_result * waitblockheight_fail (struct command * cmd ,
361
+ const char * method UNUSED ,
362
+ const char * buffer ,
363
+ const jsmntok_t * toks ,
364
+ struct renesendpay * renesendpay )
365
+ {
366
+ plugin_log (cmd -> plugin , LOG_UNUSUAL ,
367
+ "renesendpay failed calling waitblockheight: %.*s" ,
368
+ json_tok_full_len (toks ), json_tok_full (buffer , toks ));
369
+ const jsmntok_t * codetok = json_get_member (buffer , toks , "code" );
370
+ const jsmntok_t * msgtok = json_get_member (buffer , toks , "message" );
371
+ const char * msg ;
372
+ if (msgtok )
373
+ msg = json_strdup (tmpctx , buffer , msgtok );
374
+ else
375
+ msg = "" ;
376
+ u32 errcode ;
377
+ if (codetok != NULL )
378
+ json_to_u32 (buffer , codetok , & errcode );
379
+ else
380
+ errcode = PLUGIN_ERROR ;
381
+ struct json_stream * response = jsonrpc_stream_fail (
382
+ cmd , errcode ,
383
+ tal_fmt (tmpctx , "waitblockheight failed: %s" , msg ? msg : "\"\"" ));
384
+ json_object_start (response , "data" );
385
+ json_add_sha256 (response , "payment_hash" , & renesendpay -> payment_hash );
386
+ json_add_string (response , "status" , "failed" );
387
+ json_add_amount_msat (response , "amount_sent_msat" ,
388
+ renesendpay -> sent_amount );
389
+ json_object_end (response );
390
+ return command_finished (cmd , response );
391
+ }
392
+
328
393
static struct command_result * waitblockheight_done (struct command * cmd ,
329
394
const char * method UNUSED ,
330
395
const char * buffer ,
@@ -346,7 +411,7 @@ static struct command_result *waitblockheight_done(struct command *cmd,
346
411
if (tal_count (renesendpay -> route ) > 0 ) {
347
412
onion = create_onion (tmpctx , renesendpay ,
348
413
renesendpay -> route [0 ].node_id , 1 );
349
- req = jsonrpc_request_start (cmd , "sendonion" , sendonion_done ,
414
+ req = jsonrpc_request_start (cmd , "sendonion" , renesendpay_done ,
350
415
sendpay_rpc_failure , renesendpay );
351
416
json_add_hex_talarr (req -> js , "onion" , onion );
352
417
@@ -376,8 +441,8 @@ static struct command_result *waitblockheight_done(struct command *cmd,
376
441
} else {
377
442
/* self payment */
378
443
onion = NULL ;
379
- req = jsonrpc_request_start (cmd , "sendpay" , sendonion_done ,
380
- sendpay_rpc_failure , renesendpay );
444
+ req = jsonrpc_request_start (cmd , "sendpay" , renesendpay_done ,
445
+ sendpay_fail , renesendpay );
381
446
json_array_start (req -> js , "route" );
382
447
json_array_end (req -> js );
383
448
json_add_amount_msat (req -> js , "amount_msat" ,
@@ -482,7 +547,7 @@ struct command_result *json_renesendpay(struct command *cmd,
482
547
483
548
struct out_req * req =
484
549
jsonrpc_request_start (cmd , "waitblockheight" , waitblockheight_done ,
485
- sendpay_rpc_failure , renesendpay );
550
+ waitblockheight_fail , renesendpay );
486
551
json_add_num (req -> js , "blockheight" , 0 );
487
552
return send_outreq (req );
488
553
}
0 commit comments