pub struct SolanaClientRpc {
pub rpc_client: Arc<RpcClient>,
pub limits: Vec<SolanaClientRateLimit>,
}
Expand description
A single Solana RPC client. Includes its limits to calculate usage.
Fields§
§rpc_client: Arc<RpcClient>
§limits: Vec<SolanaClientRateLimit>
The list of all limits applied to the RPC client. All limits must succeed in order to send a request.
Implementations§
Source§impl SolanaClientRpc
impl SolanaClientRpc
Sourcepub fn new(rpc_client: Arc<RpcClient>) -> Self
pub fn new(rpc_client: Arc<RpcClient>) -> Self
Creates a SolanaClientRpc
without limits.
Examples found in repository?
examples/genesysgo.rs (line 17)
11async fn main() {
12 let default_rpc = Arc::new(RpcClient::new(
13 "https://api.mainnet-beta.solana.com".to_string(),
14 ));
15 let genesysgo_rpc = Arc::new(RpcClient::new("<your-genesysgo-rpc-url>".to_string()));
16 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
17 SolanaClientRpc::new(genesysgo_rpc)
18 // Requests per second limit.
19 .add_limit(
20 SolanaClientRateLimit::new(
21 1000, /* 1 second */
22 1, /* 1 request per second */
23 1, /* all requests count the same */
24 )
25 // Ignore GetMultipleAccounts requests here to track them in the next limit.
26 .ignore_endpoint(RpcRequest::GetMultipleAccounts),
27 )
28 // Requests per second limit for GetMultipleAccounts.
29 .add_limit(
30 SolanaClientRateLimit::new(
31 60 * 1000, /* 1 minute */
32 6, /* 6 request per minute */
33 1, /* all requests count the same */
34 )
35 // Ignore all endpoints and include only GetMultipleAccounts requests here.
36 .ignores_all_endpoints()
37 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 1),
38 ),
39 );
40
41 let version = client.get_version().await.unwrap();
42
43 println!("Cluster version: {}", version.solana_core);
44}
More examples
examples/quicknode.rs (line 18)
12async fn main() {
13 let default_rpc = Arc::new(RpcClient::new(
14 "https://api.mainnet-beta.solana.com".to_string(),
15 ));
16 let quicknode_rpc = Arc::new(RpcClient::new("<your-quicknode-rpc-url>".to_string()));
17 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
18 SolanaClientRpc::new(quicknode_rpc)
19 // Credits / month limits.
20 .add_limit(
21 SolanaClientRateLimit::new(
22 30 * 24 * 60 * 60 * 1000, /* 30 days */
23 10_000_000, /* credits per month */
24 1, /* default cost in credits for endpoints */
25 )
26 // List of all endpoints whose credits are different than the default value.
27 .add_endpoint_amount(RpcRequest::GetAccountInfo, 2)
28 .add_endpoint_amount(RpcRequest::GetBlockTime, 2)
29 .add_endpoint_amount(RpcRequest::GetClusterNodes, 2)
30 .add_endpoint_amount(RpcRequest::GetBlock, 23)
31 .add_endpoint_amount(RpcRequest::GetEpochInfo, 2)
32 .add_endpoint_amount(RpcRequest::GetFirstAvailableBlock, 3)
33 .add_endpoint_amount(RpcRequest::GetHealth, 2)
34 .add_endpoint_amount(RpcRequest::GetHighestSnapshotSlot, 2)
35 .add_endpoint_amount(RpcRequest::GetInflationGovernor, 2)
36 .add_endpoint_amount(RpcRequest::GetLatestBlockhash, 2)
37 .add_endpoint_amount(RpcRequest::GetMinimumBalanceForRentExemption, 3)
38 .add_endpoint_amount(RpcRequest::GetProgramAccounts, 35)
39 .add_endpoint_amount(RpcRequest::GetRecentPerformanceSamples, 4)
40 .add_endpoint_amount(RpcRequest::GetSignaturesForAddress, 3)
41 .add_endpoint_amount(RpcRequest::GetTokenSupply, 2)
42 .add_endpoint_amount(RpcRequest::GetTransaction, 3)
43 .add_endpoint_amount(RpcRequest::GetVersion, 2)
44 .add_endpoint_amount(RpcRequest::SimulateTransaction, 4)
45 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 10)
46 .add_endpoint_amount(RpcRequest::GetLargestAccounts, 259),
47 )
48 // Requests / second limit.
49 .add_limit(SolanaClientRateLimit::new(
50 1000, /* 1 second */
51 25, /* 25 requests per second */
52 1, /* all requests count the same */
53 )),
54 );
55
56 let version = client.get_version().await.unwrap();
57
58 println!("Cluster version: {}", version.solana_core);
59}
Sourcepub fn add_limit(self, limit: SolanaClientRateLimit) -> Self
pub fn add_limit(self, limit: SolanaClientRateLimit) -> Self
Adds a SolanaClientRateLimit
to the list of limits.
Examples found in repository?
examples/genesysgo.rs (lines 19-27)
11async fn main() {
12 let default_rpc = Arc::new(RpcClient::new(
13 "https://api.mainnet-beta.solana.com".to_string(),
14 ));
15 let genesysgo_rpc = Arc::new(RpcClient::new("<your-genesysgo-rpc-url>".to_string()));
16 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
17 SolanaClientRpc::new(genesysgo_rpc)
18 // Requests per second limit.
19 .add_limit(
20 SolanaClientRateLimit::new(
21 1000, /* 1 second */
22 1, /* 1 request per second */
23 1, /* all requests count the same */
24 )
25 // Ignore GetMultipleAccounts requests here to track them in the next limit.
26 .ignore_endpoint(RpcRequest::GetMultipleAccounts),
27 )
28 // Requests per second limit for GetMultipleAccounts.
29 .add_limit(
30 SolanaClientRateLimit::new(
31 60 * 1000, /* 1 minute */
32 6, /* 6 request per minute */
33 1, /* all requests count the same */
34 )
35 // Ignore all endpoints and include only GetMultipleAccounts requests here.
36 .ignores_all_endpoints()
37 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 1),
38 ),
39 );
40
41 let version = client.get_version().await.unwrap();
42
43 println!("Cluster version: {}", version.solana_core);
44}
More examples
examples/quicknode.rs (lines 20-47)
12async fn main() {
13 let default_rpc = Arc::new(RpcClient::new(
14 "https://api.mainnet-beta.solana.com".to_string(),
15 ));
16 let quicknode_rpc = Arc::new(RpcClient::new("<your-quicknode-rpc-url>".to_string()));
17 let client = SolanaClient::new_with_default(default_rpc).add_rpc(
18 SolanaClientRpc::new(quicknode_rpc)
19 // Credits / month limits.
20 .add_limit(
21 SolanaClientRateLimit::new(
22 30 * 24 * 60 * 60 * 1000, /* 30 days */
23 10_000_000, /* credits per month */
24 1, /* default cost in credits for endpoints */
25 )
26 // List of all endpoints whose credits are different than the default value.
27 .add_endpoint_amount(RpcRequest::GetAccountInfo, 2)
28 .add_endpoint_amount(RpcRequest::GetBlockTime, 2)
29 .add_endpoint_amount(RpcRequest::GetClusterNodes, 2)
30 .add_endpoint_amount(RpcRequest::GetBlock, 23)
31 .add_endpoint_amount(RpcRequest::GetEpochInfo, 2)
32 .add_endpoint_amount(RpcRequest::GetFirstAvailableBlock, 3)
33 .add_endpoint_amount(RpcRequest::GetHealth, 2)
34 .add_endpoint_amount(RpcRequest::GetHighestSnapshotSlot, 2)
35 .add_endpoint_amount(RpcRequest::GetInflationGovernor, 2)
36 .add_endpoint_amount(RpcRequest::GetLatestBlockhash, 2)
37 .add_endpoint_amount(RpcRequest::GetMinimumBalanceForRentExemption, 3)
38 .add_endpoint_amount(RpcRequest::GetProgramAccounts, 35)
39 .add_endpoint_amount(RpcRequest::GetRecentPerformanceSamples, 4)
40 .add_endpoint_amount(RpcRequest::GetSignaturesForAddress, 3)
41 .add_endpoint_amount(RpcRequest::GetTokenSupply, 2)
42 .add_endpoint_amount(RpcRequest::GetTransaction, 3)
43 .add_endpoint_amount(RpcRequest::GetVersion, 2)
44 .add_endpoint_amount(RpcRequest::SimulateTransaction, 4)
45 .add_endpoint_amount(RpcRequest::GetMultipleAccounts, 10)
46 .add_endpoint_amount(RpcRequest::GetLargestAccounts, 259),
47 )
48 // Requests / second limit.
49 .add_limit(SolanaClientRateLimit::new(
50 1000, /* 1 second */
51 25, /* 25 requests per second */
52 1, /* all requests count the same */
53 )),
54 );
55
56 let version = client.get_version().await.unwrap();
57
58 println!("Cluster version: {}", version.solana_core);
59}
Sourcepub fn execute_endpoint(&mut self, endpoint: RpcRequest) -> bool
pub fn execute_endpoint(&mut self, endpoint: RpcRequest) -> bool
Process the execution of a Solana RPC endpoint.
Sourcepub fn execute_endpoints(&mut self, endpoints: &[RpcRequest]) -> bool
pub fn execute_endpoints(&mut self, endpoints: &[RpcRequest]) -> bool
Process the execution of a Solana RPC endpoints.
Auto Trait Implementations§
impl Freeze for SolanaClientRpc
impl !RefUnwindSafe for SolanaClientRpc
impl Send for SolanaClientRpc
impl Sync for SolanaClientRpc
impl Unpin for SolanaClientRpc
impl !UnwindSafe for SolanaClientRpc
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more