rust-blocktank-client 0.0.16

A Rust client for the Blocktank LSP HTTP API
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
use crate::BlocktankError;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum BitcoinNetworkEnum {
    #[serde(rename = "mainnet")]
    Mainnet,
    #[serde(rename = "testnet")]
    Testnet,
    #[serde(rename = "signet")]
    Signet,
    #[serde(rename = "regtest")]
    Regtest,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum BtBolt11InvoiceState {
    /// Expect payment
    #[serde(rename = "pending")]
    Pending,
    /// Payment received but not confirmed/rejected yet. Only possible with HODL invoices.
    #[serde(rename = "holding")]
    Holding,
    /// Payment confirmed
    #[serde(rename = "paid")]
    Paid,
    /// Payment rejected or invoice expired.
    #[serde(rename = "canceled")]
    Canceled,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum BtChannelOrderErrorType {
    /// Order is not in the right state to open a channel. Should be `order.state`=`created` and `order.payment.state`=`paid`.
    #[serde(rename = "WRONG_ORDER_STATE")]
    WrongOrderState,
    /// Could not establish connection to peer.
    #[serde(rename = "PEER_NOT_REACHABLE")]
    PeerNotReachable,
    /// Peer rejected channel open request.
    #[serde(rename = "CHANNEL_REJECTED_BY_DESTINATION")]
    ChannelRejectedByDestination,
    /// LSP rejected channel open request.
    #[serde(rename = "CHANNEL_REJECTED_BY_LSP")]
    ChannelRejectedByLsp,
    /// Blocktank service is temporarily unavailable.
    #[serde(rename = "BLOCKTANK_NOT_READY")]
    BlocktankNotReady,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum BtOpenChannelState {
    /// Channel is waiting for the required confirmations.
    #[serde(rename = "opening")]
    Opening,
    /// Channel is ready to transact.
    #[serde(rename = "open")]
    Open,
    /// Channel is has been closed with at least 1 onchain confirmation.
    #[serde(rename = "closed")]
    Closed,
}

/// @deprecated Use BtOrderState2 instead.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum BtOrderState {
    #[serde(rename = "created")]
    Created,
    /// No payment made, order expired.
    #[serde(rename = "expired")]
    Expired,
    #[serde(rename = "open")]
    Open,
    #[serde(rename = "closed")]
    Closed,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum BtOrderState2 {
    /// Order created. Ready to receive payment.
    #[serde(rename = "created")]
    Created,
    /// Order expired.
    #[serde(rename = "expired")]
    Expired,
    /// Order successfully executed.
    #[serde(rename = "executed")]
    Executed,
    /// Order paid and ready to open channel.
    #[serde(rename = "paid")]
    Paid,
}

/// @deprecated Use BtPaymentState2 instead.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum BtPaymentState {
    /// Ready to receive payments
    #[serde(rename = "created")]
    Created,
    /// Partially paid order will just be displayed as `created`.
    #[serde(rename = "partiallyPaid")]
    PartiallyPaid,
    /// Order is paid
    #[serde(rename = "paid")]
    Paid,
    /// Order is refunded.
    #[serde(rename = "refunded")]
    Refunded,
    /// Onchain refunds can't be done automatically. `refundAvailable` is displayed in this case.
    #[serde(rename = "refundAvailable")]
    RefundAvailable,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum BtPaymentState2 {
    /// Ready to receive payments
    #[serde(rename = "created")]
    Created,
    /// Order is paid
    #[serde(rename = "paid")]
    Paid,
    /// Order is refunded.
    #[serde(rename = "refunded")]
    Refunded,
    /// Onchain refunds can't be done automatically. `refundAvailable` is displayed in this case.
    #[serde(rename = "refundAvailable")]
    RefundAvailable,
    /// Payments not possible anymore.
    #[serde(rename = "canceled")]
    Canceled,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum CJitStateEnum {
    /// Invoice is ready to receive funds.
    #[serde(rename = "created")]
    Created,
    /// Channel opened and funds pushed to client.
    #[serde(rename = "completed")]
    Completed,
    /// Invoice expired.
    #[serde(rename = "expired")]
    Expired,
    /// Channel open failed.
    #[serde(rename = "failed")]
    Failed,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBt0ConfMinTxFeeWindow {
    /// Minimum fee rate that is required for Blocktank to accept the onchain payment to be 0conf.
    #[serde(rename = "satPerVByte")]
    pub sat_per_vbyte: f64,
    /// How long this fee rate is valid for.
    pub validity_ends_at: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtBolt11Invoice {
    pub request: String,
    pub state: BtBolt11InvoiceState,
    pub expires_at: String,
    pub updated_at: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FundingTx {
    pub id: String,
    pub vout: u64,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtChannel {
    pub state: BtOpenChannelState,
    pub lsp_node_pubkey: String,
    pub client_node_pubkey: String,
    pub announce_channel: bool,
    pub funding_tx: FundingTx,
    /// @deprecated Use close.tx_id instead.
    pub closing_tx_id: Option<String>,
    /// Only available if state === closed. Channels before Oct 2023 may have default values assigned that do not represent reality.
    pub close: Option<IBtChannelClose>,
    /// @deprecated Available as soon as the channel is confirmed.
    pub short_channel_id: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtChannelClose {
    /// Transaction id of the closing transaction. Only available if state === OpenChannelOrderState.CLOSED.
    pub tx_id: String,
    /// Which method has been used to close this channel?
    #[serde(rename = "type")]
    pub close_type: String, // 'cooperative' | 'force' | 'breach'
    /// Who closed this channel?
    pub initiator: String, // 'lsp' | 'client'
    /// When Blocktank registered the channel close.
    pub registered_at: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtEstimateFeeResponse {
    pub fee_sat: u64,
    #[serde(rename = "min0ConfTxFee")]
    pub min_0_conf_tx_fee: IBt0ConfMinTxFeeWindow,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtEstimateFeeResponse2 {
    /// Sum fee to pay
    pub fee_sat: u64,
    /// Network fee that Blocktank needs to pay to open and close the channel.
    pub network_fee_sat: u64,
    /// Service fee that Blocktank charges to open the channel.
    pub service_fee_sat: u64,
    #[serde(rename = "min0ConfTxFee")]
    pub min_0_conf_tx_fee: IBt0ConfMinTxFeeWindow,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtInfoOptions {
    /// Minimum channel size
    pub min_channel_size_sat: u64,
    /// Maximum channel size
    pub max_channel_size_sat: u64,
    /// Minimum channel lease time in weeks.
    pub min_expiry_weeks: u32,
    /// Maximum channel lease time in weeks.
    pub max_expiry_weeks: u32,
    /// Minimum payment confirmation for safe payments.
    pub min_payment_confirmations: u32,
    /// Minimum payment confirmations for high value payments.
    pub min_high_risk_payment_confirmations: u32,
    /// Maximum clientBalanceSat that is accepted as 0conf/turbochannel.
    pub max_0_conf_client_balance_sat: u64,
    /// @deprecated Same as maxChannelSizeSat.
    pub max_client_balance_sat: u64,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct IBtInfoVersions {
    /// SemVer versions of the http micro services.
    pub http: String,
    /// SemVer versions of the btc micro services.
    pub btc: String,
    /// SemVer versions of the ln2 micro services.
    pub ln2: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct FeeRates {
    /// Fast fee in sat/vbyte.
    pub fast: u32,
    /// Mid fee in sat/vbyte.
    pub mid: u32,
    /// Slow fee in sat/vbyte.
    pub slow: u32,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtInfoOnchain {
    pub network: BitcoinNetworkEnum,
    pub fee_rates: FeeRates,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct IBtInfo {
    /// @deprecated Use the `versions` object instead.
    pub version: u32,
    /// Available nodes.
    pub nodes: Vec<ILspNode>,
    pub options: IBtInfoOptions,
    /// SemVer versions of the micro services.
    pub versions: IBtInfoVersions,
    pub onchain: IBtInfoOnchain,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtOnchainTransaction {
    pub amount_sat: u64,
    pub tx_id: String,
    pub vout: u32,
    pub block_height: Option<u32>,
    pub block_confirmation_count: u32,
    #[serde(rename = "feeRateSatPerVbyte")]
    pub fee_rate_sat_per_vbyte: f64,
    pub confirmed: bool,
    #[serde(rename = "suspicious0ConfReason")]
    pub suspicious_0_conf_reason: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtOnchainTransactions {
    pub address: String,
    pub confirmed_sat: u64,
    pub required_confirmations: u32,
    pub transactions: Vec<IBtOnchainTransaction>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtOrder {
    pub id: String,
    /// @deprecated Will be removed in future releases. Use state2 instead.
    pub state: BtOrderState,
    /// State of the order
    pub state2: Option<BtOrderState2>,
    /// Fees in satoshi to pay before the channel open is possible.
    pub fee_sat: u64,
    /// Onchain transaction fees for the channel open.
    /// This is variable depending on the network fee conditions.
    pub network_fee_sat: u64,
    /// Service fees to pay for us to fulfill the channel open. Includes liquidity fees.
    pub service_fee_sat: u64,
    pub lsp_balance_sat: u64,
    /// Requested funds on the client side.
    pub client_balance_sat: u64,
    /// If this the channel should be a turbo channel.
    #[serde(rename = "zeroConf")]
    pub zero_conf: bool,
    /// If the LSP allows the client to have a minimal channel reserve.
    pub zero_reserve: bool,
    /// Node id to notify in case the node is offline and the order is ready to open the channel.
    pub client_node_id: Option<String>,
    /// Weeks how long Blocktank guarantees to keep the channel open.
    pub channel_expiry_weeks: u32,
    /// How long Blocktank guarantees to keep the channel open.
    pub channel_expires_at: String,
    /// How long the order with its proposed feeSat is valid for.
    pub order_expires_at: String,
    /// Channel in case the order has been executed.
    pub channel: Option<IBtChannel>,
    /// Node if of the LSP that will/has opened the channel.
    pub lsp_node: Option<ILspNode>,
    /// LNURL to open the channel.
    pub lnurl: Option<String>,
    /// Payment object showing invoices and the status of the payment.
    pub payment: Option<IBtPayment>,
    /// @deprecated Use the `source` field.
    pub coupon_code: Option<String>,
    /// Source what created this order. Example: bitkit, widget
    pub source: Option<String>,
    /// Discount if discount was given.
    pub discount: Option<IDiscount>,
    pub updated_at: String,
    pub created_at: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IBtPayment {
    /// @deprecated Will be removed in future releases. Use state2 instead.
    pub state: BtPaymentState,
    pub state2: Option<BtPaymentState2>,
    pub paid_sat: u64,
    pub bolt11_invoice: Option<IBtBolt11Invoice>,
    pub onchain: Option<IBtOnchainTransactions>,
    /// Internal flag
    pub is_manually_paid: Option<bool>,
    /// Refund objects
    pub manual_refunds: Option<Vec<IManualRefund>>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ICJitEntry {
    /// Id of this CJitEntry
    pub id: String,
    /// State of this entry
    pub state: CJitStateEnum,
    /// Fee in satoshi to open this channel.
    pub fee_sat: u64,
    /// Onchain transaction fees for the channel open.
    /// This is variable depending on the network fee conditions.
    pub network_fee_sat: u64,
    /// Service fees to pay for us to fulfill the channel open. Includes liquidity fees.
    pub service_fee_sat: u64,
    /// Requested channel size in satoshi
    pub channel_size_sat: u64,
    /// Number of weeks before Blocktank might close then channel.
    pub channel_expiry_weeks: u32,
    /// Channel open error if the channel open failed.
    pub channel_open_error: Option<String>,
    /// Node id of the node to open the channel to.
    pub node_id: String,
    /// Invoice to be paid for the channel open.
    pub invoice: IBtBolt11Invoice,
    /// Opened channel
    pub channel: Option<IBtChannel>,
    /// LSP node the channel is opened from. The client needs to establish a peer connection to it before the channel open.
    pub lsp_node: ILspNode,
    /// @deprecated Use `source` instead
    pub coupon_code: String,
    /// Source what created this Cjit. Example: 'bitkit', 'widget'.
    pub source: Option<String>,
    /// Discount if available
    pub discount: Option<IDiscount>,
    /// Date when this CJit offer expires.
    pub expires_at: String,
    pub updated_at: String,
    pub created_at: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IDiscount {
    /// User provided discount code label
    pub code: String,
    /// Absolute discount given for this code.
    pub absolute_sat: u64,
    /// Relative discount % given for this code.
    pub relative: f64,
    /// Overall sum of the discount calculated by `fee * relative + absoluteSat`.
    pub overall_sat: u64,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ILspNode {
    pub alias: String,
    pub pubkey: String,
    pub connection_strings: Vec<String>,
    pub readonly: Option<bool>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum ManualRefundStateEnum {
    #[serde(rename = "CREATED")]
    Created,
    #[serde(rename = "APPROVED")]
    Approved,
    #[serde(rename = "REJECTED")]
    Rejected,
    #[serde(rename = "SENT")]
    Sent,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IManualRefund {
    pub amount_sat: u64,
    pub target: String,
    pub state: ManualRefundStateEnum,
    pub created_by_name: String,
    pub voted_by_name: Option<String>,
    pub reason: Option<String>,
    #[serde(rename = "targetType")]
    pub target_type: String, // 'lightning' | 'onchain'
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CreateOrderOptions {
    /// Initial number of satoshis the client wants to provide on their channel side. The client pays this balance
    /// to the LSP. The LSP will push the balance to the LSP on channel creation. Defaults to 0.
    pub client_balance_sat: u64,

    /// Node id the client wants to receive the channel from. The id must come from the node list provided by `get_info`.
    /// If not provided, a random node will be chosen.
    pub lsp_node_id: Option<String>,

    /// @deprecated Use `source` field instead.
    pub coupon_code: String,

    /// What created this order. Example: 'bitkit', 'widget'.
    pub source: Option<String>,

    /// User-entered discount code.
    pub discount_code: Option<String>,

    /// If the channel opened should be a turbo aka. zeroConf channel.
    pub zero_conf: bool,

    /// If the on-chain payment should be accepted without any block confirmations.
    pub zero_conf_payment: Option<bool>,

    /// Allow the peer to have zero channel reserve (dust limit).
    pub zero_reserve: bool,

    /// Optional id of the node that the channel should be opened to. If supplied,
    /// performs a channel limit check on the node at order creation to prevent
    /// any surprises when the channel is actually getting opened.
    /// Node that should be woken up via a push notification as soon as the payment is confirmed.
    /// Ownership of the node must be proven with a signature.
    pub client_node_id: Option<String>,

    /// Timestamp that has been used to sign the open proof.
    pub timestamp: Option<String>,

    /// Signature `channelOpen-${ISO-timestamp}` created by the private key of the node.
    pub signature: Option<String>,

    /// User-entered refund on-chain address.
    pub refund_onchain_address: Option<String>,

    /// Should the channel be public.
    pub announce_channel: bool,
}

// Default values for CreateOrderOptions
impl Default for CreateOrderOptions {
    fn default() -> Self {
        Self {
            client_balance_sat: 0,
            lsp_node_id: None,
            coupon_code: String::new(),
            source: None,
            discount_code: None,
            zero_conf: false,
            zero_conf_payment: None,
            zero_reserve: false,
            client_node_id: None,
            timestamp: None,
            signature: None,
            refund_onchain_address: None,
            announce_channel: false,
        }
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CreateCjitOptions {
    /// What created this order. Example: 'bitkit', 'widget'.
    pub source: Option<String>,

    /// User-entered discount code.
    pub discount_code: Option<String>,
}

// Default values for CreateCjitOptions
impl Default for CreateCjitOptions {
    fn default() -> Self {
        Self {
            source: None,
            discount_code: None,
        }
    }
}

impl std::str::FromStr for BtOrderState2 {
    type Err = BlocktankError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "Created" => Ok(BtOrderState2::Created),
            "Expired" => Ok(BtOrderState2::Expired),
            "Executed" => Ok(BtOrderState2::Executed),
            "Paid" => Ok(BtOrderState2::Paid),
            _ => Err(BlocktankError::DataError {
                error_details: format!("Invalid BtOrderState2 value: {}", s),
            }),
        }
    }
}

impl std::str::FromStr for BtOrderState {
    type Err = BlocktankError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "Created" => Ok(BtOrderState::Created),
            "Expired" => Ok(BtOrderState::Expired),
            "Open" => Ok(BtOrderState::Open),
            "Closed" => Ok(BtOrderState::Closed),
            _ => Err(BlocktankError::DataError {
                error_details: format!("Invalid BtOrderState value: {}", s),
            }),
        }
    }
}

impl std::str::FromStr for CJitStateEnum {
    type Err = BlocktankError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "Created" => Ok(CJitStateEnum::Created),
            "Completed" => Ok(CJitStateEnum::Completed),
            "Expired" => Ok(CJitStateEnum::Expired),
            "Failed" => Ok(CJitStateEnum::Failed),
            _ => Err(BlocktankError::DataError {
                error_details: format!("Invalid CJitStateEnum value: {}", s),
            }),
        }
    }
}

#[derive(Debug, Deserialize)]
pub struct ApiValidationError {
    #[serde(rename = "type")]
    error_type: String,
    pub(crate) errors: ApiErrorDetails,
}

#[derive(Debug, Deserialize)]
pub struct ApiErrorDetails {
    pub(crate) issues: Vec<ApiErrorIssue>,
    name: String,
}

#[derive(Debug, Deserialize)]
pub struct ApiErrorIssue {
    code: String,
    pub(crate) message: String,
    path: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IGiftCode {
    pub id: String,
    pub code: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub scope: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub gift_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_count: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IGiftBtcAddress {
    pub id: String,
    pub address: String,
    #[serde(default)]
    pub transactions: Vec<serde_json::Value>,
    #[serde(default)]
    pub all_transactions: Vec<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_blacklisted: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub watch_until: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub watch_for_block_confirmations: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IGiftBolt11Invoice {
    pub id: String,
    pub request: String,
    pub state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_hodl_invoice: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub payment_hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amount_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amount_msat: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub internal_node_pubkey: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IGiftPayment {
    pub id: String,
    pub state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub old_state: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub onchain_state: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ln_state: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paid_onchain_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paid_ln_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paid_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_overpaid: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_refunded: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub overpaid_amount_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub required_onchain_confirmations: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub settlement_state: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expected_amount_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_manually_paid: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub btc_address: Option<IGiftBtcAddress>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub btc_address_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bolt11_invoice: Option<IGiftBolt11Invoice>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bolt11_invoice_id: Option<String>,
    #[serde(default)]
    pub manual_refunds: Vec<serde_json::Value>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IGiftLspNode {
    pub alias: String,
    pub pubkey: String,
    pub connection_strings: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IGiftOrder {
    pub id: String,
    pub state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub old_state: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_channel_expired: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_order_expired: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lsp_balance_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub client_balance_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub channel_expiry_weeks: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub zero_conf: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub zero_reserve: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub announced: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub client_node_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "channelExiresAt")]
    pub channel_expires_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_expires_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fee_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub network_fee_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub service_fee_sat: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub payment: Option<IGiftPayment>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lsp_node: Option<IGiftLspNode>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub node_id_verified: Option<bool>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IGift {
    pub id: String,
    pub node_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<IGiftOrder>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bolt11_payment_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bolt11_payment: Option<IGiftPayment>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub applied_gift_code_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub applied_gift_code: Option<IGiftCode>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,
}