erpc-sdk 0.11.0

Async multi-network Rust SDK for ERPC
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
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
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
use std::{collections::HashMap, ops::Deref, sync::Arc};

use serde::{Deserialize, Serialize, de::DeserializeOwned};
use serde_json::Value;

use crate::{
    PendingRpcRequest, Result, RpcNamespace,
    rpc::{BatchPolicy, HttpJsonRpcTransport},
    subscriptions::{RpcSubscription, WebSocketJsonRpcTransport},
};

/// Solana commitment level.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum SolanaCommitment {
    /// Confirmed by a supermajority of the cluster.
    Confirmed,
    /// Finalized by the cluster.
    Finalized,
    /// Processed by the connected node.
    Processed,
}

/// Solana account or transaction encoding.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum SolanaEncoding {
    /// Base58 encoding.
    #[serde(rename = "base58")]
    Base58,
    /// Base64 encoding.
    #[serde(rename = "base64")]
    Base64,
    /// Zstandard-compressed base64 encoding.
    #[serde(rename = "base64+zstd")]
    Base64Zstd,
    /// Parsed JSON encoding.
    #[serde(rename = "jsonParsed")]
    JsonParsed,
}

/// Standard Solana response context.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SolanaContext {
    /// RPC software API version when supplied.
    pub api_version: Option<String>,
    /// Context slot.
    pub slot: u64,
}

/// Value wrapped with a Solana response context.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct SolanaContextResult<T> {
    /// Response context.
    pub context: SolanaContext,
    /// Method result.
    pub value: T,
}

/// Priority fee estimate with forward-compatible additional fields.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PriorityFeeEstimate {
    /// Estimated priority fee.
    pub priority_fee_estimate: f64,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Named request for one indexed asset or proof.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AssetRequest {
    /// Asset identifier.
    pub id: String,
    /// Optional display flags.
    pub display_options: Option<HashMap<String, bool>>,
}

/// Named request for a batch of indexed assets or proofs.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AssetBatchRequest {
    /// Asset identifiers.
    pub ids: Vec<String>,
    /// Optional display flags.
    pub display_options: Option<HashMap<String, bool>>,
}

/// Shared indexed-asset pagination request.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AssetListRequest {
    /// Cursor pagination token.
    pub cursor: Option<String>,
    /// Maximum item count.
    pub limit: Option<u64>,
    /// Page number.
    pub page: Option<u64>,
    /// Method-specific named parameters.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Forward-compatible indexed asset object.
pub type IndexedAsset = HashMap<String, Value>;
/// Forward-compatible indexed asset proof object.
pub type IndexedAssetProof = HashMap<String, Value>;

/// Paginated indexed-asset list.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct IndexedAssetList<T = IndexedAsset> {
    /// Next cursor when available.
    pub cursor: Option<String>,
    /// Returned items.
    pub items: Vec<T>,
    /// Effective page limit.
    pub limit: Option<u64>,
    /// Effective page number.
    pub page: Option<u64>,
    /// Total item count when supplied.
    pub total: Option<u64>,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Numeric range filter for indexed history.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct NumericFilter {
    /// Equal to.
    pub eq: Option<f64>,
    /// Greater than.
    pub gt: Option<f64>,
    /// Greater than or equal to.
    pub gte: Option<f64>,
    /// Less than.
    pub lt: Option<f64>,
    /// Less than or equal to.
    pub lte: Option<f64>,
}

/// Options for indexed address transactions.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddressTransactionsOptions {
    /// Return signatures before this signature.
    pub before: Option<String>,
    /// Requested commitment.
    pub commitment: Option<SolanaCommitment>,
    /// Transaction encoding.
    pub encoding: Option<String>,
    /// Additional indexed filters.
    pub filters: Option<HashMap<String, Value>>,
    /// Maximum item count.
    pub limit: Option<u64>,
    /// Maximum supported transaction version.
    pub max_supported_transaction_version: Option<u64>,
    /// Opaque pagination token.
    pub pagination_token: Option<String>,
    /// Sort order.
    pub sort_order: Option<String>,
    /// Transaction detail level.
    pub transaction_details: Option<String>,
    /// Return signatures up to this signature.
    pub until: Option<String>,
}

