Skip to content

Commit

Permalink
feat: update to pcli config.toml file
Browse files Browse the repository at this point in the history
  • Loading branch information
conorsch committed Nov 17, 2023
1 parent b2e70b4 commit 9858c71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions src/opt/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 8 additions & 4 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -12,13 +13,16 @@ pub struct Wallet {
impl Wallet {
/// Read the wallet data from the provided path.
pub fn load(path: impl AsRef<std::path::Path>) -> anyhow::Result<Self> {
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"
))
}
};
Expand Down

0 comments on commit 9858c71

Please sign in to comment.