From 69fb3517129ab479d923adde99759148978cf797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= Date: Wed, 25 Dec 2024 18:02:11 +0200 Subject: [PATCH] chore: fixes #398 --- workspaces/src/network/sandbox.rs | 16 +++++----------- workspaces/src/network/server.rs | 2 +- workspaces/src/types/mod.rs | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/workspaces/src/network/sandbox.rs b/workspaces/src/network/sandbox.rs index 9c975261..9e675dd2 100644 --- a/workspaces/src/network/sandbox.rs +++ b/workspaces/src/network/sandbox.rs @@ -1,3 +1,4 @@ +use std::convert::TryFrom; use std::path::PathBuf; use std::str::FromStr; @@ -36,16 +37,7 @@ pub struct Sandbox { impl Sandbox { pub(crate) fn root_signer(&self) -> Result { - 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 { @@ -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"), }; diff --git a/workspaces/src/network/server.rs b/workspaces/src/network/server.rs index 0693c3a4..94f50fdc 100644 --- a/workspaces/src/network/server.rs +++ b/workspaces/src/network/server.rs @@ -75,7 +75,7 @@ async fn init_home_dir_with_version(version: &str) -> Result { Ok(home_dir) } -#[derive(Debug)] +#[derive(Debug, Clone)] #[non_exhaustive] pub enum ValidatorKey { HomeDir(PathBuf), diff --git a/workspaces/src/types/mod.rs b/workspaces/src/types/mod.rs index c04fd647..bbf624c4 100644 --- a/workspaces/src/types/mod.rs +++ b/workspaces/src/types/mod.rs @@ -305,6 +305,22 @@ impl InMemorySigner { } } +impl TryFrom for InMemorySigner { + type Error = crate::error::Error; + + fn try_from(value: crate::network::ValidatorKey) -> std::result::Result { + 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)]