Skip to content

Commit a30379b

Browse files
authored
Merge pull request #56 from G8XSU/2025-03-18-close-channel-api-fix
Consistently use UserChannelId and PaymentId as Strings.
2 parents c814064 + 35e9dd7 commit a30379b

File tree

7 files changed

+33
-37
lines changed

7 files changed

+33
-37
lines changed

ldk-server-protos/src/api.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ pub struct Bolt11SendRequest {
147147
#[allow(clippy::derive_partial_eq_without_eq)]
148148
#[derive(Clone, PartialEq, ::prost::Message)]
149149
pub struct Bolt11SendResponse {
150-
/// An identifier used to uniquely identify a payment.
151-
#[prost(bytes = "bytes", tag = "1")]
152-
pub payment_id: ::prost::bytes::Bytes,
150+
/// An identifier used to uniquely identify a payment in hex-encoded form.
151+
#[prost(string, tag = "1")]
152+
pub payment_id: ::prost::alloc::string::String,
153153
}
154154
/// Returns a BOLT12 offer for the given amount, if specified.
155155
///
@@ -211,9 +211,9 @@ pub struct Bolt12SendRequest {
211211
#[allow(clippy::derive_partial_eq_without_eq)]
212212
#[derive(Clone, PartialEq, ::prost::Message)]
213213
pub struct Bolt12SendResponse {
214-
/// An identifier used to uniquely identify a payment.
215-
#[prost(bytes = "bytes", tag = "1")]
216-
pub payment_id: ::prost::bytes::Bytes,
214+
/// An identifier used to uniquely identify a payment in hex-encoded form.
215+
#[prost(string, tag = "1")]
216+
pub payment_id: ::prost::alloc::string::String,
217217
}
218218
/// Creates a new outbound channel to the given remote node.
219219
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.connect_open_channel>
@@ -245,16 +245,16 @@ pub struct OpenChannelRequest {
245245
#[allow(clippy::derive_partial_eq_without_eq)]
246246
#[derive(Clone, PartialEq, ::prost::Message)]
247247
pub struct OpenChannelResponse {
248-
/// The channel id of the created channel that user can use to refer to channel.
249-
#[prost(bytes = "bytes", tag = "1")]
250-
pub user_channel_id: ::prost::bytes::Bytes,
248+
/// The local channel id of the created channel that user can use to refer to channel.
249+
#[prost(string, tag = "1")]
250+
pub user_channel_id: ::prost::alloc::string::String,
251251
}
252252
/// Update the config for a previously opened channel.
253253
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.update_channel_config>
254254
#[allow(clippy::derive_partial_eq_without_eq)]
255255
#[derive(Clone, PartialEq, ::prost::Message)]
256256
pub struct UpdateChannelConfigRequest {
257-
/// The hex-encoded local `user_channel_id` of this channel.
257+
/// The local `user_channel_id` of this channel.
258258
#[prost(string, tag = "1")]
259259
pub user_channel_id: ::prost::alloc::string::String,
260260
/// The hex-encoded public key of the counterparty node to update channel config with.
@@ -276,9 +276,9 @@ pub struct UpdateChannelConfigResponse {}
276276
#[allow(clippy::derive_partial_eq_without_eq)]
277277
#[derive(Clone, PartialEq, ::prost::Message)]
278278
pub struct CloseChannelRequest {
279-
/// The channel id of the created channel that user can use to refer to channel.
280-
#[prost(bytes = "bytes", tag = "1")]
281-
pub user_channel_id: ::prost::bytes::Bytes,
279+
/// The local `user_channel_id` of this channel.
280+
#[prost(string, tag = "1")]
281+
pub user_channel_id: ::prost::alloc::string::String,
282282
/// The hex-encoded public key of the node to close a channel with.
283283
#[prost(string, tag = "2")]
284284
pub counterparty_node_id: ::prost::alloc::string::String,

ldk-server-protos/src/proto/api.proto

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ message Bolt11SendRequest {
145145
// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.
146146
message Bolt11SendResponse {
147147

148-
// An identifier used to uniquely identify a payment.
149-
bytes payment_id = 1;
148+
// An identifier used to uniquely identify a payment in hex-encoded form.
149+
string payment_id = 1;
150150
}
151151

152152
// Returns a BOLT12 offer for the given amount, if specified.
@@ -205,8 +205,8 @@ message Bolt12SendRequest {
205205
// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.
206206
message Bolt12SendResponse {
207207

208-
// An identifier used to uniquely identify a payment.
209-
bytes payment_id = 1;
208+
// An identifier used to uniquely identify a payment in hex-encoded form.
209+
string payment_id = 1;
210210
}
211211

212212
// Creates a new outbound channel to the given remote node.
@@ -237,15 +237,15 @@ message OpenChannelRequest {
237237
// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.
238238
message OpenChannelResponse {
239239

240-
// The channel id of the created channel that user can use to refer to channel.
241-
bytes user_channel_id = 1;
240+
// The local channel id of the created channel that user can use to refer to channel.
241+
string user_channel_id = 1;
242242
}
243243

244244
// Update the config for a previously opened channel.
245245
// See more: https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.update_channel_config
246246
message UpdateChannelConfigRequest {
247247

248-
// The hex-encoded local `user_channel_id` of this channel.
248+
// The local `user_channel_id` of this channel.
249249
string user_channel_id = 1;
250250

251251
// The hex-encoded public key of the counterparty node to update channel config with.
@@ -266,8 +266,8 @@ message UpdateChannelConfigResponse {
266266
// - https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.force_close_channel
267267
message CloseChannelRequest {
268268

269-
// The channel id of the created channel that user can use to refer to channel.
270-
bytes user_channel_id = 1;
269+
// The local `user_channel_id` of this channel.
270+
string user_channel_id = 1;
271271

272272
// The hex-encoded public key of the node to close a channel with.
273273
string counterparty_node_id = 2;

ldk-server/src/api/bolt11_send.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::api::error::LdkServerError;
22
use crate::service::Context;
3-
use bytes::Bytes;
43
use ldk_node::lightning_invoice::Bolt11Invoice;
54
use ldk_server_protos::api::{Bolt11SendRequest, Bolt11SendResponse};
65
use std::str::FromStr;
@@ -20,6 +19,6 @@ pub(crate) fn handle_bolt11_send_request(
2019
},
2120
}?;
2221

23-
let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
22+
let response = Bolt11SendResponse { payment_id: payment_id.to_string() };
2423
Ok(response)
2524
}

ldk-server/src/api/bolt12_send.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::api::error::LdkServerError;
22
use crate::service::Context;
3-
use bytes::Bytes;
43
use ldk_node::lightning::offers::offer::Offer;
54
use ldk_server_protos::api::{Bolt12SendRequest, Bolt12SendResponse};
65
use std::str::FromStr;
@@ -23,6 +22,6 @@ pub(crate) fn handle_bolt12_send_request(
2322
),
2423
}?;
2524

26-
let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
25+
let response = Bolt12SendResponse { payment_id: payment_id.to_string() };
2726
Ok(response)
2827
}

ldk-server/src/api/close_channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ pub(crate) const CLOSE_CHANNEL_PATH: &str = "CloseChannel";
1111
pub(crate) fn handle_close_channel_request(
1212
context: Context, request: CloseChannelRequest,
1313
) -> Result<CloseChannelResponse, LdkServerError> {
14-
//TODO: Should this be string?
15-
let mut user_channel_id_bytes = [0u8; 16];
16-
user_channel_id_bytes.copy_from_slice(&request.user_channel_id);
17-
let user_channel_id = UserChannelId(u128::from_be_bytes(user_channel_id_bytes));
14+
let user_channel_id =
15+
UserChannelId((&request.user_channel_id).parse::<u128>().map_err(|_| {
16+
LdkServerError::new(InvalidRequestError, "Invalid UserChannelId.".to_string())
17+
})?);
1818
let counterparty_node_id = PublicKey::from_str(&request.counterparty_node_id).map_err(|e| {
1919
LdkServerError::new(
2020
InvalidRequestError,

ldk-server/src/api/open_channel.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::api::error::LdkServerError;
22
use crate::service::Context;
3-
use bytes::Bytes;
43
use ldk_node::bitcoin::secp256k1::PublicKey;
54
use ldk_node::lightning::ln::msgs::SocketAddress;
65
use ldk_server_protos::api::{OpenChannelRequest, OpenChannelResponse};
@@ -35,8 +34,6 @@ pub(crate) fn handle_open_channel(
3534
)?
3635
};
3736

38-
let response = OpenChannelResponse {
39-
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
40-
};
37+
let response = OpenChannelResponse { user_channel_id: user_channel_id.0.to_string() };
4138
Ok(response)
4239
}

ldk-server/src/api/update_channel_config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ pub(crate) const UPDATE_CHANNEL_CONFIG_PATH: &str = "UpdateChannelConfig";
1313
pub(crate) fn handle_update_channel_config_request(
1414
context: Context, request: UpdateChannelConfigRequest,
1515
) -> Result<UpdateChannelConfigResponse, LdkServerError> {
16-
let user_channel_id: u128 = request.user_channel_id.parse().map_err(|_| {
17-
LdkServerError::new(InvalidRequestError, "Failed to parse user_channel_id: invalid format.")
18-
})?;
16+
let user_channel_id: u128 = request
17+
.user_channel_id
18+
.parse::<u128>()
19+
.map_err(|_| LdkServerError::new(InvalidRequestError, "Invalid UserChannelId."))?;
1920

2021
//FIXME: Use ldk/ldk-node's partial config update api.
2122
let current_config = context

0 commit comments

Comments
 (0)