/// One indexed address transaction.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddressTransaction {
    /// Block time.
    pub block_time: Option<i64>,
    /// Confirmation status.
    pub confirmation_status: SolanaCommitment,
    /// Transaction error.
    pub err: Value,
    /// Memo when present.
    pub memo: Option<String>,
    /// Transaction metadata when requested.
    pub meta: Option<Value>,
    /// Transaction signature.
    pub signature: String,
    /// Slot.
    pub slot: u64,
    /// Transaction body when requested.
    pub transaction: Option<Value>,
    /// Index within the block.
    pub transaction_index: u64,
    /// Transaction version when supplied.
    pub version: Option<Value>,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Paginated indexed address transactions.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddressTransactionPage {
    /// Transactions.
    pub data: Vec<AddressTransaction>,
    /// Next pagination token.
    pub pagination_token: Option<String>,
    /// Earliest slot or time in the current window.
    pub window_start: Option<i64>,
}

/// Direction for an indexed transfer query.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum AddressTransferDirection {
    /// Transfers in either direction.
    Any,
    /// Incoming transfers.
    In,
    /// Outgoing transfers.
    Out,
}

/// Numeric filters for indexed transfers.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddressTransferFilters {
    /// Amount filter.
    pub amount: Option<NumericFilter>,
    /// Block-time filter.
    pub block_time: Option<NumericFilter>,
    /// Slot filter.
    pub slot: Option<NumericFilter>,
}

/// Options for indexed address transfers.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddressTransfersOptions {
    /// Requested commitment.
    pub commitment: Option<SolanaCommitment>,
    /// Transfer direction.
    pub direction: Option<AddressTransferDirection>,
    /// Numeric filters.
    pub filters: Option<AddressTransferFilters>,
    /// Maximum item count.
    pub limit: Option<u64>,
    /// Optional mint filter.
    pub mint: Option<String>,
    /// Opaque pagination token.
    pub pagination_token: Option<String>,
    /// Native transfer projection mode.
    pub sol_mode: Option<String>,
    /// Sort order.
    pub sort_order: Option<String>,
    /// Counterparty filter.
    pub with: Option<String>,
}

/// Indexed transfer operation.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum AddressTransferType {
    /// Token burn.
    #[serde(rename = "burn")]
    Burn,
    /// Account owner change.
    #[serde(rename = "changeOwner")]
    ChangeOwner,
    /// Token mint.
    #[serde(rename = "mint")]
    Mint,
    /// Token or native transfer.
    #[serde(rename = "transfer")]
    Transfer,
    /// Native token unwrap.
    #[serde(rename = "unwrap")]
    Unwrap,
    /// Withheld fee withdrawal.
    #[serde(rename = "withdrawWithheldFee")]
    WithdrawWithheldFee,
    /// Native token wrap.
    #[serde(rename = "wrap")]
    Wrap,
}

/// One indexed address transfer.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddressTransfer {
    /// Integer amount string.
    pub amount: String,
    /// Block time.
    pub block_time: Option<i64>,
    /// Confirmation status.
    pub confirmation_status: SolanaCommitment,
    /// Mint decimals.
    pub decimals: u8,
    /// Integer fee amount.
    pub fee_amount: Option<String>,
    /// Display fee amount.
    pub fee_ui_amount: Option<String>,
    /// Source token account.
    pub from_token_account: Option<String>,
    /// Source user account.
    pub from_user_account: Option<String>,
    /// Inner instruction index.
    pub inner_instruction_idx: u64,
    /// Instruction index.
    pub instruction_idx: u64,
    /// Mint address for token transfers.
    pub mint: Option<String>,
    /// Transaction signature.
    pub signature: String,
    /// Slot.
    pub slot: u64,
    /// Destination token account.
    pub to_token_account: Option<String>,
    /// Destination user account.
    pub to_user_account: Option<String>,
    /// Transaction index.
    pub transaction_idx: u64,
    /// Transfer operation.
    #[serde(rename = "type")]
    pub transfer_type: AddressTransferType,
    /// Display amount.
    pub ui_amount: String,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Paginated indexed address transfers.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddressTransferPage {
    /// Transfers.
    pub data: Vec<AddressTransfer>,
    /// Next pagination token.
    pub pagination_token: Option<String>,
    /// Earliest slot or time in the current window.
    pub window_start: Option<i64>,
}

