neptune-rpc-api 0.14.0

Neptune JSON-RPC API contract: the RpcApi trait and its data-transfer model types
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
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
use std::time::Duration;

use async_trait::async_trait;
use multiaddr::Multiaddr;
use neptune_primitives::announcement_flag::AnnouncementFlag;
use neptune_primitives::timestamp::Timestamp;
use neptune_wallet::address::KeyType;
use serde::Deserialize;
use serde::Serialize;
use tasm_lib::prelude::Digest;
use tasm_lib::triton_vm::prelude::BFieldElement;
use thiserror::Error;

use crate::model::block::RpcBlock;
use crate::model::block::header::RpcBlockHeight;
use crate::model::block::header::RpcBlockPow;
use crate::model::block::transaction_kernel::RpcAbsoluteIndexSet;
use crate::model::block::transaction_kernel::RpcAdditionRecord;
use crate::model::block::transaction_kernel::RpcTransactionKernelId;
use crate::model::common::RpcBlockSelector;
use crate::model::common::RpcNativeCurrencyAmount;
use crate::model::json::JsonError;
use crate::model::message::*;
use crate::model::wallet::transaction::RpcTransaction;

#[derive(Debug, Clone, Copy, Error, Eq, PartialEq, Serialize, Deserialize)]
pub enum RestoreMembershipProofError {
    #[error("Failed for index {0}")]
    Failed(usize),

    #[error("Exceeds the allowed limit")]
    ExceedsAllowed,
}

#[derive(Debug, Clone, Copy, Error, Eq, PartialEq, Serialize, Deserialize)]
pub enum SubmitTransactionError {
    #[error("Invalid transaction")]
    InvalidTransaction,

    #[error("Coinbase transactions are not allowed")]
    CoinbaseTransaction,

    #[error("Transaction fee is negative")]
    FeeNegative,

    #[error("Transaction is future-dated")]
    FutureDated,

    #[error("Transaction timestamp is too old")]
    TooOld,

    #[error("Transaction not confirmable relative to the mutator set")]
    NotConfirmable,

    #[error("Transaction fails to lustrate the required inputs")]
    MissingLustration,

    #[error("Transaction cannot be mined since it would make the lustration counter negative")]
    LustrationMakesCounterNegative,
}

#[derive(Debug, Clone, Copy, Error, Eq, PartialEq, Serialize, Deserialize)]
pub enum SubmitBlockError {
    #[error("Invalid block")]
    InvalidBlock,

    #[error("The block's proof-of-work does not meet the required target")]
    InsufficientWork,
}

#[derive(Debug, Clone, Error, Eq, PartialEq, Serialize, Deserialize)]
pub enum RpcError {
    #[error("JSON-RPC server error: {0}")]
    Server(JsonError),

    // Call-specific errors
    #[error("Failed to restore membership proof: {0}")]
    RestoreMembershipProof(RestoreMembershipProofError),

    #[error("Failed to submit transaction: {0}")]
    SubmitTransaction(SubmitTransactionError),

    #[error("Failed to submit block: {0}")]
    SubmitBlock(SubmitBlockError),

    #[error("Invalid block range")]
    BlockRangeError,

    #[error("Endpoint requires UTXO index which is not present")]
    UtxoIndexNotPresent,

    #[error("Filtering conditions may not be empty")]
    EmptyFilteringConditions,

    #[error("Too many absolute index sets requested: maximum is {max}, got {got}")]
    TooManyAbsoluteIndexSets { max: usize, got: usize },

    // Common case errors
    #[error("Invalid address provided in arguments")]
    InvalidAddress,

    #[error("Access to this endpoint is restricted")]
    RestrictedAccess,

    // Application-level errors
    #[error("Internal response timed out: {0:?}.")]
    Timeout(Duration),

    #[error("Sender dropped while awaiting response.")]
    RxChannel,

    #[error("Derivation index must be in range [{0}; {1}].")]
    InvalidDerivationIndexRange(u64, u64),

    #[error("Wallet key counter is zero.")]
    WalletKeyCounterIsZero,

    #[error("Number of confirmations is wrong.")]
    BadConfirmationCount,

    #[error("Failed to create transaction. Error: {0}")]
    SendError(String),

    #[error("The UTXO that you try to claim cannot be registered by the wallet. Error: {0}")]
    CannotClaimUtxo(String),

