Skip to content

Commit a1fc379

Browse files
Return PaymentId from send_*payment functions
Used in upcoming commits for retries
1 parent 28eea12 commit a1fc379

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct ClaimableHTLC {
174174

175175
/// A payment identifier used to uniquely identify a payment to LDK.
176176
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
177-
pub(crate) struct PaymentId(pub [u8; 32]);
177+
pub struct PaymentId(pub [u8; 32]);
178178

179179
impl Writeable for PaymentId {
180180
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
@@ -1997,11 +1997,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
19971997
/// If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
19981998
/// bit set (either as required or as available). If multiple paths are present in the Route,
19991999
/// we assume the invoice had the basic_mpp feature set.
2000-
pub fn send_payment(&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>) -> Result<(), PaymentSendFailure> {
2000+
pub fn send_payment(&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>) -> Result<PaymentId, PaymentSendFailure> {
20012001
self.send_payment_internal(route, payment_hash, payment_secret, None)
20022002
}
20032003

2004-
fn send_payment_internal(&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>, keysend_preimage: Option<PaymentPreimage>) -> Result<(), PaymentSendFailure> {
2004+
fn send_payment_internal(&self, route: &Route, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>, keysend_preimage: Option<PaymentPreimage>) -> Result<PaymentId, PaymentSendFailure> {
20052005
if route.paths.len() < 1 {
20062006
return Err(PaymentSendFailure::ParameterError(APIError::RouteError{err: "There must be at least one path to send over"}));
20072007
}
@@ -2059,7 +2059,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
20592059
} else if has_err {
20602060
Err(PaymentSendFailure::AllFailedRetrySafe(results.drain(..).map(|r| r.unwrap_err()).collect()))
20612061
} else {
2062-
Ok(())
2062+
Ok(payment_id)
20632063
}
20642064
}
20652065

@@ -2077,14 +2077,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
20772077
/// Note that `route` must have exactly one path.
20782078
///
20792079
/// [`send_payment`]: Self::send_payment
2080-
pub fn send_spontaneous_payment(&self, route: &Route, payment_preimage: Option<PaymentPreimage>) -> Result<PaymentHash, PaymentSendFailure> {
2080+
pub fn send_spontaneous_payment(&self, route: &Route, payment_preimage: Option<PaymentPreimage>) -> Result<(PaymentHash, PaymentId), PaymentSendFailure> {
20812081
let preimage = match payment_preimage {
20822082
Some(p) => p,
20832083
None => PaymentPreimage(self.keys_manager.get_secure_random_bytes()),
20842084
};
20852085
let payment_hash = PaymentHash(Sha256::hash(&preimage.0).into_inner());
20862086
match self.send_payment_internal(route, payment_hash, &None, Some(preimage)) {
2087-
Ok(()) => Ok(payment_hash),
2087+
Ok(payment_id) => Ok((payment_hash, payment_id)),
20882088
Err(e) => Err(e)
20892089
}
20902090
}
@@ -5877,7 +5877,7 @@ mod tests {
58775877
// To start (2), send a keysend payment but don't claim it.
58785878
let payment_preimage = PaymentPreimage([42; 32]);
58795879
let route = get_route(&nodes[0].node.get_our_node_id(), &nodes[0].net_graph_msg_handler.network_graph, &expected_route.last().unwrap().node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 100_000, TEST_FINAL_CLTV, &logger).unwrap();
5880-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
5880+
let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
58815881
check_added_monitors!(nodes[0], 1);
58825882
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
58835883
assert_eq!(events.len(), 1);

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9224,7 +9224,7 @@ fn test_keysend_payments_to_public_node() {
92249224
nodes[0].logger).unwrap();
92259225

92269226
let test_preimage = PaymentPreimage([42; 32]);
9227-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage)).unwrap();
9227+
let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage)).unwrap();
92289228
check_added_monitors!(nodes[0], 1);
92299229
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
92309230
assert_eq!(events.len(), 1);
@@ -9254,7 +9254,7 @@ fn test_keysend_payments_to_private_node() {
92549254
nodes[0].logger).unwrap();
92559255

92569256
let test_preimage = PaymentPreimage([42; 32]);
9257-
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage)).unwrap();
9257+
let (payment_hash, _) = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage)).unwrap();
92589258
check_added_monitors!(nodes[0], 1);
92599259
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
92609260
assert_eq!(events.len(), 1);

0 commit comments

Comments
 (0)