/// One network measurement to a scheduled leader.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PingMeasurement {
    /// City inferred from the target address.
    pub city: Option<String>,
    /// Country inferred from the target address.
    pub country: Option<String>,
    /// Measurement source address.
    pub from_ip: Option<String>,
    /// Whether ICMP replied.
    pub icmp_replied: bool,
    /// Latitude.
    pub lat: Option<f64>,
    /// Longitude.
    pub lon: Option<f64>,
    /// Measurement timestamp.
    pub measured_at: Option<String>,
    /// Round-trip milliseconds.
    pub ms: Option<f64>,
    /// Network organization.
    pub org: Option<String>,
    /// Postal code.
    pub postal: Option<String>,
    /// Region.
    pub region: Option<String>,
    /// Time zone.
    pub timezone: Option<String>,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Scheduled leader and public network metadata.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LeaderSlot {
    /// Epoch.
    pub epoch: u64,
    /// Feature-set identifier.
    pub feature_set: Option<String>,
    /// Gossip port.
    pub gossip_port: Option<u16>,
    /// Gossip observation timestamp.
    pub gossip_updated_at: Option<String>,
    /// Validator identity.
    pub identity: String,
    /// Public IP address.
    pub ip_address: Option<String>,
    /// Leader city.
    pub leader_city: Option<String>,
    /// Leader country.
    pub leader_country: Option<String>,
    /// Leader latitude.
    pub leader_lat: Option<f64>,
    /// Leader longitude.
    pub leader_lon: Option<f64>,
    /// Leader network organization.
    pub leader_org: Option<String>,
    /// Leader region.
    pub leader_region: Option<String>,
    /// Leader time zone.
    pub leader_timezone: Option<String>,
    /// Measurements to scheduled leaders.
    pub ping_to_leaders: Vec<PingMeasurement>,
    /// Public RPC address.
    pub rpc_address: Option<String>,
    /// Slot represented as a decimal string.
    pub slot: String,
    /// Stake weight.
    pub stake_weight: f64,
    /// TPU port.
    pub tpu_port: Option<u16>,
    /// QUIC TPU port.
    pub tpu_quic_port: Option<u16>,
    /// Validator software version.
    pub version: Option<String>,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Leader slot response envelope.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct LeaderSlotsResult {
    /// Leader slots.
    pub data: Vec<LeaderSlot>,
    /// Service message.
    pub message: String,
    /// Success flag.
    pub success: bool,
    /// Returned row count.
    pub total: u64,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Validator information query.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct ValidatorsInformationOptions {
    /// Country filter.
    pub country: Option<String>,
    /// Maximum validator count.
    pub limit: Option<u64>,
    /// Region filter.
    pub region: Option<String>,
}

/// Validator information and public network metadata.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ValidatorInformation {
    /// Feature-set identifier.
    pub feature_set: Option<String>,
    /// Gossip database row identifier.
    pub gossip_node_id: Option<u64>,
    /// Gossip port.
    pub gossip_port: Option<u16>,
    /// Gossip observation timestamp.
    pub gossip_updated_at: Option<String>,
    /// Validator identity.
    pub identity: String,
    /// Public IP address.
    pub ip_address: Option<String>,
    /// Validator city.
    pub leader_city: Option<String>,
    /// Validator country.
    pub leader_country: Option<String>,
    /// Validator latitude.
    pub leader_lat: Option<f64>,
    /// Validator longitude.
    pub leader_lon: Option<f64>,
    /// Validator network organization.
    pub leader_org: Option<String>,
    /// Validator region.
    pub leader_region: Option<String>,
    /// Validator time zone.
    pub leader_timezone: Option<String>,
    /// Measurements to scheduled leaders.
    pub ping_to_leaders: Vec<PingMeasurement>,
    /// Public RPC address.
    pub rpc_address: Option<String>,
    /// Scheduled slot count.
    pub slot_count: u64,
    /// Stake weight.
    pub stake_weight: f64,
    /// TPU port.
    pub tpu_port: Option<u16>,
    /// QUIC TPU port.
    pub tpu_quic_port: Option<u16>,
    /// Validator software version.
    pub version: Option<String>,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Validator information response envelope.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ValidatorsInformationResult {
    /// Validators.
    pub data: Vec<ValidatorInformation>,
    /// Epoch.
    pub epoch: u64,
    /// Service message.
    pub message: String,
    /// Success flag.
    pub success: bool,
    /// Returned row count.
    pub total: u64,
    /// Total validator count before limiting.
    pub total_validators: u64,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Number or timestamp string accepted by analytics time bounds.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(untagged)]
pub enum AnalyticsTimeBound {
    /// Numeric Unix timestamp.
    Number(i64),
    /// Server-supported timestamp string.
    String(String),
}

/// Top-program analytics options.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TopProgramsOptions {
    /// Include vote transactions.
    pub include_votes: Option<bool>,
    /// Maximum row count.
    pub limit: Option<u64>,
    /// Inclusive lower time bound.
    pub since: Option<AnalyticsTimeBound>,
    /// Exclusive upper time bound.
    pub until: Option<AnalyticsTimeBound>,
}

/// One top-program analytics row.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct TopProgramRow {
    /// Error count as a decimal string.
    pub errors: String,
    /// Invocation count as a decimal string.
    pub invocations: String,
    /// Program address.
    pub program: String,
    /// Total compute units as a decimal string.
    pub total_cus: String,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Slot statistics query by one slot or inclusive range.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(untagged)]
