Skip to content

Commit

Permalink
chore: fixes near#398
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Dec 25, 2024
1 parent 1f11dea commit 69fb351
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
16 changes: 5 additions & 11 deletions workspaces/src/network/sandbox.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::convert::TryFrom;
use std::path::PathBuf;
use std::str::FromStr;

Expand Down Expand Up @@ -36,16 +37,7 @@ pub struct Sandbox {

impl Sandbox {
pub(crate) fn root_signer(&self) -> Result<InMemorySigner> {
match &self.server.validator_key {
ValidatorKey::HomeDir(home_dir) => {
let path = home_dir.join("validator_key.json");
InMemorySigner::from_file(&path)
}
ValidatorKey::Known(account_id, secret_key) => Ok(InMemorySigner::from_secret_key(
account_id.clone(),
secret_key.clone(),
)),
}
InMemorySigner::try_from(self.server.validator_key.clone())
}

pub(crate) fn registrar_signer(&self) -> Result<InMemorySigner> {
Expand Down Expand Up @@ -95,9 +87,11 @@ impl Sandbox {
// lockfiles as soon as possible.
server.unlock_lockfiles()?;

let root_id = InMemorySigner::try_from(server.validator_key.clone())?.account_id;

let info = Info {
name: build.name.into(),
root_id: AccountId::from_str("test.near").unwrap(),
root_id,
keystore_path: PathBuf::from(".near-credentials/sandbox/"),
rpc_url: url::Url::parse(&server.rpc_addr()).expect("url is hardcoded"),
};
Expand Down
2 changes: 1 addition & 1 deletion workspaces/src/network/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn init_home_dir_with_version(version: &str) -> Result<TempDir> {
Ok(home_dir)
}

#[derive(Debug)]
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ValidatorKey {
HomeDir(PathBuf),
Expand Down
16 changes: 16 additions & 0 deletions workspaces/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@ impl InMemorySigner {
}
}

impl TryFrom<crate::network::ValidatorKey> for InMemorySigner {
type Error = crate::error::Error;

fn try_from(value: crate::network::ValidatorKey) -> std::result::Result<Self, Self::Error> {
match value {
crate::network::ValidatorKey::HomeDir(home_dir) => {
let path = home_dir.join("validator_key.json");
Self::from_file(&path)
}
crate::network::ValidatorKey::Known(account_id, secret_key) => {
Ok(Self::from_secret_key(account_id, secret_key))
}
}
}
}

// type taken from near_primitives::hash::CryptoHash.
/// CryptoHash is type for storing the hash of a specific block.
#[derive(Copy, Clone, Default, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down

0 comments on commit 69fb351

Please sign in to comment.