@@ -48,9 +48,9 @@ impl OfferBuilder {
48
48
Destination :: Path ( path) => ( None , Some ( vec ! [ path] ) ) ,
49
49
} ;
50
50
let offer = Offer {
51
- id, chains : None , amount : None , description , features : None , absolute_expiry : None ,
52
- issuer : None , paths, quantity_min : None , quantity_max : None , node_id ,
53
- send_invoice : None , signature : None ,
51
+ id, chains : None , metadata : None , amount : None , description , features : None ,
52
+ absolute_expiry : None , issuer : None , paths, quantity_min : None , quantity_max : None ,
53
+ node_id , send_invoice : None , signature : None ,
54
54
} ;
55
55
OfferBuilder { offer }
56
56
}
@@ -66,6 +66,12 @@ impl OfferBuilder {
66
66
self
67
67
}
68
68
69
+ ///
70
+ pub fn metadata ( mut self , metadata : Vec < u8 > ) -> Self {
71
+ self . offer . metadata = Some ( metadata) ;
72
+ self
73
+ }
74
+
69
75
///
70
76
pub fn amount ( mut self , amount : Amount ) -> Self {
71
77
self . offer . amount = Some ( amount) ;
@@ -298,6 +304,7 @@ impl Offer {
298
304
299
305
reference:: OfferTlvStream {
300
306
chains : self . chains . as_ref ( ) . map ( Into :: into) ,
307
+ metadata : self . metadata . as_ref ( ) . map ( Into :: into) ,
301
308
currency,
302
309
amount,
303
310
description : Some ( ( & self . description ) . into ( ) ) ,
@@ -341,6 +348,7 @@ pub struct SendInvoice;
341
348
342
349
tlv_stream ! ( struct OfferTlvStream {
343
350
( 2 , chains: Vec <BlockHash >) ,
351
+ ( 4 , metadata: Vec <u8 >) ,
344
352
( 6 , currency: CurrencyCode ) ,
345
353
( 8 , amount: u64 ) ,
346
354
( 10 , description: String ) ,
@@ -409,6 +417,7 @@ mod tests {
409
417
410
418
assert_eq ! ( offer. id( ) , merkle:: root_hash( & offer. to_bytes( ) ) ) ;
411
419
assert_eq ! ( offer. chain( ) , genesis_block( Network :: Bitcoin ) . block_hash( ) ) ;
420
+ assert_eq ! ( offer. metadata( ) , None ) ;
412
421
assert_eq ! ( offer. amount( ) , None ) ;
413
422
assert_eq ! ( offer. description( ) , "foo" ) ;
414
423
assert_eq ! ( offer. features( ) , None ) ;
@@ -423,6 +432,7 @@ mod tests {
423
432
assert_eq ! ( offer. signature( ) , None ) ;
424
433
425
434
assert_eq ! ( tlv_stream. chains, None ) ;
435
+ assert_eq ! ( tlv_stream. metadata, None ) ;
426
436
assert_eq ! ( tlv_stream. currency, None ) ;
427
437
assert_eq ! ( tlv_stream. amount, None ) ;
428
438
assert_eq ! ( tlv_stream. description, Some ( ( & String :: from( "foo" ) ) . into( ) ) ) ;
@@ -485,6 +495,22 @@ mod tests {
485
495
assert_eq ! ( offer. as_tlv_stream( ) . chains, Some ( ( & block_hashes) . into( ) ) ) ;
486
496
}
487
497
498
+ #[ test]
499
+ fn builds_offer_with_metadata ( ) {
500
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , Destination :: NodeId ( pubkey ( ) ) )
501
+ . metadata ( vec ! [ 42 ; 32 ] )
502
+ . build ( ) ;
503
+ assert_eq ! ( offer. metadata( ) , Some ( & vec![ 42 ; 32 ] ) ) ;
504
+ assert_eq ! ( offer. as_tlv_stream( ) . metadata, Some ( ( & vec![ 42 ; 32 ] ) . into( ) ) ) ;
505
+
506
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , Destination :: NodeId ( pubkey ( ) ) )
507
+ . metadata ( vec ! [ 42 ; 32 ] )
508
+ . metadata ( vec ! [ 43 ; 32 ] )
509
+ . build ( ) ;
510
+ assert_eq ! ( offer. metadata( ) , Some ( & vec![ 43 ; 32 ] ) ) ;
511
+ assert_eq ! ( offer. as_tlv_stream( ) . metadata, Some ( ( & vec![ 43 ; 32 ] ) . into( ) ) ) ;
512
+ }
513
+
488
514
#[ test]
489
515
fn builds_offer_with_amount ( ) {
490
516
let bitcoin_amount = Amount :: Bitcoin { amount_msats : 1000 } ;
0 commit comments