pub enum SlotStatsOptions {
    /// One slot.
    Slot {
        /// Slot number.
        slot: u64,
    },
    /// Slot range.
    Range {
        /// First slot.
        #[serde(rename = "fromSlot")]
        from_slot: u64,
        /// Last slot.
        #[serde(rename = "toSlot")]
        to_slot: u64,
    },
}

/// One slot statistics row.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct SlotStatsRow {
    /// Block time.
    pub block_time: i64,
    /// Non-vote transaction count.
    pub non_vote_transaction_count: u64,
    /// Slot.
    pub slot: u64,
    /// Total transaction count.
    pub transaction_count: u64,
    /// Vote transaction count.
    pub vote_transaction_count: u64,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// TPS time-series options.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TpsTimeseriesOptions {
    /// Bucket width in seconds.
    pub bucket_sec: Option<u64>,
    /// Inclusive lower time bound.
    pub from: AnalyticsTimeBound,
    /// Exclusive upper time bound.
    pub to: AnalyticsTimeBound,
}

/// One TPS time bucket.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct TpsBucket {
    /// Bucket timestamp.
    pub bucket: i64,
    /// Non-vote TPS.
    pub non_vote_tps: f64,
    /// Total TPS.
    pub total_tps: f64,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Epoch analytics summary.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct EpochSummary {
    /// Distinct invoked programs.
    pub distinct_programs: String,
    /// Epoch.
    pub epoch: u64,
    /// First block time.
    pub first_block_time: i64,
    /// Last block time.
    pub last_block_time: i64,
    /// Non-vote transaction count.
    pub non_vote_txs: String,
    /// Program invocation count.
    pub program_invocations: String,
    /// Slot count.
    pub slots: String,
    /// Total transaction count.
    pub total_txs: String,
    /// Vote transaction count.
    pub vote_txs: String,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Program statistics options.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProgramStatsOptions {
    /// Bucket width in seconds.
    pub bucket_sec: Option<u64>,
    /// Program address.
    pub program_id_base58: String,
    /// Inclusive lower time bound.
    pub since: Option<AnalyticsTimeBound>,
    /// Exclusive upper time bound.
    pub until: Option<AnalyticsTimeBound>,
}

/// One program statistics time bucket.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ProgramStatsBucket {
    /// Bucket timestamp.
    pub bucket: i64,
    /// Error count as a decimal string.
    pub errors: String,
    /// Invocation count as a decimal string.
    pub invocations: String,
    /// Total compute units as a decimal string.
    pub total_cus: String,
    /// Forward-compatible response fields.
    #[serde(flatten)]
    pub additional: HashMap<String, Value>,
}

