11
11
12
12
use bitcoin:: blockdata:: constants:: genesis_block;
13
13
use bitcoin:: hash_types:: BlockHash ;
14
- use bitcoin:: hashes:: { Hash , sha256} ;
15
14
use bitcoin:: network:: constants:: Network ;
16
15
use bitcoin:: secp256k1:: PublicKey ;
17
16
use core:: num:: NonZeroU64 ;
@@ -21,7 +20,6 @@ use ln::features::OfferFeatures;
21
20
use util:: ser:: WithLength ;
22
21
23
22
use prelude:: * ;
24
- use super :: merkle;
25
23
26
24
#[ cfg( feature = "std" ) ]
27
25
use std:: time:: SystemTime ;
@@ -42,13 +40,13 @@ pub enum Destination {
42
40
impl OfferBuilder {
43
41
///
44
42
pub fn new ( description : String , destination : Destination ) -> Self {
45
- let id = sha256 :: Hash :: all_zeros ( ) ;
43
+ let bytes = Vec :: new ( ) ;
46
44
let ( node_id, paths) = match destination {
47
45
Destination :: NodeId ( node_id) => ( Some ( node_id) , None ) ,
48
46
Destination :: Path ( path) => ( None , Some ( vec ! [ path] ) ) ,
49
47
} ;
50
48
let offer = Offer {
51
- id , chains : None , metadata : None , amount : None , description, features : None ,
49
+ bytes , chains : None , metadata : None , amount : None , description, features : None ,
52
50
absolute_expiry : None , issuer : None , paths, quantity_min : None , quantity_max : None ,
53
51
node_id, send_invoice : None ,
54
52
} ;
@@ -154,7 +152,7 @@ impl OfferBuilder {
154
152
155
153
///
156
154
pub fn build ( mut self ) -> Offer {
157
- self . offer . id = merkle :: root_hash ( & self . offer . to_bytes ( ) ) ;
155
+ self . offer . bytes = self . offer . to_bytes ( ) ;
158
156
self . offer
159
157
}
160
158
}
@@ -256,6 +254,11 @@ impl Offer {
256
254
self . send_invoice . as_ref ( )
257
255
}
258
256
257
+ #[ cfg( test) ]
258
+ fn as_bytes ( & self ) -> & [ u8 ] {
259
+ & self . bytes
260
+ }
261
+
259
262
fn to_bytes ( & self ) -> Vec < u8 > {
260
263
use util:: ser:: Writeable ;
261
264
let mut buffer = Vec :: new ( ) ;
@@ -351,7 +354,7 @@ type Empty = ();
351
354
352
355
#[ cfg( test) ]
353
356
mod tests {
354
- use super :: { Amount , BlindedPath , Destination , OfferBuilder , OnionMessagePath , SendInvoice , merkle } ;
357
+ use super :: { Amount , BlindedPath , Destination , OfferBuilder , OnionMessagePath , SendInvoice } ;
355
358
356
359
use bitcoin:: blockdata:: constants:: genesis_block;
357
360
use bitcoin:: network:: constants:: Network ;
@@ -383,7 +386,7 @@ mod tests {
383
386
let offer = OfferBuilder :: new ( "foo" . into ( ) , Destination :: NodeId ( pubkey ( ) ) ) . build ( ) ;
384
387
let tlv_stream = offer. as_tlv_stream ( ) ;
385
388
386
- assert_eq ! ( offer. id ( ) , merkle :: root_hash ( & offer. to_bytes( ) ) ) ;
389
+ assert_eq ! ( offer. as_bytes ( ) , & offer. to_bytes( ) [ .. ] ) ;
387
390
assert_eq ! ( offer. chain( ) , genesis_block( Network :: Bitcoin ) . block_hash( ) ) ;
388
391
assert_eq ! ( offer. metadata( ) , None ) ;
389
392
assert_eq ! ( offer. amount( ) , None ) ;
0 commit comments