1use std::{collections::HashMap, ops::Deref, sync::Arc};
2
3use serde::{Deserialize, Serialize, de::DeserializeOwned};
4use serde_json::Value;
5
6use crate::{
7 PendingRpcRequest, Result, RpcNamespace,
8 rpc::{BatchPolicy, HttpJsonRpcTransport},
9 subscriptions::{RpcSubscription, WebSocketJsonRpcTransport},
10};
11
12#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
14#[serde(rename_all = "lowercase")]
15pub enum SolanaCommitment {
16 Confirmed,
18 Finalized,
20 Processed,
22}
23
24#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
26pub enum SolanaEncoding {
27 #[serde(rename = "base58")]
29 Base58,
30 #[serde(rename = "base64")]
32 Base64,
33 #[serde(rename = "base64+zstd")]
35 Base64Zstd,
36 #[serde(rename = "jsonParsed")]
38 JsonParsed,
39}
40
41#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
43#[serde(rename_all = "camelCase")]
44pub struct SolanaContext {
45 pub api_version: Option<String>,
47 pub slot: u64,
49}
50
51#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
53pub struct SolanaContextResult<T> {
54 pub context: SolanaContext,
56 pub value: T,
58}
59
60#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
62#[serde(rename_all = "camelCase")]
63pub struct PriorityFeeEstimate {
64 pub priority_fee_estimate: f64,
66 #[serde(flatten)]
68 pub additional: HashMap<String, Value>,
69}
70
71#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
73#[serde(rename_all = "camelCase")]
74pub struct AssetRequest {
75 pub id: String,
77 pub display_options: Option<HashMap<String, bool>>,
79}
80
81#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
83#[serde(rename_all = "camelCase")]
84pub struct AssetBatchRequest {
85 pub ids: Vec<String>,
87 pub display_options: Option<HashMap<String, bool>>,
89}
90
91#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
93#[serde(rename_all = "camelCase")]
94pub struct AssetListRequest {
95 pub cursor: Option<String>,
97 pub limit: Option<u64>,
99 pub page: Option<u64>,
101 #[serde(flatten)]
103 pub additional: HashMap<String, Value>,
104}
105
106pub type IndexedAsset = HashMap<String, Value>;
108pub type IndexedAssetProof = HashMap<String, Value>;
110
111#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
113pub struct IndexedAssetList<T = IndexedAsset> {
114 pub cursor: Option<String>,
116 pub items: Vec<T>,
118 pub limit: Option<u64>,
120 pub page: Option<u64>,
122 pub total: Option<u64>,
124 #[serde(flatten)]
126 pub additional: HashMap<String, Value>,
127}
128
129#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
131pub struct NumericFilter {
132 pub eq: Option<f64>,
134 pub gt: Option<f64>,
136 pub gte: Option<f64>,
138 pub lt: Option<f64>,
140 pub lte: Option<f64>,
142}
143
144#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
146#[serde(rename_all = "camelCase")]
147pub struct AddressTransactionsOptions {
148 pub before: Option<String>,
150 pub commitment: Option<SolanaCommitment>,
152 pub encoding: Option<String>,
154 pub filters: Option<HashMap<String, Value>>,
156 pub limit: Option<u64>,
158 pub max_supported_transaction_version: Option<u64>,
160 pub pagination_token: Option<String>,
162 pub sort_order: Option<String>,
164 pub transaction_details: Option<String>,
166 pub until: Option<String>,
168}
169
170#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
172#[serde(rename_all = "camelCase")]
173pub struct AddressTransaction {
174 pub block_time: Option<i64>,
176 pub confirmation_status: SolanaCommitment,
178 pub err: Value,
180 pub memo: Option<String>,
182 pub meta: Option<Value>,
184 pub signature: String,
186 pub slot: u64,
188 pub transaction: Option<Value>,
190 pub transaction_index: u64,
192 pub version: Option<Value>,
194 #[serde(flatten)]
196 pub additional: HashMap<String, Value>,
197}
198
199#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
201#[serde(rename_all = "camelCase")]
202pub struct AddressTransactionPage {
203 pub data: Vec<AddressTransaction>,
205 pub pagination_token: Option<String>,
207 pub window_start: Option<i64>,
209}
210
211#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
213#[serde(rename_all = "lowercase")]
214pub enum AddressTransferDirection {
215 Any,
217 In,
219 Out,
221}
222
223#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
225#[serde(rename_all = "camelCase")]
226pub struct AddressTransferFilters {
227 pub amount: Option<NumericFilter>,
229 pub block_time: Option<NumericFilter>,
231 pub slot: Option<NumericFilter>,
233}
234
235#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
237#[serde(rename_all = "camelCase")]
238pub struct AddressTransfersOptions {
239 pub commitment: Option<SolanaCommitment>,
241 pub direction: Option<AddressTransferDirection>,
243 pub filters: Option<AddressTransferFilters>,
245 pub limit: Option<u64>,
247 pub mint: Option<String>,
249 pub pagination_token: Option<String>,
251 pub sol_mode: Option<String>,
253 pub sort_order: Option<String>,
255 pub with: Option<String>,
257}
258
259#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
261pub enum AddressTransferType {
262 #[serde(rename = "burn")]
264 Burn,
265 #[serde(rename = "changeOwner")]
267 ChangeOwner,
268 #[serde(rename = "mint")]
270 Mint,
271 #[serde(rename = "transfer")]
273 Transfer,
274 #[serde(rename = "unwrap")]
276 Unwrap,
277 #[serde(rename = "withdrawWithheldFee")]
279 WithdrawWithheldFee,
280 #[serde(rename = "wrap")]
282 Wrap,
283}
284
285#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
287#[serde(rename_all = "camelCase")]
288pub struct AddressTransfer {
289 pub amount: String,
291 pub block_time: Option<i64>,
293 pub confirmation_status: SolanaCommitment,
295 pub decimals: u8,
297 pub fee_amount: Option<String>,
299 pub fee_ui_amount: Option<String>,
301 pub from_token_account: Option<String>,
303 pub from_user_account: Option<String>,
305 pub inner_instruction_idx: u64,
307 pub instruction_idx: u64,
309 pub mint: Option<String>,
311 pub signature: String,
313 pub slot: u64,
315 pub to_token_account: Option<String>,
317 pub to_user_account: Option<String>,
319 pub transaction_idx: u64,
321 #[serde(rename = "type")]
323 pub transfer_type: AddressTransferType,
324 pub ui_amount: String,
326 #[serde(flatten)]
328 pub additional: HashMap<String, Value>,
329}
330
331#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
333#[serde(rename_all = "camelCase")]
334pub struct AddressTransferPage {
335 pub data: Vec<AddressTransfer>,
337 pub pagination_token: Option<String>,
339 pub window_start: Option<i64>,
341}
342
343#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
345#[serde(rename_all = "camelCase")]
346pub struct PingMeasurement {
347 pub city: Option<String>,
349 pub country: Option<String>,
351 pub from_ip: Option<String>,
353 pub icmp_replied: bool,
355 pub lat: Option<f64>,
357 pub lon: Option<f64>,
359 pub measured_at: Option<String>,
361 pub ms: Option<f64>,
363 pub org: Option<String>,
365 pub postal: Option<String>,
367 pub region: Option<String>,
369 pub timezone: Option<String>,
371 #[serde(flatten)]
373 pub additional: HashMap<String, Value>,
374}
375
376#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
378#[serde(rename_all = "camelCase")]
379pub struct LeaderSlot {
380 pub epoch: u64,
382 pub feature_set: Option<String>,
384 pub gossip_port: Option<u16>,
386 pub gossip_updated_at: Option<String>,
388 pub identity: String,
390 pub ip_address: Option<String>,
392 pub leader_city: Option<String>,
394 pub leader_country: Option<String>,
396 pub leader_lat: Option<f64>,
398 pub leader_lon: Option<f64>,
400 pub leader_org: Option<String>,
402 pub leader_region: Option<String>,
404 pub leader_timezone: Option<String>,
406 pub ping_to_leaders: Vec<PingMeasurement>,
408 pub rpc_address: Option<String>,
410 pub slot: String,
412 pub stake_weight: f64,
414 pub tpu_port: Option<u16>,
416 pub tpu_quic_port: Option<u16>,
418 pub version: Option<String>,
420 #[serde(flatten)]
422 pub additional: HashMap<String, Value>,
423}
424
425#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
427pub struct LeaderSlotsResult {
428 pub data: Vec<LeaderSlot>,
430 pub message: String,
432 pub success: bool,
434 pub total: u64,
436 #[serde(flatten)]
438 pub additional: HashMap<String, Value>,
439}
440
441#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
443pub struct ValidatorsInformationOptions {
444 pub country: Option<String>,
446 pub limit: Option<u64>,
448 pub region: Option<String>,
450}
451
452#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
454#[serde(rename_all = "camelCase")]
455pub struct ValidatorInformation {
456 pub feature_set: Option<String>,
458 pub gossip_node_id: Option<u64>,
460 pub gossip_port: Option<u16>,
462 pub gossip_updated_at: Option<String>,
464 pub identity: String,
466 pub ip_address: Option<String>,
468 pub leader_city: Option<String>,
470 pub leader_country: Option<String>,
472 pub leader_lat: Option<f64>,
474 pub leader_lon: Option<f64>,
476 pub leader_org: Option<String>,
478 pub leader_region: Option<String>,
480 pub leader_timezone: Option<String>,
482 pub ping_to_leaders: Vec<PingMeasurement>,
484 pub rpc_address: Option<String>,
486 pub slot_count: u64,
488 pub stake_weight: f64,
490 pub tpu_port: Option<u16>,
492 pub tpu_quic_port: Option<u16>,
494 pub version: Option<String>,
496 #[serde(flatten)]
498 pub additional: HashMap<String, Value>,
499}
500
501#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
503#[serde(rename_all = "camelCase")]
504pub struct ValidatorsInformationResult {
505 pub data: Vec<ValidatorInformation>,
507 pub epoch: u64,
509 pub message: String,
511 pub success: bool,
513 pub total: u64,
515 pub total_validators: u64,
517 #[serde(flatten)]
519 pub additional: HashMap<String, Value>,
520}
521
522#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
524#[serde(untagged)]
525pub enum AnalyticsTimeBound {
526 Number(i64),
528 String(String),
530}
531
532#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
534#[serde(rename_all = "camelCase")]
535pub struct TopProgramsOptions {
536 pub include_votes: Option<bool>,
538 pub limit: Option<u64>,
540 pub since: Option<AnalyticsTimeBound>,
542 pub until: Option<AnalyticsTimeBound>,
544}
545
546#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
548pub struct TopProgramRow {
549 pub errors: String,
551 pub invocations: String,
553 pub program: String,
555 pub total_cus: String,
557 #[serde(flatten)]
559 pub additional: HashMap<String, Value>,
560}
561
562#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
564#[serde(untagged)]
565pub enum SlotStatsOptions {
566 Slot {
568 slot: u64,
570 },
571 Range {
573 #[serde(rename = "fromSlot")]
575 from_slot: u64,
576 #[serde(rename = "toSlot")]
578 to_slot: u64,
579 },
580}
581
582#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
584pub struct SlotStatsRow {
585 pub block_time: i64,
587 pub non_vote_transaction_count: u64,
589 pub slot: u64,
591 pub transaction_count: u64,
593 pub vote_transaction_count: u64,
595 #[serde(flatten)]
597 pub additional: HashMap<String, Value>,
598}
599
600#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
602#[serde(rename_all = "camelCase")]
603pub struct TpsTimeseriesOptions {
604 pub bucket_sec: Option<u64>,
606 pub from: AnalyticsTimeBound,
608 pub to: AnalyticsTimeBound,
610}
611
612#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
614pub struct TpsBucket {
615 pub bucket: i64,
617 pub non_vote_tps: f64,
619 pub total_tps: f64,
621 #[serde(flatten)]
623 pub additional: HashMap<String, Value>,
624}
625
626#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
628pub struct EpochSummary {
629 pub distinct_programs: String,
631 pub epoch: u64,
633 pub first_block_time: i64,
635 pub last_block_time: i64,
637 pub non_vote_txs: String,
639 pub program_invocations: String,
641 pub slots: String,
643 pub total_txs: String,
645 pub vote_txs: String,
647 #[serde(flatten)]
649 pub additional: HashMap<String, Value>,
650}
651
652#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
654#[serde(rename_all = "camelCase")]
655pub struct ProgramStatsOptions {
656 pub bucket_sec: Option<u64>,
658 pub program_id_base58: String,
660 pub since: Option<AnalyticsTimeBound>,
662 pub until: Option<AnalyticsTimeBound>,
664}
665
666#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
668pub struct ProgramStatsBucket {
669 pub bucket: i64,
671 pub errors: String,
673 pub invocations: String,
675 pub total_cus: String,
677 #[serde(flatten)]
679 pub additional: HashMap<String, Value>,
680}
681
682pub const SOLANA_RPC_METHODS: &[&str] = &[
684 "getAccountInfo",
685 "getBalance",
686 "getBlock",
687 "getBlockCommitment",
688 "getBlockHeight",
689 "getBlockProduction",
690 "getBlockTime",
691 "getBlocks",
692 "getBlocksWithLimit",
693 "getClusterNodes",
694 "getEpochInfo",
695 "getEpochSchedule",
696 "getFeeForMessage",
697 "getFirstAvailableBlock",
698 "getGenesisHash",
699 "getHealth",
700 "getHighestSnapshotSlot",
701 "getIdentity",
702 "getInflationGovernor",
703 "getInflationRate",
704 "getInflationReward",
705 "getLargestAccounts",
706 "getLatestBlockhash",
707 "getLeaderSchedule",
708 "getMaxRetransmitSlot",
709 "getMaxShredInsertSlot",
710 "getMinimumBalanceForRentExemption",
711 "getMultipleAccounts",
712 "getParsedTransaction",
713 "getPriorityFeeEstimate",
714 "getProgramAccounts",
715 "getProgramAccountsV2",
716 "getRecentPerformanceSamples",
717 "getRecentPrioritizationFees",
718 "getSignatureStatuses",
719 "getSignaturesForAddress",
720 "getSlot",
721 "getSlotLeader",
722 "getSlotLeaders",
723 "getStakeMinimumDelegation",
724 "getSupply",
725 "getTokenAccountBalance",
726 "getTokenAccountsByDelegate",
727 "getTokenAccountsByOwner",
728 "getTokenLargestAccounts",
729 "getTokenSupply",
730 "getTransaction",
731 "getTransactionCount",
732 "getVersion",
733 "getVoteAccounts",
734 "isBlockhashValid",
735 "minimumLedgerSlot",
736 "requestAirdrop",
737 "sendTransaction",
738 "simulateTransaction",
739];
740
741pub const SOLANA_DAS_METHODS: &[&str] = &[
743 "getAsset",
744 "getAssetBatch",
745 "getAssetProof",
746 "getAssetProofBatch",
747 "getAssetsByAuthority",
748 "getAssetsByCreator",
749 "getAssetsByGroup",
750 "getAssetsByOwner",
751 "getNftEditions",
752 "getSignaturesForAsset",
753 "getTokenAccounts",
754 "getTokensByDelegate",
755 "getTokensByOwner",
756 "searchAssets",
757];
758
759pub const SOLANA_HISTORY_METHODS: &[&str] = &["getTransactionsForAddress", "getTransfersByAddress"];
761
762pub const SOLANA_LEADER_METHODS: &[&str] = &["getLeaderSlots", "getValidatorsInformation"];
764
765pub const SOLANA_ANALYTICS_METHODS: &[&str] = &[
767 "jetEpochSummary",
768 "jetProgramStats",
769 "jetSlotStats",
770 "jetTopPrograms",
771 "jetTpsTimeseries",
772];
773
774#[derive(Clone)]
776pub struct SolanaRpcClient {
777 namespace: RpcNamespace,
778}
779
780impl SolanaRpcClient {
781 const fn new(transport: Arc<HttpJsonRpcTransport>) -> Self {
782 Self {
783 namespace: RpcNamespace::new(transport, BatchPolicy::SolanaStandard),
784 }
785 }
786}
787
788impl Deref for SolanaRpcClient {
789 type Target = RpcNamespace;
790
791 fn deref(&self) -> &Self::Target {
792 &self.namespace
793 }
794}
795
796macro_rules! solana_no_params {
797 ($(($name:ident, $wire:literal, $result:ty)),* $(,)?) => {
798 impl SolanaRpcClient {
799 $(
800 #[doc = concat!("Creates a pending `", $wire, "` request.")]
801 #[must_use]
802 pub fn $name(&self) -> PendingRpcRequest<$result> {
803 self.namespace.request($wire, Vec::<Value>::new()).expect("empty parameters serialize")
804 }
805 )*
806 }
807 };
808}
809
810macro_rules! solana_with_params {
811 ($(($name:ident, $wire:literal, $result:ty)),* $(,)?) => {
812 impl SolanaRpcClient {
813 $(
814 #[doc = concat!("Creates a pending `", $wire, "` request from positional parameters.")]
815 pub fn $name<P: Serialize>(&self, params: P) -> Result<PendingRpcRequest<$result>> {
816 self.namespace.request($wire, params)
817 }
818 )*
819 }
820 };
821}
822
823solana_no_params!(
824 (get_cluster_nodes, "getClusterNodes", Value),
825 (get_epoch_schedule, "getEpochSchedule", Value),
826 (get_first_available_block, "getFirstAvailableBlock", u64),
827 (get_genesis_hash, "getGenesisHash", String),
828 (get_health, "getHealth", String),
829 (get_highest_snapshot_slot, "getHighestSnapshotSlot", Value),
830 (get_identity, "getIdentity", Value),
831 (get_inflation_rate, "getInflationRate", Value),
832 (get_max_retransmit_slot, "getMaxRetransmitSlot", u64),
833 (get_max_shred_insert_slot, "getMaxShredInsertSlot", u64),
834 (get_version, "getVersion", Value),
835 (minimum_ledger_slot, "minimumLedgerSlot", u64),
836);
837
838solana_with_params!(
839 (get_account_info, "getAccountInfo", SolanaContextResult<Option<Value>>),
840 (get_balance, "getBalance", SolanaContextResult<u64>),
841 (get_block, "getBlock", Option<Value>),
842 (get_block_commitment, "getBlockCommitment", Value),
843 (get_block_height, "getBlockHeight", u64),
844 (get_block_production, "getBlockProduction", Value),
845 (get_block_time, "getBlockTime", Option<i64>),
846 (get_blocks, "getBlocks", Vec<u64>),
847 (get_blocks_with_limit, "getBlocksWithLimit", Vec<u64>),
848 (get_epoch_info, "getEpochInfo", Value),
849 (get_fee_for_message, "getFeeForMessage", SolanaContextResult<Option<u64>>),
850 (get_inflation_governor, "getInflationGovernor", Value),
851 (get_inflation_reward, "getInflationReward", Value),
852 (get_largest_accounts, "getLargestAccounts", Value),
853 (get_latest_blockhash, "getLatestBlockhash", Value),
854 (get_leader_schedule, "getLeaderSchedule", Option<Value>),
855 (
856 get_minimum_balance_for_rent_exemption,
857 "getMinimumBalanceForRentExemption",
858 u64
859 ),
860 (get_multiple_accounts, "getMultipleAccounts", SolanaContextResult<Value>),
861 (get_parsed_transaction, "getParsedTransaction", Option<Value>),
862 (
863 get_priority_fee_estimate,
864 "getPriorityFeeEstimate",
865 PriorityFeeEstimate
866 ),
867 (get_program_accounts, "getProgramAccounts", Value),
868 (get_program_accounts_v2, "getProgramAccountsV2", Value),
869 (get_recent_performance_samples, "getRecentPerformanceSamples", Value),
870 (
871 get_recent_prioritization_fees,
872 "getRecentPrioritizationFees",
873 Value
874 ),
875 (get_signature_statuses, "getSignatureStatuses", Value),
876 (get_signatures_for_address, "getSignaturesForAddress", Value),
877 (get_slot, "getSlot", u64),
878 (get_slot_leader, "getSlotLeader", String),
879 (get_slot_leaders, "getSlotLeaders", Vec<String>),
880 (
881 get_stake_minimum_delegation,
882 "getStakeMinimumDelegation",
883 SolanaContextResult<u64>
884 ),
885 (get_supply, "getSupply", Value),
886 (get_token_account_balance, "getTokenAccountBalance", Value),
887 (
888 get_token_accounts_by_delegate,
889 "getTokenAccountsByDelegate",
890 Value
891 ),
892 (get_token_accounts_by_owner, "getTokenAccountsByOwner", Value),
893 (get_token_largest_accounts, "getTokenLargestAccounts", Value),
894 (get_token_supply, "getTokenSupply", Value),
895 (get_transaction, "getTransaction", Option<Value>),
896 (get_transaction_count, "getTransactionCount", u64),
897 (get_vote_accounts, "getVoteAccounts", Value),
898 (
899 is_blockhash_valid,
900 "isBlockhashValid",
901 SolanaContextResult<bool>
902 ),
903 (request_airdrop, "requestAirdrop", String),
904 (send_transaction, "sendTransaction", String),
905 (simulate_transaction, "simulateTransaction", Value),
906);
907
908macro_rules! namespace_client {
909 ($name:ident, $policy:expr, $(($method:ident, $wire:literal, $result:ty)),* $(,)?) => {
910 #[doc = concat!(stringify!($name), " JSON-RPC namespace.")]
911 #[derive(Clone)]
912 pub struct $name {
913 namespace: RpcNamespace,
914 }
915
916 impl $name {
917 const fn new(transport: Arc<HttpJsonRpcTransport>) -> Self {
918 Self { namespace: RpcNamespace::new(transport, $policy) }
919 }
920
921 $(
922 #[doc = concat!("Creates a pending `", $wire, "` request.")]
923 pub fn $method<P: Serialize>(&self, params: P) -> Result<PendingRpcRequest<$result>> {
924 self.namespace.request($wire, params)
925 }
926 )*
927 }
928
929 impl Deref for $name {
930 type Target = RpcNamespace;
931
932 fn deref(&self) -> &Self::Target {
933 &self.namespace
934 }
935 }
936 };
937}
938
939namespace_client!(
940 SolanaDasClient,
941 BatchPolicy::Any,
942 (get_asset, "getAsset", Option<IndexedAsset>),
943 (
944 get_asset_batch,
945 "getAssetBatch",
946 Vec<Option<IndexedAsset>>
947 ),
948 (get_asset_proof, "getAssetProof", Option<IndexedAssetProof>),
949 (
950 get_asset_proof_batch,
951 "getAssetProofBatch",
952 Vec<Option<IndexedAssetProof>>
953 ),
954 (
955 get_assets_by_authority,
956 "getAssetsByAuthority",
957 IndexedAssetList
958 ),
959 (
960 get_assets_by_creator,
961 "getAssetsByCreator",
962 IndexedAssetList
963 ),
964 (get_assets_by_group, "getAssetsByGroup", IndexedAssetList),
965 (get_assets_by_owner, "getAssetsByOwner", IndexedAssetList),
966 (get_nft_editions, "getNftEditions", HashMap<String, Value>),
967 (
968 get_signatures_for_asset,
969 "getSignaturesForAsset",
970 HashMap<String, Value>
971 ),
972 (
973 get_token_accounts,
974 "getTokenAccounts",
975 HashMap<String, Value>
976 ),
977 (
978 get_tokens_by_delegate,
979 "getTokensByDelegate",
980 HashMap<String, Value>
981 ),
982 (
983 get_tokens_by_owner,
984 "getTokensByOwner",
985 HashMap<String, Value>
986 ),
987 (search_assets, "searchAssets", IndexedAssetList),
988);
989
990namespace_client!(
991 SolanaHistoryClient,
992 BatchPolicy::Any,
993 (
994 get_transactions_for_address,
995 "getTransactionsForAddress",
996 Option<AddressTransactionPage>
997 ),
998 (
999 get_transfers_by_address,
1000 "getTransfersByAddress",
1001 AddressTransferPage
1002 ),
1003);
1004
1005namespace_client!(
1006 SolanaLeaderClient,
1007 BatchPolicy::Unsupported,
1008 (get_leader_slots, "getLeaderSlots", LeaderSlotsResult),
1009 (
1010 get_validators_information,
1011 "getValidatorsInformation",
1012 ValidatorsInformationResult
1013 ),
1014);
1015
1016namespace_client!(
1017 SolanaAnalyticsClient,
1018 BatchPolicy::Any,
1019 (jet_epoch_summary, "jetEpochSummary", Option<EpochSummary>),
1020 (
1021 jet_program_stats,
1022 "jetProgramStats",
1023 Vec<ProgramStatsBucket>
1024 ),
1025 (jet_slot_stats, "jetSlotStats", Vec<SlotStatsRow>),
1026 (jet_top_programs, "jetTopPrograms", Vec<TopProgramRow>),
1027 (jet_tps_timeseries, "jetTpsTimeseries", Vec<TpsBucket>),
1028);
1029
1030pub const SOLANA_ENHANCED_SUBSCRIPTION_METHODS: &[&str] = &[
1032 "accountSubscribe",
1033 "accountUnsubscribe",
1034 "transactionSubscribe",
1035 "transactionUnsubscribe",
1036];
1037
1038#[derive(Clone)]
1040pub struct SolanaSubscriptions {
1041 transport: Arc<WebSocketJsonRpcTransport>,
1042}
1043
1044impl SolanaSubscriptions {
1045 pub(crate) const fn new(transport: Arc<WebSocketJsonRpcTransport>) -> Self {
1046 Self { transport }
1047 }
1048
1049 #[must_use]
1051 pub fn endpoint(&self) -> &str {
1052 self.transport.endpoint()
1053 }
1054
1055 pub async fn account_subscribe(
1057 &self,
1058 address: &str,
1059 options: Option<Value>,
1060 ) -> Result<RpcSubscription> {
1061 let mut params = vec![Value::String(address.to_owned())];
1062 if let Some(options) = options {
1063 params.push(options);
1064 }
1065 self.raw_subscribe(
1066 "accountSubscribe",
1067 Value::Array(params),
1068 "accountUnsubscribe",
1069 )
1070 .await
1071 }
1072
1073 pub async fn transaction_subscribe(
1075 &self,
1076 filter: Value,
1077 options: Option<Value>,
1078 ) -> Result<RpcSubscription> {
1079 let mut params = vec![filter];
1080 if let Some(options) = options {
1081 params.push(options);
1082 }
1083 self.raw_subscribe(
1084 "transactionSubscribe",
1085 Value::Array(params),
1086 "transactionUnsubscribe",
1087 )
1088 .await
1089 }
1090
1091 pub async fn raw_subscribe(
1093 &self,
1094 subscribe_method: &str,
1095 params: Value,
1096 unsubscribe_method: &str,
1097 ) -> Result<RpcSubscription> {
1098 let receiver = self.transport.subscribe_notifications();
1099 let id: crate::SubscriptionId = self
1100 .transport
1101 .request(subscribe_method, params, None)
1102 .await?;
1103 Ok(RpcSubscription::new(
1104 id,
1105 Arc::clone(&self.transport),
1106 unsubscribe_method,
1107 receiver,
1108 ))
1109 }
1110
1111 pub async fn raw<T: DeserializeOwned>(&self, method: &str, params: Value) -> Result<T> {
1113 self.transport.request(method, params, None).await
1114 }
1115
1116 pub async fn close(&self) {
1118 self.transport.close().await;
1119 }
1120}
1121
1122#[derive(Clone)]
1124pub struct SolanaClient {
1125 pub rpc: SolanaRpcClient,
1127 pub das: SolanaDasClient,
1129 pub history: SolanaHistoryClient,
1131 pub leaders: SolanaLeaderClient,
1133 pub analytics: SolanaAnalyticsClient,
1135 pub subscriptions: SolanaSubscriptions,
1137}
1138
1139impl SolanaClient {
1140 pub(crate) fn new(
1141 transport: Arc<HttpJsonRpcTransport>,
1142 websocket: Arc<WebSocketJsonRpcTransport>,
1143 ) -> Self {
1144 Self {
1145 rpc: SolanaRpcClient::new(Arc::clone(&transport)),
1146 das: SolanaDasClient::new(Arc::clone(&transport)),
1147 history: SolanaHistoryClient::new(Arc::clone(&transport)),
1148 leaders: SolanaLeaderClient::new(Arc::clone(&transport)),
1149 analytics: SolanaAnalyticsClient::new(transport),
1150 subscriptions: SolanaSubscriptions::new(websocket),
1151 }
1152 }
1153}