    #[error(
        "The consensus rules require lustration of the input, but the lustration flag was not set."
    )]
    TransactionRequiresLustration,
}

pub type RpcResult<T> = Result<T, RpcError>;

pub const MAX_BATCH_ARE_BLOOM_INDICES_SET_INDEX_SETS: usize = 1000;
pub const MAX_UTXO_ORIGIN_ABSOLUTE_INDEX_SETS: usize = 1000;

#[async_trait]
pub trait RpcApi: Sync + Send {
    /* Node */

    async fn network(&self) -> RpcResult<NetworkResponse> {
        self.network_call(NetworkRequest {}).await
    }
    async fn network_call(&self, request: NetworkRequest) -> RpcResult<NetworkResponse>;

    /* Chain */

    async fn height(&self) -> RpcResult<HeightResponse> {
        self.height_call(HeightRequest {}).await
    }
    async fn height_call(&self, request: HeightRequest) -> RpcResult<HeightResponse>;

    async fn tip_digest(&self) -> RpcResult<TipDigestResponse> {
        self.tip_digest_call(TipDigestRequest {}).await
    }
    async fn tip_digest_call(&self, request: TipDigestRequest) -> RpcResult<TipDigestResponse>;

    async fn tip(&self) -> RpcResult<TipResponse> {
        self.tip_call(TipRequest {}).await
    }
    async fn tip_call(&self, request: TipRequest) -> RpcResult<TipResponse>;

    async fn tip_proof(&self) -> RpcResult<TipProofResponse> {
        self.tip_proof_call(TipProofRequest {}).await
    }
    async fn tip_proof_call(&self, request: TipProofRequest) -> RpcResult<TipProofResponse>;

    async fn tip_kernel(&self) -> RpcResult<TipKernelResponse> {
        self.tip_kernel_call(TipKernelRequest {}).await
    }
    async fn tip_kernel_call(&self, request: TipKernelRequest) -> RpcResult<TipKernelResponse>;

    async fn tip_header(&self) -> RpcResult<TipHeaderResponse> {
        self.tip_header_call(TipHeaderRequest {}).await
    }
    async fn tip_header_call(&self, request: TipHeaderRequest) -> RpcResult<TipHeaderResponse>;

    async fn tip_body(&self) -> RpcResult<TipBodyResponse> {
        self.tip_body_call(TipBodyRequest {}).await
    }
    async fn tip_body_call(&self, request: TipBodyRequest) -> RpcResult<TipBodyResponse>;

    async fn tip_transaction_kernel(&self) -> RpcResult<TipTransactionKernelResponse> {
        self.tip_transaction_kernel_call(TipTransactionKernelRequest {})
            .await
    }
    async fn tip_transaction_kernel_call(
        &self,
        request: TipTransactionKernelRequest,
    ) -> RpcResult<TipTransactionKernelResponse>;

    async fn tip_announcements(&self) -> RpcResult<TipAnnouncementsResponse> {
        self.tip_announcements_call(TipAnnouncementsRequest {})
            .await
    }
    async fn tip_announcements_call(
        &self,
        request: TipAnnouncementsRequest,
    ) -> RpcResult<TipAnnouncementsResponse>;

    /* Archival */

    async fn get_block_digests(&self, height: BFieldElement) -> RpcResult<GetBlockDigestsResponse> {
        self.get_block_digests_call(GetBlockDigestsRequest { height })
            .await
    }
    async fn get_block_digests_call(
        &self,
        request: GetBlockDigestsRequest,
    ) -> RpcResult<GetBlockDigestsResponse>;

    async fn get_block_digest(
        &self,
        selector: RpcBlockSelector,
    ) -> RpcResult<GetBlockDigestResponse> {
        self.get_block_digest_call(GetBlockDigestRequest { selector })
            .await
    }
    async fn get_block_digest_call(
        &self,
        request: GetBlockDigestRequest,
    ) -> RpcResult<GetBlockDigestResponse>;

    async fn get_block(&self, selector: RpcBlockSelector) -> RpcResult<GetBlockResponse> {
        self.get_block_call(GetBlockRequest { selector }).await
    }
    async fn get_block_call(&self, request: GetBlockRequest) -> RpcResult<GetBlockResponse>;

    async fn get_block_proof(
        &self,
        selector: RpcBlockSelector,
    ) -> RpcResult<GetBlockProofResponse> {
        self.get_block_proof_call(GetBlockProofRequest { selector })
            .await
    }
    async fn get_block_proof_call(
        &self,
        request: GetBlockProofRequest,
    ) -> RpcResult<GetBlockProofResponse>;

