Skip to content

Commit

Permalink
Add reason to Event::PaymentFailed
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Feb 22, 2024
1 parent 980b14c commit 0804231
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
13 changes: 11 additions & 2 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,22 @@ enum BuildError {
[Enum]
interface Event {
PaymentSuccessful( PaymentHash payment_hash );
PaymentFailed( PaymentHash payment_hash );
PaymentReceived( PaymentHash payment_hash, u64 amount_msat);
PaymentFailed ( PaymentHash payment_hash, PaymentFailureReason? reason );
PaymentReceived ( PaymentHash payment_hash, u64 amount_msat);
ChannelPending ( ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo );
ChannelReady ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
};

enum PaymentFailureReason {
"RecipientRejected",
"UserAbandoned",
"RetriesExhausted",
"PaymentExpired",
"RouteNotFound",
"UnexpectedError",
};

enum PaymentDirection {
"Inbound",
"Outbound",
Expand Down
20 changes: 12 additions & 8 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::io::{
use crate::logger::{log_error, log_info, Logger};

use lightning::chain::chaininterface::ConfirmationTarget;
use lightning::events::Event as LdkEvent;
use lightning::events::PaymentPurpose;
use lightning::events::{Event as LdkEvent, PaymentFailureReason};
use lightning::impl_writeable_tlv_based_enum;
use lightning::ln::{ChannelId, PaymentHash};
use lightning::routing::gossip::NodeId;
Expand Down Expand Up @@ -52,6 +52,8 @@ pub enum Event {
PaymentFailed {
/// The hash of the payment.
payment_hash: PaymentHash,
/// The reason why the payment failed.
reason: Option<PaymentFailureReason>,
},
/// A payment has been received.
PaymentReceived {
Expand Down Expand Up @@ -103,6 +105,7 @@ impl_writeable_tlv_based_enum!(Event,
},
(1, PaymentFailed) => {
(0, payment_hash, required),
(1, reason, option),
},
(2, PaymentReceived) => {
(0, payment_hash, required),
Expand Down Expand Up @@ -609,11 +612,12 @@ where
panic!("Failed to push to event queue");
});
}
LdkEvent::PaymentFailed { payment_hash, .. } => {
LdkEvent::PaymentFailed { payment_hash, reason, .. } => {
log_info!(
self.logger,
"Failed to send payment to payment hash {:?}.",
hex_utils::to_string(&payment_hash.0)
"Failed to send payment to payment hash {:?} due to {:?}.",
hex_utils::to_string(&payment_hash.0),
reason
);

let update = PaymentDetailsUpdate {
Expand All @@ -624,12 +628,12 @@ where
log_error!(self.logger, "Failed to access payment store: {}", e);
panic!("Failed to access payment store");
});
self.event_queue.add_event(Event::PaymentFailed { payment_hash }).unwrap_or_else(
|e| {
self.event_queue
.add_event(Event::PaymentFailed { payment_hash, reason })
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to push to event queue: {}", e);
panic!("Failed to push to event queue");
},
);
});
}

LdkEvent::PaymentPathSuccessful { .. } => {}
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ pub use types::ChannelConfig;
pub use io::utils::generate_entropy_mnemonic;

#[cfg(feature = "uniffi")]
use {bip39::Mnemonic, bitcoin::OutPoint, lightning::ln::PaymentSecret, uniffi_types::*};
use {
bip39::Mnemonic, bitcoin::OutPoint, lightning::events::PaymentFailureReason,
lightning::ln::ChannelId, lightning::ln::PaymentSecret, uniffi_types::*,
};

#[cfg(feature = "uniffi")]
pub use builder::ArcedNodeBuilder as Builder;
Expand All @@ -135,8 +138,6 @@ use lightning::ln::channelmanager::{self, PaymentId, RecipientOnionFields, Retry
use lightning::ln::msgs::SocketAddress;
use lightning::ln::{PaymentHash, PaymentPreimage};

#[cfg(feature = "uniffi")]
use lightning::ln::ChannelId;
use lightning::sign::EntropySource;

use lightning::util::persist::KVStore;
Expand Down

0 comments on commit 0804231

Please sign in to comment.