/// Standard Solana JSON-RPC methods represented by this release.
pub const SOLANA_RPC_METHODS: &[&str] = &[
    "getAccountInfo",
    "getBalance",
    "getBlock",
    "getBlockCommitment",
    "getBlockHeight",
    "getBlockProduction",
    "getBlockTime",
    "getBlocks",
    "getBlocksWithLimit",
    "getClusterNodes",
    "getEpochInfo",
    "getEpochSchedule",
    "getFeeForMessage",
    "getFirstAvailableBlock",
    "getGenesisHash",
    "getHealth",
    "getHighestSnapshotSlot",
    "getIdentity",
    "getInflationGovernor",
    "getInflationRate",
    "getInflationReward",
    "getLargestAccounts",
    "getLatestBlockhash",
    "getLeaderSchedule",
    "getMaxRetransmitSlot",
    "getMaxShredInsertSlot",
    "getMinimumBalanceForRentExemption",
    "getMultipleAccounts",
    "getParsedTransaction",
    "getPriorityFeeEstimate",
    "getProgramAccounts",
    "getProgramAccountsV2",
    "getRecentPerformanceSamples",
    "getRecentPrioritizationFees",
    "getSignatureStatuses",
    "getSignaturesForAddress",
    "getSlot",
    "getSlotLeader",
    "getSlotLeaders",
    "getStakeMinimumDelegation",
    "getSupply",
    "getTokenAccountBalance",
    "getTokenAccountsByDelegate",
    "getTokenAccountsByOwner",
    "getTokenLargestAccounts",
    "getTokenSupply",
    "getTransaction",
    "getTransactionCount",
    "getVersion",
    "getVoteAccounts",
    "isBlockhashValid",
    "minimumLedgerSlot",
    "requestAirdrop",
    "sendTransaction",
    "simulateTransaction",
];

/// Indexed asset RPC methods represented by this release.
pub const SOLANA_DAS_METHODS: &[&str] = &[
    "getAsset",
    "getAssetBatch",
    "getAssetProof",
    "getAssetProofBatch",
    "getAssetsByAuthority",
    "getAssetsByCreator",
    "getAssetsByGroup",
    "getAssetsByOwner",
    "getNftEditions",
    "getSignaturesForAsset",
    "getTokenAccounts",
    "getTokensByDelegate",
    "getTokensByOwner",
    "searchAssets",
];

/// Indexed address history RPC methods represented by this release.
pub const SOLANA_HISTORY_METHODS: &[&str] = &["getTransactionsForAddress", "getTransfersByAddress"];

/// Leader information RPC methods represented by this release.
pub const SOLANA_LEADER_METHODS: &[&str] = &["getLeaderSlots", "getValidatorsInformation"];

/// Analytics RPC methods represented by this release.
pub const SOLANA_ANALYTICS_METHODS: &[&str] = &[
    "jetEpochSummary",
    "jetProgramStats",
    "jetSlotStats",
    "jetTopPrograms",
    "jetTpsTimeseries",
];

/// Standard Solana JSON-RPC namespace.
#[derive(Clone)]
pub struct SolanaRpcClient {
    namespace: RpcNamespace,
}

impl SolanaRpcClient {
    const fn new(transport: Arc<HttpJsonRpcTransport>) -> Self {
        Self {
            namespace: RpcNamespace::new(transport, BatchPolicy::SolanaStandard),
        }
    }
}

impl Deref for SolanaRpcClient {
    type Target = RpcNamespace;

    fn deref(&self) -> &Self::Target {
        &self.namespace
    }
}

