Skip to content

Commit d396de2

Browse files
committed
f - add offer metadata
1 parent d85b5d9 commit d396de2

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
@@ -49,9 +49,9 @@ impl OfferBuilder {
4949
Destination::Path(path) => (None, Some(vec![path])),
5050
};
5151
let offer = Offer {
52-
id, chains: None, amount: None, description, features: None, absolute_expiry: None,
53-
issuer: None, paths, quantity_min: None, quantity_max: None, node_id,
54-
send_invoice: None, signature: None,
52+
id, chains: None, metadata: None, amount: None, description, features: None,
53+
absolute_expiry: None, issuer: None, paths, quantity_min: None, quantity_max: None,
54+
node_id, send_invoice: None, signature: None,
5555
};
5656
OfferBuilder { offer }
5757
}
@@ -67,6 +67,12 @@ impl OfferBuilder {
6767
self
6868
}
6969

70+
///
71+
pub fn metadata(mut self, metadata: Vec<u8>) -> Self {
72+
self.offer.metadata = Some(metadata);
73+
self
74+
}
75+
7076
///
7177
pub fn amount(mut self, amount: Amount) -> Self {
7278
self.offer.amount = Some(amount);
@@ -310,6 +316,7 @@ impl Offer {
310316

311317
reference::OfferTlvStream {
312318
chains: self.chains.as_ref().map(Into::into),
319+
metadata: self.metadata.as_ref().map(Into::into),
313320
currency,
314321
amount,
315322
description: Some((&self.description).into()),
@@ -353,6 +360,7 @@ pub struct SendInvoice;
353360

354361
tlv_stream!(struct OfferTlvStream {
355362
(2, chains: Vec<BlockHash>),
363+
(4, metadata: Vec<u8>),
356364
(6, currency: CurrencyCode),
357365
(8, amount: u64),
358366
(10, description: String),
@@ -421,6 +429,7 @@ mod tests {
421429

422430
assert_eq!(offer.id(), merkle::root_hash(&offer.to_bytes()));
423431
assert_eq!(offer.chain(), genesis_block(Network::Bitcoin).block_hash());
432+
assert_eq!(offer.metadata(), None);
424433
assert_eq!(offer.amount(), None);
425434
assert_eq!(offer.description(), "foo");
426435
assert_eq!(offer.features(), None);
@@ -435,6 +444,7 @@ mod tests {
435444
assert_eq!(offer.signature(), None);
436445

437446
assert_eq!(tlv_stream.chains, None);
447+
assert_eq!(tlv_stream.metadata, None);
438448
assert_eq!(tlv_stream.currency, None);
439449
assert_eq!(tlv_stream.amount, None);
440450
assert_eq!(tlv_stream.description, Some((&String::from("foo")).into()));
@@ -497,6 +507,22 @@ mod tests {
497507
assert_eq!(offer.as_tlv_stream().chains, Some((&block_hashes).into()));
498508
}
499509

510+
#[test]
511+
fn builds_offer_with_metadata() {
512+
let offer = OfferBuilder::new("foo".into(), Destination::NodeId(pubkey()))
513+
.metadata(vec![42; 32])
514+
.build();
515+
assert_eq!(offer.metadata(), Some(&vec![42; 32]));
516+
assert_eq!(offer.as_tlv_stream().metadata, Some((&vec![42; 32]).into()));
517+
518+
let offer = OfferBuilder::new("foo".into(), Destination::NodeId(pubkey()))
519+
.metadata(vec![42; 32])
520+
.metadata(vec![43; 32])
521+
.build();
522+
assert_eq!(offer.metadata(), Some(&vec![43; 32]));
523+
assert_eq!(offer.as_tlv_stream().metadata, Some((&vec![43; 32]).into()));
524+
}
525+
500526
#[test]
501527
fn builds_offer_with_amount() {
502528
let bitcoin_amount = Amount::Bitcoin { amount_msats: 1000 };

0 commit comments

Comments
 (0)