Skip to content

Commit

Permalink
Add quantity param to initiate_refund
Browse files Browse the repository at this point in the history
  • Loading branch information
slanesuke committed Jul 23, 2024
1 parent cfac29f commit b1ddd4d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 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);
Refund initiate_refund(u64 amount_msat, u64? quantity,u32 expiry_secs);
};

interface SpontaneousPayment {
Expand Down
7 changes: 5 additions & 2 deletions src/payment/bolt12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ 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) -> Result<Refund, Error> {
pub fn initiate_refund(
&self, amount_msat: u64, quantity: Option<u64>, expiry_secs: u32,
) -> Result<Refund, Error> {
let mut random_bytes = [0u8; 32];
rand::thread_rng().fill_bytes(&mut random_bytes);
let payment_id = PaymentId(random_bytes);
Expand All @@ -337,6 +339,7 @@ impl Bolt12Payment {
log_error!(self.logger, "Failed to create refund builder: {:?}", e);
Error::RefundCreationFailed
})?
.quantity(quantity.unwrap_or(1))
.build()
.map_err(|e| {
log_error!(self.logger, "Failed to create refund: {:?}", e);
Expand All @@ -350,7 +353,7 @@ impl Bolt12Payment {
preimage: None,
secret: None,
payer_note: refund.payer_note().map(|note| UntrustedString(note.to_string())),
quantity: refund.quantity(),
quantity,
};
let payment = PaymentDetails::new(
payment_id,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ 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).unwrap();
let refund = node_b.bolt12_payment().initiate_refund(overpaid_amount, None, 3600).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 b1ddd4d

Please sign in to comment.