@@ -111,6 +111,11 @@ struct payment {
111111
112112 /* Requests currently outstanding */
113113 struct out_req * * requests ;
114+
115+ /* Are we pretending to be "pay"? */
116+ bool pay_compat ;
117+ /* When did we start? */
118+ struct timeabs start_time ;
114119};
115120
116121/* One step in a path. */
@@ -374,11 +379,19 @@ static void payment_succeeded(struct payment *payment,
374379 if (payment -> cmd ) {
375380 js = jsonrpc_stream_success (payment -> cmd );
376381 json_add_preimage (js , "payment_preimage" , preimage );
377- json_add_u64 (js , "failed_parts" , payment -> num_failures );
378- json_add_u64 (js , "successful_parts" ,
379- payment -> total_num_attempts - payment -> num_failures );
380382 json_add_amount_msat (js , "amount_msat" , payment -> amount );
381383 json_add_amount_msat (js , "amount_sent_msat" , total_sent (payment , attempt ));
384+ /* Pay's schema expects these fields */
385+ if (payment -> pay_compat ) {
386+ json_add_u64 (js , "parts" , payment -> total_num_attempts );
387+ json_add_sha256 (js , "payment_hash" , & payment -> payment_hash );
388+ json_add_string (js , "status" , "complete" );
389+ json_add_u64 (js , "created_at" , (u64 )payment -> start_time .ts .tv_sec );
390+ } else {
391+ json_add_u64 (js , "failed_parts" , payment -> num_failures );
392+ json_add_u64 (js , "successful_parts" ,
393+ payment -> total_num_attempts - payment -> num_failures );
394+ }
382395 was_pending (command_finished (payment -> cmd , js ));
383396 payment -> cmd = NULL ;
384397 }
@@ -1436,9 +1449,10 @@ preapproveinvoice_succeed(struct command *cmd,
14361449 return populate_private_layer (cmd , payment );
14371450}
14381451
1439- static struct command_result * json_xpay (struct command * cmd ,
1440- const char * buffer ,
1441- const jsmntok_t * params )
1452+ static struct command_result * json_xpay_core (struct command * cmd ,
1453+ const char * buffer ,
1454+ const jsmntok_t * params ,
1455+ bool as_pay )
14421456{
14431457 struct xpay * xpay = xpay_of (cmd -> plugin );
14441458 struct amount_msat * msat , * maxfee , * partial ;
@@ -1468,6 +1482,8 @@ static struct command_result *json_xpay(struct command *cmd,
14681482 payment -> requests = tal_arr (payment , struct out_req * , 0 );
14691483 payment -> prior_results = tal_strdup (payment , "" );
14701484 payment -> deadline = timemono_add (time_mono (), time_from_sec (* retryfor ));
1485+ payment -> start_time = time_now ();
1486+ payment -> pay_compat = as_pay ;
14711487
14721488 if (bolt12_has_prefix (payment -> invstring )) {
14731489 struct gossmap * gossmap = get_gossmap (xpay );
@@ -1595,6 +1611,20 @@ static struct command_result *json_xpay(struct command *cmd,
15951611 return send_outreq (req );
15961612}
15971613
1614+ static struct command_result * json_xpay (struct command * cmd ,
1615+ const char * buffer ,
1616+ const jsmntok_t * params )
1617+ {
1618+ return json_xpay_core (cmd , buffer , params , false);
1619+ }
1620+
1621+ static struct command_result * json_xpay_as_pay (struct command * cmd ,
1622+ const char * buffer ,
1623+ const jsmntok_t * params )
1624+ {
1625+ return json_xpay_core (cmd , buffer , params , true);
1626+ }
1627+
15981628static struct command_result * getchaininfo_done (struct command * aux_cmd ,
15991629 const char * method ,
16001630 const char * buf ,
@@ -1727,6 +1757,10 @@ static const struct plugin_command commands[] = {
17271757 "xpay" ,
17281758 json_xpay ,
17291759 },
1760+ {
1761+ "xpay-as-pay" ,
1762+ json_xpay_as_pay ,
1763+ },
17301764};
17311765
17321766static struct command_result * handle_block_added (struct command * cmd ,
@@ -1930,7 +1964,7 @@ static struct command_result *handle_rpc_command(struct command *cmd,
19301964 json_object_start (response , "replace" );
19311965 json_add_string (response , "jsonrpc" , "2.0" );
19321966 json_add_tok (response , "id" , id_tok , buf );
1933- json_add_string (response , "method" , "xpay" );
1967+ json_add_string (response , "method" , "xpay-as-pay " );
19341968 json_object_start (response , "params" );
19351969 json_add_tok (response , "invstring" , bolt11 , buf );
19361970 if (amount_msat )
0 commit comments