forked from bitcoin-dev-project/sim-ln
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathldk.rs
More file actions
90 lines (74 loc) · 2.3 KB
/
Copy pathldk.rs
File metadata and controls
90 lines (74 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use std::str::FromStr;
use async_trait::async_trait;
use bitcoin::Network;
use ldk_server_client::client::LdkServerClient;
use lightning::ln::features::NodeFeatures;
use crate::{LightningError, LightningNode, NodeInfo};
pub struct LdkServerConnection {
pub base_url: String,
pub api_key: String,
pub server_cert_pem: Vec<u8>,
}
pub struct LdkServer {
client: LdkServerClient,
info: NodeInfo,
network: Network,
}
impl LdkServer {
/// Creates a new instance that connects to a running `ldk-server` node (daemon).
pub async fn new(connection: LdkServerConnection) -> Result<Self, LightningError> {
let client = LdkServerClient::new(base_url, api_key, server_cert_pem)
.map_err(|e| LightningError::ConnectionError(e))?;
let node_info_res = client
.get_node_info(node_info_req)
.await
.map_err(|e| LightningError::GetNodeInfoError(e.to_string()))?;
let network = Network::from_str(node_info_res.network.as_str())
.map_err(|e| LightningError::GetNodeInfoError(e.to_string()))?;
let info = NodeInfo {
pubkey: node_info_res.node_id.into(),
alias: node_info_res.node_alias().to_string(),
features: match node_info_res.features {
Some(features) => NodeFeatures::from_be_bytes(features.node.to_vec()),
None => NodeFeatures::empty(),
},
};
Ok(Self {
client,
info,
network,
})
}
}
#[async_trait]
impl LightningNode for LdkServer {
fn get_info(&self) -> &NodeInfo {
todo!()
}
fn get_network(&self) -> Network {
todo!()
}
async fn send_payment(
&self,
dest: PublicKey,
amount_msat: u64,
) -> Result<PaymentHash, LightningError> {
todo!()
}
async fn track_payment(
&self,
hash: &PaymentHash,
shutdown: Listener,
) -> Result<PaymentResult, LightningError> {
todo!()
}
async fn get_node_info(&self, node_id: &PublicKey) -> Result<NodeInfo, LightningError> {
todo!()
}
async fn channel_capacities(&self) -> Result<u64, LightningError> {
todo!()
}
async fn get_graph(&self) -> Result<Graph, LightningError> {
todo!()
}
}