Skip to content

Commit e5b69ca

Browse files
committed
Add a send_spontaneous_payment_probe method
We add the capability to send a payment probe given an amount and a payee node id.
1 parent 5d6e41a commit e5b69ca

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ interface LDKNode {
7474
[Throws=NodeError]
7575
void send_payment_probe([ByRef]Invoice invoice);
7676
[Throws=NodeError]
77+
void send_spontaneous_payment_probe(u64 amount_msat, PublicKey node_id);
78+
[Throws=NodeError]
7779
Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
7880
[Throws=NodeError]
7981
Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);

src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,29 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
13221322
self.send_payment_probe_internal(route_params)
13231323
}
13241324

1325+
/// Sends payment probes over all paths of a route that would be used to pay the given
1326+
/// amount to the given `node_id`.
1327+
///
1328+
/// This may be used to send "pre-flight" probes, i.e., to train our scorer before conducting
1329+
/// the actual payment. Note this is only useful if there likely is sufficient time for the
1330+
/// probe to settle before sending out the actual payment, e.g., when waiting for user
1331+
/// confirmation in a wallet UI.
1332+
pub fn send_spontaneous_payment_probe(
1333+
&self, amount_msat: u64, node_id: PublicKey,
1334+
) -> Result<(), Error> {
1335+
let rt_lock = self.runtime.read().unwrap();
1336+
if rt_lock.is_none() {
1337+
return Err(Error::NotRunning);
1338+
}
1339+
1340+
let payment_params =
1341+
PaymentParameters::from_node_id(node_id, self.config.default_cltv_expiry_delta);
1342+
1343+
let route_params = RouteParameters { payment_params, final_value_msat: amount_msat };
1344+
1345+
self.send_payment_probe_internal(route_params)
1346+
}
1347+
13251348
fn send_payment_probe_internal(&self, route_params: RouteParameters) -> Result<(), Error> {
13261349
let payer = self.channel_manager.get_our_node_id();
13271350
let first_hops = self.channel_manager.list_usable_channels();

0 commit comments

Comments
 (0)