Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tokio = { version = "1.38.0", default-features = false, features = ["time", "sig
prost = { version = "0.11.6", default-features = false, features = ["std"] }
protos = { path = "../protos" }
bytes = "1.4.0"
hex = { package = "hex-conservative", version = "0.2.1", default-features = false }
15 changes: 15 additions & 0 deletions server/src/api/list_channels.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::util::proto_adapter::channel_to_proto;
use ldk_node::Node;
use protos::{ListChannelsRequest, ListChannelsResponse};
use std::sync::Arc;

pub(crate) const LIST_CHANNELS_PATH: &str = "ListChannels";

pub(crate) fn handle_list_channels_request(
node: Arc<Node>, _request: ListChannelsRequest,
) -> Result<ListChannelsResponse, ldk_node::NodeError> {
let channels = node.list_channels().into_iter().map(|c| channel_to_proto(c)).collect();

let response = ListChannelsResponse { channels };
Ok(response)
}
1 change: 1 addition & 0 deletions server/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub(crate) mod bolt11_send;
pub(crate) mod bolt12_receive;
pub(crate) mod bolt12_send;
pub(crate) mod close_channel;
pub(crate) mod list_channels;
pub(crate) mod onchain_receive;
pub(crate) mod onchain_send;
pub(crate) mod open_channel;
1 change: 1 addition & 0 deletions server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod api;
mod service;
mod util;

use crate::service::NodeService;

Expand Down
2 changes: 2 additions & 0 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::api::bolt11_send::{handle_bolt11_send_request, BOLT11_SEND_PATH};
use crate::api::bolt12_receive::{handle_bolt12_receive_request, BOLT12_RECEIVE_PATH};
use crate::api::bolt12_send::{handle_bolt12_send_request, BOLT12_SEND_PATH};
use crate::api::close_channel::{handle_close_channel_request, CLOSE_CHANNEL_PATH};
use crate::api::list_channels::{handle_list_channels_request, LIST_CHANNELS_PATH};
use crate::api::onchain_receive::{handle_onchain_receive_request, ONCHAIN_RECEIVE_PATH};
use crate::api::onchain_send::{handle_onchain_send_request, ONCHAIN_SEND_PATH};
use crate::api::open_channel::{handle_open_channel, OPEN_CHANNEL_PATH};
Expand Down Expand Up @@ -54,6 +55,7 @@ impl Service<Request<Incoming>> for NodeService {
BOLT12_SEND_PATH => Box::pin(handle_request(node, req, handle_bolt12_send_request)),
OPEN_CHANNEL_PATH => Box::pin(handle_request(node, req, handle_open_channel)),
CLOSE_CHANNEL_PATH => Box::pin(handle_request(node, req, handle_close_channel_request)),
LIST_CHANNELS_PATH => Box::pin(handle_request(node, req, handle_list_channels_request)),
path => {
let error = format!("Unknown request: {}", path).into_bytes();
Box::pin(async {
Expand Down
1 change: 1 addition & 0 deletions server/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod proto_adapter;
55 changes: 55 additions & 0 deletions server/src/util/proto_adapter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use protos::{Channel, OutPoint};
Comment thread
G8XSU marked this conversation as resolved.
pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
counterparty_node_id: channel.counterparty_node_id.to_string(),
funding_txo: channel
.funding_txo
.map(|o| OutPoint { txid: o.txid.to_string(), vout: o.vout }),
user_channel_id: channel.user_channel_id.0.to_string(),
unspendable_punishment_reserve: channel.unspendable_punishment_reserve,
channel_value_sats: channel.channel_value_sats,
feerate_sat_per_1000_weight: channel.feerate_sat_per_1000_weight,
outbound_capacity_msat: channel.outbound_capacity_msat,
inbound_capacity_msat: channel.inbound_capacity_msat,
confirmations_required: channel.confirmations_required,
confirmations: channel.confirmations,
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
counterparty_outbound_htlc_minimum_msat: channel.counterparty_outbound_htlc_minimum_msat,
counterparty_outbound_htlc_maximum_msat: channel.counterparty_outbound_htlc_maximum_msat,
counterparty_unspendable_punishment_reserve: channel
.counterparty_unspendable_punishment_reserve,
counterparty_forwarding_info_fee_base_msat: channel
.counterparty_forwarding_info_fee_base_msat,
counterparty_forwarding_info_fee_proportional_millionths: channel
.counterparty_forwarding_info_fee_proportional_millionths,
counterparty_forwarding_info_cltv_expiry_delta: channel
.counterparty_forwarding_info_cltv_expiry_delta
.map(|x| x as u32),
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
}
}