    async fn get_block_kernel(
        &self,
        selector: RpcBlockSelector,
    ) -> RpcResult<GetBlockKernelResponse> {
        self.get_block_kernel_call(GetBlockKernelRequest { selector })
            .await
    }
    async fn get_block_kernel_call(
        &self,
        request: GetBlockKernelRequest,
    ) -> RpcResult<GetBlockKernelResponse>;

    async fn get_block_header(
        &self,
        selector: RpcBlockSelector,
    ) -> RpcResult<GetBlockHeaderResponse> {
        self.get_block_header_call(GetBlockHeaderRequest { selector })
            .await
    }
    async fn get_block_header_call(
        &self,
        request: GetBlockHeaderRequest,
    ) -> RpcResult<GetBlockHeaderResponse>;

    async fn get_block_body(&self, selector: RpcBlockSelector) -> RpcResult<GetBlockBodyResponse> {
        self.get_block_body_call(GetBlockBodyRequest { selector })
            .await
    }
    async fn get_block_body_call(
        &self,
        request: GetBlockBodyRequest,
    ) -> RpcResult<GetBlockBodyResponse>;

    async fn get_block_transaction_kernel(
        &self,
        selector: RpcBlockSelector,
    ) -> RpcResult<GetBlockTransactionKernelResponse> {
        self.get_block_transaction_kernel_call(GetBlockTransactionKernelRequest { selector })
            .await
    }
    async fn get_block_transaction_kernel_call(
        &self,
        request: GetBlockTransactionKernelRequest,
    ) -> RpcResult<GetBlockTransactionKernelResponse>;

    async fn get_block_announcements(
        &self,
        selector: RpcBlockSelector,
    ) -> RpcResult<GetBlockAnnouncementsResponse> {
        self.get_block_announcements_call(GetBlockAnnouncementsRequest { selector })
            .await
    }
    async fn get_block_announcements_call(
        &self,
        request: GetBlockAnnouncementsRequest,
    ) -> RpcResult<GetBlockAnnouncementsResponse>;

    async fn is_block_canonical(&self, digest: Digest) -> RpcResult<IsBlockCanonicalResponse> {
        self.is_block_canonical_call(IsBlockCanonicalRequest { digest })
            .await
    }
    async fn is_block_canonical_call(
        &self,
        request: IsBlockCanonicalRequest,
    ) -> RpcResult<IsBlockCanonicalResponse>;

    async fn get_utxo_digest(&self, leaf_index: u64) -> RpcResult<GetUtxoDigestResponse> {
        self.get_utxo_digest_call(GetUtxoDigestRequest { leaf_index })
            .await
    }
    async fn get_utxo_digest_call(
        &self,
        request: GetUtxoDigestRequest,
    ) -> RpcResult<GetUtxoDigestResponse>;

    async fn find_utxo_origin(
        &self,
        addition_record: RpcAdditionRecord,
        search_depth: Option<u64>,
    ) -> RpcResult<FindUtxoOriginResponse> {
        self.find_utxo_origin_call(FindUtxoOriginRequest {
            addition_record,
            search_depth,
        })
        .await
    }
    async fn find_utxo_origin_call(
        &self,
        request: FindUtxoOriginRequest,
    ) -> RpcResult<FindUtxoOriginResponse>;

    async fn utxo_origin_from_absolute_indices(
        &self,
        absolute_index_sets: Vec<RpcAbsoluteIndexSet>,
    ) -> RpcResult<UtxoOriginFromAbsoluteIndicesResponse> {
        self.utxo_origin_from_absolute_indices_call(UtxoOriginFromAbsoluteIndicesRequest {
            absolute_index_sets,
        })
        .await
    }
    async fn utxo_origin_from_absolute_indices_call(
        &self,
        request: UtxoOriginFromAbsoluteIndicesRequest,
    ) -> RpcResult<UtxoOriginFromAbsoluteIndicesResponse>;

    /// Check if indices in an absolute index set are set in the node's archival
    /// mutator set. Can be used to check  if a UTXO is spent without having to
    /// know the mutator set membership proof.
    async fn are_bloom_indices_set(
        &self,
        absolute_index_set: RpcAbsoluteIndexSet,
    ) -> RpcResult<AreBloomIndicesSetResponse> {
        self.are_bloom_indices_set_call(AreBloomIndicesSetRequest { absolute_index_set })
            .await
    }

