Skip to content

Commit 091e391

Browse files
committed
Add funding_redeem_script to ChannelDetails
Exposes the funding_redeem_script that LDK already exposes
1 parent 2b87cc8 commit 091e391

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

bindings/ldk_node.udl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ enum NodeError {
339339
"InvalidNodeAlias",
340340
"InvalidDateTime",
341341
"InvalidFeeRate",
342+
"InvalidScriptPubKey",
342343
"DuplicatePayment",
343344
"UnsupportedCurrency",
344345
"InsufficientFunds",
@@ -575,6 +576,7 @@ dictionary ChannelDetails {
575576
ChannelId channel_id;
576577
PublicKey counterparty_node_id;
577578
OutPoint? funding_txo;
579+
ScriptBuf? funding_redeem_script;
578580
u64? short_channel_id;
579581
u64? outbound_scid_alias;
580582
u64? inbound_scid_alias;
@@ -901,3 +903,6 @@ typedef string LSPS1OrderId;
901903

902904
[Custom]
903905
typedef string LSPSDateTime;
906+
907+
[Custom]
908+
typedef string ScriptBuf;

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ pub enum Error {
113113
InvalidDateTime,
114114
/// The given fee rate is invalid.
115115
InvalidFeeRate,
116+
/// The given script public key is invalid.
117+
InvalidScriptPubKey,
116118
/// A payment with the given hash has already been initiated.
117119
DuplicatePayment,
118120
/// The provided offer was denonminated in an unsupported currency.
@@ -186,6 +188,7 @@ impl fmt::Display for Error {
186188
Self::InvalidNodeAlias => write!(f, "The given node alias is invalid."),
187189
Self::InvalidDateTime => write!(f, "The given date time is invalid."),
188190
Self::InvalidFeeRate => write!(f, "The given fee rate is invalid."),
191+
Self::InvalidScriptPubKey => write!(f, "The given script pubkey is invalid."),
189192
Self::DuplicatePayment => {
190193
write!(f, "A payment with the given hash has already been initiated.")
191194
},

src/ffi/types.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use bip39::Mnemonic;
2020
use bitcoin::hashes::sha256::Hash as Sha256;
2121
use bitcoin::hashes::Hash;
2222
use bitcoin::secp256k1::PublicKey;
23-
pub use bitcoin::{Address, BlockHash, FeeRate, Network, OutPoint, Txid};
23+
pub use bitcoin::{Address, BlockHash, FeeRate, Network, OutPoint, Txid, ScriptBuf};
2424
pub use lightning::chain::channelmonitor::BalanceSource;
2525
pub use lightning::events::{ClosureReason, PaymentFailureReason};
2626
use lightning::ln::channelmanager::PaymentId;
@@ -106,6 +106,22 @@ impl UniffiCustomTypeConverter for Address {
106106
}
107107
}
108108

109+
impl UniffiCustomTypeConverter for ScriptBuf {
110+
type Builtin = String;
111+
112+
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
113+
if let Ok(key) = ScriptBuf::from_hex(&val) {
114+
return Ok(key);
115+
}
116+
117+
Err(Error::InvalidScriptPubKey.into())
118+
}
119+
120+
fn from_custom(obj: Self) -> Self::Builtin {
121+
obj.to_string()
122+
}
123+
}
124+
109125
#[derive(Debug, Clone, PartialEq, Eq)]
110126
pub enum OfferAmount {
111127
Bitcoin { amount_msats: u64 },

src/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ pub struct ChannelDetails {
222222
/// state until the splice transaction reaches sufficient confirmations to be locked (and we
223223
/// exchange `splice_locked` messages with our peer).
224224
pub funding_txo: Option<OutPoint>,
225+
/// The witness script that is used to lock the channel's funding output to commitment transactions.
226+
///
227+
/// This field will be `None` if we have not negotiated the funding transaction with our
228+
/// counterparty already.
229+
///
230+
/// When a channel is spliced, this continues to refer to the original pre-splice channel
231+
/// state until the splice transaction reaches sufficient confirmations to be locked (and we
232+
/// exchange `splice_locked` messages with our peer).
233+
pub funding_redeem_script: Option<bitcoin::ScriptBuf>,
225234
/// The position of the funding transaction in the chain. None if the funding transaction has
226235
/// not yet been confirmed and the channel fully opened.
227236
///
@@ -378,6 +387,7 @@ impl From<LdkChannelDetails> for ChannelDetails {
378387
channel_id: value.channel_id,
379388
counterparty_node_id: value.counterparty.node_id,
380389
funding_txo: value.funding_txo.map(|o| o.into_bitcoin_outpoint()),
390+
funding_redeem_script: value.funding_redeem_script,
381391
short_channel_id: value.short_channel_id,
382392
outbound_scid_alias: value.outbound_scid_alias,
383393
inbound_scid_alias: value.inbound_scid_alias,

0 commit comments

Comments
 (0)