diff --git a/Cargo.toml b/Cargo.toml index 8297c27..547cf39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,3 +60,4 @@ csv = "1.2" url = "2" num-traits = "0.2" tonic = { version = "0.10", features = ["tls-webpki-roots", "tls"] } +toml = "0.7" diff --git a/src/opt/serve.rs b/src/opt/serve.rs index 9deda40..7c73bfc 100644 --- a/src/opt/serve.rs +++ b/src/opt/serve.rs @@ -99,11 +99,11 @@ impl Serve { std::fs::create_dir_all(&data_dir).context("can create data dir")?; let view_file = data_dir.clone().join("pcli-view.sqlite"); - let custody_file = data_dir.clone().join("custody.json"); + let pcli_config_file = data_dir.clone().join("config.toml"); // Build a custody service... - let wallet = - Wallet::load(custody_file).context("Failed to load wallet from local custody file")?; + let wallet = Wallet::load(pcli_config_file) + .context("Failed to load wallet from local custody file")?; let soft_kms = SoftKms::new(wallet.spend_key.clone().into()); let custody = CustodyProtocolServiceClient::new(CustodyProtocolServiceServer::new(soft_kms)); diff --git a/src/wallet.rs b/src/wallet.rs index 1f6d722..990dad4 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -2,6 +2,7 @@ use anyhow::Context; use penumbra_keys::keys::SpendKey; use serde::{Deserialize, Serialize}; use std::str::FromStr; +use toml; /// A wallet file storing a single spend authority. #[derive(Debug, Clone, Serialize, Deserialize)] @@ -12,13 +13,16 @@ pub struct Wallet { impl Wallet { /// Read the wallet data from the provided path. pub fn load(path: impl AsRef) -> anyhow::Result { - let custody_json: serde_json::Value = - serde_json::from_slice(std::fs::read(path)?.as_slice())?; - let sk_str = match custody_json["spend_key"].as_str() { + let config_contents = std::fs::read_to_string(&path).context( + "pcli config file not found. hint: run 'pcli init soft-kms import-phrase' to import key material", + )?; + let config_toml: toml::Table = toml::from_str(&config_contents)?; + + let sk_str = match config_toml["custody"]["spend_key"].as_str() { Some(s) => s, None => { return Err(anyhow::anyhow!( - "'spend_key' field not found in custody JSON file" + "'spend_key' field not found in custody TOML file" )) } };