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
// 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 std::collections::HashMap;
use strason::Json;

use common;

/// structure for network addresses
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct NetworkAddress {
    #[serde(rename = "type")]
    pub type_: String,
    pub address: String,
    pub port: String,
}

/// 'getinfo' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct GetInfo {
    pub id: String,
    pub alias: String,
    pub color: String,
    pub address: Vec<NetworkAddress>,
    pub binding: Vec<NetworkAddress>,
    pub version: String,
    pub blockheight: i64,
    pub network: String,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FeeRatesInner {
    pub urgent: i64,
    pub normal: i64,
    pub slow: i64,
    pub min_acceptable: i64,
    pub max_acceptable: i64,
}

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

/// 'feerates' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FeeRates {
    pub perkb: Option<FeeRatesInner>,
    pub perkw: Option<FeeRatesInner>,
    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<i64>,
    pub global_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 satoshis: i64,
    pub flags: i64,
    pub active: bool,
    pub last_update: i64,
    pub base_fee_millisatoshi: i64,
    pub fee_per_millionth: i64,
    pub delay: i64,
}

/// '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 description: String,
}

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

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

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

/// 'listconfigs' command
pub type ListConfigs = HashMap<String, Json>;

/// Sub-structure for channel in 'listpeers'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Channel {
    pub state: String,
    pub owner: Option<String>,
    pub short_channel_id: String,
    pub channel_id: String,
    pub funding_txid: String,
    pub msatoshi_to_us: i64,
    pub msatoshi_to_us_min: i64,
    pub msatoshi_to_us_max: i64,
    pub msatoshi_total: i64,
    pub dust_limit_satoshis: i64,
    pub max_htlc_value_in_flight_msat: u64, // this exceeds what fits into i64
    pub their_channel_reserve_satoshis: i64,
    pub our_channel_reserve_satoshis: i64,
    pub spendable_msatoshi: i64,
    pub htlc_minimum_msat: i64,
    pub their_to_self_delay: i64,
    pub our_to_self_delay: i64,
    pub max_accepted_htlcs: i64,
    pub status: Vec<String>,
    pub in_payments_offered: i64,
    pub in_msatoshi_offered: i64,
    pub in_payments_fulfilled: i64,
    pub in_msatoshi_fulfilled: i64,
    pub out_payments_offered: i64,
    pub out_msatoshi_offered: i64,
    pub out_payments_fulfilled: i64,
    pub out_msatoshi_fulfilled: i64,
}

/// Sub-structure for log entry in 'listpeers'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Log {
    #[serde(rename = "type")]
    pub type_: String,
    pub time: String,
    pub source: String,
    pub log: String,
}

/// 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 local_features: Option<String>,
    pub global_features: Option<String>,
    pub channels: Vec<Channel>,
    pub log: Option<Vec<Log>>,
}

/// '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 msatoshi: i64,
    pub status: String,
    pub expires_at: i64,
    pub pay_index: Option<i64>,
    pub paid_at: Option<i64>,
}

/// '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: i64,
    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: i64,
    pub failcode: i64,
    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: i64,
    pub payment_hash: String,
    pub destination: String,
    pub msatoshi: i64,
    pub msatoshi_sent: i64,
    pub created_at: i64,
    pub status: String,
    pub payment_preimage: String,
    pub description: String,
    pub getroute_tries: i64,
    pub sendpay_tries: i64,
    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: i64,
    pub payment_hash: String,
    pub destination: String,
    pub msatoshi: i64,
    pub msatoshi_sent: i64,
    pub created_at: i64,
    pub status: String,
    pub payment_preimage: Option<String>,
    pub description: Option<String>,
}

/// Sub-structure for payments in 'listpayments' and 'waitsendpay'
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListPaymentsItem {
    pub id: i64,
    pub payment_hash: String,
    pub destination: String,
    pub msatoshi: i64,
    pub msatoshi_sent: i64,
    pub created_at: i64,
    pub status: String,
    pub payment_preimage: Option<String>,
    pub description: Option<String>,
}

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

/// 'listpayments' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListPayments {
    pub payments: Vec<ListPaymentsItem>,
}

/// 'decodepay' command
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DecodePay {
    pub currency: String,
    pub created_at: i64,
    pub expiry: i64,
    pub payee: String,
    pub msatoshi: i64,
    pub description: String,
    pub min_final_cltv_expiry: i64,
    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,
}

/// '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: i64,
}

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

/// Sub-structure for 'listfunds' channel
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ListFundsChannel {
    pub peer_id: String,
    pub short_channel_id: String,
    pub channel_sat: i64,
    pub channel_total_sat: i64,
    pub funding_txid: String,
}

/// '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: String,
}

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