@@ -85,9 +85,9 @@ impl OfferBuilder {
85
85
/// Use a different pubkey per offer to avoid correlating offers.
86
86
pub fn new ( description : String , signing_pubkey : PublicKey ) -> Self {
87
87
let offer = OfferContents {
88
- chains : None , metadata : None , amount : None , description, features : None ,
89
- absolute_expiry : None , issuer : None , paths : None , quantity_min : None ,
90
- quantity_max : None , signing_pubkey : Some ( signing_pubkey) ,
88
+ chains : None , metadata : None , amount : None , description,
89
+ features : OfferFeatures :: empty ( ) , absolute_expiry : None , issuer : None , paths : None ,
90
+ quantity_min : None , quantity_max : None , signing_pubkey : Some ( signing_pubkey) ,
91
91
} ;
92
92
OfferBuilder { offer }
93
93
}
@@ -127,7 +127,7 @@ impl OfferBuilder {
127
127
/// Successive calls to this method will override the previous setting.
128
128
#[ cfg( test) ]
129
129
pub fn features ( mut self , features : OfferFeatures ) -> Self {
130
- self . offer . features = Some ( features) ;
130
+ self . offer . features = features;
131
131
self
132
132
}
133
133
@@ -350,13 +350,17 @@ impl OfferContents {
350
350
) ,
351
351
} ;
352
352
353
+ let features = {
354
+ if self . features == OfferFeatures :: empty ( ) { None } else { Some ( & self . features ) }
355
+ } ;
356
+
353
357
OfferTlvStreamRef {
354
358
chains : self . chains . as_ref ( ) ,
355
359
metadata : self . metadata . as_ref ( ) ,
356
360
currency,
357
361
amount,
358
362
description : Some ( & self . description ) ,
359
- features : self . features . as_ref ( ) ,
363
+ features,
360
364
absolute_expiry : self . absolute_expiry . map ( |duration| duration. as_secs ( ) ) ,
361
365
paths : self . paths . as_ref ( ) ,
362
366
issuer : self . issuer . as_ref ( ) ,
@@ -443,11 +447,11 @@ mod tests {
443
447
assert_eq ! ( offer. metadata( ) , None ) ;
444
448
assert_eq ! ( offer. amount( ) , None ) ;
445
449
assert_eq ! ( offer. description( ) , "foo" ) ;
446
- assert_eq ! ( offer. features( ) , None ) ;
450
+ assert_eq ! ( offer. features( ) , & OfferFeatures :: empty ( ) ) ;
447
451
assert_eq ! ( offer. absolute_expiry( ) , None ) ;
448
452
#[ cfg( feature = "std" ) ]
449
453
assert ! ( !offer. is_expired( ) ) ;
450
- assert_eq ! ( offer. paths( ) , None ) ;
454
+ assert_eq ! ( offer. paths( ) , & [ ] ) ;
451
455
assert_eq ! ( offer. issuer( ) , None ) ;
452
456
assert_eq ! ( offer. quantity_min( ) , 1 ) ;
453
457
assert_eq ! ( offer. quantity_max( ) , 1 ) ;
@@ -553,19 +557,19 @@ mod tests {
553
557
#[ test]
554
558
fn builds_offer_with_features ( ) {
555
559
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
556
- . features ( OfferFeatures :: empty ( ) )
560
+ . features ( OfferFeatures :: unknown ( ) )
557
561
. build ( )
558
562
. unwrap ( ) ;
559
- assert_eq ! ( offer. features( ) , Some ( & OfferFeatures :: empty ( ) ) ) ;
560
- assert_eq ! ( offer. as_tlv_stream( ) . features, Some ( & OfferFeatures :: empty ( ) ) ) ;
563
+ assert_eq ! ( offer. features( ) , & OfferFeatures :: unknown ( ) ) ;
564
+ assert_eq ! ( offer. as_tlv_stream( ) . features, Some ( & OfferFeatures :: unknown ( ) ) ) ;
561
565
562
566
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
563
567
. features ( OfferFeatures :: unknown ( ) )
564
568
. features ( OfferFeatures :: empty ( ) )
565
569
. build ( )
566
570
. unwrap ( ) ;
567
- assert_eq ! ( offer. features( ) , Some ( & OfferFeatures :: empty( ) ) ) ;
568
- assert_eq ! ( offer. as_tlv_stream( ) . features, Some ( & OfferFeatures :: empty ( ) ) ) ;
571
+ assert_eq ! ( offer. features( ) , & OfferFeatures :: empty( ) ) ;
572
+ assert_eq ! ( offer. as_tlv_stream( ) . features, None ) ;
569
573
}
570
574
571
575
#[ test]
@@ -620,7 +624,7 @@ mod tests {
620
624
. build ( )
621
625
. unwrap ( ) ;
622
626
let tlv_stream = offer. as_tlv_stream ( ) ;
623
- assert_eq ! ( offer. paths( ) , Some ( & paths) ) ;
627
+ assert_eq ! ( offer. paths( ) , paths. as_slice ( ) ) ;
624
628
assert_eq ! ( offer. signing_pubkey( ) , pubkey( 42 ) ) ;
625
629
assert_ne ! ( pubkey( 42 ) , pubkey( 44 ) ) ;
626
630
assert_eq ! ( tlv_stream. paths, Some ( & paths) ) ;
@@ -633,15 +637,15 @@ mod tests {
633
637
. issuer ( "bar" . into ( ) )
634
638
. build ( )
635
639
. unwrap ( ) ;
636
- assert_eq ! ( offer. issuer( ) , Some ( & String :: from ( "bar" ) ) ) ;
640
+ assert_eq ! ( offer. issuer( ) , Some ( "bar" ) ) ;
637
641
assert_eq ! ( offer. as_tlv_stream( ) . issuer, Some ( & String :: from( "bar" ) ) ) ;
638
642
639
643
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
640
644
. issuer ( "bar" . into ( ) )
641
645
. issuer ( "baz" . into ( ) )
642
646
. build ( )
643
647
. unwrap ( ) ;
644
- assert_eq ! ( offer. issuer( ) , Some ( & String :: from ( "baz" ) ) ) ;
648
+ assert_eq ! ( offer. issuer( ) , Some ( "baz" ) ) ;
645
649
assert_eq ! ( offer. as_tlv_stream( ) . issuer, Some ( & String :: from( "baz" ) ) ) ;
646
650
}
647
651
0 commit comments