Skip to content

Commit 252c434

Browse files
committed
f - add offer metadata
1 parent ee8019a commit 252c434

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lightning/src/offers/offer.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ impl OfferBuilder {
4848
Destination::Path(path) => (None, Some(vec![path])),
4949
};
5050
let offer = Offer {
51-
id, chains: None, amount: None, description, features: None, absolute_expiry: None,
52-
issuer: None, paths, quantity_min: None, quantity_max: None, node_id,
53-
send_invoice: None, signature: None,
51+
id, chains: None, metadata: None, amount: None, description, features: None,
52+
absolute_expiry: None, issuer: None, paths, quantity_min: None, quantity_max: None,
53+
node_id, send_invoice: None, signature: None,
5454
};
5555
OfferBuilder { offer }
5656
}
@@ -66,6 +66,12 @@ impl OfferBuilder {
6666
self
6767
}
6868

69+
///
70+
pub fn metadata(mut self, metadata: Vec<u8>) -> Self {
71+
self.offer.metadata = Some(metadata);
72+
self
73+
}
74+
6975
///
7076
pub fn amount(mut self, amount: Amount) -> Self {
7177
self.offer.amount = Some(amount);
@@ -298,6 +304,7 @@ impl Offer {
298304

299305
reference::OfferTlvStream {
300306
chains: self.chains.as_ref().map(Into::into),
307+
metadata: self.metadata.as_ref().map(Into::into),
301308
currency,
302309
amount,
303310
description: Some((&self.description).into()),
@@ -341,6 +348,7 @@ pub struct SendInvoice;
341348

342349
tlv_stream!(struct OfferTlvStream {
343350
(2, chains: Vec<BlockHash>),
351+
(4, metadata: Vec<u8>),
344352
(6, currency: CurrencyCode),
345353
(8, amount: u64),
346354
(10, description: String),
@@ -409,6 +417,7 @@ mod tests {
409417

410418
assert_eq!(offer.id(), merkle::root_hash(&offer.to_bytes()));
411419
assert_eq!(offer.chain(), genesis_block(Network::Bitcoin).block_hash());
420+
assert_eq!(offer.metadata(), None);
412421
assert_eq!(offer.amount(), None);
413422
assert_eq!(offer.description(), "foo");
414423
assert_eq!(offer.features(), None);
@@ -423,6 +432,7 @@ mod tests {
423432
assert_eq!(offer.signature(), None);
424433

425434
assert_eq!(tlv_stream.chains, None);
435+
assert_eq!(tlv_stream.metadata, None);
426436
assert_eq!(tlv_stream.currency, None);
427437
assert_eq!(tlv_stream.amount, None);
428438
assert_eq!(tlv_stream.description, Some((&String::from("foo")).into()));
@@ -485,6 +495,22 @@ mod tests {
485495
assert_eq!(offer.as_tlv_stream().chains, Some((&block_hashes).into()));
486496
}
487497

498+
#[test]
499+
fn builds_offer_with_metadata() {
500+
let offer = OfferBuilder::new("foo".into(), Destination::NodeId(pubkey()))
501+
.metadata(vec![42; 32])
502+
.build();
503+
assert_eq!(offer.metadata(), Some(&vec![42; 32]));
504+
assert_eq!(offer.as_tlv_stream().metadata, Some((&vec![42; 32]).into()));
505+
506+
let offer = OfferBuilder::new("foo".into(), Destination::NodeId(pubkey()))
507+
.metadata(vec![42; 32])
508+
.metadata(vec![43; 32])
509+
.build();
510+
assert_eq!(offer.metadata(), Some(&vec![43; 32]));
511+
assert_eq!(offer.as_tlv_stream().metadata, Some((&vec![43; 32]).into()));
512+
}
513+
488514
#[test]
489515
fn builds_offer_with_amount() {
490516
let bitcoin_amount = Amount::Bitcoin { amount_msats: 1000 };

0 commit comments

Comments
 (0)