@@ -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
@@ -348,13 +348,17 @@ impl OfferContents {
348
348
) ,
349
349
} ;
350
350
351
+ let features = {
352
+ if self . features == OfferFeatures :: empty ( ) { None } else { Some ( & self . features ) }
353
+ } ;
354
+
351
355
OfferTlvStreamRef {
352
356
chains : self . chains . as_ref ( ) ,
353
357
metadata : self . metadata . as_ref ( ) ,
354
358
currency,
355
359
amount,
356
360
description : Some ( & self . description ) ,
357
- features : self . features . as_ref ( ) ,
361
+ features,
358
362
absolute_expiry : self . absolute_expiry . map ( |duration| duration. as_secs ( ) ) ,
359
363
paths : self . paths . as_ref ( ) ,
360
364
issuer : self . issuer . as_ref ( ) ,
@@ -441,11 +445,11 @@ mod tests {
441
445
assert_eq ! ( offer. metadata( ) , None ) ;
442
446
assert_eq ! ( offer. amount( ) , None ) ;
443
447
assert_eq ! ( offer. description( ) , "foo" ) ;
444
- assert_eq ! ( offer. features( ) , None ) ;
448
+ assert_eq ! ( offer. features( ) , & OfferFeatures :: empty ( ) ) ;
445
449
assert_eq ! ( offer. absolute_expiry( ) , None ) ;
446
450
#[ cfg( feature = "std" ) ]
447
451
assert ! ( !offer. is_expired( ) ) ;
448
- assert_eq ! ( offer. paths( ) , None ) ;
452
+ assert_eq ! ( offer. paths( ) , & [ ] ) ;
449
453
assert_eq ! ( offer. issuer( ) , None ) ;
450
454
assert_eq ! ( offer. quantity_min( ) , 1 ) ;
451
455
assert_eq ! ( offer. quantity_max( ) , 1 ) ;
@@ -551,19 +555,19 @@ mod tests {
551
555
#[ test]
552
556
fn builds_offer_with_features ( ) {
553
557
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
554
- . features ( OfferFeatures :: empty ( ) )
558
+ . features ( OfferFeatures :: unknown ( ) )
555
559
. build ( )
556
560
. unwrap ( ) ;
557
- assert_eq ! ( offer. features( ) , Some ( & OfferFeatures :: empty ( ) ) ) ;
558
- assert_eq ! ( offer. as_tlv_stream( ) . features, Some ( & OfferFeatures :: empty ( ) ) ) ;
561
+ assert_eq ! ( offer. features( ) , & OfferFeatures :: unknown ( ) ) ;
562
+ assert_eq ! ( offer. as_tlv_stream( ) . features, Some ( & OfferFeatures :: unknown ( ) ) ) ;
559
563
560
564
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
561
565
. features ( OfferFeatures :: unknown ( ) )
562
566
. features ( OfferFeatures :: empty ( ) )
563
567
. build ( )
564
568
. unwrap ( ) ;
565
- assert_eq ! ( offer. features( ) , Some ( & OfferFeatures :: empty( ) ) ) ;
566
- assert_eq ! ( offer. as_tlv_stream( ) . features, Some ( & OfferFeatures :: empty ( ) ) ) ;
569
+ assert_eq ! ( offer. features( ) , & OfferFeatures :: empty( ) ) ;
570
+ assert_eq ! ( offer. as_tlv_stream( ) . features, None ) ;
567
571
}
568
572
569
573
#[ test]
@@ -618,7 +622,7 @@ mod tests {
618
622
. build ( )
619
623
. unwrap ( ) ;
620
624
let tlv_stream = offer. as_tlv_stream ( ) ;
621
- assert_eq ! ( offer. paths( ) , Some ( & paths) ) ;
625
+ assert_eq ! ( offer. paths( ) , paths. as_slice ( ) ) ;
622
626
assert_eq ! ( offer. signing_pubkey( ) , pubkey( 42 ) ) ;
623
627
assert_ne ! ( pubkey( 42 ) , pubkey( 44 ) ) ;
624
628
assert_eq ! ( tlv_stream. paths, Some ( & paths) ) ;
@@ -631,15 +635,15 @@ mod tests {
631
635
. issuer ( "bar" . into ( ) )
632
636
. build ( )
633
637
. unwrap ( ) ;
634
- assert_eq ! ( offer. issuer( ) , Some ( & String :: from ( "bar" ) ) ) ;
638
+ assert_eq ! ( offer. issuer( ) , Some ( "bar" ) ) ;
635
639
assert_eq ! ( offer. as_tlv_stream( ) . issuer, Some ( & String :: from( "bar" ) ) ) ;
636
640
637
641
let offer = OfferBuilder :: new ( "foo" . into ( ) , pubkey ( 42 ) )
638
642
. issuer ( "bar" . into ( ) )
639
643
. issuer ( "baz" . into ( ) )
640
644
. build ( )
641
645
. unwrap ( ) ;
642
- assert_eq ! ( offer. issuer( ) , Some ( & String :: from ( "baz" ) ) ) ;
646
+ assert_eq ! ( offer. issuer( ) , Some ( "baz" ) ) ;
643
647
assert_eq ! ( offer. as_tlv_stream( ) . issuer, Some ( & String :: from( "baz" ) ) ) ;
644
648
}
645
649
0 commit comments