Skip to content

Commit

Permalink
Don't require Refund::description in API
Browse files Browse the repository at this point in the history
Refunds currently require a description, though this may change to be
optional. Remove the description requirement from the API, setting and
empty string by default.
  • Loading branch information
jkczyz committed Apr 24, 2024
1 parent 728ce39 commit 1814a22
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 69 deletions.
10 changes: 5 additions & 5 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,13 +1658,13 @@ where
/// let payment_id = PaymentId([42; 32]);
/// let refund = channel_manager
/// .create_refund_builder(
/// "coffee".to_string(), amount_msats, absolute_expiry, payment_id, retry,
/// max_total_routing_fee_msat
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
/// )?
/// # ;
/// # // Needed for compiling for c_bindings
/// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
/// # let refund = builder
/// .description("coffee".to_string())
/// .payer_note("refund for order 1234".to_string())
/// .build()?;
/// let bech32_refund = refund.to_string();
Expand Down Expand Up @@ -8621,8 +8621,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
pub fn create_refund_builder(
&$self, description: String, amount_msats: u64, absolute_expiry: Duration,
payment_id: PaymentId, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
Expand All @@ -8631,7 +8631,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {

let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let builder = RefundBuilder::deriving_payer_id(
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
)?
.chain_hash($self.chain_hash)
.absolute_expiry(absolute_expiry)
Expand Down
30 changes: 9 additions & 21 deletions lightning/src/ln/offers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand Down Expand Up @@ -613,9 +611,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
Expand Down Expand Up @@ -724,9 +720,7 @@ fn pays_for_refund_without_blinded_paths() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.clear_paths()
.build().unwrap();
Expand Down Expand Up @@ -780,7 +774,7 @@ fn fails_creating_refund_without_blinded_paths() {
let payment_id = PaymentId([1; 32]);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
Expand Down Expand Up @@ -831,9 +825,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = bob.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.chain(Network::Signet)
.build().unwrap();
Expand Down Expand Up @@ -932,13 +924,13 @@ fn fails_creating_refund_with_duplicate_payment_id() {
let payment_id = PaymentId([1; 32]);
assert!(
nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
).is_ok()
);
expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);

match nodes[0].node.create_refund_builder(
"refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
) {
Ok(_) => panic!("Expected error"),
Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
Expand Down Expand Up @@ -1049,9 +1041,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();

Expand Down Expand Up @@ -1100,9 +1090,7 @@ fn fails_paying_invoice_more_than_once() {
let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);
let refund = david.node
.create_refund_builder(
"refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
)
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
.unwrap()
.build().unwrap();
expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
Expand Down
12 changes: 6 additions & 6 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ mod tests {
let payment_paths = payment_paths();
let payment_hash = payment_hash();
let now = now();
let invoice = RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), 1000).unwrap()
let invoice = RefundBuilder::new(vec![1; 32], payer_pubkey(), 1000).unwrap()
.build().unwrap()
.respond_with_no_std(payment_paths.clone(), payment_hash, recipient_pubkey(), now)
.unwrap()
Expand All @@ -1688,7 +1688,7 @@ mod tests {
assert_eq!(invoice.offer_chains(), None);
assert_eq!(invoice.metadata(), None);
assert_eq!(invoice.amount(), None);
assert_eq!(invoice.description(), PrintableString("foo"));
assert_eq!(invoice.description(), PrintableString(""));
assert_eq!(invoice.offer_features(), None);
assert_eq!(invoice.absolute_expiry(), None);
assert_eq!(invoice.message_paths(), &[]);
Expand Down Expand Up @@ -1724,7 +1724,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,
Expand Down Expand Up @@ -1803,7 +1803,7 @@ mod tests {
let future_expiry = Duration::from_secs(u64::max_value());
let past_expiry = Duration::from_secs(0);

if let Err(e) = RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), 1000).unwrap()
if let Err(e) = RefundBuilder::new(vec![1; 32], payer_pubkey(), 1000).unwrap()
.absolute_expiry(future_expiry)
.build().unwrap()
.respond_with(payment_paths(), payment_hash(), recipient_pubkey())
Expand All @@ -1813,7 +1813,7 @@ mod tests {
panic!("error building invoice: {:?}", e);
}

match RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), 1000).unwrap()
match RefundBuilder::new(vec![1; 32], payer_pubkey(), 1000).unwrap()
.absolute_expiry(past_expiry)
.build().unwrap()
.respond_with(payment_paths(), payment_hash(), recipient_pubkey())
Expand Down Expand Up @@ -1887,7 +1887,7 @@ mod tests {
let entropy = FixedEntropy {};
let secp_ctx = Secp256k1::new();

let refund = RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), 1000).unwrap()
let refund = RefundBuilder::new(vec![1; 32], payer_pubkey(), 1000).unwrap()
.build().unwrap();

if let Err(e) = refund
Expand Down

0 comments on commit 1814a22

Please sign in to comment.