@@ -27,16 +27,14 @@ pub struct EclairConnection {
27
27
pub api_password : String ,
28
28
}
29
29
30
- pub struct EclairNode {
30
+ struct EclairClient {
31
31
base_url : Url ,
32
32
api_username : String ,
33
33
api_password : String ,
34
34
http_client : Client ,
35
- info : NodeInfo ,
36
- network : Network ,
37
35
}
38
36
39
- impl EclairNode {
37
+ impl EclairClient {
40
38
async fn request_static < T : for < ' de > Deserialize < ' de > > (
41
39
client : & Client ,
42
40
base_url : & Url ,
@@ -73,7 +71,7 @@ impl EclairNode {
73
71
endpoint : & str ,
74
72
params : Option < HashMap < String , String > > ,
75
73
) -> Result < T , Box < dyn Error > > {
76
- EclairNode :: request_static (
74
+ EclairClient :: request_static (
77
75
& self . http_client ,
78
76
& self . base_url ,
79
77
& self . api_username ,
@@ -83,12 +81,20 @@ impl EclairNode {
83
81
)
84
82
. await
85
83
}
84
+ }
85
+
86
+ pub struct EclairNode {
87
+ client : EclairClient ,
88
+ info : NodeInfo ,
89
+ network : Network ,
90
+ }
86
91
92
+ impl EclairNode {
87
93
pub async fn new ( connection : EclairConnection ) -> Result < Self , LightningError > {
88
94
let base_url = Url :: parse ( & connection. base_url )
89
95
. map_err ( |err| LightningError :: GetInfoError ( err. to_string ( ) ) ) ?;
90
96
let client = Client :: new ( ) ;
91
- let info: GetInfoResponse = EclairNode :: request_static (
97
+ let info: GetInfoResponse = EclairClient :: request_static (
92
98
& client,
93
99
& base_url,
94
100
& connection. api_username ,
@@ -113,10 +119,12 @@ impl EclairNode {
113
119
let features = parse_json_to_node_features ( & info. features ) ;
114
120
115
121
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
+ } ,
120
128
info : NodeInfo {
121
129
pubkey,
122
130
alias : info. alias ,
@@ -148,6 +156,7 @@ impl LightningNode for EclairNode {
148
156
params. insert ( "amountMsat" . to_string ( ) , amount_msat. to_string ( ) ) ;
149
157
params. insert ( "paymentHash" . to_string ( ) , hex:: encode ( preimage) ) ;
150
158
let uuid: String = self
159
+ . client
151
160
. request ( "sendtonode" , Some ( params) )
152
161
. await
153
162
. map_err ( |err| LightningError :: SendPaymentError ( err. to_string ( ) ) ) ?;
@@ -156,6 +165,7 @@ impl LightningNode for EclairNode {
156
165
params. insert ( "paymentHash" . to_string ( ) , hex:: encode ( preimage) ) ;
157
166
params. insert ( "id" . to_string ( ) , uuid) ;
158
167
let payment_parts: PaymentInfoResponse = self
168
+ . client
159
169
. request ( "getsentinfo" , Some ( params) )
160
170
. await
161
171
. map_err ( |_| LightningError :: InvalidPaymentHash ) ?;
@@ -182,7 +192,9 @@ impl LightningNode for EclairNode {
182
192
let mut params = HashMap :: new( ) ;
183
193
params. insert( "paymentHash" . to_string( ) , hex:: encode( hash. 0 ) ) ;
184
194
185
- let payment_parts: PaymentInfoResponse = self . request( "getsentinfo" , Some ( params) )
195
+ let payment_parts: PaymentInfoResponse = self
196
+ . client
197
+ . request( "getsentinfo" , Some ( params) )
186
198
. await
187
199
. map_err( |err| LightningError :: TrackPaymentError ( err. to_string( ) ) ) ?;
188
200
@@ -211,6 +223,7 @@ impl LightningNode for EclairNode {
211
223
params. insert ( "nodeId" . to_string ( ) , hex:: encode ( node_id. serialize ( ) ) ) ;
212
224
213
225
let node_info: NodeResponse = self
226
+ . client
214
227
. request ( "node" , Some ( params) )
215
228
. await
216
229
. map_err ( |err| LightningError :: GetNodeInfoError ( err. to_string ( ) ) ) ?;
@@ -231,6 +244,7 @@ impl LightningNode for EclairNode {
231
244
) ;
232
245
233
246
let channels: ChannelsResponse = self
247
+ . client
234
248
. request ( "channels" , Some ( params) )
235
249
. await
236
250
. map_err ( |err| LightningError :: ListChannelsError ( err. to_string ( ) ) ) ?;
0 commit comments