Skip to content

Commit

Permalink
add listchannels to execute_dev_command
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Apr 26, 2024
1 parent 4de689c commit 69f350c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
50 changes: 49 additions & 1 deletion libs/sdk-core/src/greenlight/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Vec<GraphChannel>>();
Ok(format!("{resp:?}"))
}
}
}

Expand Down Expand Up @@ -1710,6 +1746,18 @@ enum NodeCommand {
#[strum(serialize = "listpeerchannels")]
ListPeerChannels,

/// See <https://docs.corelightning.org/reference/lightning-listchannels>
#[command(name = "listchannels")]
#[strum(serialize = "listchannels")]
ListChannels {
#[arg(long)]
source: Option<String>,
#[arg(long)]
destination: Option<String>,
#[arg(long)]
short_channel_id: Option<String>,
},

/// Stops the node.
///
/// Note that this command will return an error, as the node is stopped before it can reply.
Expand Down
16 changes: 16 additions & 0 deletions libs/sdk-core/src/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
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<u64>,
pub htlc_max_msat: Option<u64>,
}

pub struct CreateInvoiceRequest {
pub amount_msat: u64,
pub description: String,
Expand Down

0 comments on commit 69f350c

Please sign in to comment.