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/// [`workspaces::betanet_archival`]: crate::betanet_archival
23/// [`Worker`]: crate::Worker
24pub struct Betanet {
25    client: Client,
26    info: Info,
27}
28
29#[async_trait::async_trait]
30impl FromNetworkBuilder for Betanet {
31    async fn from_builder<'a>(build: NetworkBuilder<'a, Self>) -> crate::result::Result<Self> {
32        let rpc_url = build.rpc_addr.unwrap_or_else(|| RPC_URL.into());
33        let client = Client::new(&rpc_url, build.api_key)?;
34        client.wait_for_rpc().await?;
35
36        Ok(Self {
37            client,
38            info: Info {
39                name: build.name.into(),
40                root_id: "near".parse().unwrap(),
41                keystore_path: PathBuf::from(".near-credentials/betanet/"),
42                rpc_url: Url::parse(&rpc_url).expect("url is hardcoded"),
43            },
44        })
45    }
46}
47
48impl NetworkClient for Betanet {
49    fn client(&self) -> &Client {
50        &self.client
51    }
52}
53
54impl NetworkInfo for Betanet {
55    fn info(&self) -> &Info {
56        &self.info
57    }
58}