Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions api/src/common/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,27 @@ where
self.fetch_from(&network).await
}

/// Fetch the queries from the default mainnet archival network configuration.
pub async fn fetch_from_mainnet_archival(
self,
) -> ResultWithMethod<Handler::Response, Query::Error> {
let network = NetworkConfig::mainnet_archival();
self.fetch_from(&network).await
}

/// Fetch the queries from the default testnet network configuration.
pub async fn fetch_from_testnet(self) -> ResultWithMethod<Handler::Response, Query::Error> {
let network = NetworkConfig::testnet();
self.fetch_from(&network).await
}

/// Fetch the queries from the default testnet archival network configuration.
pub async fn fetch_from_testnet_archival(
self,
) -> ResultWithMethod<Handler::Response, Query::Error> {
let network = NetworkConfig::testnet_archival();
self.fetch_from(&network).await
}
}

pub struct RpcBuilder<Query, Handler>
Expand Down Expand Up @@ -445,9 +461,25 @@ where
self.fetch_from(&network).await
}

/// Fetch the query from the default mainnet archival network configuration.
pub async fn fetch_from_mainnet_archival(
self,
) -> ResultWithMethod<Handler::Response, Query::Error> {
let network = NetworkConfig::mainnet_archival();
self.fetch_from(&network).await
}

/// Fetch the query from the default testnet network configuration.
pub async fn fetch_from_testnet(self) -> ResultWithMethod<Handler::Response, Query::Error> {
let network = NetworkConfig::testnet();
self.fetch_from(&network).await
}

/// Fetch the query from the default testnet archival network configuration.
pub async fn fetch_from_testnet_archival(
self,
) -> ResultWithMethod<Handler::Response, Query::Error> {
let network = NetworkConfig::testnet_archival();
self.fetch_from(&network).await
}
}
38 changes: 38 additions & 0 deletions api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ impl RPCEndpoint {
Self::new("https://free.rpc.fastnear.com".parse().unwrap())
}

/// Constructs default mainnet archival configuration.
pub fn mainnet_archival() -> Self {
Self::new("https://archival-rpc.mainnet.fastnear.com".parse().unwrap())
}

/// Constructs default testnet configuration.
pub fn testnet() -> Self {
Self::new("https://test.rpc.fastnear.com".parse().unwrap())
}

/// Constructs default testnet archival configuration.
pub fn testnet_archival() -> Self {
Self::new("https://archival-rpc.testnet.fastnear.com".parse().unwrap())
}

/// Set API key for the endpoint.
pub fn with_api_key(mut self, api_key: String) -> Self {
self.bearer_header = Some(format!("Bearer {api_key}"));
Expand Down Expand Up @@ -177,6 +187,20 @@ impl NetworkConfig {
}
}

/// Constructs default mainnet archival configuration.
pub fn mainnet_archival() -> Self {
Self {
network_name: "mainnet-archival".to_string(),
rpc_endpoints: vec![RPCEndpoint::mainnet_archival()],
linkdrop_account_id: Some("near".parse().unwrap()),
near_social_db_contract_account_id: Some("social.near".parse().unwrap()),
faucet_url: None,
meta_transaction_relayer_url: None,
fastnear_url: Some("https://api.fastnear.com/".parse().unwrap()),
staking_pools_factory_account_id: Some("poolv1.near".parse().unwrap()),
}
}

/// Constructs default testnet configuration.
pub fn testnet() -> Self {
Self {
Expand All @@ -191,6 +215,20 @@ impl NetworkConfig {
}
}

/// Constructs default testnet archival configuration.
pub fn testnet_archival() -> Self {
Self {
network_name: "testnet-archival".to_string(),
rpc_endpoints: vec![RPCEndpoint::testnet_archival()],
linkdrop_account_id: Some("testnet".parse().unwrap()),
near_social_db_contract_account_id: Some("v1.social08.testnet".parse().unwrap()),
faucet_url: Some("https://helper.nearprotocol.com/account".parse().unwrap()),
meta_transaction_relayer_url: None,
fastnear_url: None,
staking_pools_factory_account_id: Some("pool.f863973.m0".parse().unwrap()),
}
}

pub fn from_rpc_url(name: &str, rpc_url: Url) -> Self {
Self {
network_name: name.to_string(),
Expand Down