2019-02-21 03:38:35 +01:00
# include "../amount.c"
2017-11-24 05:12:55 +01:00
# include "../bech32.c"
2018-04-23 16:20:55 +02:00
# include "../bech32_util.c"
2017-11-24 05:12:55 +01:00
# include "../bolt11.c"
2019-09-05 03:07:16 +02:00
# include "../features.c"
2019-04-08 11:58:32 +02:00
# include "../node_id.c"
2017-11-24 05:12:55 +01:00
# include "../hash_u5.c"
# include <ccan/err/err.h>
# include <ccan/mem/mem.h>
# include <ccan/str/hex/hex.h>
# include <stdio.h>
2018-03-28 04:32:39 +02:00
# include <wally_core.h>
2017-11-24 05:12:55 +01:00
/* AUTOGENERATED MOCKS START */
2019-06-21 02:11:41 +02:00
/* Generated stub for fromwire_fail */
const void * fromwire_fail ( const u8 * * cursor UNNEEDED , size_t * max UNNEEDED )
{ fprintf ( stderr , " fromwire_fail called! \n " ) ; abort ( ) ; }
2019-04-08 11:58:32 +02:00
/* Generated stub for fromwire_node_id */
void fromwire_node_id ( const u8 * * cursor UNNEEDED , size_t * max UNNEEDED , struct node_id * id UNNEEDED )
{ fprintf ( stderr , " fromwire_node_id called! \n " ) ; abort ( ) ; }
2017-11-24 05:12:55 +01:00
/* Generated stub for fromwire_short_channel_id */
void fromwire_short_channel_id ( const u8 * * cursor UNNEEDED , size_t * max UNNEEDED ,
struct short_channel_id * short_channel_id UNNEEDED )
{ fprintf ( stderr , " fromwire_short_channel_id called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_u16 */
u16 fromwire_u16 ( const u8 * * cursor UNNEEDED , size_t * max UNNEEDED )
{ fprintf ( stderr , " fromwire_u16 called! \n " ) ; abort ( ) ; }
2017-12-12 01:34:07 +01:00
/* Generated stub for fromwire_u32 */
u32 fromwire_u32 ( const u8 * * cursor UNNEEDED , size_t * max UNNEEDED )
{ fprintf ( stderr , " fromwire_u32 called! \n " ) ; abort ( ) ; }
2019-04-08 11:58:32 +02:00
/* Generated stub for towire_node_id */
void towire_node_id ( u8 * * pptr UNNEEDED , const struct node_id * id UNNEEDED )
{ fprintf ( stderr , " towire_node_id called! \n " ) ; abort ( ) ; }
2017-11-24 05:12:55 +01:00
/* Generated stub for towire_short_channel_id */
void towire_short_channel_id ( u8 * * pptr UNNEEDED ,
const struct short_channel_id * short_channel_id UNNEEDED )
{ fprintf ( stderr , " towire_short_channel_id called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_u16 */
void towire_u16 ( u8 * * pptr UNNEEDED , u16 v UNNEEDED )
{ fprintf ( stderr , " towire_u16 called! \n " ) ; abort ( ) ; }
2017-12-12 01:34:07 +01:00
/* Generated stub for towire_u32 */
void towire_u32 ( u8 * * pptr UNNEEDED , u32 v UNNEEDED )
{ fprintf ( stderr , " towire_u32 called! \n " ) ; abort ( ) ; }
2019-04-08 11:58:32 +02:00
/* Generated stub for type_to_string_ */
const char * type_to_string_ ( const tal_t * ctx UNNEEDED , const char * typename UNNEEDED ,
union printable_types u UNNEEDED )
{ fprintf ( stderr , " type_to_string_ called! \n " ) ; abort ( ) ; }
2017-11-24 05:12:55 +01:00
/* AUTOGENERATED MOCKS END */
static struct privkey privkey ;
static bool test_sign ( const u5 * u5bytes ,
const u8 * hrpu8 ,
secp256k1_ecdsa_recoverable_signature * rsig ,
2018-02-21 16:06:07 +01:00
void * unused UNUSED )
2017-11-24 05:12:55 +01:00
{
struct hash_u5 hu5 ;
char * hrp ;
struct sha256 sha ;
2018-07-28 08:00:16 +02:00
hrp = tal_dup_arr ( NULL , char , ( char * ) hrpu8 , tal_count ( hrpu8 ) , 1 ) ;
hrp [ tal_count ( hrpu8 ) ] = ' \0 ' ;
2017-11-24 05:12:55 +01:00
hash_u5_init ( & hu5 , hrp ) ;
2018-07-28 08:00:16 +02:00
hash_u5 ( & hu5 , u5bytes , tal_count ( u5bytes ) ) ;
2017-11-24 05:12:55 +01:00
hash_u5_done ( & hu5 , & sha ) ;
tal_free ( hrp ) ;
if ( ! secp256k1_ecdsa_sign_recoverable ( secp256k1_ctx , rsig ,
( const u8 * ) & sha ,
privkey . secret . data ,
NULL , NULL ) )
abort ( ) ;
return true ;
}
static void test_b11 ( const char * b11str ,
const struct bolt11 * expect_b11 ,
const char * hashed_desc )
{
struct bolt11 * b11 ;
char * fail ;
char * reproduce ;
2019-05-10 03:17:49 +02:00
struct bolt11_field * b11_extra , * expect_extra ;
2017-11-24 05:12:55 +01:00
b11 = bolt11_decode ( tmpctx , b11str , hashed_desc , & fail ) ;
if ( ! b11 )
errx ( 1 , " %s:%u:%s " , __FILE__ , __LINE__ , fail ) ;
assert ( b11 - > chain = = expect_b11 - > chain ) ;
assert ( b11 - > timestamp = = expect_b11 - > timestamp ) ;
2019-02-21 03:38:35 +01:00
if ( ! b11 - > msat )
assert ( ! expect_b11 - > msat ) ;
2017-11-24 05:12:55 +01:00
else
2019-02-21 03:38:35 +01:00
assert ( amount_msat_eq ( * b11 - > msat , * expect_b11 - > msat ) ) ;
2018-07-04 07:30:02 +02:00
assert ( sha256_eq ( & b11 - > payment_hash , & expect_b11 - > payment_hash ) ) ;
2017-11-24 05:12:55 +01:00
if ( ! b11 - > description )
assert ( ! expect_b11 - > description ) ;
else
assert ( streq ( b11 - > description , expect_b11 - > description ) ) ;
2019-09-05 03:07:16 +02:00
assert ( memeq ( b11 - > features , tal_bytelen ( b11 - > features ) ,
expect_b11 - > features , tal_bytelen ( expect_b11 - > features ) ) ) ;
2017-11-24 05:12:55 +01:00
assert ( b11 - > expiry = = expect_b11 - > expiry ) ;
assert ( b11 - > min_final_cltv_expiry = = expect_b11 - > min_final_cltv_expiry ) ;
2018-04-05 07:13:51 +02:00
assert ( tal_count ( b11 - > fallbacks ) = = tal_count ( expect_b11 - > fallbacks ) ) ;
for ( size_t i = 0 ; i < tal_count ( b11 - > fallbacks ) ; i + + )
2018-07-28 08:00:16 +02:00
assert ( memeq ( b11 - > fallbacks [ i ] , tal_count ( b11 - > fallbacks [ i ] ) ,
2018-04-05 07:13:51 +02:00
expect_b11 - > fallbacks [ i ] ,
2018-07-28 08:00:16 +02:00
tal_count ( expect_b11 - > fallbacks [ i ] ) ) ) ;
2017-11-24 05:12:55 +01:00
/* FIXME: compare routes. */
assert ( tal_count ( b11 - > routes ) = = tal_count ( expect_b11 - > routes ) ) ;
2019-05-10 03:17:49 +02:00
expect_extra = list_top ( & expect_b11 - > extra_fields , struct bolt11_field ,
list ) ;
list_for_each ( & b11 - > extra_fields , b11_extra , list ) {
assert ( expect_extra - > tag = = b11_extra - > tag ) ;
assert ( memeq ( expect_extra - > data , tal_bytelen ( expect_extra - > data ) ,
b11_extra - > data , tal_bytelen ( b11_extra - > data ) ) ) ;
expect_extra = list_next ( & expect_b11 - > extra_fields ,
expect_extra , list ) ;
}
assert ( ! expect_extra ) ;
2017-11-24 05:12:55 +01:00
/* Re-encode to check */
reproduce = bolt11_encode ( tmpctx , b11 , false , test_sign , NULL ) ;
for ( size_t i = 0 ; i < strlen ( reproduce ) ; i + + ) {
2018-10-31 03:00:11 +01:00
if ( reproduce [ i ] ! = b11str [ i ]
& & reproduce [ i ] ! = tolower ( b11str [ i ] ) )
2017-11-24 05:12:55 +01:00
abort ( ) ;
}
2018-10-31 03:00:11 +01:00
assert ( strlen ( reproduce ) = = strlen ( b11str ) ) ;
2017-11-24 05:12:55 +01:00
}
int main ( void )
{
2018-04-25 12:55:34 +02:00
setup_locale ( ) ;
2017-11-24 05:12:55 +01:00
struct bolt11 * b11 ;
2019-04-08 11:58:32 +02:00
struct node_id node ;
2019-02-21 03:38:35 +01:00
struct amount_msat msatoshi ;
2018-10-31 02:21:01 +01:00
const char * badstr ;
2019-05-10 03:17:49 +02:00
struct bolt11_field * extra ;
2019-09-05 03:07:16 +02:00
char * fail ;
2017-11-24 05:12:55 +01:00
2018-10-16 10:48:13 +02:00
wally_init ( 0 ) ;
2019-04-22 15:10:17 +02:00
secp256k1_ctx = wally_get_secp_context ( ) ;
2018-03-15 07:10:20 +01:00
setup_tmpctx ( ) ;
2017-11-24 05:12:55 +01:00
/* BOLT #11:
*
* # Examples
*
* NB : all the following examples are signed with ` priv_key ` = ` e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734 ` .
*/
if ( ! hex_decode ( " e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734 " ,
strlen ( " e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734 " ) ,
& privkey , sizeof ( privkey ) ) )
abort ( ) ;
/* BOLT #11:
*
* > # # # Please make a donation of any amount using payment_hash 00010203040506070 80900010203040506070809000102030405060708090102 to me @ 03e7156 ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad
* > lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w
*/
2019-04-08 11:58:32 +02:00
if ( ! node_id_from_hexstr ( " 03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad " , strlen ( " 03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad " ) , & node ) )
2017-11-24 05:12:55 +01:00
abort ( ) ;
/* BOLT #11:
*
* Breakdown :
*
2019-01-14 03:26:25 +01:00
* * ` lnbc ` : prefix , Lightning on Bitcoin mainnet
2017-11-24 05:12:55 +01:00
* * ` 1 ` : Bech32 separator
* * ` pvjluez ` : timestamp ( 1496314658 )
* * ` p ` : payment hash
2018-06-17 12:10:53 +02:00
* * ` p5 ` : ` data_length ` ( ` p ` = 1 , ` 5 ` = 20 ; 1 * 32 + 20 = = 52 )
2017-11-24 05:12:55 +01:00
* * ` qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypq ` : payment hash 00010203040506070 80900010203040506070809000102030405060708090102
* * ` d ` : short description
2018-06-17 12:10:53 +02:00
* * ` pl ` : ` data_length ` ( ` p ` = 1 , ` l ` = 31 ; 1 * 32 + 31 = = 63 )
2017-11-24 05:12:55 +01:00
* * ` 2 pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq ` : ' Please consider supporting this project '
* * ` 8 rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcq ` : signature
* * ` ca784w ` : Bech32 checksum
*/
2018-03-15 07:10:20 +01:00
b11 = new_bolt11 ( tmpctx , NULL ) ;
2017-11-24 05:12:55 +01:00
b11 - > chain = chainparams_for_network ( " bitcoin " ) ;
b11 - > timestamp = 1496314658 ;
if ( ! hex_decode ( " 0001020304050607080900010203040506070809000102030405060708090102 " ,
strlen ( " 0001020304050607080900010203040506070809000102030405060708090102 " ) ,
& b11 - > payment_hash , sizeof ( b11 - > payment_hash ) ) )
abort ( ) ;
b11 - > receiver_id = node ;
b11 - > description = " Please consider supporting this project " ;
test_b11 ( " lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w " , b11 , NULL ) ;
/* BOLT #11:
*
2019-01-14 03:26:25 +01:00
* > # # # Please send $ 3 for a cup of coffee to the same peer , within one minute
2017-11-24 05:12:55 +01:00
* > lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaztrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspfj9srp
*
* Breakdown :
*
2019-01-14 03:26:25 +01:00
* * ` lnbc ` : prefix , Lightning on Bitcoin mainnet
2017-11-24 05:12:55 +01:00
* * ` 2500u ` : amount ( 2500 micro - bitcoin )
* * ` 1 ` : Bech32 separator
* * ` pvjluez ` : timestamp ( 1496314658 )
* * ` p ` : payment hash . . .
* * ` d ` : short description
2018-06-17 12:10:53 +02:00
* * ` q5 ` : ` data_length ` ( ` q ` = 0 , ` 5 ` = 20 ; 0 * 32 + 20 = = 20 )
2017-11-24 05:12:55 +01:00
* * ` xysxxatsyp3k7enxv4js ` : ' 1 cup coffee '
* * ` x ` : expiry time
2018-06-17 12:10:53 +02:00
* * ` qz ` : ` data_length ` ( ` q ` = 0 , ` z ` = 2 ; 0 * 32 + 2 = = 2 )
2019-01-14 03:26:25 +01:00
* * ` pu ` : 60 seconds ( ` p ` = 1 , ` u ` = 28 ; 1 * 32 + 28 = = 60 )
2017-11-24 05:12:55 +01:00
* * ` aztrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rsp ` : signature
* * ` fj9srp ` : Bech32 checksum
*/
2019-02-21 03:38:35 +01:00
msatoshi = AMOUNT_MSAT ( 2500 * ( 1000ULL * 100000000 ) / 1000000 ) ;
2018-03-15 07:10:20 +01:00
b11 = new_bolt11 ( tmpctx , & msatoshi ) ;
2017-11-24 05:12:55 +01:00
b11 - > chain = chainparams_for_network ( " bitcoin " ) ;
b11 - > timestamp = 1496314658 ;
if ( ! hex_decode ( " 0001020304050607080900010203040506070809000102030405060708090102 " ,
strlen ( " 0001020304050607080900010203040506070809000102030405060708090102 " ) ,
& b11 - > payment_hash , sizeof ( b11 - > payment_hash ) ) )
abort ( ) ;
b11 - > receiver_id = node ;
b11 - > description = " 1 cup coffee " ;
b11 - > expiry = 60 ;
test_b11 ( " lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaztrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspfj9srp " , b11 , NULL ) ;
/* BOLT #11:
*
* > # # # Now send $ 24 for an entire list of things ( hashed )
* > lnbc20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqscc6gd6ql3jrc5yzme8v4ntcewwz5cnw92tz0pc8qcuufvq7khhr8wpald05e92xw006sq94mg8v2ndf4sefvf9sygkshp5zfem29trqq2yxxz7
*
* Breakdown :
*
2019-01-14 03:26:25 +01:00
* * ` lnbc ` : prefix , Lightning on Bitcoin mainnet
2017-11-24 05:12:55 +01:00
* * ` 20 m ` : amount ( 20 milli - bitcoin )
* * ` 1 ` : Bech32 separator
* * ` pvjluez ` : timestamp ( 1496314658 )
* * ` p ` : payment hash . . .
* * ` h ` : tagged field : hash of description
2018-06-17 12:10:53 +02:00
* * ` p5 ` : ` data_length ` ( ` p ` = 1 , ` 5 ` = 20 ; 1 * 32 + 20 = = 52 )
2017-11-24 05:12:55 +01:00
* * ` 8 yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqs ` : SHA256 of ' One piece of chocolate cake , one icecream cone , one pickle , one slice of swiss cheese , one slice of salami , one lollypop , one piece of cherry pie , one sausage , one cupcake , and one slice of watermelon '
* * ` cc6gd6ql3jrc5yzme8v4ntcewwz5cnw92tz0pc8qcuufvq7khhr8wpald05e92xw006sq94mg8v2ndf4sefvf9sygkshp5zfem29trqq ` : signature
* * ` 2 yxxz7 ` : Bech32 checksum
*/
2019-02-21 03:38:35 +01:00
msatoshi = AMOUNT_MSAT ( 20 * ( 1000ULL * 100000000 ) / 1000 ) ;
2018-03-15 07:10:20 +01:00
b11 = new_bolt11 ( tmpctx , & msatoshi ) ;
2017-11-24 05:12:55 +01:00
b11 - > chain = chainparams_for_network ( " bitcoin " ) ;
b11 - > timestamp = 1496314658 ;
if ( ! hex_decode ( " 0001020304050607080900010203040506070809000102030405060708090102 " ,
strlen ( " 0001020304050607080900010203040506070809000102030405060708090102 " ) ,
& b11 - > payment_hash , sizeof ( b11 - > payment_hash ) ) )
abort ( ) ;
b11 - > receiver_id = node ;
b11 - > description_hash = tal ( b11 , struct sha256 ) ;
test_b11 ( " lnbc20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqscc6gd6ql3jrc5yzme8v4ntcewwz5cnw92tz0pc8qcuufvq7khhr8wpald05e92xw006sq94mg8v2ndf4sefvf9sygkshp5zfem29trqq2yxxz7 " , b11 , " One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon " ) ;
2018-10-31 02:21:01 +01:00
/* Malformed bolt11 strings (no '1'). */
badstr = " lnbc20mpvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqscc6gd6ql3jrc5yzme8v4ntcewwz5cnw92tz0pc8qcuufvq7khhr8wpald05e92xw006sq94mg8v2ndf4sefvf9sygkshp5zfem29trqq2yxxz7 " ;
for ( size_t i = 0 ; i < = strlen ( badstr ) ; i + + ) {
if ( bolt11_decode ( tmpctx , tal_strndup ( tmpctx , badstr , i ) ,
NULL , & fail ) )
abort ( ) ;
assert ( strstr ( fail , " Bad bech32 " )
| | strstr ( fail , " Invoices must start with ln " ) ) ;
}
2018-10-31 03:00:11 +01:00
/* ALL UPPERCASE is allowed (useful for QR codes) */
2019-02-21 03:38:35 +01:00
msatoshi = AMOUNT_MSAT ( 2500 * ( 1000ULL * 100000000 ) / 1000000 ) ;
2018-10-31 03:00:11 +01:00
b11 = new_bolt11 ( tmpctx , & msatoshi ) ;
b11 - > chain = chainparams_for_network ( " bitcoin " ) ;
b11 - > timestamp = 1496314658 ;
if ( ! hex_decode ( " 0001020304050607080900010203040506070809000102030405060708090102 " ,
strlen ( " 0001020304050607080900010203040506070809000102030405060708090102 " ) ,
& b11 - > payment_hash , sizeof ( b11 - > payment_hash ) ) )
abort ( ) ;
b11 - > receiver_id = node ;
b11 - > description = " 1 cup coffee " ;
b11 - > expiry = 60 ;
test_b11 ( " LNBC2500U1PVJLUEZPP5QQQSYQCYQ5RQWZQFQQQSYQCYQ5RQWZQFQQQSYQCYQ5RQWZQFQYPQDQ5XYSXXATSYP3K7ENXV4JSXQZPUAZTRNWNGZN3KDZW5HYDLZF03QDGM2HDQ27CQV3AGM2AWHZ5SE903VRUATFHQ77W3LS4EVS3CH9ZW97J25EMUDUPQ63NYW24CG27H2RSPFJ9SRP " , b11 , NULL ) ;
2019-05-10 03:17:49 +02:00
/* Unknown field handling */
if ( ! node_id_from_hexstr ( " 02330d13587b67a85c0a36ea001c4dba14bcd48dda8988f7303275b040bffb6abd " , strlen ( " 02330d13587b67a85c0a36ea001c4dba14bcd48dda8988f7303275b040bffb6abd " ) , & node ) )
abort ( ) ;
msatoshi = AMOUNT_MSAT ( 3000000000 ) ;
b11 = new_bolt11 ( tmpctx , & msatoshi ) ;
b11 - > chain = chainparams_for_network ( " testnet " ) ;
b11 - > timestamp = 1554294928 ;
if ( ! hex_decode ( " 850aeaf5f69670e8889936fc2e0cff3ceb0c3b5eab8f04ae57767118db673a91 " ,
strlen ( " 850aeaf5f69670e8889936fc2e0cff3ceb0c3b5eab8f04ae57767118db673a91 " ) ,
& b11 - > payment_hash , sizeof ( b11 - > payment_hash ) ) )
abort ( ) ;
b11 - > min_final_cltv_expiry = 9 ;
b11 - > receiver_id = node ;
b11 - > description = " Payment request with multipart support " ;
b11 - > expiry = 28800 ;
extra = tal ( b11 , struct bolt11_field ) ;
extra - > tag = ' v ' ;
extra - > data = tal_arr ( extra , u5 , 77 ) ;
for ( size_t i = 0 ; i < 77 ; i + + )
extra - > data [ i ] = bech32_charset_rev [ ( u8 ) " dp68gup69uhnzwfj9cejuvf3xshrwde68qcrswf0d46kcarfwpshyaplw3skw0tdw4k8g6tsv9e8g " [ i ] ] ;
list_add ( & b11 - > extra_fields , & extra - > list ) ;
test_b11 ( " lntb30m1pw2f2yspp5s59w4a0kjecw3zyexm7zur8l8n4scw674w8sftjhwec33km882gsdpa2pshjmt9de6zqun9w96k2um5ypmkjargypkh2mr5d9cxzun5ypeh2ursdae8gxqruyqvzddp68gup69uhnzwfj9cejuvf3xshrwde68qcrswf0d46kcarfwpshyaplw3skw0tdw4k8g6tsv9e8g4a3hx0v945csrmpm7yxyaamgt2xu7mu4xyt3vp7045n4k4czxf9kj0vw0m8dr5t3pjxuek04rtgyy8uzss5eet5gcyekd6m7u0mzv5sp7mdsag " , b11 , NULL ) ;
2019-09-05 03:07:16 +02:00
/* BOLT-a76d61dc9893eec75b2e9c4a361354c356c46894 #11:
*
* > # # # Please send $ 30 for coffee beans to the same peer , which supports features 1 and 9
* > lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdees9qzsze992adudgku8p05pstl6zh7av6rx2f297pv89gu5q93a0hf3g7lynl3xq56t23dpvah6u7y9qey9lccrdml3gaqwc6nxsl5ktzm464sq73t7cl
*
* Breakdown :
*
* * ` lnbc ` : prefix , Lightning on Bitcoin mainnet
* * ` 25 m ` : amount ( 25 milli - bitcoin )
* * ` 1 ` : Bech32 separator
* * ` pvjluez ` : timestamp ( 1496314658 )
* * ` p ` : payment hash . . .
* * ` d ` : short description
* * ` q5 ` : ` data_length ` ( ` q ` = 0 , ` 5 ` = 20 ; 0 * 32 + 20 = = 20 )
* * ` vdhkven9v5sxyetpdees ` : ' coffee beans '
* * ` 9 ` : features
* * ` qz ` : ` data_length ` ( ` q ` = 0 , ` z ` = 2 ; 0 * 32 + 2 = = 2 )
* * ` sz ` : b1000000010
* * ` e992adudgku8p05pstl6zh7av6rx2f297pv89gu5q93a0hf3g7lynl3xq56t23dpvah6u7y9qey9lccrdml3gaqwc6nxsl5ktzm464sq ` : signature
* * ` 73 t7cl ` : Bech32 checksum
*/
msatoshi = AMOUNT_MSAT ( 25 * ( 1000ULL * 100000000 ) / 1000 ) ;
b11 = new_bolt11 ( tmpctx , & msatoshi ) ;
b11 - > chain = chainparams_for_network ( " bitcoin " ) ;
b11 - > timestamp = 1496314658 ;
if ( ! hex_decode ( " 0001020304050607080900010203040506070809000102030405060708090102 " ,
strlen ( " 0001020304050607080900010203040506070809000102030405060708090102 " ) ,
& b11 - > payment_hash , sizeof ( b11 - > payment_hash ) ) )
abort ( ) ;
b11 - > receiver_id = node ;
b11 - > description = " coffee beans " ;
set_feature_bit ( & b11 - > features , 1 ) ;
set_feature_bit ( & b11 - > features , 9 ) ;
test_b11 ( " lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdees9qzsze992adudgku8p05pstl6zh7av6rx2f297pv89gu5q93a0hf3g7lynl3xq56t23dpvah6u7y9qey9lccrdml3gaqwc6nxsl5ktzm464sq73t7cl " , b11 , NULL ) ;
/* BOLT-a76d61dc9893eec75b2e9c4a361354c356c46894 #11:
*
* > # Same , but using invalid unknown feature 100
* > lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdees9q4pqqqqqqqqqqqqqqqqqqszk3ed62snp73037h4py4gry05eltlp0uezm2w9ajnerhmxzhzhsu40g9mgyx5v3ad4aqwkmvyftzk4k9zenz90mhjcy9hcevc7r3lx2sphzfxz7
*/
/* This one can be encoded, but not decoded */
set_feature_bit ( & b11 - > features , 100 ) ;
badstr = bolt11_encode ( tmpctx , b11 , false , test_sign , NULL ) ;
assert ( streq ( badstr , " lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdees9q4pqqqqqqqqqqqqqqqqqqszk3ed62snp73037h4py4gry05eltlp0uezm2w9ajnerhmxzhzhsu40g9mgyx5v3ad4aqwkmvyftzk4k9zenz90mhjcy9hcevc7r3lx2sphzfxz7 " ) ) ;
assert ( ! bolt11_decode ( tmpctx , badstr , NULL , & fail ) ) ;
assert ( streq ( fail , " 9: unknown feature bit 100 " ) ) ;
2017-11-24 05:12:55 +01:00
/* FIXME: Test the others! */
2018-03-28 04:32:39 +02:00
wally_cleanup ( 0 ) ;
2018-03-15 07:10:20 +01:00
tal_free ( tmpctx ) ;
2017-11-24 05:12:55 +01:00
return 0 ;
}