macro_rules! solana_no_params {
    ($(($name:ident, $wire:literal, $result:ty)),* $(,)?) => {
        impl SolanaRpcClient {
            $(
                #[doc = concat!("Creates a pending `", $wire, "` request.")]
                #[must_use]
                pub fn $name(&self) -> PendingRpcRequest<$result> {
                    self.namespace.request($wire, Vec::<Value>::new()).expect("empty parameters serialize")
                }
            )*
        }
    };
}

macro_rules! solana_with_params {
    ($(($name:ident, $wire:literal, $result:ty)),* $(,)?) => {
        impl SolanaRpcClient {
            $(
                #[doc = concat!("Creates a pending `", $wire, "` request from positional parameters.")]
                pub fn $name<P: Serialize>(&self, params: P) -> Result<PendingRpcRequest<$result>> {
                    self.namespace.request($wire, params)
                }
            )*
        }
    };
}

solana_no_params!(
    (get_cluster_nodes, "getClusterNodes", Value),
    (get_epoch_schedule, "getEpochSchedule", Value),
    (get_first_available_block, "getFirstAvailableBlock", u64),
    (get_genesis_hash, "getGenesisHash", String),
    (get_health, "getHealth", String),
    (get_highest_snapshot_slot, "getHighestSnapshotSlot", Value),
    (get_identity, "getIdentity", Value),
    (get_inflation_rate, "getInflationRate", Value),
    (get_max_retransmit_slot, "getMaxRetransmitSlot", u64),
    (get_max_shred_insert_slot, "getMaxShredInsertSlot", u64),
    (get_version, "getVersion", Value),
    (minimum_ledger_slot, "minimumLedgerSlot", u64),
);

solana_with_params!(
    (get_account_info, "getAccountInfo", SolanaContextResult<Option<Value>>),
    (get_balance, "getBalance", SolanaContextResult<u64>),
    (get_block, "getBlock", Option<Value>),
    (get_block_commitment, "getBlockCommitment", Value),
    (get_block_height, "getBlockHeight", u64),
    (get_block_production, "getBlockProduction", Value),
    (get_block_time, "getBlockTime", Option<i64>),
    (get_blocks, "getBlocks", Vec<u64>),
    (get_blocks_with_limit, "getBlocksWithLimit", Vec<u64>),
    (get_epoch_info, "getEpochInfo", Value),
    (get_fee_for_message, "getFeeForMessage", SolanaContextResult<Option<u64>>),
    (get_inflation_governor, "getInflationGovernor", Value),
    (get_inflation_reward, "getInflationReward", Value),
    (get_largest_accounts, "getLargestAccounts", Value),
    (get_latest_blockhash, "getLatestBlockhash", Value),
    (get_leader_schedule, "getLeaderSchedule", Option<Value>),
    (
        get_minimum_balance_for_rent_exemption,
        "getMinimumBalanceForRentExemption",
        u64
    ),
    (get_multiple_accounts, "getMultipleAccounts", SolanaContextResult<Value>),
    (get_parsed_transaction, "getParsedTransaction", Option<Value>),
    (
        get_priority_fee_estimate,
        "getPriorityFeeEstimate",
        PriorityFeeEstimate
    ),
    (get_program_accounts, "getProgramAccounts", Value),
    (get_program_accounts_v2, "getProgramAccountsV2", Value),
    (get_recent_performance_samples, "getRecentPerformanceSamples", Value),
    (
        get_recent_prioritization_fees,
        "getRecentPrioritizationFees",
        Value
    ),
    (get_signature_statuses, "getSignatureStatuses", Value),
    (get_signatures_for_address, "getSignaturesForAddress", Value),
    (get_slot, "getSlot", u64),
    (get_slot_leader, "getSlotLeader", String),
    (get_slot_leaders, "getSlotLeaders", Vec<String>),
    (
        get_stake_minimum_delegation,
        "getStakeMinimumDelegation",
        SolanaContextResult<u64>
    ),
    (get_supply, "getSupply", Value),
    (get_token_account_balance, "getTokenAccountBalance", Value),
    (
        get_token_accounts_by_delegate,
        "getTokenAccountsByDelegate",
        Value
    ),
    (get_token_accounts_by_owner, "getTokenAccountsByOwner", Value),
    (get_token_largest_accounts, "getTokenLargestAccounts", Value),
    (get_token_supply, "getTokenSupply", Value),
    (get_transaction, "getTransaction", Option<Value>),
    (get_transaction_count, "getTransactionCount", u64),
    (get_vote_accounts, "getVoteAccounts", Value),
    (
        is_blockhash_valid,
        "isBlockhashValid",
        SolanaContextResult<bool>
    ),
    (request_airdrop, "requestAirdrop", String),
    (send_transaction, "sendTransaction", String),
    (simulate_transaction, "simulateTransaction", Value),
);

