From 69f350cba521b67c081677e4f21c496fcf15230f Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Fri, 26 Apr 2024 09:47:41 +0200 Subject: [PATCH] add listchannels to execute_dev_command --- libs/sdk-core/src/greenlight/node_api.rs | 50 +++++++++++++++++++++++- libs/sdk-core/src/node_api.rs | 16 ++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/libs/sdk-core/src/greenlight/node_api.rs b/libs/sdk-core/src/greenlight/node_api.rs index 7d8c97e5b..8dd443f67 100644 --- a/libs/sdk-core/src/greenlight/node_api.rs +++ b/libs/sdk-core/src/greenlight/node_api.rs @@ -48,7 +48,9 @@ use crate::invoice::{parse_invoice, validate_network, InvoiceError, RouteHintHop use crate::lightning::util::message_signing::verify; use crate::lightning_invoice::{RawBolt11Invoice, SignedRawBolt11Invoice}; use crate::models::*; -use crate::node_api::{CreateInvoiceRequest, FetchBolt11Result, NodeAPI, NodeError, NodeResult}; +use crate::node_api::{ + CreateInvoiceRequest, FetchBolt11Result, GraphChannel, NodeAPI, NodeError, NodeResult, +}; use crate::persist::db::SqliteStorage; use crate::{ NodeConfig, PrepareRedeemOnchainFundsRequest, PrepareRedeemOnchainFundsResponse, RouteHint, @@ -1512,6 +1514,40 @@ impl NodeAPI for Greenlight { .into_inner(); Ok(format!("{resp:?}")) } + NodeCommand::ListChannels { + source, + destination, + short_channel_id, + } => { + let resp = self + .get_node_client() + .await? + .list_channels(cln::ListchannelsRequest { + source: source.and_then(|d| hex::decode(d).ok()), + destination: destination.and_then(|d| hex::decode(d).ok()), + short_channel_id, + }) + .await? + .into_inner() + .channels + .iter() + .map(|c| GraphChannel { + active: c.active, + public: c.public, + base_fee_msat: c.base_fee_millisatoshi, + capacity_sat: c.amount_msat.clone().map(|a| a.msat / 1000), + cltv_delta: c.delay, + fee_per_millionth: c.fee_per_millionth as u64, + htlc_max_msat: c.htlc_maximum_msat.clone().map(|m| m.msat), + destination: hex::encode(c.destination.clone()), + short_channel_id: c.short_channel_id.clone(), + source: hex::encode(c.source.clone()), + htlc_min_msat: c.htlc_minimum_msat.clone().map(|m| m.msat), + last_update: c.last_update, + }) + .collect::>(); + Ok(format!("{resp:?}")) + } } } @@ -1710,6 +1746,18 @@ enum NodeCommand { #[strum(serialize = "listpeerchannels")] ListPeerChannels, + /// See + #[command(name = "listchannels")] + #[strum(serialize = "listchannels")] + ListChannels { + #[arg(long)] + source: Option, + #[arg(long)] + destination: Option, + #[arg(long)] + short_channel_id: Option, + }, + /// Stops the node. /// /// Note that this command will return an error, as the node is stopped before it can reply. diff --git a/libs/sdk-core/src/node_api.rs b/libs/sdk-core/src/node_api.rs index 0aa102ba8..7f78a2cc6 100644 --- a/libs/sdk-core/src/node_api.rs +++ b/libs/sdk-core/src/node_api.rs @@ -56,6 +56,22 @@ pub enum NodeError { ServiceConnectivity(anyhow::Error), } +#[derive(Debug)] +pub struct GraphChannel { + pub source: String, + pub destination: String, + pub short_channel_id: String, + pub public: bool, + pub capacity_sat: Option, + pub active: bool, + pub last_update: u32, + pub base_fee_msat: u32, + pub fee_per_millionth: u64, + pub cltv_delta: u32, + pub htlc_min_msat: Option, + pub htlc_max_msat: Option, +} + pub struct CreateInvoiceRequest { pub amount_msat: u64, pub description: String,