Skip to content

Commit 2f9efe6

Browse files
committed
spontaneous payment send_with_custom_tlv
1 parent 2753ac4 commit 2f9efe6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ interface SpontaneousPayment {
152152
[Throws=NodeError]
153153
PaymentId send(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters);
154154
[Throws=NodeError]
155+
PaymentId send_with_custom_tlv(u64 amount_msat, PublicKey node_id, SendingParameters? sending_parameters, u64 custom_tlv_key, sequence<u8> custom_tlv_value);
156+
[Throws=NodeError]
155157
void send_probes(u64 amount_msat, PublicKey node_id);
156158
};
157159

src/payment/spontaneous.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@ impl SpontaneousPayment {
5858
/// node-wide parameters configured via [`Config::sending_parameters`] on a per-field basis.
5959
pub fn send(
6060
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>,
61+
) -> Result<PaymentId, Error> {
62+
self.send_inner(amount_msat, node_id, sending_parameters, None)
63+
}
64+
65+
/// Send a spontaneous payment including a custom TLV key and value.
66+
pub fn send_with_custom_tlv(
67+
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>,
68+
custom_tlv_type: u64, custom_tlv_value: Vec<u8>,
69+
) -> Result<PaymentId, Error> {
70+
self.send_inner(
71+
amount_msat,
72+
node_id,
73+
sending_parameters,
74+
Some((custom_tlv_type, custom_tlv_value)),
75+
)
76+
}
77+
78+
/// Send a spontaneous aka. "keysend", payment.
79+
fn send_inner(
80+
&self, amount_msat: u64, node_id: PublicKey, sending_parameters: Option<SendingParameters>,
81+
custom_tlv: Option<(u64, Vec<u8>)>,
6182
) -> Result<PaymentId, Error> {
6283
let rt_lock = self.runtime.read().unwrap();
6384
if rt_lock.is_none() {
@@ -97,7 +118,12 @@ impl SpontaneousPayment {
97118
.map(|s| route_params.payment_params.max_channel_saturation_power_of_half = s);
98119
};
99120

100-
let recipient_fields = RecipientOnionFields::spontaneous_empty();
121+
let recipient_fields = match custom_tlv {
122+
Some((tlv_type, tlv_value)) => RecipientOnionFields::spontaneous_empty()
123+
.with_custom_tlvs(vec![(tlv_type, tlv_value)])
124+
.map_err(|_| Error::PaymentSendingFailed)?,
125+
None => RecipientOnionFields::spontaneous_empty(),
126+
};
101127

102128
match self.channel_manager.send_spontaneous_payment_with_retry(
103129
Some(payment_preimage),

0 commit comments

Comments
 (0)