    async fn are_bloom_indices_set_call(
        &self,
        request: AreBloomIndicesSetRequest,
    ) -> RpcResult<AreBloomIndicesSetResponse>;

    /// Batched form of [`Self::are_bloom_indices_set`]: for each absolute index
    /// set, check whether all of its indices are set in the node's archival
    /// mutator set, in a single request instead of one request per index set.
    ///
    /// The returned `are_set` vector corresponds element-by-element, and in the
    /// same order, to the `absolute_index_sets` argument (duplicate inputs are
    /// preserved). An empty input yields an empty response. At most 1000
    /// absolute index sets may be requested at once.
    async fn batch_are_bloom_indices_set(
        &self,
        absolute_index_sets: Vec<RpcAbsoluteIndexSet>,
    ) -> RpcResult<BatchAreBloomIndicesSetResponse> {
        self.batch_are_bloom_indices_set_call(BatchAreBloomIndicesSetRequest {
            absolute_index_sets,
        })
        .await
    }

    async fn batch_are_bloom_indices_set_call(
        &self,
        request: BatchAreBloomIndicesSetRequest,
    ) -> RpcResult<BatchAreBloomIndicesSetResponse>;

    async fn circulating_supply(&self) -> RpcResult<CirculatingSupplyResponse> {
        self.circulating_supply_call(CirculatingSupplyRequest {})
            .await
    }
    async fn circulating_supply_call(
        &self,
        _request: CirculatingSupplyRequest,
    ) -> RpcResult<CirculatingSupplyResponse>;

    async fn max_supply(&self) -> RpcResult<MaxSupplyResponse> {
        self.max_supply_call(MaxSupplyRequest {}).await
    }
    async fn max_supply_call(&self, _request: MaxSupplyRequest) -> RpcResult<MaxSupplyResponse>;

    async fn burned_supply(&self) -> RpcResult<BurnedSupplyResponse> {
        self.burned_supply_call(BurnedSupplyRequest {}).await
    }

    async fn burned_supply_call(
        &self,
        _request: BurnedSupplyRequest,
    ) -> RpcResult<BurnedSupplyResponse>;

    /* Wallet */

    /// Check if a string is a valid Neptune address. Returns metadata about
    /// the address if the address is valid.
    async fn validate_address(&self, address_string: String) -> RpcResult<ValidateAddressResponse> {
        self.validate_address_call(ValidateAddressRequest { address_string })
            .await
    }

    async fn validate_address_call(
        &self,
        request: ValidateAddressRequest,
    ) -> RpcResult<ValidateAddressResponse>;

    /// Check if a string represents a valid, non-negative amount of NPT,
    /// Neptune coins.
    ///
    /// If the amount is valid, returns the amount.
    async fn validate_coins_amount(
        &self,
        amount_string: String,
    ) -> RpcResult<ValidateCoinsAmountResponse> {
        self.validate_coins_amount_call(ValidateCoinsAmountRequest { amount_string })
            .await
    }

    async fn validate_coins_amount_call(
        &self,
        request: ValidateCoinsAmountRequest,
    ) -> RpcResult<ValidateCoinsAmountResponse>;

    /// Check if a string represents a valid, non-negative amount of NPT,
    /// atomical units, AKA NAU. This is equivalent to checking if the string
    /// represents a valid, non-negative i128 not exceeding the maximum allowed
    /// coins amount of 42.000.000.
    ///
    /// If the amount is valid, returns the amount.
    async fn validate_nau_amount(
        &self,
        nau_string: String,
    ) -> RpcResult<ValidateNauAmountResponse> {
        self.validate_nau_amount_call(ValidateNauAmountRequest { nau_string })
            .await
    }

    async fn validate_nau_amount_call(
        &self,
        request: ValidateNauAmountRequest,
    ) -> RpcResult<ValidateNauAmountResponse>;

    /// Return all blocks in the specified range (inclusive). Will not return
    /// the genesis block.
    async fn get_blocks(
        &self,
        from_height: RpcBlockHeight,
        to_height: RpcBlockHeight,
    ) -> RpcResult<GetBlocksResponse> {
        self.get_blocks_call(GetBlocksRequest {
            from_height,
            to_height,
        })
        .await
    }
    async fn get_blocks_call(&self, request: GetBlocksRequest) -> RpcResult<GetBlocksResponse>;

