clightningrpc 0.2.0

Crate that provides an RPC binding from rust code to the c-lightning daemon
Documentation
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
// Rust JSON-RPC Library
// Written by
//     Andrew Poelstra <apoelstra@wpsoftware.net>
//     Wladimir J. van der Laan <laanwj@gmail.com>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
// along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
//
#![allow(missing_docs)]
//! Structures representing responses to API calls
use serde_json;
use std::collections::HashMap;
use std::net::{Ipv4Addr, Ipv6Addr};

use crate::common;
use crate::common::MSat;

/// structure for network addresses
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum NetworkAddress {
    Ipv4 {
        address: Ipv4Addr,
        port: u16,
    },
    Ipv6 {
        address: Ipv6Addr,
        port: u16,
    },
    Torv2 {
        address: String,
        port: u16,
    },
    Torv3 {
        address: String,
        port: u16,
    },
}

/// 'getinfo' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct GetInfo {
    pub id: String,
    pub alias: String,
    pub color: String,
    pub num_peers: u64,
    pub num_pending_channels: u64,
    pub num_active_channels: u64,
    pub num_inactive_channels: u64,
    pub address: Vec<NetworkAddress>,
    pub binding: Vec<NetworkAddress>,
    pub version: String,
    pub blockheight: u64,
    pub fees_collected_msat: MSat,
    pub network: String,
    #[serde(rename = "lightning-dir")]
    pub ligthning_dir: String,
    pub warning_bitcoind_sync: Option<String>,
    pub warning_lightningd_sync: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FeeRatesInner {
    pub urgent: Option<u64>,
    pub normal: Option<u64>,
    pub slow: Option<u64>,
    pub opening: u64,
    pub mutual_close: u64,
    pub unilateral_close: u64,
    pub delayed_to_us: u64,
    pub htlc_resolution: u64,
    pub penalty: u64,
    pub min_acceptable: u64,
    pub max_acceptable: u64,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FeeRatesOnchain {
    pub opening_channel_satoshis: u64,
    pub mutual_close_satoshis: u64,
    pub unilateral_close_satoshis: u64,
    pub htlc_timeout_satoshis: u64,
    pub htlc_success_satoshis: u64,
}

/// 'feerates' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FeeRates {
    pub perkb: Option<FeeRatesInner>,
    pub perkw: Option<FeeRatesInner>,
    pub warning: Option<String>,
    pub onchain_fee_estimates: Option<FeeRatesOnchain>,
}

/// Sub-structure for 'listnodes' items
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListNodesItem {
    pub nodeid: String,
    pub alias: Option<String>,
    pub color: Option<String>,
    pub last_timestamp: Option<u64>,
    pub features: Option<String>,
    pub addresses: Option<Vec<NetworkAddress>>,
}

/// 'listnodes' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListNodes {
    pub nodes: Vec<ListNodesItem>,
}

/// Sub-structure for 'listchannels' item
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListChannelsItem {
    pub source: String,
    pub destination: String,
    pub short_channel_id: String,
    pub public: bool,
    pub amount_msat: MSat,
    pub message_flags: u64,
    pub channel_flags: u64,
    pub active: bool,
    pub last_update: u64,
    pub base_fee_millisatoshi: u64,
    pub fee_per_millionth: u64,
    pub delay: u64,
    pub htlc_minimum_msat: MSat,
    pub htlc_maximum_msat: MSat,
    pub features: String,
}

/// 'listchannels' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListChannels {
    pub channels: Vec<ListChannelsItem>,
}

/// Sub-structure for 'help' item
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct HelpItem {
    pub command: String,
    pub category: String,
    pub description: String,
    pub verbose: String,
}

/// 'help' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Help {
    pub help: Option<Vec<HelpItem>>,
}

/// Sub-structure for 'getlog' and 'listpeers' item
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct LogEntry {
    #[serde(rename = "type")]
    pub type_: String,
    pub num_skipped: Option<u64>,
    pub time: Option<String>,
    pub node_id: Option<String>,
    pub source: Option<String>,
    pub log: Option<String>,
    pub data: Option<String>,
}

/// 'getlog' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct GetLog {
    pub created_at: String,
    pub bytes_used: u64,
    pub bytes_max: u64,
    pub log: Vec<LogEntry>,
}

