further simplfied path retrieval

This commit is contained in:
rachel-rose
2021-06-07 11:51:21 +02:00
parent c9796207d0
commit 1d54c62e2b
3 changed files with 9 additions and 26 deletions

View File

@@ -49,7 +49,7 @@ impl ProgramState for State {
fn is_valid_cashier_public_key(&self, _public: &jubjub::SubgroupPoint) -> bool {
// TODO
// Still needs to be tested
//let path = WalletDB::wallet_path();
let path = WalletDB::path("cashier.db");
//let connect = Connection::open(&path).expect("Failed to connect to database.");
//connect.execute(
// " SELECT key_public FROM cashier WHERE key_public IN (SELECT key_public)",

View File

@@ -12,55 +12,37 @@ impl RpcAdapter {
Arc::new(Self {})
}
pub async fn get_path(wallet: &str) -> Result<PathBuf> {
debug!(target: "adapter", "TEST PATH [START]");
let mut path = WalletDB::path().await.expect("Failed to get path");
debug!(target: "adapter", "TEST PATH {:?}", path);
path.push(wallet);
Ok(path)
}
pub async fn key_gen() -> Result<PathBuf> {
debug!(target: "adapter", "key_gen() [START]");
let path = Self::get_path("wallet.db")
.await
.expect("Failed to get path");
let path = WalletDB::path("wallet.db").await.expect("Failed to get path");
//WalletDB::key_gen(path).await?;
Ok(path)
}
pub async fn new_wallet() -> Result<()> {
debug!(target: "adapter", "new_wallet() [START]");
let path = Self::get_path("wallet.db")
.await
.expect("Failed to get path");
let path = WalletDB::path("wallet.db").await.expect("Failed to get path");
WalletDB::new(path).await?;
Ok(())
}
pub async fn new_cashier_wallet() -> Result<()> {
debug!(target: "adapter", "new_cashier_wallet() [START]");
let path = Self::get_path("cashier.db")
.await
.expect("Failed to get path");
let path = WalletDB::path("cashier.db").await.expect("Failed to get path");
WalletDB::new(path).await?;
Ok(())
}
pub async fn save_cash_key(pubkey: Vec<u8>) -> Result<()> {
debug!(target: "adapter", "save_cash_key() [START]");
let path = Self::get_path("cashier.db")
.await
.expect("Failed to get path");
let path = WalletDB::path("cashier.db").await.expect("Failed to get path");
WalletDB::save(path, pubkey).await?;
Ok(())
}
pub async fn save_key(pubkey: Vec<u8>) -> Result<()> {
debug!(target: "adapter", "save_key() [START]");
let path = Self::get_path("wallet.db")
.await
.expect("Failed to get path");
let path = WalletDB::path("wallet.db").await.expect("Failed to get path");
WalletDB::save(path, pubkey).await?;
Ok(())
}

View File

@@ -24,12 +24,13 @@ impl WalletDB {
// let privkey = serial::serialize(&secret);
// Ok(pubkey, privkey)
// }
pub async fn path() -> Result<PathBuf> {
let path = dirs::home_dir()
pub async fn path(wallet: &str) -> Result<PathBuf> {
let mut path = dirs::home_dir()
.expect("cannot find home directory.")
.as_path()
.join(".config/darkfi/");
debug!(target: "walletdb", "CREATE PATH {:?}", path);
path.push(wallet);
Ok(path)
}