Skip to content

Commit

Permalink
Add payer_note argument for initiate_refund
Browse files Browse the repository at this point in the history
  • Loading branch information
slanesuke committed Aug 7, 2024
1 parent 93c706b commit f35c8bb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ interface Bolt12Payment {
[Throws=NodeError]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity);
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, string? payer_note, u64? quantity);
};

interface SpontaneousPayment {
Expand Down
7 changes: 6 additions & 1 deletion src/payment/bolt12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ impl Bolt12Payment {

/// Returns a [`Refund`] object that can be used to offer a refund payment of the amount given.
pub fn initiate_refund(
&self, amount_msat: u64, expiry_secs: u32, quantity: Option<u64>,
&self, amount_msat: u64, expiry_secs: u32, payer_note: Option<String>,
quantity: Option<u64>,
) -> Result<Refund, Error> {
let mut random_bytes = [0u8; 32];
rand::thread_rng().fill_bytes(&mut random_bytes);
Expand Down Expand Up @@ -344,6 +345,10 @@ impl Bolt12Payment {
refund_builder = refund_builder.quantity(qty);
}

if let Some(note) = payer_note {
refund_builder = refund_builder.payer_note(note);
}

let refund = refund_builder.build().map_err(|e| {
log_error!(self.logger, "Failed to create refund: {:?}", e);
Error::RefundCreationFailed
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ fn simple_bolt12_send_receive() {

// Now node_b refunds the amount node_a just overpaid.
let overpaid_amount = expected_amount_msat - offer_amount_msat;
let refund = node_b.bolt12_payment().initiate_refund(overpaid_amount, 3600, None).unwrap();
let refund =
node_b.bolt12_payment().initiate_refund(overpaid_amount, 3600, None, None).unwrap();
let invoice = node_a.bolt12_payment().request_refund_payment(&refund).unwrap();
expect_payment_received_event!(node_a, overpaid_amount);

Expand Down

0 comments on commit f35c8bb

Please sign in to comment.