/// 'listconfigs' command
pub type ListConfigs = HashMap<String, serde_json::Value>;

/// Sub-structure for htlcs in 'listpeers'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Htlc {
    pub direction: String,
    pub id: u64,
    pub amount_msat: MSat,
    pub expiry: u64,
    pub payment_hash: String,
    pub state: String,
    pub local_trimmed: Option<bool>,
}

/// Sub-structure for channel in 'listpeers'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Channel {
    pub state: String,
    pub scratch_txid: Option<String>,
    pub owner: Option<String>,
    pub short_channel_id: Option<String>,
    pub direction: Option<u64>,
    pub channel_id: String,
    pub funding_txid: String,
    pub close_to_addr: Option<String>,
    pub close_to: Option<String>,
    pub private: bool,
    pub funding_msat: HashMap<String, MSat>,
    pub to_us_msat: MSat,
    pub min_to_us_msat: MSat,
    pub max_to_us_msat: MSat,
    pub total_msat: MSat,
    pub dust_limit_msat: MSat,
    pub max_total_htlc_in_msat: MSat, // this exceeds what fits into u64
    pub their_reserve_msat: MSat,
    pub our_reserve_msat: MSat,
    pub spendable_msat: MSat,
    pub receivable_msat: MSat,
    pub minimum_htlc_in_msat: MSat,
    pub their_to_self_delay: u64,
    pub our_to_self_delay: u64,
    pub max_accepted_htlcs: u64,
    pub status: Vec<String>,
    pub in_payments_offered: u64,
    pub in_offered_msat: MSat,
    pub in_payments_fulfilled: u64,
    pub in_fulfilled_msat: MSat,
    pub out_payments_offered: u64,
    pub out_offered_msat: MSat,
    pub out_payments_fulfilled: u64,
    pub out_fulfilled_msat: MSat,
    pub htlcs: Vec<Htlc>,
}

/// Sub-structure for peer in 'listpeers'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Peer {
    pub id: String,
    pub connected: bool,
    pub netaddr: Option<Vec<String>>,
    pub features: Option<String>,
    pub channels: Vec<Channel>,
    pub log: Option<Vec<LogEntry>>,
}

/// 'listpeers' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListPeers {
    pub peers: Vec<Peer>,
}

/// Sub-structure for invoices in 'listinvoices'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListInvoice {
    pub label: String,
    pub bolt11: String,
    pub payment_hash: String,
    pub amount_msat: Option<MSat>,
    pub status: String,
    pub pay_index: Option<u64>,
    pub amount_received_msat: Option<MSat>,
    pub paid_at: Option<u64>,
    pub payment_preimage: Option<String>,
    pub description: Option<String>,
    pub expires_at: u64,
}

/// 'listinvoices' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListInvoices {
    pub invoices: Vec<ListInvoice>,
}

/// 'invoice' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Invoice {
    pub payment_hash: String,
    pub expires_at: u64,
    pub bolt11: String,
}

/// 'delinvoice' command
pub type DelInvoice = ListInvoice;

/// 'delexpiredinvoice' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DelExpiredInvoice {}

/// 'autocleaninvoice' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AutoCleanInvoice {}

/// 'waitanyinvoice' command
pub type WaitAnyInvoice = ListInvoice;

/// 'waitinvoice' command
pub type WaitInvoice = ListInvoice;

/// Sub-structure for failure in 'pay'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FailureItem {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: String,
    pub erring_index: u64,
    pub failcode: u64,
    pub erring_node: String,
    pub erring_channel: String,
    pub channel_update: Option<String>,
    pub route: Vec<common::RouteItem>,
}

/// 'pay' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Pay {
    pub id: u64,
    pub payment_hash: String,
    pub destination: String,
    pub msatoshi: u64,
    pub msatoshi_sent: u64,
    pub created_at: u64,
    pub status: String,
    pub payment_preimage: String,
    pub description: String,
    pub getroute_tries: u64,
    pub sendpay_tries: u64,
    pub route: Vec<common::RouteItem>,
    pub failures: Vec<FailureItem>,
}

