Skip to content

Commit ebb9e8b

Browse files
committed
f - replace offer id with bytes
1 parent f2dbaf5 commit ebb9e8b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lightning/src/offers/offer.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
use bitcoin::blockdata::constants::genesis_block;
1313
use bitcoin::hash_types::BlockHash;
14-
use bitcoin::hashes::{Hash, sha256};
1514
use bitcoin::network::constants::Network;
1615
use bitcoin::secp256k1::PublicKey;
1716
use core::num::NonZeroU64;
@@ -21,7 +20,6 @@ use ln::features::OfferFeatures;
2120
use util::ser::WithLength;
2221

2322
use prelude::*;
24-
use super::merkle;
2523

2624
#[cfg(feature = "std")]
2725
use std::time::SystemTime;
@@ -42,13 +40,13 @@ pub enum Destination {
4240
impl OfferBuilder {
4341
///
4442
pub fn new(description: String, destination: Destination) -> Self {
45-
let id = sha256::Hash::all_zeros();
43+
let bytes = Vec::new();
4644
let (node_id, paths) = match destination {
4745
Destination::NodeId(node_id) => (Some(node_id), None),
4846
Destination::Path(path) => (None, Some(vec![path])),
4947
};
5048
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,
5250
absolute_expiry: None, issuer: None, paths, quantity_min: None, quantity_max: None,
5351
node_id, send_invoice: None,
5452
};
@@ -154,7 +152,7 @@ impl OfferBuilder {
154152

155153
///
156154
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();
158156
self.offer
159157
}
160158
}
@@ -256,6 +254,11 @@ impl Offer {
256254
self.send_invoice.as_ref()
257255
}
258256

257+
#[cfg(test)]
258+
fn as_bytes(&self) -> &[u8] {
259+
&self.bytes
260+
}
261+
259262
fn to_bytes(&self) -> Vec<u8> {
260263
use util::ser::Writeable;
261264
let mut buffer = Vec::new();
@@ -351,7 +354,7 @@ type Empty = ();
351354

352355
#[cfg(test)]
353356
mod tests {
354-
use super::{Amount, BlindedPath, Destination, OfferBuilder, OnionMessagePath, SendInvoice, merkle};
357+
use super::{Amount, BlindedPath, Destination, OfferBuilder, OnionMessagePath, SendInvoice};
355358

356359
use bitcoin::blockdata::constants::genesis_block;
357360
use bitcoin::network::constants::Network;
@@ -383,7 +386,7 @@ mod tests {
383386
let offer = OfferBuilder::new("foo".into(), Destination::NodeId(pubkey())).build();
384387
let tlv_stream = offer.as_tlv_stream();
385388

386-
assert_eq!(offer.id(), merkle::root_hash(&offer.to_bytes()));
389+
assert_eq!(offer.as_bytes(), &offer.to_bytes()[..]);
387390
assert_eq!(offer.chain(), genesis_block(Network::Bitcoin).block_hash());
388391
assert_eq!(offer.metadata(), None);
389392
assert_eq!(offer.amount(), None);

0 commit comments

Comments
 (0)