Skip to content

Commit ce5235f

Browse files
committed
revert to parameter-based approach
1 parent a2116cc commit ce5235f

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

bindings/ldk_node.udl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ interface SpontaneousPayment {
213213
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters, sequence<CustomTlvRecord> custom_tlvs);
214214
[Throws=NodeError]
215215
void send_probes(u64 amount_msat, PublicKey node_id);
216+
[Throws=NodeError]
217+
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters, PaymentPreimage preimage);
218+
[Throws=NodeError]
219+
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage);
216220
};
217221

218222
interface OnchainPayment {
@@ -451,7 +455,6 @@ dictionary SendingParameters {
451455
u32? max_total_cltv_expiry_delta;
452456
u8? max_path_count;
453457
u8? max_channel_saturation_power_of_half;
454-
PaymentPreimage? preimage;
455458
};
456459

457460
dictionary CustomTlvRecord {

src/payment/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ mod unified_qr;
1616

1717
pub use bolt11::Bolt11Payment;
1818
pub use bolt12::Bolt12Payment;
19-
pub use lightning_types::payment::PaymentPreimage;
2019
pub use onchain::OnchainPayment;
2120
pub use spontaneous::SpontaneousPayment;
2221
pub use store::{
@@ -77,8 +76,6 @@ pub struct SendingParameters {
7776
///
7877
/// Default value: 2
7978
pub max_channel_saturation_power_of_half: Option<u8>,
80-
/// Custom preimage to use for the payment.
81-
pub preimage: Option<PaymentPreimage>,
8279
}
8380

8481
/// Represents the possible states of [`SendingParameters::max_total_routing_fee_msat`].

src/payment/spontaneous.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,43 @@ impl SpontaneousPayment {
5757
pub fn send(
5858
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>,
5959
) -> Result<PaymentId, Error> {
60-
self.send_inner(amount_msat, node_id, sending_parameters, None)
60+
self.send_inner(amount_msat, node_id, sending_parameters, None, None)
6161
}
6262

6363
/// Send a spontaneous payment including a list of custom TLVs.
6464
pub fn send_with_custom_tlvs(
6565
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>,
6666
custom_tlvs: Vec<CustomTlvRecord>,
6767
) -> Result<PaymentId, Error> {
68-
self.send_inner(amount_msat, node_id, sending_parameters, Some(custom_tlvs))
68+
self.send_inner(amount_msat, node_id, sending_parameters, Some(custom_tlvs), None)
69+
}
70+
71+
/// Send a spontaneous payment with custom preimage
72+
pub fn send_with_preimage(
73+
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>,
74+
preimage: PaymentPreimage,
75+
) -> Result<PaymentId, Error> {
76+
self.send_inner(amount_msat, node_id, sending_parameters, None, Some(preimage))
77+
}
78+
79+
/// Send a spontaneous payment with custom preimage including a list of custom TLVs.
80+
pub fn send_with_preimage_and_custom_tlvs(
81+
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>,
82+
custom_tlvs: Vec<CustomTlvRecord>, preimage: PaymentPreimage,
83+
) -> Result<PaymentId, Error> {
84+
self.send_inner(amount_msat, node_id, sending_parameters, Some(custom_tlvs), Some(preimage))
6985
}
7086

7187
fn send_inner(
7288
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>,
73-
custom_tlvs: Option<Vec<CustomTlvRecord>>,
89+
custom_tlvs: Option<Vec<CustomTlvRecord>>, preimage: Option<PaymentPreimage>,
7490
) -> Result<PaymentId, Error> {
7591
let rt_lock = self.runtime.read().unwrap();
7692
if rt_lock.is_none() {
7793
return Err(Error::NotRunning);
7894
}
7995

80-
let payment_preimage = sending_parameters
81-
.as_ref()
82-
.and_then(|sp| sp.preimage)
96+
let payment_preimage = preimage
8397
.unwrap_or_else(|| PaymentPreimage(self.keys_manager.get_secure_random_bytes()));
8498
let payment_hash = PaymentHash::from(payment_preimage);
8599
let payment_id = PaymentId(payment_hash.0);

tests/integration_tests_rust.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ fn multi_hop_sending() {
207207
max_total_cltv_expiry_delta: Some(1000),
208208
max_path_count: Some(10),
209209
max_channel_saturation_power_of_half: Some(2),
210-
preimage: None,
211210
};
212211

213212
let invoice_description =
@@ -1413,18 +1412,10 @@ fn spontaneous_send_with_custom_preimage() {
14131412
let custom_bytes = bytes.to_byte_array();
14141413
let custom_preimage = PaymentPreimage(custom_bytes);
14151414

1416-
let sending_parameters = SendingParameters {
1417-
max_total_routing_fee_msat: Some(Some(75_000).into()),
1418-
max_total_cltv_expiry_delta: Some(1000),
1419-
max_path_count: Some(10),
1420-
max_channel_saturation_power_of_half: Some(2),
1421-
preimage: Some(custom_preimage),
1422-
};
1423-
14241415
let amount_msat = 100_000;
14251416
let payment_id = node_a
14261417
.spontaneous_payment()
1427-
.send(amount_msat, node_b.node_id(), Some(sending_parameters))
1418+
.send_with_preimage(amount_msat, node_b.node_id(), None, custom_preimage.clone())
14281419
.unwrap();
14291420

14301421
// check payment status and verify stored preimage

0 commit comments

Comments
 (0)