Skip to content

Commit 06bd82d

Browse files
committed
Add reason to Event::ChannelClosed
1 parent 311c500 commit 06bd82d

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

bindings/ldk_node.udl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ interface Event {
162162
PaymentReceived ( PaymentHash payment_hash, u64 amount_msat);
163163
ChannelPending ( ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo );
164164
ChannelReady ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
165-
ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id );
165+
ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id, ClosureReason? reason );
166166
};
167167

168168
enum PaymentFailureReason {
@@ -174,6 +174,20 @@ enum PaymentFailureReason {
174174
"UnexpectedError",
175175
};
176176

177+
[Enum]
178+
interface ClosureReason {
179+
CounterpartyForceClosed ( UntrustedString peer_msg );
180+
HolderForceClosed ();
181+
CooperativeClosure ();
182+
CommitmentTxConfirmed ();
183+
FundingTimedOut ();
184+
ProcessingError ( string err );
185+
DisconnectedPeer ();
186+
OutdatedChannelManager ();
187+
CounterpartyCoopClosedUnfundedChannel ();
188+
FundingBatchClosure ();
189+
};
190+
177191
enum PaymentDirection {
178192
"Inbound",
179193
"Outbound",
@@ -309,3 +323,6 @@ typedef string UserChannelId;
309323

310324
[Custom]
311325
typedef string Mnemonic;
326+
327+
[Custom]
328+
typedef string UntrustedString;

src/event.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::io::{
1414
use crate::logger::{log_error, log_info, Logger};
1515

1616
use lightning::chain::chaininterface::ConfirmationTarget;
17-
use lightning::events::PaymentPurpose;
17+
use lightning::events::{ClosureReason, PaymentPurpose};
1818
use lightning::events::{Event as LdkEvent, PaymentFailureReason};
1919
use lightning::impl_writeable_tlv_based_enum;
2020
use lightning::ln::{ChannelId, PaymentHash};
@@ -98,6 +98,8 @@ pub enum Event {
9898
///
9999
/// This will be `None` for events serialized by LDK Node v0.1.0 and prior.
100100
counterparty_node_id: Option<PublicKey>,
101+
/// This will be `None` for events serialized by LDK Node v0.2.1 and prior.
102+
reason: Option<ClosureReason>,
101103
},
102104
}
103105

@@ -129,6 +131,7 @@ impl_writeable_tlv_based_enum!(Event,
129131
(0, channel_id, required),
130132
(1, counterparty_node_id, option),
131133
(2, user_channel_id, required),
134+
(3, reason, upgradable_option),
132135
};
133136
);
134137

@@ -858,6 +861,7 @@ where
858861
channel_id,
859862
user_channel_id: UserChannelId(user_channel_id),
860863
counterparty_node_id,
864+
reason: Some(reason),
861865
})
862866
.unwrap_or_else(|e| {
863867
log_error!(self.logger, "Failed to push to event queue: {}", e);

src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ pub use io::utils::generate_entropy_mnemonic;
109109

110110
#[cfg(feature = "uniffi")]
111111
use {
112-
bip39::Mnemonic, bitcoin::OutPoint, lightning::events::PaymentFailureReason,
113-
lightning::ln::ChannelId, lightning::ln::PaymentSecret, uniffi_types::*,
112+
bip39::Mnemonic,
113+
bitcoin::OutPoint,
114+
lightning::events::{ClosureReason, PaymentFailureReason},
115+
lightning::ln::ChannelId,
116+
lightning::ln::PaymentSecret,
117+
lightning::util::string::UntrustedString,
118+
uniffi_types::*,
114119
};
115120

116121
#[cfg(feature = "uniffi")]

src/uniffi_types.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use bitcoin::hashes::Hash;
1010
use bitcoin::secp256k1::PublicKey;
1111
use bitcoin::{Address, Txid};
1212
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
13+
use lightning::util::string::UntrustedString;
1314
use lightning_invoice::{Bolt11Invoice, SignedRawBolt11Invoice};
1415

1516
use bip39::Mnemonic;
@@ -186,3 +187,14 @@ impl UniffiCustomTypeConverter for SocketAddress {
186187
obj.to_string()
187188
}
188189
}
190+
191+
impl UniffiCustomTypeConverter for UntrustedString {
192+
type Builtin = String;
193+
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
194+
Ok(UntrustedString(val))
195+
}
196+
197+
fn from_custom(obj: Self) -> Self::Builtin {
198+
obj.to_string()
199+
}
200+
}

0 commit comments

Comments
 (0)