From: Jeffrey Czyz Date: Wed, 24 Apr 2024 17:40:22 +0000 (-0500) Subject: Don't require Offer::description in API X-Git-Tag: v0.0.123-rc1~1^2~3^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=48cba2954b245f351c875c36fd22a7173d532ebe;p=rust-lightning Don't require Offer::description in API Offers currently require a description, though this may change to be optional. Remove the description requirement from the API, setting and empty string by default. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index d10c62791..e05a3ba46 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1554,11 +1554,12 @@ where /// # fn example(channel_manager: T) -> Result<(), Bolt12SemanticError> { /// # let channel_manager = channel_manager.get_cm(); /// let offer = channel_manager -/// .create_offer_builder("coffee".to_string())? +/// .create_offer_builder()? /// # ; /// # // Needed for compiling for c_bindings /// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into(); /// # let offer = builder +/// .description("coffee".to_string()) /// .amount_msats(10_000_000) /// .build()?; /// let bech32_offer = offer.to_string(); @@ -8553,9 +8554,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => { /// /// [`Offer`]: crate::offers::offer::Offer /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest - pub fn create_offer_builder( - &$self, description: String - ) -> Result<$builder, Bolt12SemanticError> { + pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> { let node_id = $self.get_our_node_id(); let expanded_key = &$self.inbound_payment_key; let entropy = &*$self.entropy_source; @@ -8563,7 +8562,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => { let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?; let builder = OfferBuilder::deriving_signing_pubkey( - description, node_id, expanded_key, entropy, secp_ctx + node_id, expanded_key, entropy, secp_ctx ) .chain_hash($self.chain_hash) .path(path); diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index e89e113e8..b36e9de39 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -268,7 +268,7 @@ fn prefers_non_tor_nodes_in_blinded_paths() { announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone()); let offer = bob.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .amount_msats(10_000_000) .build().unwrap(); assert_ne!(offer.signing_pubkey(), Some(bob_id)); @@ -283,7 +283,7 @@ fn prefers_non_tor_nodes_in_blinded_paths() { announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone()); let offer = bob.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .amount_msats(10_000_000) .build().unwrap(); assert_ne!(offer.signing_pubkey(), Some(bob_id)); @@ -333,7 +333,7 @@ fn prefers_more_connected_nodes_in_blinded_paths() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = bob.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .amount_msats(10_000_000) .build().unwrap(); assert_ne!(offer.signing_pubkey(), Some(bob_id)); @@ -382,7 +382,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder("coffee".to_string()) + .create_offer_builder() .unwrap() .amount_msats(10_000_000) .build().unwrap(); @@ -544,7 +544,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() { let bob_id = bob.node.get_our_node_id(); let offer = alice.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .amount_msats(10_000_000) .build().unwrap(); assert_ne!(offer.signing_pubkey(), Some(alice_id)); @@ -668,7 +668,7 @@ fn pays_for_offer_without_blinded_paths() { let bob_id = bob.node.get_our_node_id(); let offer = alice.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .clear_paths() .amount_msats(10_000_000) .build().unwrap(); @@ -760,7 +760,7 @@ fn fails_creating_offer_without_blinded_paths() { create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000); - match nodes[0].node.create_offer_builder("coffee".to_string()) { + match nodes[0].node.create_offer_builder() { Ok(_) => panic!("Expected error"), Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths), } @@ -803,7 +803,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() { let bob = &nodes[1]; let offer = alice.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .clear_chains() .chain(Network::Signet) .build().unwrap(); @@ -865,7 +865,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .amount_msats(10_000_000) .build().unwrap(); @@ -899,7 +899,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() { disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .amount_msats(10_000_000) .build().unwrap(); @@ -985,7 +985,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder("coffee".to_string()).unwrap() + .create_offer_builder().unwrap() .amount_msats(10_000_000) .build().unwrap(); diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index b05d6f3f7..f37a74507 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -2194,7 +2194,7 @@ mod tests { assert!(outbound_payments.has_pending_payments()); let created_at = now() - DEFAULT_RELATIVE_EXPIRY; - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2237,7 +2237,7 @@ mod tests { let payment_id = PaymentId([0; 32]); let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100)); - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2296,7 +2296,7 @@ mod tests { let payment_id = PaymentId([0; 32]); let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100)); - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 75bbcab93..647da4c4f 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -1529,7 +1529,7 @@ mod tests { let payment_paths = payment_paths(); let payment_hash = payment_hash(); let now = now(); - let unsigned_invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let unsigned_invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1546,7 +1546,7 @@ mod tests { assert_eq!(unsigned_invoice.offer_chains(), Some(vec![ChainHash::using_genesis_block(Network::Bitcoin)])); assert_eq!(unsigned_invoice.metadata(), None); assert_eq!(unsigned_invoice.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 })); - assert_eq!(unsigned_invoice.description(), PrintableString("foo")); + assert_eq!(unsigned_invoice.description(), PrintableString("")); assert_eq!(unsigned_invoice.offer_features(), Some(&OfferFeatures::empty())); assert_eq!(unsigned_invoice.absolute_expiry(), None); assert_eq!(unsigned_invoice.message_paths(), &[]); @@ -1590,7 +1590,7 @@ mod tests { assert_eq!(invoice.offer_chains(), Some(vec![ChainHash::using_genesis_block(Network::Bitcoin)])); assert_eq!(invoice.metadata(), None); assert_eq!(invoice.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 })); - assert_eq!(invoice.description(), PrintableString("foo")); + assert_eq!(invoice.description(), PrintableString("")); assert_eq!(invoice.offer_features(), Some(&OfferFeatures::empty())); assert_eq!(invoice.absolute_expiry(), None); assert_eq!(invoice.message_paths(), &[]); @@ -1631,7 +1631,7 @@ mod tests { metadata: None, currency: None, amount: Some(1000), - description: Some(&String::from("foo")), + description: Some(&String::from("")), features: None, absolute_expiry: None, paths: None, @@ -1767,7 +1767,7 @@ mod tests { let future_expiry = Duration::from_secs(u64::max_value()); let past_expiry = Duration::from_secs(0); - if let Err(e) = OfferBuilder::new("foo".into(), recipient_pubkey()) + if let Err(e) = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .absolute_expiry(future_expiry) .build().unwrap() @@ -1781,7 +1781,7 @@ mod tests { panic!("error building invoice: {:?}", e); } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .absolute_expiry(past_expiry) .build().unwrap() @@ -1827,7 +1827,6 @@ mod tests { #[test] fn builds_invoice_from_offer_using_derived_keys() { - let desc = "foo".to_string(); let node_id = recipient_pubkey(); let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); let entropy = FixedEntropy {}; @@ -1845,7 +1844,7 @@ mod tests { #[cfg(c_bindings)] use crate::offers::offer::OfferWithDerivedMetadataBuilder as OfferBuilder; let offer = OfferBuilder - ::deriving_signing_pubkey(desc, node_id, &expanded_key, &entropy, &secp_ctx) + ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx) .amount_msats(1000) .path(blinded_path) .build().unwrap(); @@ -1864,9 +1863,8 @@ mod tests { let expanded_key = ExpandedKey::new(&KeyMaterial([41; 32])); assert!(invoice_request.verify(&expanded_key, &secp_ctx).is_err()); - let desc = "foo".to_string(); let offer = OfferBuilder - ::deriving_signing_pubkey(desc, node_id, &expanded_key, &entropy, &secp_ctx) + ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx) .amount_msats(1000) // Omit the path so that node_id is used for the signing pubkey instead of deriving .build().unwrap(); @@ -1908,7 +1906,7 @@ mod tests { let now = now(); let one_hour = Duration::from_secs(3600); - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1924,7 +1922,7 @@ mod tests { assert_eq!(invoice.relative_expiry(), one_hour); assert_eq!(tlv_stream.relative_expiry, Some(one_hour.as_secs() as u32)); - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1943,7 +1941,7 @@ mod tests { #[test] fn builds_invoice_with_amount_from_request() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1960,7 +1958,7 @@ mod tests { #[test] fn builds_invoice_with_quantity_from_request() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -1975,7 +1973,7 @@ mod tests { assert_eq!(invoice.amount_msats(), 2000); assert_eq!(tlv_stream.amount, Some(2000)); - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -1997,7 +1995,7 @@ mod tests { let x_only_pubkey = XOnlyPublicKey::from_keypair(&recipient_keys()).0; let tweaked_pubkey = TweakedPublicKey::dangerous_assume_tweaked(x_only_pubkey); - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2042,7 +2040,7 @@ mod tests { let mut features = Bolt12InvoiceFeatures::empty(); features.set_basic_mpp_optional(); - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2059,7 +2057,7 @@ mod tests { #[test] fn fails_signing_invoice() { - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2073,7 +2071,7 @@ mod tests { Err(e) => assert_eq!(e, SignError::Signing), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2090,7 +2088,7 @@ mod tests { #[test] fn parses_invoice_with_payment_paths() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2145,7 +2143,7 @@ mod tests { #[test] fn parses_invoice_with_created_at() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2175,7 +2173,7 @@ mod tests { #[test] fn parses_invoice_with_relative_expiry() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2197,7 +2195,7 @@ mod tests { #[test] fn parses_invoice_with_payment_hash() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2227,7 +2225,7 @@ mod tests { #[test] fn parses_invoice_with_amount() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2255,7 +2253,7 @@ mod tests { #[test] fn parses_invoice_with_allow_mpp() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2286,7 +2284,7 @@ mod tests { let x_only_pubkey = XOnlyPublicKey::from_keypair(&recipient_keys()).0; let tweaked_pubkey = TweakedPublicKey::dangerous_assume_tweaked(x_only_pubkey); - let offer = OfferBuilder::new("foo".into(), recipient_pubkey()) + let offer = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap(); let invoice_request = offer @@ -2341,7 +2339,7 @@ mod tests { #[test] fn parses_invoice_with_node_id() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2407,7 +2405,7 @@ mod tests { Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys)) }; - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .clear_signing_pubkey() .amount_msats(1000) .path(paths[0].clone()) @@ -2429,7 +2427,7 @@ mod tests { panic!("error parsing invoice: {:?}", e); } - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .clear_signing_pubkey() .amount_msats(1000) .path(paths[0].clone()) @@ -2458,7 +2456,7 @@ mod tests { #[test] fn fails_parsing_invoice_without_signature() { let mut buffer = Vec::new(); - OfferBuilder::new("foo".into(), recipient_pubkey()) + OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2477,7 +2475,7 @@ mod tests { #[test] fn fails_parsing_invoice_with_invalid_signature() { - let mut invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let mut invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2502,7 +2500,7 @@ mod tests { #[test] fn fails_parsing_invoice_with_extra_tlv_records() { - let invoice = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index 60d1e3c02..90d6d5bf3 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -1247,7 +1247,7 @@ mod tests { #[test] fn builds_invoice_request_with_defaults() { - let unsigned_invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let unsigned_invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1263,7 +1263,7 @@ mod tests { assert_eq!(unsigned_invoice_request.chains(), vec![ChainHash::using_genesis_block(Network::Bitcoin)]); assert_eq!(unsigned_invoice_request.metadata(), None); assert_eq!(unsigned_invoice_request.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 })); - assert_eq!(unsigned_invoice_request.description(), PrintableString("foo")); + assert_eq!(unsigned_invoice_request.description(), PrintableString("")); assert_eq!(unsigned_invoice_request.offer_features(), &OfferFeatures::empty()); assert_eq!(unsigned_invoice_request.absolute_expiry(), None); assert_eq!(unsigned_invoice_request.paths(), &[]); @@ -1295,7 +1295,7 @@ mod tests { assert_eq!(invoice_request.chains(), vec![ChainHash::using_genesis_block(Network::Bitcoin)]); assert_eq!(invoice_request.metadata(), None); assert_eq!(invoice_request.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 })); - assert_eq!(invoice_request.description(), PrintableString("foo")); + assert_eq!(invoice_request.description(), PrintableString("")); assert_eq!(invoice_request.offer_features(), &OfferFeatures::empty()); assert_eq!(invoice_request.absolute_expiry(), None); assert_eq!(invoice_request.paths(), &[]); @@ -1321,7 +1321,7 @@ mod tests { metadata: None, currency: None, amount: Some(1000), - description: Some(&String::from("foo")), + description: Some(&String::from("")), features: None, absolute_expiry: None, paths: None, @@ -1353,7 +1353,7 @@ mod tests { let future_expiry = Duration::from_secs(u64::max_value()); let past_expiry = Duration::from_secs(0); - if let Err(e) = OfferBuilder::new("foo".into(), recipient_pubkey()) + if let Err(e) = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .absolute_expiry(future_expiry) .build().unwrap() @@ -1363,7 +1363,7 @@ mod tests { panic!("error building invoice_request: {:?}", e); } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .absolute_expiry(past_expiry) .build().unwrap() @@ -1383,7 +1383,7 @@ mod tests { let secp_ctx = Secp256k1::new(); let payment_id = PaymentId([1; 32]); - let offer = OfferBuilder::new("foo".into(), recipient_pubkey()) + let offer = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap(); let invoice_request = offer @@ -1456,7 +1456,7 @@ mod tests { let secp_ctx = Secp256k1::new(); let payment_id = PaymentId([1; 32]); - let offer = OfferBuilder::new("foo".into(), recipient_pubkey()) + let offer = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap(); let invoice_request = offer @@ -1526,7 +1526,7 @@ mod tests { let mainnet = ChainHash::using_genesis_block(Network::Bitcoin); let testnet = ChainHash::using_genesis_block(Network::Testnet); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1537,7 +1537,7 @@ mod tests { assert_eq!(invoice_request.chain(), mainnet); assert_eq!(tlv_stream.chain, None); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .chain(Network::Testnet) .build().unwrap() @@ -1549,7 +1549,7 @@ mod tests { assert_eq!(invoice_request.chain(), testnet); assert_eq!(tlv_stream.chain, Some(&testnet)); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .chain(Network::Bitcoin) .chain(Network::Testnet) @@ -1562,7 +1562,7 @@ mod tests { assert_eq!(invoice_request.chain(), mainnet); assert_eq!(tlv_stream.chain, None); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .chain(Network::Bitcoin) .chain(Network::Testnet) @@ -1576,7 +1576,7 @@ mod tests { assert_eq!(invoice_request.chain(), testnet); assert_eq!(tlv_stream.chain, Some(&testnet)); - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .chain(Network::Testnet) .build().unwrap() @@ -1587,7 +1587,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .chain(Network::Testnet) .build().unwrap() @@ -1601,7 +1601,7 @@ mod tests { #[test] fn builds_invoice_request_with_amount() { - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1612,7 +1612,7 @@ mod tests { assert_eq!(invoice_request.amount_msats(), Some(1000)); assert_eq!(tlv_stream.amount, Some(1000)); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1624,7 +1624,7 @@ mod tests { assert_eq!(invoice_request.amount_msats(), Some(1000)); assert_eq!(tlv_stream.amount, Some(1000)); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1635,7 +1635,7 @@ mod tests { assert_eq!(invoice_request.amount_msats(), Some(1001)); assert_eq!(tlv_stream.amount, Some(1001)); - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1645,7 +1645,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -1657,7 +1657,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1667,7 +1667,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -1680,7 +1680,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build() @@ -1689,7 +1689,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::MissingAmount), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -1704,7 +1704,7 @@ mod tests { #[test] fn builds_invoice_request_with_features() { - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1715,7 +1715,7 @@ mod tests { assert_eq!(invoice_request.invoice_request_features(), &InvoiceRequestFeatures::unknown()); assert_eq!(tlv_stream.features, Some(&InvoiceRequestFeatures::unknown())); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1733,7 +1733,7 @@ mod tests { let one = NonZeroU64::new(1).unwrap(); let ten = NonZeroU64::new(10).unwrap(); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::One) .build().unwrap() @@ -1744,7 +1744,7 @@ mod tests { assert_eq!(invoice_request.quantity(), None); assert_eq!(tlv_stream.quantity, None); - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::One) .build().unwrap() @@ -1756,7 +1756,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::UnexpectedQuantity), } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Bounded(ten)) .build().unwrap() @@ -1769,7 +1769,7 @@ mod tests { assert_eq!(invoice_request.amount_msats(), Some(10_000)); assert_eq!(tlv_stream.amount, Some(10_000)); - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Bounded(ten)) .build().unwrap() @@ -1781,7 +1781,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidQuantity), } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -1794,7 +1794,7 @@ mod tests { assert_eq!(invoice_request.amount_msats(), Some(2_000)); assert_eq!(tlv_stream.amount, Some(2_000)); - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -1805,7 +1805,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::MissingQuantity), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Bounded(one)) .build().unwrap() @@ -1819,7 +1819,7 @@ mod tests { #[test] fn builds_invoice_request_with_payer_note() { - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1830,7 +1830,7 @@ mod tests { assert_eq!(invoice_request.payer_note(), Some(PrintableString("bar"))); assert_eq!(tlv_stream.payer_note, Some(&String::from("bar"))); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1845,7 +1845,7 @@ mod tests { #[test] fn fails_signing_invoice_request() { - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1856,7 +1856,7 @@ mod tests { Err(e) => assert_eq!(e, SignError::Signing), } - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1870,7 +1870,7 @@ mod tests { #[test] fn fails_responding_with_unknown_required_features() { - match OfferBuilder::new("foo".into(), recipient_pubkey()) + match OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![42; 32], payer_pubkey()).unwrap() @@ -1886,7 +1886,7 @@ mod tests { #[test] fn parses_invoice_request_with_metadata() { - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1903,7 +1903,7 @@ mod tests { #[test] fn parses_invoice_request_with_chain() { - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1918,7 +1918,7 @@ mod tests { panic!("error parsing invoice_request: {:?}", e); } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1937,7 +1937,7 @@ mod tests { #[test] fn parses_invoice_request_with_amount() { - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1951,7 +1951,7 @@ mod tests { panic!("error parsing invoice_request: {:?}", e); } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() .amount_msats(1000).unwrap() @@ -1965,7 +1965,7 @@ mod tests { panic!("error parsing invoice_request: {:?}", e); } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build_unchecked() @@ -1979,7 +1979,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount)), } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -1995,7 +1995,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InsufficientAmount)), } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount(Amount::Currency { iso4217_code: *b"USD", amount: 1000 }) .build_unchecked() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2012,7 +2012,7 @@ mod tests { }, } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -2035,7 +2035,7 @@ mod tests { let one = NonZeroU64::new(1).unwrap(); let ten = NonZeroU64::new(10).unwrap(); - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::One) .build().unwrap() @@ -2050,7 +2050,7 @@ mod tests { panic!("error parsing invoice_request: {:?}", e); } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::One) .build().unwrap() @@ -2070,7 +2070,7 @@ mod tests { }, } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Bounded(ten)) .build().unwrap() @@ -2087,7 +2087,7 @@ mod tests { panic!("error parsing invoice_request: {:?}", e); } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Bounded(ten)) .build().unwrap() @@ -2105,7 +2105,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidQuantity)), } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -2122,7 +2122,7 @@ mod tests { panic!("error parsing invoice_request: {:?}", e); } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap() @@ -2138,7 +2138,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingQuantity)), } - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .supported_quantity(Quantity::Bounded(one)) .build().unwrap() @@ -2157,7 +2157,7 @@ mod tests { #[test] fn fails_parsing_invoice_request_without_metadata() { - let offer = OfferBuilder::new("foo".into(), recipient_pubkey()) + let offer = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap(); let unsigned_invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2178,7 +2178,7 @@ mod tests { #[test] fn fails_parsing_invoice_request_without_payer_id() { - let offer = OfferBuilder::new("foo".into(), recipient_pubkey()) + let offer = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap(); let unsigned_invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2197,7 +2197,7 @@ mod tests { #[test] fn fails_parsing_invoice_request_without_node_id() { - let offer = OfferBuilder::new("foo".into(), recipient_pubkey()) + let offer = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap(); let unsigned_invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2219,7 +2219,7 @@ mod tests { #[test] fn fails_parsing_invoice_request_without_signature() { let mut buffer = Vec::new(); - OfferBuilder::new("foo".into(), recipient_pubkey()) + OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2235,7 +2235,7 @@ mod tests { #[test] fn fails_parsing_invoice_request_with_invalid_signature() { - let mut invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let mut invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -2259,7 +2259,7 @@ mod tests { fn fails_parsing_invoice_request_with_extra_tlv_records() { let secp_ctx = Secp256k1::new(); let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()); - let invoice_request = OfferBuilder::new("foo".into(), keys.public_key()) + let invoice_request = OfferBuilder::new(keys.public_key()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], keys.public_key()).unwrap() @@ -2283,7 +2283,6 @@ mod tests { #[test] fn copies_verified_invoice_request_fields() { - let desc = "foo".to_string(); let node_id = recipient_pubkey(); let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); let entropy = FixedEntropy {}; @@ -2292,7 +2291,7 @@ mod tests { #[cfg(c_bindings)] use crate::offers::offer::OfferWithDerivedMetadataBuilder as OfferBuilder; let offer = OfferBuilder - ::deriving_signing_pubkey(desc, node_id, &expanded_key, &entropy, &secp_ctx) + ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx) .chain(Network::Testnet) .amount_msats(1000) .supported_quantity(Quantity::Unbounded) diff --git a/lightning/src/offers/merkle.rs b/lightning/src/offers/merkle.rs index a39798669..d8d1a90e3 100644 --- a/lightning/src/offers/merkle.rs +++ b/lightning/src/offers/merkle.rs @@ -346,7 +346,8 @@ mod tests { }; // BOLT 12 test vectors - let invoice_request = OfferBuilder::new("A Mathematical Treatise".into(), recipient_pubkey) + let invoice_request = OfferBuilder::new(recipient_pubkey) + .description("A Mathematical Treatise".into()) .amount(Amount::Currency { iso4217_code: *b"USD", amount: 100 }) .build_unchecked() .request_invoice(vec![0; 8], payer_keys.public_key()).unwrap() @@ -371,7 +372,7 @@ mod tests { #[test] fn compute_tagged_hash() { - let unsigned_invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey()) + let unsigned_invoice_request = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() .request_invoice(vec![1; 32], payer_pubkey()).unwrap() @@ -400,7 +401,7 @@ mod tests { KeyPair::from_secret_key(&secp_ctx, &secret_key) }; - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey) + let invoice_request = OfferBuilder::new(recipient_pubkey) .amount_msats(100) .build_unchecked() .request_invoice(vec![0; 8], payer_keys.public_key()).unwrap() @@ -432,7 +433,7 @@ mod tests { KeyPair::from_secret_key(&secp_ctx, &secret_key) }; - let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey) + let invoice_request = OfferBuilder::new(recipient_pubkey) .amount_msats(100) .build_unchecked() .request_invoice(vec![0; 8], payer_keys.public_key()).unwrap() diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index 8e93a93f8..baac94951 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -43,7 +43,8 @@ //! let pubkey = PublicKey::from(keys); //! //! let expiration = SystemTime::now() + Duration::from_secs(24 * 60 * 60); -//! let offer = OfferBuilder::new("coffee, large".to_string(), pubkey) +//! let offer = OfferBuilder::new(pubkey) +//! .description("coffee, large".to_string()) //! .amount_msats(20_000) //! .supported_quantity(Quantity::Unbounded) //! .absolute_expiry(expiration.duration_since(SystemTime::UNIX_EPOCH).unwrap()) @@ -208,7 +209,7 @@ impl MetadataStrategy for DerivedMetadata {} macro_rules! offer_explicit_metadata_builder_methods { ( $self: ident, $self_type: ty, $return_type: ty, $return_value: expr ) => { - /// Creates a new builder for an offer setting the [`Offer::description`] and using the + /// Creates a new builder for an offer setting an empty [`Offer::description`] and using the /// [`Offer::signing_pubkey`] for signing invoices. The associated secret key must be remembered /// while the offer is valid. /// @@ -221,10 +222,10 @@ macro_rules! offer_explicit_metadata_builder_methods { ( /// /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager /// [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder - pub fn new(description: String, signing_pubkey: PublicKey) -> Self { + pub fn new(signing_pubkey: PublicKey) -> Self { Self { offer: OfferContents { - chains: None, metadata: None, amount: None, description, + chains: None, metadata: None, amount: None, description: String::new(), features: OfferFeatures::empty(), absolute_expiry: None, issuer: None, paths: None, supported_quantity: Quantity::One, signing_pubkey: Some(signing_pubkey), }, @@ -255,7 +256,7 @@ macro_rules! offer_derived_metadata_builder_methods { ($secp_context: ty) => { /// [`InvoiceRequest::verify`]: crate::offers::invoice_request::InvoiceRequest::verify /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey pub fn deriving_signing_pubkey( - description: String, node_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES, + node_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES, secp_ctx: &'a Secp256k1<$secp_context> ) -> Self where ES::Target: EntropySource { let nonce = Nonce::from_entropy_source(entropy_source); @@ -263,7 +264,7 @@ macro_rules! offer_derived_metadata_builder_methods { ($secp_context: ty) => { let metadata = Metadata::DerivedSigningPubkey(derivation_material); Self { offer: OfferContents { - chains: None, metadata: Some(metadata), amount: None, description, + chains: None, metadata: Some(metadata), amount: None, description: String::new(), features: OfferFeatures::empty(), absolute_expiry: None, issuer: None, paths: None, supported_quantity: Quantity::One, signing_pubkey: Some(node_id), }, @@ -325,6 +326,14 @@ macro_rules! offer_builder_methods { ( $return_value } + /// Sets the [`Offer::description`]. + /// + /// Successive calls to this method will override the previous setting. + pub fn description($($self_mut)* $self: $self_type, description: String) -> $return_type { + $self.offer.description = description; + $return_value + } + /// Sets the [`Offer::issuer`]. /// /// Successive calls to this method will override the previous setting. @@ -1147,7 +1156,7 @@ mod tests { #[test] fn builds_offer_with_defaults() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)).build().unwrap(); + let offer = OfferBuilder::new(pubkey(42)).build().unwrap(); let mut buffer = Vec::new(); offer.write(&mut buffer).unwrap(); @@ -1157,7 +1166,7 @@ mod tests { assert!(offer.supports_chain(ChainHash::using_genesis_block(Network::Bitcoin))); assert_eq!(offer.metadata(), None); assert_eq!(offer.amount(), None); - assert_eq!(offer.description(), PrintableString("foo")); + assert_eq!(offer.description(), PrintableString("")); assert_eq!(offer.offer_features(), &OfferFeatures::empty()); assert_eq!(offer.absolute_expiry(), None); #[cfg(feature = "std")] @@ -1174,7 +1183,7 @@ mod tests { metadata: None, currency: None, amount: None, - description: Some(&String::from("foo")), + description: Some(&String::from("")), features: None, absolute_expiry: None, paths: None, @@ -1194,7 +1203,7 @@ mod tests { let mainnet = ChainHash::using_genesis_block(Network::Bitcoin); let testnet = ChainHash::using_genesis_block(Network::Testnet); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .chain(Network::Bitcoin) .build() .unwrap(); @@ -1202,7 +1211,7 @@ mod tests { assert_eq!(offer.chains(), vec![mainnet]); assert_eq!(offer.as_tlv_stream().chains, None); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .chain(Network::Testnet) .build() .unwrap(); @@ -1210,7 +1219,7 @@ mod tests { assert_eq!(offer.chains(), vec![testnet]); assert_eq!(offer.as_tlv_stream().chains, Some(&vec![testnet])); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .chain(Network::Testnet) .chain(Network::Testnet) .build() @@ -1219,7 +1228,7 @@ mod tests { assert_eq!(offer.chains(), vec![testnet]); assert_eq!(offer.as_tlv_stream().chains, Some(&vec![testnet])); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .chain(Network::Bitcoin) .chain(Network::Testnet) .build() @@ -1232,14 +1241,14 @@ mod tests { #[test] fn builds_offer_with_metadata() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .metadata(vec![42; 32]).unwrap() .build() .unwrap(); assert_eq!(offer.metadata(), Some(&vec![42; 32])); assert_eq!(offer.as_tlv_stream().metadata, Some(&vec![42; 32])); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .metadata(vec![42; 32]).unwrap() .metadata(vec![43; 32]).unwrap() .build() @@ -1250,7 +1259,6 @@ mod tests { #[test] fn builds_offer_with_metadata_derived() { - let desc = "foo".to_string(); let node_id = recipient_pubkey(); let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); let entropy = FixedEntropy {}; @@ -1259,7 +1267,7 @@ mod tests { #[cfg(c_bindings)] use super::OfferWithDerivedMetadataBuilder as OfferBuilder; let offer = OfferBuilder - ::deriving_signing_pubkey(desc, node_id, &expanded_key, &entropy, &secp_ctx) + ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx) .amount_msats(1000) .build().unwrap(); assert_eq!(offer.signing_pubkey(), Some(node_id)); @@ -1302,7 +1310,6 @@ mod tests { #[test] fn builds_offer_with_derived_signing_pubkey() { - let desc = "foo".to_string(); let node_id = recipient_pubkey(); let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); let entropy = FixedEntropy {}; @@ -1320,7 +1327,7 @@ mod tests { #[cfg(c_bindings)] use super::OfferWithDerivedMetadataBuilder as OfferBuilder; let offer = OfferBuilder - ::deriving_signing_pubkey(desc, node_id, &expanded_key, &entropy, &secp_ctx) + ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx) .amount_msats(1000) .path(blinded_path) .build().unwrap(); @@ -1367,7 +1374,7 @@ mod tests { let bitcoin_amount = Amount::Bitcoin { amount_msats: 1000 }; let currency_amount = Amount::Currency { iso4217_code: *b"USD", amount: 10 }; - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .amount_msats(1000) .build() .unwrap(); @@ -1377,10 +1384,10 @@ mod tests { assert_eq!(tlv_stream.currency, None); #[cfg(not(c_bindings))] - let builder = OfferBuilder::new("foo".into(), pubkey(42)) + let builder = OfferBuilder::new(pubkey(42)) .amount(currency_amount.clone()); #[cfg(c_bindings)] - let mut builder = OfferBuilder::new("foo".into(), pubkey(42)); + let mut builder = OfferBuilder::new(pubkey(42)); #[cfg(c_bindings)] builder.amount(currency_amount.clone()); let tlv_stream = builder.offer.as_tlv_stream(); @@ -1392,7 +1399,7 @@ mod tests { Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedCurrency), } - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .amount(currency_amount.clone()) .amount(bitcoin_amount.clone()) .build() @@ -1402,22 +1409,40 @@ mod tests { assert_eq!(tlv_stream.currency, None); let invalid_amount = Amount::Bitcoin { amount_msats: MAX_VALUE_MSAT + 1 }; - match OfferBuilder::new("foo".into(), pubkey(42)).amount(invalid_amount).build() { + match OfferBuilder::new(pubkey(42)).amount(invalid_amount).build() { Ok(_) => panic!("expected error"), Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount), } } + #[test] + fn builds_offer_with_description() { + let offer = OfferBuilder::new(pubkey(42)) + .description("foo".into()) + .build() + .unwrap(); + assert_eq!(offer.description(), PrintableString("foo")); + assert_eq!(offer.as_tlv_stream().description, Some(&String::from("foo"))); + + let offer = OfferBuilder::new(pubkey(42)) + .description("foo".into()) + .description("bar".into()) + .build() + .unwrap(); + assert_eq!(offer.description(), PrintableString("bar")); + assert_eq!(offer.as_tlv_stream().description, Some(&String::from("bar"))); + } + #[test] fn builds_offer_with_features() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .features_unchecked(OfferFeatures::unknown()) .build() .unwrap(); assert_eq!(offer.offer_features(), &OfferFeatures::unknown()); assert_eq!(offer.as_tlv_stream().features, Some(&OfferFeatures::unknown())); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .features_unchecked(OfferFeatures::unknown()) .features_unchecked(OfferFeatures::empty()) .build() @@ -1432,7 +1457,7 @@ mod tests { let past_expiry = Duration::from_secs(0); let now = future_expiry - Duration::from_secs(1_000); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .absolute_expiry(future_expiry) .build() .unwrap(); @@ -1442,7 +1467,7 @@ mod tests { assert_eq!(offer.absolute_expiry(), Some(future_expiry)); assert_eq!(offer.as_tlv_stream().absolute_expiry, Some(future_expiry.as_secs())); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .absolute_expiry(future_expiry) .absolute_expiry(past_expiry) .build() @@ -1475,7 +1500,7 @@ mod tests { }, ]; - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .path(paths[0].clone()) .path(paths[1].clone()) .build() @@ -1490,20 +1515,20 @@ mod tests { #[test] fn builds_offer_with_issuer() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)) - .issuer("bar".into()) + let offer = OfferBuilder::new(pubkey(42)) + .issuer("foo".into()) .build() .unwrap(); - assert_eq!(offer.issuer(), Some(PrintableString("bar"))); - assert_eq!(offer.as_tlv_stream().issuer, Some(&String::from("bar"))); + assert_eq!(offer.issuer(), Some(PrintableString("foo"))); + assert_eq!(offer.as_tlv_stream().issuer, Some(&String::from("foo"))); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) + .issuer("foo".into()) .issuer("bar".into()) - .issuer("baz".into()) .build() .unwrap(); - assert_eq!(offer.issuer(), Some(PrintableString("baz"))); - assert_eq!(offer.as_tlv_stream().issuer, Some(&String::from("baz"))); + assert_eq!(offer.issuer(), Some(PrintableString("bar"))); + assert_eq!(offer.as_tlv_stream().issuer, Some(&String::from("bar"))); } #[test] @@ -1511,7 +1536,7 @@ mod tests { let one = NonZeroU64::new(1).unwrap(); let ten = NonZeroU64::new(10).unwrap(); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::One) .build() .unwrap(); @@ -1519,7 +1544,7 @@ mod tests { assert_eq!(offer.supported_quantity(), Quantity::One); assert_eq!(tlv_stream.quantity_max, None); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::Unbounded) .build() .unwrap(); @@ -1527,7 +1552,7 @@ mod tests { assert_eq!(offer.supported_quantity(), Quantity::Unbounded); assert_eq!(tlv_stream.quantity_max, Some(0)); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::Bounded(ten)) .build() .unwrap(); @@ -1535,7 +1560,7 @@ mod tests { assert_eq!(offer.supported_quantity(), Quantity::Bounded(ten)); assert_eq!(tlv_stream.quantity_max, Some(10)); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::Bounded(one)) .build() .unwrap(); @@ -1543,7 +1568,7 @@ mod tests { assert_eq!(offer.supported_quantity(), Quantity::Bounded(one)); assert_eq!(tlv_stream.quantity_max, Some(1)); - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::Bounded(ten)) .supported_quantity(Quantity::One) .build() @@ -1555,7 +1580,7 @@ mod tests { #[test] fn fails_requesting_invoice_with_unknown_required_features() { - match OfferBuilder::new("foo".into(), pubkey(42)) + match OfferBuilder::new(pubkey(42)) .features_unchecked(OfferFeatures::unknown()) .build().unwrap() .request_invoice(vec![1; 32], pubkey(43)) @@ -1567,7 +1592,7 @@ mod tests { #[test] fn parses_offer_with_chains() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .chain(Network::Bitcoin) .chain(Network::Testnet) .build() @@ -1579,7 +1604,7 @@ mod tests { #[test] fn parses_offer_with_amount() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .amount(Amount::Bitcoin { amount_msats: 1000 }) .build() .unwrap(); @@ -1625,7 +1650,7 @@ mod tests { #[test] fn parses_offer_with_description() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)).build().unwrap(); + let offer = OfferBuilder::new(pubkey(42)).build().unwrap(); if let Err(e) = offer.to_string().parse::() { panic!("error parsing offer: {:?}", e); } @@ -1646,7 +1671,7 @@ mod tests { #[test] fn parses_offer_with_paths() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .path(BlindedPath { introduction_node: IntroductionNode::NodeId(pubkey(40)), blinding_point: pubkey(41), @@ -1669,7 +1694,7 @@ mod tests { panic!("error parsing offer: {:?}", e); } - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .path(BlindedPath { introduction_node: IntroductionNode::NodeId(pubkey(40)), blinding_point: pubkey(41), @@ -1685,7 +1710,7 @@ mod tests { panic!("error parsing offer: {:?}", e); } - let mut builder = OfferBuilder::new("foo".into(), pubkey(42)); + let mut builder = OfferBuilder::new(pubkey(42)); builder.offer.paths = Some(vec![]); let offer = builder.build().unwrap(); @@ -1699,7 +1724,7 @@ mod tests { #[test] fn parses_offer_with_quantity() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::One) .build() .unwrap(); @@ -1707,7 +1732,7 @@ mod tests { panic!("error parsing offer: {:?}", e); } - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::Unbounded) .build() .unwrap(); @@ -1715,7 +1740,7 @@ mod tests { panic!("error parsing offer: {:?}", e); } - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::Bounded(NonZeroU64::new(10).unwrap())) .build() .unwrap(); @@ -1723,7 +1748,7 @@ mod tests { panic!("error parsing offer: {:?}", e); } - let offer = OfferBuilder::new("foo".into(), pubkey(42)) + let offer = OfferBuilder::new(pubkey(42)) .supported_quantity(Quantity::Bounded(NonZeroU64::new(1).unwrap())) .build() .unwrap(); @@ -1734,7 +1759,7 @@ mod tests { #[test] fn parses_offer_with_node_id() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)).build().unwrap(); + let offer = OfferBuilder::new(pubkey(42)).build().unwrap(); if let Err(e) = offer.to_string().parse::() { panic!("error parsing offer: {:?}", e); } @@ -1755,7 +1780,7 @@ mod tests { #[test] fn fails_parsing_offer_with_extra_tlv_records() { - let offer = OfferBuilder::new("foo".into(), pubkey(42)).build().unwrap(); + let offer = OfferBuilder::new(pubkey(42)).build().unwrap(); let mut encoded_offer = Vec::new(); offer.write(&mut encoded_offer).unwrap();