rust-sdk: make new_from_dir return result

This commit is contained in:
Jon Häggblad
2023-01-10 23:28:26 +01:00
parent 751e3ccd27
commit df3d478caa
4 changed files with 37 additions and 15 deletions
Generated
+21 -10
View File
@@ -686,7 +686,7 @@ dependencies = [
[[package]]
name = "client-core"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"async-trait",
"client-connections",
@@ -1788,7 +1788,7 @@ dependencies = [
[[package]]
name = "explorer-api"
version = "1.1.1"
version = "1.1.2"
dependencies = [
"chrono",
"clap 4.0.26",
@@ -2085,6 +2085,7 @@ dependencies = [
"nymsphinx",
"pemstore",
"rand 0.7.3",
"serde",
"task",
"thiserror",
"tokio",
@@ -3233,7 +3234,7 @@ dependencies = [
[[package]]
name = "nym-api"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"anyhow",
"async-trait",
@@ -3329,7 +3330,7 @@ dependencies = [
[[package]]
name = "nym-cli"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"anyhow",
"base64",
@@ -3360,14 +3361,18 @@ dependencies = [
"bs58",
"cfg-if 1.0.0",
"clap 4.0.26",
"coconut-bandwidth-contract-common",
"coconut-dkg-common",
"comfy-table",
"cosmrs",
"cosmwasm-std",
"cw-utils",
"handlebars",
"humantime-serde",
"k256",
"log",
"mixnet-contract-common",
"multisig-contract-common",
"network-defaults",
"rand 0.6.5",
"serde",
@@ -3383,7 +3388,7 @@ dependencies = [
[[package]]
name = "nym-client"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"build-information",
"clap 4.0.26",
@@ -3423,10 +3428,11 @@ dependencies = [
[[package]]
name = "nym-gateway"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"anyhow",
"async-trait",
"atty",
"bip39",
"bs58",
"build-information",
@@ -3450,12 +3456,14 @@ dependencies = [
"mixnode-common",
"network-defaults",
"nym-api-requests",
"nym-types",
"nymsphinx",
"once_cell",
"pemstore",
"pretty_env_logger",
"rand 0.7.3",
"serde",
"serde_json",
"sqlx 0.5.11",
"statistics-common",
"subtle-encoding",
@@ -3471,9 +3479,10 @@ dependencies = [
[[package]]
name = "nym-mixnode"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"anyhow",
"atty",
"bs58",
"build-information",
"clap 4.0.26",
@@ -3492,6 +3501,7 @@ dependencies = [
"mixnet-client",
"mixnode-common",
"nonexhaustive-delayqueue",
"nym-types",
"nymsphinx",
"nymsphinx-params",
"nymsphinx-types",
@@ -3500,6 +3510,7 @@ dependencies = [
"rand 0.7.3",
"rocket",
"serde",
"serde_json",
"sysinfo",
"task",
"tokio",
@@ -3513,7 +3524,7 @@ dependencies = [
[[package]]
name = "nym-network-requester"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"async-trait",
"clap 4.0.26",
@@ -3545,7 +3556,7 @@ dependencies = [
[[package]]
name = "nym-network-statistics"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"dirs",
"log",
@@ -3601,7 +3612,7 @@ dependencies = [
[[package]]
name = "nym-socks5-client"
version = "1.1.4"
version = "1.1.5"
dependencies = [
"build-information",
"clap 4.0.26",
+1 -1
View File
@@ -11,7 +11,7 @@ async fn main() {
// Setting `KeyMode::Keep` will use existing keys, and existing config, if there is one.
// Regardles of `user_chosen_gateway`.
let keys = mixnet::StoragePaths::new_from_dir(mixnet::KeyMode::Keep, &config_dir);
let keys = mixnet::StoragePaths::new_from_dir(mixnet::KeyMode::Keep, &config_dir).unwrap();
// Provide key paths for the client to read/write keys to.
let client = mixnet::ClientBuilder::new(None, Some(keys)).unwrap();
+6
View File
@@ -1,3 +1,5 @@
use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("i/o error: {0}")]
@@ -8,12 +10,16 @@ pub enum Error {
TomlDeserializationError(#[from] toml::de::Error),
#[error(transparent)]
ClientCoreError(#[from] client_core::error::ClientCoreError),
#[error("key file encountered that we don't want to overwrite")]
DontOverwrite,
#[error("shared gateway key file encountered that we don't want to overwrite")]
DontOverwriteGatewayKey,
#[error("no gateway config available for writing")]
GatewayNotAvailableForWriting,
#[error("expected to received a directory, received: {0}")]
ExpectedDirectory(PathBuf),
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
+9 -4
View File
@@ -1,6 +1,8 @@
use client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
use std::path::{Path, PathBuf};
use crate::error::{Error, Result};
#[derive(Clone, Debug)]
pub enum KeyMode {
/// Use existing key files if they exists, otherwise create new ones.
@@ -58,9 +60,12 @@ pub struct StoragePaths {
}
impl StoragePaths {
pub fn new_from_dir(operating_mode: KeyMode, dir: &Path) -> Self {
assert!(!dir.is_file(), "WIP");
Self {
pub fn new_from_dir(operating_mode: KeyMode, dir: &Path) -> Result<Self> {
if !dir.is_file() {
return Err(Error::ExpectedDirectory(dir.to_owned()))
}
Ok(Self {
// These filenames were chosen to match the ones we use in `nym-client`. Consider
// changing the defaults
operating_mode,
@@ -73,7 +78,7 @@ impl StoragePaths {
gateway_endpoint_config: dir.join("gateway_endpoint_config.toml"),
credential_database_path: dir.join("db.sqlite"),
reply_surb_database_path: dir.join("persistent_reply_store.sqlite"),
}
})
}
}