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: support async calls for the rust crate #30

Merged
merged 4 commits into from
Apr 4, 2022
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
1 change: 1 addition & 0 deletions crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Utility library for launching NEAR sandbox environments.

[dependencies]
anyhow = "1"
async-process = "1.3.0"
binary-install = "0.0.2"
chrono = "0.4"
hex = "0.3"
Expand Down
11 changes: 6 additions & 5 deletions crate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::path::{Path, PathBuf};
use std::process::{Child, Command};

use anyhow::anyhow;
use async_process::{Child, Command};
use binary_install::Cache;
use chrono::Utc;
use std::path::{Path, PathBuf};

pub mod sync;

// The current version of the sandbox node we want to point to. This can be updated from
// time to time, but probably should be close to when a release is made.
Expand Down Expand Up @@ -96,10 +97,10 @@ pub fn ensure_sandbox_bin() -> anyhow::Result<PathBuf> {
}

pub fn run_with_options(options: &[&str]) -> anyhow::Result<Child> {
let bin_path = ensure_sandbox_bin()?;
let bin_path = crate::ensure_sandbox_bin()?;
Command::new(bin_path)
.args(options)
.envs(log_vars())
.envs(crate::log_vars())
.spawn()
.map_err(Into::into)
}
Expand Down
34 changes: 34 additions & 0 deletions crate/src/sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::path::Path;
use std::process::{Child, Command};

pub fn run_with_options(options: &[&str]) -> anyhow::Result<Child> {
let bin_path = crate::ensure_sandbox_bin()?;
Command::new(bin_path)
.args(options)
.envs(crate::log_vars())
.spawn()
.map_err(Into::into)
}

pub fn run(home_dir: impl AsRef<Path>, rpc_port: u16, network_port: u16) -> anyhow::Result<Child> {
let home_dir = home_dir.as_ref().to_str().unwrap();
run_with_options(&[
"--home",
home_dir,
"run",
"--rpc-addr",
&crate::local_addr(rpc_port),
"--network-addr",
&crate::local_addr(network_port),
])
}

pub fn init(home_dir: impl AsRef<Path>) -> anyhow::Result<Child> {
let bin_path = crate::ensure_sandbox_bin()?;
let home_dir = home_dir.as_ref().to_str().unwrap();
Command::new(bin_path)
.envs(crate::log_vars())
.args(&["--home", home_dir, "init"])
.spawn()
.map_err(Into::into)
}