@@ -49,9 +49,9 @@ impl OfferBuilder {
49
49
Destination :: Path ( path) => ( None , Some ( vec ! [ path] ) ) ,
50
50
} ;
51
51
let offer = Offer {
52
- id, chains : None , amount : None , description , features : None , absolute_expiry : None ,
53
- issuer : None , paths, quantity_min : None , quantity_max : None , node_id ,
54
- send_invoice : None , signature : None ,
52
+ id, chains : None , metadata : None , amount : None , description , features : None ,
53
+ absolute_expiry : None , issuer : None , paths, quantity_min : None , quantity_max : None ,
54
+ node_id , send_invoice : None , signature : None ,
55
55
} ;
56
56
OfferBuilder { offer }
57
57
}
@@ -67,6 +67,12 @@ impl OfferBuilder {
67
67
self
68
68
}
69
69
70
+ ///
71
+ pub fn metadata ( mut self , metadata : Vec < u8 > ) -> Self {
72
+ self . offer . metadata = Some ( metadata) ;
73
+ self
74
+ }
75
+
70
76
///
71
77
pub fn amount ( mut self , amount : Amount ) -> Self {
72
78
self . offer . amount = Some ( amount) ;
@@ -310,6 +316,7 @@ impl Offer {
310
316
311
317
reference:: OfferTlvStream {
312
318
chains : self . chains . as_ref ( ) . map ( Into :: into) ,
319
+ metadata : self . metadata . as_ref ( ) . map ( Into :: into) ,
313
320
currency,
314
321
amount,
315
322
description : Some ( ( & self . description ) . into ( ) ) ,
@@ -353,6 +360,7 @@ pub struct SendInvoice;
353
360
354
361
tlv_stream ! ( struct OfferTlvStream {
355
362
( 2 , chains: Vec <BlockHash >) ,
363
+ ( 4 , metadata: Vec <u8 >) ,
356
364
( 6 , currency: CurrencyCode ) ,
357
365
( 8 , amount: u64 ) ,
358
366
( 10 , description: String ) ,
@@ -421,6 +429,7 @@ mod tests {
421
429
422
430
assert_eq ! ( offer. id( ) , merkle:: root_hash( & offer. to_bytes( ) ) ) ;
423
431
assert_eq ! ( offer. chain( ) , genesis_block( Network :: Bitcoin ) . block_hash( ) ) ;
432
+ assert_eq ! ( offer. metadata( ) , None ) ;
424
433
assert_eq ! ( offer. amount( ) , None ) ;
425
434
assert_eq ! ( offer. description( ) , "foo" ) ;
426
435
assert_eq ! ( offer. features( ) , None ) ;
@@ -435,6 +444,7 @@ mod tests {
435
444
assert_eq ! ( offer. signature( ) , None ) ;
436
445
437
446
assert_eq ! ( tlv_stream. chains, None ) ;
447
+ assert_eq ! ( tlv_stream. metadata, None ) ;
438
448
assert_eq ! ( tlv_stream. currency, None ) ;
439
449
assert_eq ! ( tlv_stream. amount, None ) ;
440
450
assert_eq ! ( tlv_stream. description, Some ( ( & String :: from( "foo" ) ) . into( ) ) ) ;
@@ -497,6 +507,22 @@ mod tests {
497
507
assert_eq ! ( offer. as_tlv_stream( ) . chains, Some ( ( & block_hashes) . into( ) ) ) ;
498
508
}
499
509
510
+ #[ test]
511
+ fn builds_offer_with_metadata ( ) {
512
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , Destination :: NodeId ( pubkey ( ) ) )
513
+ . metadata ( vec ! [ 42 ; 32 ] )
514
+ . build ( ) ;
515
+ assert_eq ! ( offer. metadata( ) , Some ( & vec![ 42 ; 32 ] ) ) ;
516
+ assert_eq ! ( offer. as_tlv_stream( ) . metadata, Some ( ( & vec![ 42 ; 32 ] ) . into( ) ) ) ;
517
+
518
+ let offer = OfferBuilder :: new ( "foo" . into ( ) , Destination :: NodeId ( pubkey ( ) ) )
519
+ . metadata ( vec ! [ 42 ; 32 ] )
520
+ . metadata ( vec ! [ 43 ; 32 ] )
521
+ . build ( ) ;
522
+ assert_eq ! ( offer. metadata( ) , Some ( & vec![ 43 ; 32 ] ) ) ;
523
+ assert_eq ! ( offer. as_tlv_stream( ) . metadata, Some ( ( & vec![ 43 ; 32 ] ) . into( ) ) ) ;
524
+ }
525
+
500
526
#[ test]
501
527
fn builds_offer_with_amount ( ) {
502
528
let bitcoin_amount = Amount :: Bitcoin { amount_msats : 1000 } ;
0 commit comments