macro_rules! namespace_client {
    ($name:ident, $policy:expr, $(($method:ident, $wire:literal, $result:ty)),* $(,)?) => {
        #[doc = concat!(stringify!($name), " JSON-RPC namespace.")]
        #[derive(Clone)]
        pub struct $name {
            namespace: RpcNamespace,
        }

        impl $name {
            const fn new(transport: Arc<HttpJsonRpcTransport>) -> Self {
                Self { namespace: RpcNamespace::new(transport, $policy) }
            }

            $(
                #[doc = concat!("Creates a pending `", $wire, "` request.")]
                pub fn $method<P: Serialize>(&self, params: P) -> Result<PendingRpcRequest<$result>> {
                    self.namespace.request($wire, params)
                }
            )*
        }

        impl Deref for $name {
            type Target = RpcNamespace;

            fn deref(&self) -> &Self::Target {
                &self.namespace
            }
        }
    };
}

namespace_client!(
    SolanaDasClient,
    BatchPolicy::Any,
    (get_asset, "getAsset", Option<IndexedAsset>),
    (
        get_asset_batch,
        "getAssetBatch",
        Vec<Option<IndexedAsset>>
    ),
    (get_asset_proof, "getAssetProof", Option<IndexedAssetProof>),
    (
        get_asset_proof_batch,
        "getAssetProofBatch",
        Vec<Option<IndexedAssetProof>>
    ),
    (
        get_assets_by_authority,
        "getAssetsByAuthority",
        IndexedAssetList
    ),
    (
        get_assets_by_creator,
        "getAssetsByCreator",
        IndexedAssetList
    ),
    (get_assets_by_group, "getAssetsByGroup", IndexedAssetList),
    (get_assets_by_owner, "getAssetsByOwner", IndexedAssetList),
    (get_nft_editions, "getNftEditions", HashMap<String, Value>),
    (
        get_signatures_for_asset,
        "getSignaturesForAsset",
        HashMap<String, Value>
    ),
    (
        get_token_accounts,
        "getTokenAccounts",
        HashMap<String, Value>
    ),
    (
        get_tokens_by_delegate,
        "getTokensByDelegate",
        HashMap<String, Value>
    ),
    (
        get_tokens_by_owner,
        "getTokensByOwner",
        HashMap<String, Value>
    ),
    (search_assets, "searchAssets", IndexedAssetList),
);

namespace_client!(
    SolanaHistoryClient,
    BatchPolicy::Any,
    (
        get_transactions_for_address,
        "getTransactionsForAddress",
        Option<AddressTransactionPage>
    ),
    (
        get_transfers_by_address,
        "getTransfersByAddress",
        AddressTransferPage
    ),
);

namespace_client!(
    SolanaLeaderClient,
    BatchPolicy::Unsupported,
    (get_leader_slots, "getLeaderSlots", LeaderSlotsResult),
    (
        get_validators_information,
        "getValidatorsInformation",
        ValidatorsInformationResult
    ),
);

namespace_client!(
    SolanaAnalyticsClient,
    BatchPolicy::Any,
    (jet_epoch_summary, "jetEpochSummary", Option<EpochSummary>),
    (
        jet_program_stats,
        "jetProgramStats",
        Vec<ProgramStatsBucket>
    ),
    (jet_slot_stats, "jetSlotStats", Vec<SlotStatsRow>),
    (jet_top_programs, "jetTopPrograms", Vec<TopProgramRow>),
    (jet_tps_timeseries, "jetTpsTimeseries", Vec<TpsBucket>),
);