    async fn restore_membership_proof(
        &self,
        absolute_index_sets: Vec<RpcAbsoluteIndexSet>,
    ) -> RpcResult<RestoreMembershipProofResponse> {
        self.restore_membership_proof_call(RestoreMembershipProofRequest {
            absolute_index_sets,
        })
        .await
    }
    async fn restore_membership_proof_call(
        &self,
        request: RestoreMembershipProofRequest,
    ) -> RpcResult<RestoreMembershipProofResponse>;

    async fn submit_transaction(
        &self,
        transaction: RpcTransaction,
    ) -> RpcResult<SubmitTransactionResponse> {
        self.submit_transaction_call(SubmitTransactionRequest { transaction })
            .await
    }
    async fn submit_transaction_call(
        &self,
        request: SubmitTransactionRequest,
    ) -> RpcResult<SubmitTransactionResponse>;

    /* Personal */

    async fn rescan_announced(
        &self,
        first: RpcBlockHeight,
        last: RpcBlockHeight,
        derivation_path: Option<(KeyType, u64)>,
    ) -> RpcResult<RescanAnnouncedResponse> {
        self.rescan_announced_call(RescanAnnouncedRequest {
            first,
            last,
            derivation_path,
        })
        .await
    }

    async fn rescan_announced_call(
        &self,
        request: RescanAnnouncedRequest,
    ) -> RpcResult<RescanAnnouncedResponse>;

    async fn rescan_expected(
        &self,
        first: RpcBlockHeight,
        last: RpcBlockHeight,
    ) -> RpcResult<RescanExpectedResponse> {
        self.rescan_expected_call(RescanExpectedRequest { first, last })
            .await
    }

    async fn rescan_expected_call(
        &self,
        request: RescanExpectedRequest,
    ) -> RpcResult<RescanExpectedResponse>;

    async fn rescan_outgoing(&self) -> RpcResult<RescanOutgoingResponse> {
        self.rescan_outgoing_call(RescanOutgoingRequest {}).await
    }

    async fn rescan_outgoing_call(
        &self,
        request: RescanOutgoingRequest,
    ) -> RpcResult<RescanOutgoingResponse>;

    async fn rescan_guesser_rewards(
        &self,
        first: RpcBlockHeight,
        last: RpcBlockHeight,
    ) -> RpcResult<RescanGuesserRewardsResponse> {
        self.rescan_guesser_rewards_call(RescanGuesserRewardsRequest { first, last })
            .await
    }

    async fn rescan_guesser_rewards_call(
        &self,
        request: RescanGuesserRewardsRequest,
    ) -> RpcResult<RescanGuesserRewardsResponse>;

    async fn derivation_index(&self, key_type: KeyType) -> RpcResult<DerivationIndexResponse> {
        self.derivation_index_call(DerivationIndexRequest { key_type })
            .await
    }

    async fn derivation_index_call(
        &self,
        request: DerivationIndexRequest,
    ) -> RpcResult<DerivationIndexResponse>;

    /// Endpoint to increase the derivation index to a new value.
    ///
    /// All keys between the current derivation value and the value given to
    /// this endpoint (both inclusive) will be added to the wallet.
    async fn set_derivation_index(
        &self,
        key_type: KeyType,
        derivation_index: u64,
    ) -> RpcResult<SetDerivationIndexResponse> {
        self.set_derivation_index_call(SetDerivationIndexRequest {
            key_type,
            derivation_index,
        })
        .await
    }

    async fn set_derivation_index_call(
        &self,
        request: SetDerivationIndexRequest,
    ) -> RpcResult<SetDerivationIndexResponse>;

    async fn generate_address(&self, key_type: KeyType) -> RpcResult<GenerateAddressResponse> {
        self.generate_address_call(GenerateAddressRequest { key_type })
            .await
    }

    async fn generate_address_call(
        &self,
        request: GenerateAddressRequest,
    ) -> RpcResult<GenerateAddressResponse>;

