near_workspaces/network/
custom.rs1use crate::network::{Info, NetworkClient, NetworkInfo};
2use crate::result::Result;
3use crate::rpc::client::Client;
4use std::path::PathBuf;
5
6use super::builder::{FromNetworkBuilder, NetworkBuilder};
7
8pub struct Custom {
10 client: Client,
11 info: Info,
12}
13
14#[async_trait::async_trait]
15impl FromNetworkBuilder for Custom {
16 async fn from_builder<'a>(build: NetworkBuilder<'a, Self>) -> Result<Self> {
17 let rpc_url = build
18 .rpc_addr
19 .expect("rpc address should be provided for custom network");
20 let client = Client::new(&rpc_url, build.api_key)?;
21 client.wait_for_rpc().await?;
22
23 Ok(Self {
24 client,
25 info: Info {
26 name: build.name.into(),
27 root_id: "near".parse().unwrap(),
28 keystore_path: PathBuf::from(".near-credentials/mainnet/"),
29 rpc_url: url::Url::parse(&rpc_url).expect("custom provided url should be valid"),
30 },
31 })
32 }
33}
34
35impl std::fmt::Debug for Custom {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 f.debug_struct("Custom")
38 .field("root_id", &self.info.root_id)
39 .field("rpc_url", &self.info.rpc_url)
40 .finish()
41 }
42}
43
44impl NetworkClient for Custom {
45 fn client(&self) -> &Client {
46 &self.client
47 }
48}
49
50impl NetworkInfo for Custom {
51 fn info(&self) -> &Info {
52 &self.info
53 }
54}