1
1
#include "invoice.h"
2
- #include <bitcoin/address.h>
3
- #include <bitcoin/base58.h>
4
- #include <bitcoin/script.h>
5
2
#include <ccan/array_size/array_size.h>
6
3
#include <ccan/asort/asort.h>
7
4
#include <ccan/json_escape/json_escape.h>
10
7
#include <common/amount.h>
11
8
#include <common/bech32.h>
12
9
#include <common/bolt11.h>
10
+ #include <common/bolt11_json.h>
13
11
#if EXPERIMENTAL_FEATURES
14
12
#include <common/bolt12.h>
15
13
#include <common/bolt12_merkle.h>
@@ -1391,41 +1389,6 @@ static const struct json_command waitinvoice_command = {
1391
1389
};
1392
1390
AUTODATA (json_command , & waitinvoice_command );
1393
1391
1394
- static void json_add_fallback (struct json_stream * response ,
1395
- const char * fieldname ,
1396
- const u8 * fallback ,
1397
- const struct chainparams * chain )
1398
- {
1399
- struct bitcoin_address pkh ;
1400
- struct ripemd160 sh ;
1401
- struct sha256 wsh ;
1402
-
1403
- json_object_start (response , fieldname );
1404
- if (is_p2pkh (fallback , & pkh )) {
1405
- json_add_string (response , "type" , "P2PKH" );
1406
- json_add_string (response , "addr" ,
1407
- bitcoin_to_base58 (tmpctx , chain , & pkh ));
1408
- } else if (is_p2sh (fallback , & sh )) {
1409
- json_add_string (response , "type" , "P2SH" );
1410
- json_add_string (response , "addr" ,
1411
- p2sh_to_base58 (tmpctx , chain , & sh ));
1412
- } else if (is_p2wpkh (fallback , & pkh )) {
1413
- char out [73 + strlen (chain -> bip173_name )];
1414
- json_add_string (response , "type" , "P2WPKH" );
1415
- if (segwit_addr_encode (out , chain -> bip173_name , 0 ,
1416
- (const u8 * )& pkh , sizeof (pkh )))
1417
- json_add_string (response , "addr" , out );
1418
- } else if (is_p2wsh (fallback , & wsh )) {
1419
- char out [73 + strlen (chain -> bip173_name )];
1420
- json_add_string (response , "type" , "P2WSH" );
1421
- if (segwit_addr_encode (out , chain -> bip173_name , 0 ,
1422
- (const u8 * )& wsh , sizeof (wsh )))
1423
- json_add_string (response , "addr" , out );
1424
- }
1425
- json_add_hex_talarr (response , "hex" , fallback );
1426
- json_object_end (response );
1427
- }
1428
-
1429
1392
static struct command_result * json_decodepay (struct command * cmd ,
1430
1393
const char * buffer ,
1431
1394
const jsmntok_t * obj UNNEEDED ,
@@ -1450,89 +1413,7 @@ static struct command_result *json_decodepay(struct command *cmd,
1450
1413
}
1451
1414
1452
1415
response = json_stream_success (cmd );
1453
- json_add_string (response , "currency" , b11 -> chain -> bip173_name );
1454
- json_add_u64 (response , "created_at" , b11 -> timestamp );
1455
- json_add_u64 (response , "expiry" , b11 -> expiry );
1456
- json_add_node_id (response , "payee" , & b11 -> receiver_id );
1457
- if (b11 -> msat )
1458
- json_add_amount_msat_compat (response , * b11 -> msat ,
1459
- "msatoshi" , "amount_msat" );
1460
- if (b11 -> description ) {
1461
- struct json_escape * esc = json_escape (NULL , b11 -> description );
1462
- json_add_escaped_string (response , "description" , take (esc ));
1463
- }
1464
- if (b11 -> description_hash )
1465
- json_add_sha256 (response , "description_hash" ,
1466
- b11 -> description_hash );
1467
- json_add_num (response , "min_final_cltv_expiry" ,
1468
- b11 -> min_final_cltv_expiry );
1469
- if (b11 -> payment_secret )
1470
- json_add_secret (response , "payment_secret" ,
1471
- b11 -> payment_secret );
1472
- if (b11 -> features )
1473
- json_add_hex_talarr (response , "features" , b11 -> features );
1474
- if (tal_count (b11 -> fallbacks )) {
1475
- json_array_start (response , "fallbacks" );
1476
- for (size_t i = 0 ; i < tal_count (b11 -> fallbacks ); i ++ )
1477
- json_add_fallback (response , NULL ,
1478
- b11 -> fallbacks [i ], b11 -> chain );
1479
- json_array_end (response );
1480
- }
1481
-
1482
- if (tal_count (b11 -> routes )) {
1483
- size_t i , n ;
1484
-
1485
- json_array_start (response , "routes" );
1486
- for (i = 0 ; i < tal_count (b11 -> routes ); i ++ ) {
1487
- json_array_start (response , NULL );
1488
- for (n = 0 ; n < tal_count (b11 -> routes [i ]); n ++ ) {
1489
- json_object_start (response , NULL );
1490
- json_add_node_id (response , "pubkey" ,
1491
- & b11 -> routes [i ][n ].pubkey );
1492
- json_add_short_channel_id (response ,
1493
- "short_channel_id" ,
1494
- & b11 -> routes [i ][n ]
1495
- .short_channel_id );
1496
- json_add_u64 (response , "fee_base_msat" ,
1497
- b11 -> routes [i ][n ].fee_base_msat );
1498
- json_add_u64 (response , "fee_proportional_millionths" ,
1499
- b11 -> routes [i ][n ].fee_proportional_millionths );
1500
- json_add_num (response , "cltv_expiry_delta" ,
1501
- b11 -> routes [i ][n ]
1502
- .cltv_expiry_delta );
1503
- json_object_end (response );
1504
- }
1505
- json_array_end (response );
1506
- }
1507
- json_array_end (response );
1508
- }
1509
-
1510
- if (!list_empty (& b11 -> extra_fields )) {
1511
- struct bolt11_field * extra ;
1512
-
1513
- json_array_start (response , "extra" );
1514
- list_for_each (& b11 -> extra_fields , extra , list ) {
1515
- char * data = tal_arr (cmd , char , tal_count (extra -> data )+ 1 );
1516
- size_t i ;
1517
-
1518
- for (i = 0 ; i < tal_count (extra -> data ); i ++ )
1519
- data [i ] = bech32_charset [extra -> data [i ]];
1520
- data [i ] = '\0' ;
1521
- json_object_start (response , NULL );
1522
- json_add_string (response , "tag" ,
1523
- tal_fmt (data , "%c" , extra -> tag ));
1524
- json_add_string (response , "data" , data );
1525
- tal_free (data );
1526
- json_object_end (response );
1527
- }
1528
- json_array_end (response );
1529
- }
1530
-
1531
- json_add_sha256 (response , "payment_hash" , & b11 -> payment_hash );
1532
-
1533
- json_add_string (response , "signature" ,
1534
- type_to_string (cmd , secp256k1_ecdsa_signature ,
1535
- & b11 -> sig ));
1416
+ json_add_bolt11 (response , b11 );
1536
1417
return command_success (cmd , response );
1537
1418
}
1538
1419
0 commit comments