/// 'sendpay' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SendPay {
    pub message: Option<String>,

    pub id: u64,
    pub payment_hash: String,
    pub partid: Option<u64>,
    pub destination: Option<String>,
    pub amount_msat: Option<MSat>,
    pub amount_sent_msat: MSat,
    pub created_at: u64,
    pub status: String,
    pub payment_preimage: Option<String>,
    pub description: Option<String>,
    pub bolt11: Option<String>,
    pub erroronion: Option<String>,

    pub onionreply: Option<String>,
    pub erring_index: Option<u64>,
    pub failcode: Option<u64>,
    pub failcodename: Option<String>,
    pub erring_node: Option<String>,
    pub erring_channel: Option<String>,
    pub erring_direction: Option<u64>,
    pub raw_message: Option<String>,
}

/// Sub-structure for payments in 'listsendpays' and 'waitsendpay'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListSendPaysItem {
    pub id: u64,
    pub payment_hash: String,
    pub partid: Option<u64>,
    pub destination: Option<String>,
    pub amount_msat: Option<MSat>,
    pub amount_sent_msat: MSat,
    pub created_at: u64,
    pub status: String,
    pub payment_preimage: Option<String>,
    pub description: Option<String>,
    pub bolt11: Option<String>,
    pub erroronion: Option<String>,
}

/// 'waitsendpay' command
pub type WaitSendPay = ListSendPaysItem;

/// 'listsendpays' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListSendPays {
    pub payments: Vec<ListSendPaysItem>,
}

/// Sub-structure for fallbacks in 'decodepay'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Fallback {
    #[serde(rename = "type")]
    pub type_: String,
    pub addr: String,
    pub hex: String,
}

/// Sub-structure for routes in 'decodepay'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DecodePayRoute {
    pub pubkey: String,
    pub short_channel_id: String,
    pub fee_base_msat: u64,
    pub fee_proportional_millionths: u64,
    pub cltv_expiry_delta: u64,
}

/// Sub-structure for extra in 'decodepay'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Extra {
    pub tag: String,
    pub data: String,
}

/// 'decodepay' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DecodePay {
    pub currency: String,
    pub created_at: u64,
    pub expiry: u64,
    pub payee: String,
    pub amount_msat: Option<MSat>,
    pub description: Option<String>,
    pub description_hash: Option<String>,
    pub min_final_cltv_expiry: u64,
    pub payment_secret: Option<String>,
    pub features: Option<String>,
    pub fallbacks: Option<Vec<Fallback>>,
    pub routes: Option<Vec<Vec<DecodePayRoute>>>,
    pub extra: Option<Vec<Extra>>,
    pub payment_hash: String,
    pub signature: String,
}

/// 'getroute' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct GetRoute {
    pub route: Vec<common::RouteItem>,
}

/// 'connect' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Connect {
    pub id: String,
    pub features: String,
}

/// 'disconnect' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Disconnect {}

/// 'fundchannel' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FundChannel {
    pub tx: String,
    pub txid: String,
    pub channel_id: String,
}

/// 'close' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Close {
    pub tx: String,
    pub txid: String,
    #[serde(rename = "type")]
    pub type_: String,
}

/// 'ping' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Ping {
    pub totlen: u64,
}

/// Sub-structure for 'listfunds' output
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListFundsOutput {
    pub txid: String,
    pub output: u64,
    pub amount_msat: MSat,
    pub address: String,
    pub status: String,
}

/// Sub-structure for 'listfunds' channel
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListFundsChannel {
    pub peer_id: String,
    pub connected: bool,
    pub short_channel_id: Option<String>,
    pub our_amount_msat: MSat,
    pub amount_msat: MSat,
    pub funding_txid: String,
    pub funding_output: u64,
}

/// 'listfunds' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListFunds {
    pub outputs: Vec<ListFundsOutput>,
    pub channels: Vec<ListFundsChannel>,
}

/// 'withdraw' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Withdraw {
    pub tx: String,
    pub txid: String,
}

/// 'newaddr' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct NewAddr {
    pub address: Option<String>,
    pub bech32: Option<String>,
    #[serde(rename = "p2sh-segwit")]
    pub p2sh_segwit: Option<String>,
}

/// 'stop' command
pub type Stop = String;