/// Solana enhanced WebSocket subscription methods.
pub const SOLANA_ENHANCED_SUBSCRIPTION_METHODS: &[&str] = &[
    "accountSubscribe",
    "accountUnsubscribe",
    "transactionSubscribe",
    "transactionUnsubscribe",
];

/// Solana WebSocket subscription client.
#[derive(Clone)]
pub struct SolanaSubscriptions {
    transport: Arc<WebSocketJsonRpcTransport>,
}

impl SolanaSubscriptions {
    pub(crate) const fn new(transport: Arc<WebSocketJsonRpcTransport>) -> Self {
        Self { transport }
    }

    /// Credential-free WebSocket endpoint.
    #[must_use]
    pub fn endpoint(&self) -> &str {
        self.transport.endpoint()
    }

    /// Starts an `accountSubscribe` subscription.
    pub async fn account_subscribe(
        &self,
        address: &str,
        options: Option<Value>,
    ) -> Result<RpcSubscription> {
        let mut params = vec![Value::String(address.to_owned())];
        if let Some(options) = options {
            params.push(options);
        }
        self.raw_subscribe(
            "accountSubscribe",
            Value::Array(params),
            "accountUnsubscribe",
        )
        .await
    }

    /// Starts a `transactionSubscribe` subscription.
    pub async fn transaction_subscribe(
        &self,
        filter: Value,
        options: Option<Value>,
    ) -> Result<RpcSubscription> {
        let mut params = vec![filter];
        if let Some(options) = options {
            params.push(options);
        }
        self.raw_subscribe(
            "transactionSubscribe",
            Value::Array(params),
            "transactionUnsubscribe",
        )
        .await
    }

    /// Starts an arbitrary subscribe/unsubscribe method pair.
    pub async fn raw_subscribe(
        &self,
        subscribe_method: &str,
        params: Value,
        unsubscribe_method: &str,
    ) -> Result<RpcSubscription> {
        let receiver = self.transport.subscribe_notifications();
        let id: crate::SubscriptionId = self
            .transport
            .request(subscribe_method, params, None)
            .await?;
        Ok(RpcSubscription::new(
            id,
            Arc::clone(&self.transport),
            unsubscribe_method,
            receiver,
        ))
    }

    /// Sends an arbitrary request on the subscription connection.
    pub async fn raw<T: DeserializeOwned>(&self, method: &str, params: Value) -> Result<T> {
        self.transport.request(method, params, None).await
    }

    /// Closes the WebSocket connection.
    pub async fn close(&self) {
        self.transport.close().await;
    }
}

/// Standard and extended Solana APIs.
#[derive(Clone)]
pub struct SolanaClient {
    /// Standard Solana JSON-RPC.
    pub rpc: SolanaRpcClient,
    /// Indexed asset RPC using named parameters.
    pub das: SolanaDasClient,
    /// Indexed address history RPC.
    pub history: SolanaHistoryClient,
    /// Leader information RPC. Batching is rejected locally.
    pub leaders: SolanaLeaderClient,
    /// Analytics RPC.
    pub analytics: SolanaAnalyticsClient,
    /// Enhanced WebSocket subscriptions.
    pub subscriptions: SolanaSubscriptions,
}

impl SolanaClient {
    pub(crate) fn new(
        transport: Arc<HttpJsonRpcTransport>,
        websocket: Arc<WebSocketJsonRpcTransport>,
    ) -> Self {
        Self {
            rpc: SolanaRpcClient::new(Arc::clone(&transport)),
            das: SolanaDasClient::new(Arc::clone(&transport)),
            history: SolanaHistoryClient::new(Arc::clone(&transport)),
            leaders: SolanaLeaderClient::new(Arc::clone(&transport)),
            analytics: SolanaAnalyticsClient::new(transport),
            subscriptions: SolanaSubscriptions::new(websocket),
        }
    }
}