/// # fn example<T: AChannelManager>(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();
///
/// [`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;
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);
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));
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));
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));
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();
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));
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();
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),
}
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();
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();
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();
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();
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()
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()
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()
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()
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(), &[]);
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(), &[]);
metadata: None,
currency: None,
amount: Some(1000),
- description: Some(&String::from("foo")),
+ description: Some(&String::from("")),
features: None,
absolute_expiry: None,
paths: None,
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()
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()
#[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 {};
#[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();
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();
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()
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()
#[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()
#[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()
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()
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()
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()
#[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()
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()
#[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()
#[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()
#[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()
#[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()
#[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()
#[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()
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
#[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()
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())
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())
#[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()
#[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()
#[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()
#[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()
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(), &[]);
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(), &[]);
metadata: None,
currency: None,
amount: Some(1000),
- description: Some(&String::from("foo")),
+ description: Some(&String::from("")),
features: None,
absolute_expiry: None,
paths: None,
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()
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()
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
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
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()
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()
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)
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)
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()
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()
#[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()
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()
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()
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()
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()
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()
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()
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()
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()
#[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()
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()
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()
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()
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()
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()
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()
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()
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()
#[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()
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()
#[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()
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()
#[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()
#[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()
#[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()
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()
#[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()
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()
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()
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()
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()
},
}
- 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()
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()
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()
},
}
- 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()
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()
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()
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()
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()
#[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()
#[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()
#[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()
#[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()
#[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()
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()
#[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 {};
#[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)
};
// 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()
#[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()
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()
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()
//! 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())
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.
///
///
/// [`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),
},
/// [`InvoiceRequest::verify`]: crate::offers::invoice_request::InvoiceRequest::verify
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
pub fn deriving_signing_pubkey<ES: Deref>(
- 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);
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),
},
$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.
#[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();
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")]
metadata: None,
currency: None,
amount: None,
- description: Some(&String::from("foo")),
+ description: Some(&String::from("")),
features: None,
absolute_expiry: None,
paths: None,
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();
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();
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()
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()
#[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()
#[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 {};
#[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));
#[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 {};
#[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();
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();
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();
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()
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()
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();
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()
},
];
- let offer = OfferBuilder::new("foo".into(), pubkey(42))
+ let offer = OfferBuilder::new(pubkey(42))
.path(paths[0].clone())
.path(paths[1].clone())
.build()
#[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]
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();
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();
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();
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();
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()
#[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))
#[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()
#[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();
#[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::<Offer>() {
panic!("error parsing offer: {:?}", e);
}
#[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),
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),
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();
#[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();
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();
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();
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();
#[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::<Offer>() {
panic!("error parsing offer: {:?}", e);
}
#[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();