    /// Return all incoming UTXOs tracked by this node's wallet matching the
    /// specified filters.
    ///
    /// Returns all incoming UTXOs if no filter is specified. Allows for
    /// pagination.
    #[expect(clippy::too_many_arguments)]
    async fn incoming_history(
        &self,
        include_orphaned: bool,
        aocl_leaf_index: Option<u64>,
        output: Option<RpcAdditionRecord>,
        receiver_preimage: Option<Digest>,
        receiver_digest: Option<Digest>,
        lock_script_hash: Option<Digest>,
        sender_randomness: Option<Digest>,
        confirmed_height: Option<RpcBlockHeight>,
        confirmed_block_hash: Option<Digest>,
        max_num_elements: Option<u64>,
        page: Option<u64>,
    ) -> RpcResult<IncomingHistoryResponse> {
        self.incoming_history_call(IncomingHistoryRequest {
            aocl_leaf_index,
            output,
            receiver_preimage,
            receiver_digest,
            lock_script_hash,
            sender_randomness,
            confirmed_height,
            confirmed_block_hash,
            include_orphaned,
            max_num_elements,
            page,
        })
        .await
    }

    async fn incoming_history_call(
        &self,
        request: IncomingHistoryRequest,
    ) -> RpcResult<IncomingHistoryResponse>;

    /// Return all outgoing transactions intiated by this node's wallet matching
    /// the specified filters.
    ///
    /// Returns all outgoing transactions if no filter is specified. Allows for
    /// pagination.
    #[expect(clippy::too_many_arguments)]
    async fn outgoing_history(
        &self,
        sender_randomness: Option<Digest>,
        receiver_digest: Option<Digest>,
        output_lock_script_hash: Option<Digest>,
        output: Option<RpcAdditionRecord>,
        timestamp: Option<Timestamp>,
        max_num_elements: Option<u64>,
        page: Option<u64>,
    ) -> RpcResult<OutgoingHistoryResponse> {
        self.outgoing_history_call(OutgoingHistoryRequest {
            sender_randomness,
            receiver_digest,
            output_lock_script_hash,
            output,
            timestamp,
            max_num_elements,
            page,
        })
        .await
    }

    async fn outgoing_history_call(
        &self,
        request: OutgoingHistoryRequest,
    ) -> RpcResult<OutgoingHistoryResponse>;

    async fn unspent_utxos(&self) -> RpcResult<UnspentUtxosResponse> {
        self.unspent_utxos_call(UnspentUtxosRequest {}).await
    }

    async fn unspent_utxos_call(
        &self,
        request: UnspentUtxosRequest,
    ) -> RpcResult<UnspentUtxosResponse>;

    async fn get_balance(&self, number_of_confirmations: u32) -> RpcResult<GetBalanceResponse> {
        self.get_balance_call(GetBalanceRequest {
            number_of_confirmations,
        })
        .await
    }

    async fn get_balance_call(&self, request: GetBalanceRequest) -> RpcResult<GetBalanceResponse>;

    /// Return the number of transactions initiated while this block was tip.
    ///
    /// Does not check if the transactions have been mined, only initiated.
    async fn count_sent_transactions_at_block(
        &self,
        selector: RpcBlockSelector,
    ) -> RpcResult<CountSentTransactionsAtBlockResponse> {
        self.count_sent_transactions_at_block_call(CountSentTransactionsAtBlockRequest { selector })
            .await
    }

    async fn count_sent_transactions_at_block_call(
        &self,
        request: CountSentTransactionsAtBlockRequest,
    ) -> RpcResult<CountSentTransactionsAtBlockResponse>;

    #[expect(clippy::too_many_arguments)]
    async fn send(
        &self,
        amount: RpcNativeCurrencyAmount,
        fee: RpcNativeCurrencyAmount,
        to_address: String,
        min_input_confirmations: Option<usize>,
        max_num_inputs: Option<usize>,
        notify_self: Option<String>,
        notify_other: Option<String>,
        utxo_priority: Option<String>,
        accept_lustrations: bool,
    ) -> RpcResult<SendResponse> {
        self.send_call(SendRequest {
            amount,
            fee,
            to_address,
            min_input_confirmations,
            max_num_inputs,
            notify_self,
            notify_other,
            utxo_priority,
            accept_lustrations,
        })
        .await
    }

    async fn send_call(&self, request: SendRequest) -> RpcResult<SendResponse>;

    /// Claim a UTXO which does not have an onchain announcement but whose
    /// receiver data is shared through an offchain ciphertext.
    async fn claim_utxo(
        &self,
        ciphertext: String,
        max_search_depth: Option<u64>,
    ) -> RpcResult<ClaimUtxoResponse> {
        self.claim_utxo_call(ClaimUtxoRequest {
            ciphertext,
            max_search_depth,
        })
        .await
    }

