Skip to content

Commit 0157beb

Browse files
committed
fixup! added Eclair node support
moved request to EclairClient
1 parent 9c028fb commit 0157beb

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

simln-lib/src/eclair.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ pub struct EclairConnection {
2727
pub api_password: String,
2828
}
2929

30-
pub struct EclairNode {
30+
struct EclairClient {
3131
base_url: Url,
3232
api_username: String,
3333
api_password: String,
3434
http_client: Client,
35-
info: NodeInfo,
36-
network: Network,
3735
}
3836

39-
impl EclairNode {
37+
impl EclairClient {
4038
async fn request_static<T: for<'de> Deserialize<'de>>(
4139
client: &Client,
4240
base_url: &Url,
@@ -73,7 +71,7 @@ impl EclairNode {
7371
endpoint: &str,
7472
params: Option<HashMap<String, String>>,
7573
) -> Result<T, Box<dyn Error>> {
76-
EclairNode::request_static(
74+
EclairClient::request_static(
7775
&self.http_client,
7876
&self.base_url,
7977
&self.api_username,
@@ -83,12 +81,20 @@ impl EclairNode {
8381
)
8482
.await
8583
}
84+
}
85+
86+
pub struct EclairNode {
87+
client: EclairClient,
88+
info: NodeInfo,
89+
network: Network,
90+
}
8691

92+
impl EclairNode {
8793
pub async fn new(connection: EclairConnection) -> Result<Self, LightningError> {
8894
let base_url = Url::parse(&connection.base_url)
8995
.map_err(|err| LightningError::GetInfoError(err.to_string()))?;
9096
let client = Client::new();
91-
let info: GetInfoResponse = EclairNode::request_static(
97+
let info: GetInfoResponse = EclairClient::request_static(
9298
&client,
9399
&base_url,
94100
&connection.api_username,
@@ -113,10 +119,12 @@ impl EclairNode {
113119
let features = parse_json_to_node_features(&info.features);
114120

115121
Ok(Self {
116-
base_url,
117-
api_username: connection.api_username,
118-
api_password: connection.api_password,
119-
http_client: client,
122+
client: EclairClient {
123+
base_url,
124+
api_username: connection.api_username,
125+
api_password: connection.api_password,
126+
http_client: client,
127+
},
120128
info: NodeInfo {
121129
pubkey,
122130
alias: info.alias,
@@ -148,6 +156,7 @@ impl LightningNode for EclairNode {
148156
params.insert("amountMsat".to_string(), amount_msat.to_string());
149157
params.insert("paymentHash".to_string(), hex::encode(preimage));
150158
let uuid: String = self
159+
.client
151160
.request("sendtonode", Some(params))
152161
.await
153162
.map_err(|err| LightningError::SendPaymentError(err.to_string()))?;
@@ -156,6 +165,7 @@ impl LightningNode for EclairNode {
156165
params.insert("paymentHash".to_string(), hex::encode(preimage));
157166
params.insert("id".to_string(), uuid);
158167
let payment_parts: PaymentInfoResponse = self
168+
.client
159169
.request("getsentinfo", Some(params))
160170
.await
161171
.map_err(|_| LightningError::InvalidPaymentHash)?;
@@ -182,7 +192,9 @@ impl LightningNode for EclairNode {
182192
let mut params = HashMap::new();
183193
params.insert("paymentHash".to_string(), hex::encode(hash.0));
184194

185-
let payment_parts: PaymentInfoResponse = self.request("getsentinfo", Some(params))
195+
let payment_parts: PaymentInfoResponse = self
196+
.client
197+
.request("getsentinfo", Some(params))
186198
.await
187199
.map_err(|err| LightningError::TrackPaymentError(err.to_string()))?;
188200

@@ -211,6 +223,7 @@ impl LightningNode for EclairNode {
211223
params.insert("nodeId".to_string(), hex::encode(node_id.serialize()));
212224

213225
let node_info: NodeResponse = self
226+
.client
214227
.request("node", Some(params))
215228
.await
216229
.map_err(|err| LightningError::GetNodeInfoError(err.to_string()))?;
@@ -231,6 +244,7 @@ impl LightningNode for EclairNode {
231244
);
232245

233246
let channels: ChannelsResponse = self
247+
.client
234248
.request("channels", Some(params))
235249
.await
236250
.map_err(|err| LightningError::ListChannelsError(err.to_string()))?;

0 commit comments

Comments
 (0)