Skip to content

Consistently use UserChannelId and PaymentId as Strings. #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions ldk-server-protos/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ pub struct Bolt11SendRequest {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Bolt11SendResponse {
/// An identifier used to uniquely identify a payment.
#[prost(bytes = "bytes", tag = "1")]
pub payment_id: ::prost::bytes::Bytes,
/// An identifier used to uniquely identify a payment in hex-encoded form.
#[prost(string, tag = "1")]
pub payment_id: ::prost::alloc::string::String,
}
/// Returns a BOLT12 offer for the given amount, if specified.
///
Expand Down Expand Up @@ -211,9 +211,9 @@ pub struct Bolt12SendRequest {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Bolt12SendResponse {
/// An identifier used to uniquely identify a payment.
#[prost(bytes = "bytes", tag = "1")]
pub payment_id: ::prost::bytes::Bytes,
/// An identifier used to uniquely identify a payment in hex-encoded form.
#[prost(string, tag = "1")]
pub payment_id: ::prost::alloc::string::String,
}
/// Creates a new outbound channel to the given remote node.
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.connect_open_channel>
Expand Down Expand Up @@ -245,16 +245,16 @@ pub struct OpenChannelRequest {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OpenChannelResponse {
/// The channel id of the created channel that user can use to refer to channel.
#[prost(bytes = "bytes", tag = "1")]
pub user_channel_id: ::prost::bytes::Bytes,
/// The local channel id of the created channel that user can use to refer to channel.
#[prost(string, tag = "1")]
pub user_channel_id: ::prost::alloc::string::String,
}
/// Update the config for a previously opened channel.
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.update_channel_config>
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UpdateChannelConfigRequest {
/// The hex-encoded local `user_channel_id` of this channel.
/// The local `user_channel_id` of this channel.
#[prost(string, tag = "1")]
pub user_channel_id: ::prost::alloc::string::String,
/// The hex-encoded public key of the counterparty node to update channel config with.
Expand All @@ -276,9 +276,9 @@ pub struct UpdateChannelConfigResponse {}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CloseChannelRequest {
/// The channel id of the created channel that user can use to refer to channel.
#[prost(bytes = "bytes", tag = "1")]
pub user_channel_id: ::prost::bytes::Bytes,
/// The local `user_channel_id` of this channel.
#[prost(string, tag = "1")]
pub user_channel_id: ::prost::alloc::string::String,
/// The hex-encoded public key of the node to close a channel with.
#[prost(string, tag = "2")]
pub counterparty_node_id: ::prost::alloc::string::String,
Expand Down
18 changes: 9 additions & 9 deletions ldk-server-protos/src/proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ message Bolt11SendRequest {
// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.
message Bolt11SendResponse {

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

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

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

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

// The channel id of the created channel that user can use to refer to channel.
bytes user_channel_id = 1;
// The local channel id of the created channel that user can use to refer to channel.
string user_channel_id = 1;
}

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

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

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

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

// The hex-encoded public key of the node to close a channel with.
string counterparty_node_id = 2;
Expand Down
3 changes: 1 addition & 2 deletions ldk-server/src/api/bolt11_send.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::api::error::LdkServerError;
use crate::service::Context;
use bytes::Bytes;
use ldk_node::lightning_invoice::Bolt11Invoice;
use ldk_server_protos::api::{Bolt11SendRequest, Bolt11SendResponse};
use std::str::FromStr;
Expand All @@ -20,6 +19,6 @@ pub(crate) fn handle_bolt11_send_request(
},
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
let response = Bolt11SendResponse { payment_id: payment_id.to_string() };
Ok(response)
}
3 changes: 1 addition & 2 deletions ldk-server/src/api/bolt12_send.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::api::error::LdkServerError;
use crate::service::Context;
use bytes::Bytes;
use ldk_node::lightning::offers::offer::Offer;
use ldk_server_protos::api::{Bolt12SendRequest, Bolt12SendResponse};
use std::str::FromStr;
Expand All @@ -23,6 +22,6 @@ pub(crate) fn handle_bolt12_send_request(
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
let response = Bolt12SendResponse { payment_id: payment_id.to_string() };
Ok(response)
}
8 changes: 4 additions & 4 deletions ldk-server/src/api/close_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub(crate) const CLOSE_CHANNEL_PATH: &str = "CloseChannel";
pub(crate) fn handle_close_channel_request(
context: Context, request: CloseChannelRequest,
) -> Result<CloseChannelResponse, LdkServerError> {
//TODO: Should this be string?
let mut user_channel_id_bytes = [0u8; 16];
user_channel_id_bytes.copy_from_slice(&request.user_channel_id);
let user_channel_id = UserChannelId(u128::from_be_bytes(user_channel_id_bytes));
let user_channel_id =
UserChannelId((&request.user_channel_id).parse::<u128>().map_err(|_| {
LdkServerError::new(InvalidRequestError, "Invalid UserChannelId.".to_string())
})?);
let counterparty_node_id = PublicKey::from_str(&request.counterparty_node_id).map_err(|e| {
LdkServerError::new(
InvalidRequestError,
Expand Down
5 changes: 1 addition & 4 deletions ldk-server/src/api/open_channel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::api::error::LdkServerError;
use crate::service::Context;
use bytes::Bytes;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_server_protos::api::{OpenChannelRequest, OpenChannelResponse};
Expand Down Expand Up @@ -35,8 +34,6 @@ pub(crate) fn handle_open_channel(
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
let response = OpenChannelResponse { user_channel_id: user_channel_id.0.to_string() };
Ok(response)
}
7 changes: 4 additions & 3 deletions ldk-server/src/api/update_channel_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ pub(crate) const UPDATE_CHANNEL_CONFIG_PATH: &str = "UpdateChannelConfig";
pub(crate) fn handle_update_channel_config_request(
context: Context, request: UpdateChannelConfigRequest,
) -> Result<UpdateChannelConfigResponse, LdkServerError> {
let user_channel_id: u128 = request.user_channel_id.parse().map_err(|_| {
LdkServerError::new(InvalidRequestError, "Failed to parse user_channel_id: invalid format.")
})?;
let user_channel_id: u128 = request
.user_channel_id
.parse::<u128>()
.map_err(|_| LdkServerError::new(InvalidRequestError, "Invalid UserChannelId."))?;

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