    async fn claim_utxo_call(&self, request: ClaimUtxoRequest) -> RpcResult<ClaimUtxoResponse>;

    /* Mining */

    async fn get_block_template(
        &self,
        guesser_address: String,
    ) -> RpcResult<GetBlockTemplateResponse> {
        self.get_block_template_call(GetBlockTemplateRequest { guesser_address })
            .await
    }
    async fn get_block_template_call(
        &self,
        request: GetBlockTemplateRequest,
    ) -> RpcResult<GetBlockTemplateResponse>;

    async fn submit_block(
        &self,
        template: RpcBlock,
        pow: RpcBlockPow,
    ) -> RpcResult<SubmitBlockResponse> {
        self.submit_block_call(SubmitBlockRequest { template, pow })
            .await
    }
    async fn submit_block_call(
        &self,
        request: SubmitBlockRequest,
    ) -> RpcResult<SubmitBlockResponse>;

    /* Utxoindex */

    /// Return block heights for blocks containing announcements with specified
    /// announcement flags. May return results from orphaned blocks.
    async fn block_heights_by_flags(
        &self,
        announcement_flags: Vec<AnnouncementFlag>,
    ) -> RpcResult<BlockHeightsByFlagsResponse> {
        self.block_heights_by_flags_call(BlockHeightsByFlagsRequest { announcement_flags })
            .await
    }

    async fn block_heights_by_flags_call(
        &self,
        request: BlockHeightsByFlagsRequest,
    ) -> RpcResult<BlockHeightsByFlagsResponse>;

    /// Return block heights for blocks containing specified addition records.
    /// Returned block heights are guaranteed to reference blocks belonging to
    /// the canonical chain.
    async fn block_heights_by_addition_records(
        &self,
        addition_records: Vec<RpcAdditionRecord>,
    ) -> RpcResult<BlockHeightsByAdditionRecordsResponse> {
        self.block_heights_by_addition_records_call(BlockHeightsByAdditionRecordsRequest {
            addition_records,
        })
        .await
    }

    async fn block_heights_by_addition_records_call(
        &self,
        request: BlockHeightsByAdditionRecordsRequest,
    ) -> RpcResult<BlockHeightsByAdditionRecordsResponse>;

    async fn block_heights_by_absolute_index_sets(
        &self,
        absolute_index_sets: Vec<RpcAbsoluteIndexSet>,
    ) -> RpcResult<BlockHeightsByAbsoluteIndexSetsResponse> {
        self.block_heights_by_absolute_index_sets_call(BlockHeightsByAbsoluteIndexSetsRequest {
            absolute_index_sets,
        })
        .await
    }

    /// Return block heights for blocks containing specified absolute index
    /// sets. Returned block heights are guaranteed to reference blocks
    /// belonging to the canonical chain.
    async fn block_heights_by_absolute_index_sets_call(
        &self,
        request: BlockHeightsByAbsoluteIndexSetsRequest,
    ) -> RpcResult<BlockHeightsByAbsoluteIndexSetsResponse>;

    /// Return the block heights for blocks matching *all* elements in the
    /// specified input/output lists, for blocks belonging to the canonical
    /// chain. Will not return block heights were e.g. only one of the outputs
    /// was included if more than one output is included in the outputs list.
    ///
    /// Can return multiple blocks in the case where blocks are selected only
    /// based on addition records and multiple blocks contain the same addition
    /// records.
    ///
    /// Returns an error if no filtering conditions are set.
    async fn was_mined(
        &self,
        inputs: Vec<RpcAbsoluteIndexSet>,
        outputs: Vec<RpcAdditionRecord>,
    ) -> RpcResult<WasMinedResponse> {
        self.was_mined_call(WasMinedRequest {
            absolute_index_sets: inputs,
            addition_records: outputs,
        })
        .await
    }

    async fn was_mined_call(&self, request: WasMinedRequest) -> RpcResult<WasMinedResponse>;

    /* Mempool */

    async fn transactions(&self) -> RpcResult<TransactionsResponse> {
        self.transactions_call(TransactionsRequest {}).await
    }
    async fn transactions_call(
        &self,
        request: TransactionsRequest,
    ) -> RpcResult<TransactionsResponse>;

