Skip to content
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

feat: allow Worker<Betanet> creation #116

Merged
merged 4 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion workspaces/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ pub use types::account::{Account, AccountDetails, Contract};
pub use types::block::Block;
pub use types::{AccessKey, AccountId, BlockHeight, CryptoHash, InMemorySigner};
pub use worker::{
mainnet, mainnet_archival, sandbox, testnet, testnet_archival, with_mainnet,
betanet, mainnet, mainnet_archival, sandbox, testnet, testnet_archival, with_mainnet,
with_mainnet_archival, with_sandbox, with_testnet, with_testnet_archival, Worker,
};
50 changes: 50 additions & 0 deletions workspaces/src/network/betanet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::network::{Info, NetworkClient, NetworkInfo};
use crate::rpc::client::Client;
use std::path::PathBuf;

const RPC_URL: &str = "https://rpc.betanet.near.org";

/// Betanet related configuration for interacting with betanet. Look at
/// [`workspaces::betanet`] for how to spin up a [`Worker`] that can be
/// used to interact with betanet. Note that betanet account creation
/// is not currently supported, and these calls into creating a betanet
/// worker is meant for retrieving data and/or making queries only.
/// Also, note that betanet can be unstable and does not provide an
/// archival endpoint similiar to that of mainnet.
///
/// [`workspaces::betanet`]: crate::betanet
/// [`workspaces::betanet_archival`]: crate::betanet_archival
/// [`Worker`]: crate::Worker
pub struct Betanet {
client: Client,
info: Info,
}

impl Betanet {
pub(crate) async fn new() -> anyhow::Result<Self> {
let client = Client::new(RPC_URL.into());
client.wait_for_rpc().await?;

Ok(Self {
client,
info: Info {
name: "betanet".into(),
root_id: "near".parse().unwrap(),
keystore_path: PathBuf::from(".near-credentials/betanet/"),
rpc_url: RPC_URL.into(),
},
})
}
}

impl NetworkClient for Betanet {
fn client(&self) -> &Client {
&self.client
}
}

impl NetworkInfo for Betanet {
fn info(&self) -> &Info {
&self.info
}
}
2 changes: 2 additions & 0 deletions workspaces/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! Currently the builtin network types are [`Mainnet`], [`Testnet`], and [`Sandbox`].

mod betanet;
mod info;
mod mainnet;
mod sandbox;
Expand All @@ -11,6 +12,7 @@ pub(crate) mod variants;

pub(crate) use variants::DEV_ACCOUNT_SEED;

pub use self::betanet::Betanet;
pub use self::info::Info;
pub use self::mainnet::Mainnet;
pub use self::sandbox::Sandbox;
Expand Down
7 changes: 6 additions & 1 deletion workspaces/src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod impls;

use std::sync::Arc;

use crate::network::{Mainnet, Sandbox, Testnet};
use crate::network::{Betanet, Mainnet, Sandbox, Testnet};
use crate::Network;

/// The `Worker` type allows us to interact with any NEAR related networks, such
Expand Down Expand Up @@ -53,6 +53,11 @@ pub async fn mainnet_archival() -> anyhow::Result<Worker<Mainnet>> {
Ok(Worker::new(Mainnet::archival().await?))
}

/// Connect to the betanet network, and grab a [`Worker`] that can interact with it.
pub async fn betanet() -> anyhow::Result<Worker<Betanet>> {
ChaoticTempest marked this conversation as resolved.
Show resolved Hide resolved
Ok(Worker::new(Betanet::new().await?))
}

/// Run a locally scoped task where a [`sandbox`] instanced [`Worker`] is supplied.
pub async fn with_sandbox<F, T>(task: F) -> anyhow::Result<T::Output>
where
Expand Down