Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit e91e69c

Browse files
authored
Merge pull request #71 from johncantrell97/user-channel-id
allow user selected user_channel_id
2 parents 2a9c244 + 0fcaa1c commit e91e69c

File tree

4 files changed

+94
-63
lines changed

4 files changed

+94
-63
lines changed

src/lsps2/client.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use core::ops::Deref;
2727

2828
use crate::lsps2::msgs::{
2929
BuyRequest, BuyResponse, GetInfoRequest, GetInfoResponse, GetVersionsRequest,
30-
GetVersionsResponse, JITChannelScid, LSPS2Message, LSPS2Request, LSPS2Response,
30+
GetVersionsResponse, InterceptScid, LSPS2Message, LSPS2Request, LSPS2Response,
3131
OpeningFeeParams,
3232
};
3333

@@ -57,7 +57,7 @@ enum InboundJITChannelState {
5757
MenuRequested { version: u16 },
5858
PendingMenuSelection { version: u16 },
5959
BuyRequested { version: u16 },
60-
PendingPayment { client_trusts_lsp: bool, short_channel_id: JITChannelScid },
60+
PendingPayment { client_trusts_lsp: bool, intercept_scid: InterceptScid },
6161
}
6262

6363
impl InboundJITChannelState {
@@ -108,11 +108,11 @@ impl InboundJITChannelState {
108108
}
109109

110110
fn invoice_params_received(
111-
&self, client_trusts_lsp: bool, short_channel_id: JITChannelScid,
111+
&self, client_trusts_lsp: bool, intercept_scid: InterceptScid,
112112
) -> Result<Self, ChannelStateError> {
113113
match self {
114114
InboundJITChannelState::BuyRequested { .. } => {
115-
Ok(InboundJITChannelState::PendingPayment { client_trusts_lsp, short_channel_id })
115+
Ok(InboundJITChannelState::PendingPayment { client_trusts_lsp, intercept_scid })
116116
}
117117
state => Err(ChannelStateError(format!(
118118
"Invoice params received when JIT Channel was in state: {:?}",
@@ -167,9 +167,9 @@ impl InboundJITChannel {
167167
}
168168

169169
fn invoice_params_received(
170-
&mut self, client_trusts_lsp: bool, jit_channel_scid: JITChannelScid,
170+
&mut self, client_trusts_lsp: bool, intercept_scid: InterceptScid,
171171
) -> Result<(), LightningError> {
172-
self.state = self.state.invoice_params_received(client_trusts_lsp, jit_channel_scid)?;
172+
self.state = self.state.invoice_params_received(client_trusts_lsp, intercept_scid)?;
173173
Ok(())
174174
}
175175
}
@@ -519,17 +519,17 @@ where
519519

520520
if let Err(e) = jit_channel.invoice_params_received(
521521
result.client_trusts_lsp,
522-
result.jit_channel_scid.clone(),
522+
result.intercept_scid.clone(),
523523
) {
524524
peer_state.remove_inbound_channel(jit_channel_id);
525525
return Err(e);
526526
}
527527

528-
if let Ok(scid) = result.jit_channel_scid.to_scid() {
528+
if let Ok(intercept_scid) = result.intercept_scid.to_scid() {
529529
self.pending_events.enqueue(Event::LSPS2Client(
530530
LSPS2ClientEvent::InvoiceGenerationReady {
531531
counterparty_node_id: *counterparty_node_id,
532-
scid,
532+
intercept_scid,
533533
cltv_expiry_delta: result.lsp_cltv_expiry_delta,
534534
payment_size_msat: jit_channel.config.payment_size_msat,
535535
client_trusts_lsp: result.client_trusts_lsp,
@@ -539,8 +539,8 @@ where
539539
} else {
540540
return Err(LightningError {
541541
err: format!(
542-
"Received buy response with an invalid scid {:?}",
543-
result.jit_channel_scid
542+
"Received buy response with an invalid intercept scid {:?}",
543+
result.intercept_scid
544544
),
545545
action: ErrorAction::IgnoreAndLog(Level::Info),
546546
});

src/lsps2/event.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub enum LSPS2ClientEvent {
5252
InvoiceGenerationReady {
5353
/// The node id of the LSP.
5454
counterparty_node_id: PublicKey,
55-
/// The short channel id to use in the route hint.
56-
scid: u64,
55+
/// The intercept short channel id to use in the route hint.
56+
intercept_scid: u64,
5757
/// The `cltv_expiry_delta` to use in the route hint.
5858
cltv_expiry_delta: u32,
5959
/// The initial payment size you specified.
@@ -98,7 +98,7 @@ pub enum LSPS2ServiceEvent {
9898
/// If `payment_size_msat` is [`Option::Some`] then the payer is allowed to use MPP.
9999
/// If `payment_size_msat` is [`Option::None`] then the payer cannot use MPP.
100100
///
101-
/// You must generate an scid and `cltv_expiry_delta` for them to use
101+
/// You must generate an intercept scid and `cltv_expiry_delta` for them to use
102102
/// and call [`LSPS2ServiceHandler::invoice_parameters_generated`].
103103
///
104104
/// [`LSPS2ServiceHandler::invoice_parameters_generated`]: crate::lsps2::service::LSPS2ServiceHandler::invoice_parameters_generated
@@ -126,7 +126,9 @@ pub enum LSPS2ServiceEvent {
126126
amt_to_forward_msat: u64,
127127
/// The fee earned for opening the channel.
128128
opening_fee_msat: u64,
129-
/// An internal id used to track channel open.
129+
/// A user specified id used to track channel open.
130130
user_channel_id: u128,
131+
/// The intercept short channel id to use in the route hint.
132+
intercept_scid: u64,
131133
},
132134
}

src/lsps2/msgs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ pub struct BuyRequest {
128128

129129
/// A newtype that holds a `short_channel_id` in human readable format of BBBxTTTx000.
130130
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
131-
pub struct JITChannelScid(String);
131+
pub struct InterceptScid(String);
132132

133-
impl From<u64> for JITChannelScid {
133+
impl From<u64> for InterceptScid {
134134
fn from(scid: u64) -> Self {
135135
let block = utils::block_from_scid(&scid);
136136
let tx_index = utils::tx_index_from_scid(&scid);
@@ -140,8 +140,8 @@ impl From<u64> for JITChannelScid {
140140
}
141141
}
142142

143-
impl JITChannelScid {
144-
/// Try to convert a [`JITChannelScid`] into a u64 used by LDK.
143+
impl InterceptScid {
144+
/// Try to convert a [`InterceptScid`] into a u64 used by LDK.
145145
pub fn to_scid(&self) -> Result<u64, ()> {
146146
utils::scid_from_human_readable_string(&self.0)
147147
}
@@ -152,8 +152,8 @@ impl JITChannelScid {
152152
/// Includes information needed to construct an invoice.
153153
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
154154
pub struct BuyResponse {
155-
/// The short channel id used by LSP to identify need to open channel.
156-
pub jit_channel_scid: JITChannelScid,
155+
/// The intercept short channel id used by LSP to identify need to open channel.
156+
pub intercept_scid: InterceptScid,
157157
/// The locktime expiry delta the lsp requires.
158158
pub lsp_cltv_expiry_delta: u32,
159159
/// A flag that indicates who is trusting who.

0 commit comments

Comments
 (0)