    async fn get_transaction_kernel(
        &self,
        id: RpcTransactionKernelId,
    ) -> RpcResult<GetTransactionKernelResponse> {
        self.get_transaction_kernel_call(GetTransactionKernelRequest { id })
            .await
    }
    async fn get_transaction_kernel_call(
        &self,
        request: GetTransactionKernelRequest,
    ) -> RpcResult<GetTransactionKernelResponse>;

    async fn get_transaction_proof(
        &self,
        id: RpcTransactionKernelId,
    ) -> RpcResult<GetTransactionProofResponse> {
        self.get_transaction_proof_call(GetTransactionProofRequest { id })
            .await
    }
    async fn get_transaction_proof_call(
        &self,
        request: GetTransactionProofRequest,
    ) -> RpcResult<GetTransactionProofResponse>;

    async fn get_transactions_by_addition_records(
        &self,
        addition_records: Vec<RpcAdditionRecord>,
    ) -> RpcResult<GetTransactionsByAdditionRecordsResponse> {
        self.get_transactions_by_addition_records_call(GetTransactionsByAdditionRecordsRequest {
            addition_records,
        })
        .await
    }
    async fn get_transactions_by_addition_records_call(
        &self,
        request: GetTransactionsByAdditionRecordsRequest,
    ) -> RpcResult<GetTransactionsByAdditionRecordsResponse>;

    async fn get_transactions_by_absolute_index_sets(
        &self,
        absolute_index_sets: Vec<RpcAbsoluteIndexSet>,
    ) -> RpcResult<GetTransactionsByAbsoluteIndexSetsResponse> {
        self.get_transactions_by_absolute_index_sets_call(
            GetTransactionsByAbsoluteIndexSetsRequest {
                absolute_index_sets,
            },
        )
        .await
    }
    async fn get_transactions_by_absolute_index_sets_call(
        &self,
        request: GetTransactionsByAbsoluteIndexSetsRequest,
    ) -> RpcResult<GetTransactionsByAbsoluteIndexSetsResponse>;

    /// Return transaction most likely to be mined in next block, based on fee
    /// density, sync status, and proof quality.
    async fn best_transaction_for_next_block(
        &self,
    ) -> RpcResult<BestTransactionForNextBlockResponse> {
        self.best_transaction_for_next_block_call(BestTransactionForNextBlockRequest {})
            .await
    }
    async fn best_transaction_for_next_block_call(
        &self,
        request: BestTransactionForNextBlockRequest,
    ) -> RpcResult<BestTransactionForNextBlockResponse>;

    /* Networking */

    async fn ban_call(&self, request: BanRequest) -> RpcResult<BanResponse>;
    async fn ban(&self, address: Multiaddr) -> RpcResult<BanResponse> {
        self.ban_call(BanRequest { address }).await
    }
    async fn unban_call(&self, request: UnbanRequest) -> RpcResult<UnbanResponse>;
    async fn unban(&self, address: Multiaddr) -> RpcResult<UnbanResponse> {
        self.unban_call(UnbanRequest { address }).await
    }
    async fn unban_all_call(&self, request: UnbanAllRequest) -> RpcResult<UnbanAllResponse>;
    async fn unban_all(&self) -> RpcResult<UnbanAllResponse> {
        self.unban_all_call(UnbanAllRequest {}).await
    }
    async fn dial_call(&self, request: DialRequest) -> RpcResult<DialResponse>;
    async fn dial(&self, address: Multiaddr) -> RpcResult<DialResponse> {
        self.dial_call(DialRequest { address }).await
    }
    async fn probe_nat_call(&self, request: ProbeNatRequest) -> RpcResult<ProbeNatResponse>;
    async fn probe_nat(&self) -> RpcResult<ProbeNatResponse> {
        self.probe_nat_call(ProbeNatRequest {}).await
    }
    async fn reset_relay_reservations_call(
        &self,
        request: ResetRelayReservationsRequest,
    ) -> RpcResult<ResetRelayReservationsResponse>;
    async fn reset_relay_reservations(&self) -> RpcResult<ResetRelayReservationsResponse> {
        self.reset_relay_reservations_call(ResetRelayReservationsRequest {})
            .await
    }

    async fn get_network_overview(&self) -> RpcResult<NetworkOverviewResponse> {
        self.network_overview_call(NetworkOverviewRequest {}).await
    }
    async fn network_overview_call(
        &self,
        _request: NetworkOverviewRequest,
    ) -> RpcResult<NetworkOverviewResponse>;
}