Skip to content

Commit

Permalink
Try to add eclair/ldk support
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleTimez committed Apr 24, 2024
1 parent a574b1e commit 159d063
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
79 changes: 79 additions & 0 deletions sim-lib/src/eclair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use async_trait::async_trait;
use bitcoin::secp256k1::PublicKey;
use bitcoin::Network;

use lightning::ln::PaymentHash;

use serde::{Deserialize, Serialize};

use triggered::Listener;

use crate::{
serializers, LightningError, LightningNode, PaymentResult, NodeId, NodeInfo,
};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EclairConnection {
#[serde(with = "serializers::serde_node_id")]
pub id: NodeId,
pub address: String,
#[serde(deserialize_with = "serializers::deserialize_path")]
pub ca_cert: String,
#[serde(deserialize_with = "serializers::deserialize_path")]
pub client_cert: String,
#[serde(deserialize_with = "serializers::deserialize_path")]
pub client_key: String,
}

//TODO: Feels tmp to code real client library to connect with eclair.
struct Client {}

pub struct EclairNode {
client: Client,
info: NodeInfo,
}

impl EclairNode {
pub async fn new(connection: EclairConnection) -> Result<Self, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn node_channels(&mut self, is_source: bool) -> Result<Vec<u64>, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}
}

#[async_trait]
impl LightningNode for EclairNode {
fn get_info(&self) -> &NodeInfo {
&self.info
}

async fn get_network(&mut self) -> Result<Network, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn send_payment(
&mut self,
dest: PublicKey,
amount_msat: u64,
) -> Result<PaymentHash, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn track_payment(
&mut self,
hash: &PaymentHash,
shutdown: Listener,
) -> Result<PaymentResult, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn get_node_info(&mut self, node_id: &PublicKey) -> Result<NodeInfo, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn list_channels(&mut self) -> Result<Vec<u64>, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}
}
79 changes: 79 additions & 0 deletions sim-lib/src/ldk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use async_trait::async_trait;
use bitcoin::secp256k1::PublicKey;
use bitcoin::Network;

use lightning::ln::PaymentHash;

use serde::{Deserialize, Serialize};

use triggered::Listener;

use crate::{
serializers, LightningError, LightningNode, PaymentResult, NodeId, NodeInfo,
};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LdkConnection {
#[serde(with = "serializers::serde_node_id")]
pub id: NodeId,
pub address: String,
#[serde(deserialize_with = "serializers::deserialize_path")]
pub ca_cert: String,
#[serde(deserialize_with = "serializers::deserialize_path")]
pub client_cert: String,
#[serde(deserialize_with = "serializers::deserialize_path")]
pub client_key: String,
}

//TODO: Feels tmp to code real client library to connect with ldk.
struct Client {}

pub struct LdkNode {
client: Client,
info: NodeInfo,
}

impl LdkNode {
pub async fn new(connection: LdkConnection) -> Result<Self, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn node_channels(&mut self, is_source: bool) -> Result<Vec<u64>, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}
}

#[async_trait]
impl LightningNode for LdkNode {
fn get_info(&self) -> &NodeInfo {
&self.info
}

async fn get_network(&mut self) -> Result<Network, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn send_payment(
&mut self,
dest: PublicKey,
amount_msat: u64,
) -> Result<PaymentHash, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn track_payment(
&mut self,
hash: &PaymentHash,
shutdown: Listener,
) -> Result<PaymentResult, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn get_node_info(&mut self, node_id: &PublicKey) -> Result<NodeInfo, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}

async fn list_channels(&mut self) -> Result<Vec<u64>, LightningError> {
Err(LightningError::ConnectionError("tmp err".to_string()))
}
}
4 changes: 4 additions & 0 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use self::random_activity::{NetworkGraphView, RandomPaymentActivity};
pub mod cln;
mod defined_activity;
pub mod lnd;
pub mod eclair;
pub mod ldk;
mod random_activity;
mod serializers;
pub mod sim_node;
Expand All @@ -36,6 +38,8 @@ mod test_utils;
pub enum NodeConnection {
LND(lnd::LndConnection),
CLN(cln::ClnConnection),
LDK(ldk::LdkConnection),
Eclair(eclair::EclairConnection),
}

#[derive(Serialize, Debug, Clone)]
Expand Down

0 comments on commit 159d063

Please sign in to comment.