-
Notifications
You must be signed in to change notification settings - Fork 4
feat: hard-code SOL RPC providers #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
efb35bc
XC-286: Add relevant rpc_client types
lpahlavi c3b14c7
XC-286: Return hard-coded providers
lpahlavi 235509a
XC-286: Remove unused dependencies
lpahlavi 382b930
XC-286: Add missing documentation and update candid file
lpahlavi 67130a7
XC-286: Fix int tests
lpahlavi ad1c96f
XC-286: Fix int tests
lpahlavi be707d8
XC-286: Fix query methods name
lpahlavi dd39aae
XC-286: Add Ankr, Alchemy and PublicNodes providers
lpahlavi 0df7fa9
XC-286: Clippy
lpahlavi 9d4e0d4
XC-286: Incorporate review feedback
lpahlavi c74d454
XC-286: Clippy
lpahlavi 73a42c0
XC-286: Remove unused method
lpahlavi 56147e4
XC-286: Define providers in thread_local!
lpahlavi 7d4f13d
XC-286: Change providers to array instead of vector
lpahlavi 86d1af8
XC-286: Use .to_string() instead of String::from()
lpahlavi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,43 @@ | ||
| type DummyRequest = record {input : text}; | ||
| type DummyResponse = record {output : text}; | ||
|
|
||
| type Provider = record { | ||
| providerId : ProviderId; | ||
| cluster : SolanaCluster; | ||
| access : RpcAccess; | ||
| alias : opt RpcService; | ||
| }; | ||
| type ProviderId = text; | ||
| type SolanaCluster = variant { | ||
| Mainnet; | ||
| Devnet; | ||
| Testnet; | ||
| }; | ||
| type RpcAccess = variant { | ||
| Authenticated : record { | ||
| auth : RpcAuth; | ||
| publicUrl : opt text; | ||
| }; | ||
| Unauthenticated : record { | ||
| publicUrl : text; | ||
| }; | ||
| }; | ||
| type RpcAuth = variant { | ||
| BearerToken : record { url : text }; | ||
| UrlParameter : record { urlPattern : text }; | ||
| }; | ||
| type RpcService = variant { | ||
| Provider : ProviderId; | ||
| // TODO: Custom : RpcApi; | ||
| SolMainnet : SolMainnetService; | ||
| SolDevnet : SolDevnetService; | ||
| }; | ||
| type SolMainnetService = variant { | ||
| Alchemy; | ||
| Ankr; | ||
| PublicNode; | ||
| }; | ||
| type SolDevnetService = variant { | ||
| Alchemy; | ||
| Ankr; | ||
| }; | ||
| service : { | ||
| greet: (DummyRequest) -> (DummyResponse) query; | ||
| } | ||
| getProviders : () -> (vec Provider) query; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub const API_KEY_REPLACE_STRING: &str = "{API_KEY}"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
|
|
||
| pub mod constants; | ||
| pub mod providers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #[cfg(test)] | ||
| mod tests; | ||
|
|
||
| use sol_rpc_types::{Provider, ProviderId, RpcAccess, RpcAuth}; | ||
| use sol_rpc_types::{RpcService, SolDevnetService, SolMainnetService, SolanaCluster}; | ||
| use std::collections::HashMap; | ||
|
|
||
| thread_local! { | ||
| pub static PROVIDERS: [Provider; 5] = [ | ||
| Provider { | ||
| provider_id: "alchemy-mainnet".to_string(), | ||
| cluster: SolanaCluster::Mainnet, | ||
| access: RpcAccess::Authenticated { | ||
| auth: RpcAuth::BearerToken { | ||
| url: "https://solana-mainnet.g.alchemy.com/v2".to_string(), | ||
| }, | ||
| public_url: Some("https://solana-mainnet.g.alchemy.com/v2/demo".to_string()), | ||
| }, | ||
| alias: Some(RpcService::SolMainnet(SolMainnetService::Alchemy)), | ||
| }, | ||
| Provider { | ||
| provider_id: "alchemy-devnet".to_string(), | ||
| cluster: SolanaCluster::Devnet, | ||
| access: RpcAccess::Authenticated { | ||
| auth: RpcAuth::BearerToken { | ||
| url: "https://solana-devnet.g.alchemy.com/v2".to_string(), | ||
| }, | ||
| public_url: Some("https://solana-devnet.g.alchemy.com/v2/demo".to_string()), | ||
| }, | ||
| alias: Some(RpcService::SolDevnet(SolDevnetService::Alchemy)), | ||
| }, | ||
| Provider { | ||
| provider_id: "ankr-mainnet".to_string(), | ||
| cluster: SolanaCluster::Mainnet, | ||
| access: RpcAccess::Authenticated { | ||
| auth: RpcAuth::UrlParameter { | ||
| url_pattern: "https://rpc.ankr.com/solana/{API_KEY}".to_string(), | ||
| }, | ||
| public_url: None, | ||
| }, | ||
| alias: Some(RpcService::SolMainnet(SolMainnetService::Ankr)), | ||
| }, | ||
| Provider { | ||
| provider_id: "ankr-devnet".to_string(), | ||
| cluster: SolanaCluster::Devnet, | ||
| access: RpcAccess::Authenticated { | ||
| auth: RpcAuth::UrlParameter { | ||
| url_pattern: "https://rpc.ankr.com/solana_devnet/{API_KEY}".to_string(), | ||
| }, | ||
| public_url: Some("https://rpc.ankr.com/solana_devnet/".to_string()), | ||
| }, | ||
| alias: Some(RpcService::SolDevnet(SolDevnetService::Ankr)), | ||
| }, | ||
| Provider { | ||
| provider_id: "publicnode-mainnet".to_string(), | ||
| cluster: SolanaCluster::Mainnet, | ||
| access: RpcAccess::Unauthenticated { | ||
| public_url: "https://solana-rpc.publicnode.com".to_string(), | ||
| }, | ||
| alias: Some(RpcService::SolMainnet(SolMainnetService::PublicNode)), | ||
| }, | ||
| ]; | ||
|
|
||
| pub static PROVIDER_MAP: HashMap<ProviderId, Provider> = PROVIDERS.with(|providers| { | ||
| providers | ||
| .iter() | ||
| .map(|provider| (provider.provider_id.clone(), provider.clone())) | ||
| .collect() | ||
| }); | ||
|
|
||
| pub static SERVICE_PROVIDER_MAP: HashMap<RpcService, ProviderId> = PROVIDERS.with(|providers| { | ||
| providers | ||
| .iter() | ||
| .filter_map(|provider| Some((provider.alias.clone()?, provider.provider_id.clone()))) | ||
| .collect() | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use super::{PROVIDERS, SERVICE_PROVIDER_MAP}; | ||
| use crate::constants::API_KEY_REPLACE_STRING; | ||
| use sol_rpc_types::{Provider, RpcAccess, RpcAuth}; | ||
| use std::collections::{HashMap, HashSet}; | ||
|
|
||
| #[test] | ||
| fn test_rpc_provider_url_patterns() { | ||
| PROVIDERS.with(|providers| { | ||
| for provider in providers { | ||
| fn assert_not_url_pattern(url: &str, provider: &Provider) { | ||
| assert!( | ||
| !url.contains(API_KEY_REPLACE_STRING), | ||
| "Unexpected API key in URL for provider: {}", | ||
| provider.provider_id | ||
| ) | ||
| } | ||
| fn assert_url_pattern(url: &str, provider: &Provider) { | ||
| assert!( | ||
| url.contains(API_KEY_REPLACE_STRING), | ||
| "Missing API key in URL pattern for provider: {}", | ||
| provider.provider_id | ||
| ) | ||
| } | ||
| match &provider.access { | ||
| RpcAccess::Authenticated { auth, public_url } => { | ||
| match auth { | ||
| RpcAuth::BearerToken { url } => assert_not_url_pattern(url, provider), | ||
| RpcAuth::UrlParameter { url_pattern } => { | ||
| assert_url_pattern(url_pattern, provider) | ||
| } | ||
| } | ||
| if let Some(public_url) = public_url { | ||
| assert_not_url_pattern(public_url, provider); | ||
| } | ||
| } | ||
| RpcAccess::Unauthenticated { public_url } => { | ||
| assert_not_url_pattern(public_url, provider); | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_no_duplicate_service_providers() { | ||
| SERVICE_PROVIDER_MAP.with(|map| { | ||
| assert_eq!( | ||
| map.len(), | ||
| map.keys().collect::<HashSet<_>>().len(), | ||
| "Duplicate service in mapping" | ||
| ); | ||
| assert_eq!( | ||
| map.len(), | ||
| map.values().collect::<HashSet<_>>().len(), | ||
| "Duplicate provider in mapping" | ||
| ); | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_service_provider_coverage() { | ||
| SERVICE_PROVIDER_MAP.with(|map| { | ||
| let inverse_map: HashMap<_, _> = map.iter().map(|(k, v)| (v, k)).collect(); | ||
| PROVIDERS.with(|providers| { | ||
| for provider in providers { | ||
| assert!( | ||
| inverse_map.contains_key(&provider.provider_id), | ||
| "Missing service mapping for provider with ID: {}", | ||
| provider.provider_id, | ||
| ); | ||
| } | ||
| }) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.