near_workspaces/network/
betanet.rs

1use url::Url;
2
3use crate::network::builder::{FromNetworkBuilder, NetworkBuilder};
4use crate::network::{Info, NetworkClient, NetworkInfo};
5use crate::rpc::client::Client;
6
7use std::path::PathBuf;
8
9/// URL to the betanet RPC node provided by near.org.
10pub const RPC_URL: &str = "https://rpc.betanet.near.org";
11
12/// Betanet related configuration for interacting with betanet.
13///
14/// Look at [`workspaces::betanet`] for how to spin up a [`Worker`] that can be
15/// used to interact with betanet. Note that betanet account creation
16/// is not currently supported, and these calls into creating a betanet
17/// worker is meant for retrieving data and/or making queries only.
18/// Also, note that betanet can be unstable and does not provide an
19/// archival endpoint similar to that of mainnet.
20///
21/// [`workspaces::betanet`]: crate::betanet
22/// [`Worker`]: crate::Worker
23pub struct Betanet {
24    client: Client,
25    info: Info,
26}
27
28#[async_trait::async_trait]
29impl FromNetworkBuilder for Betanet {
30    async fn from_builder<'a>(build: NetworkBuilder<'a, Self>) -> crate::result::Result<Self> {
31        let rpc_url = build.rpc_addr.unwrap_or_else(|| RPC_URL.into());
32        let client = Client::new(&rpc_url, build.api_key)?;
33        client.wait_for_rpc().await?;
34
35        Ok(Self {
36            client,
37            info: Info {
38                name: build.name.into(),
39                root_id: "near".parse().unwrap(),
40                keystore_path: PathBuf::from(".near-credentials/betanet/"),
41                rpc_url: Url::parse(&rpc_url).expect("url is hardcoded"),
42            },
43        })
44    }
45}
46
47impl NetworkClient for Betanet {
48    fn client(&self) -> &Client {
49        &self.client
50    }
51}
52
53impl NetworkInfo for Betanet {
54    fn info(&self) -> &Info {
55        &self.info
56    }
57}