mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
use join_config_path function for both sqlite and rocksdb databases
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use async_std::sync::Arc;
|
||||
//use drk::rpc::
|
||||
use drk::rpc::adapter::{RpcAdapter};
|
||||
use drk::rpc::adapter::RpcAdapter;
|
||||
use drk::rpc::jsonserver;
|
||||
//use drk::rpc::options::ProgramOptions;
|
||||
use rand::rngs::OsRng;
|
||||
@@ -20,6 +20,7 @@ use drk::service::{ClientProgramOptions, GatewayClient, GatewaySlabsSubscriber};
|
||||
use drk::state::{state_transition, ProgramState, StateUpdate};
|
||||
use drk::wallet::{WalletDB, WalletPtr};
|
||||
use drk::{tx, Result};
|
||||
use drk::util::join_config_path;
|
||||
use rusqlite::Connection;
|
||||
|
||||
use async_executor::Executor;
|
||||
@@ -160,9 +161,10 @@ pub async fn subscribe(gateway_slabs_sub: GatewaySlabsSubscriber, mut state: Sta
|
||||
async fn start(executor: Arc<Executor<'_>>, options: Arc<ClientProgramOptions>) -> Result<()> {
|
||||
let connect_addr: SocketAddr = setup_addr(options.connect_addr, "127.0.0.1:3333".parse()?);
|
||||
let sub_addr: SocketAddr = setup_addr(options.sub_addr, "127.0.0.1:4444".parse()?);
|
||||
let database_path = options.database_path.as_path();
|
||||
let database_path = options.database_path.clone();
|
||||
|
||||
let rocks = Rocks::new(database_path)?;
|
||||
let database_path = join_config_path(&(*database_path))?;
|
||||
let rocks = Rocks::new(&database_path)?;
|
||||
|
||||
let slabstore = RocksColumn::<columns::Slabs>::new(rocks.clone());
|
||||
|
||||
@@ -285,10 +287,12 @@ mod test {
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use drk::blockchain::{rocks::columns, Rocks, RocksColumn, Slab};
|
||||
use drk::service::{GatewayClient, GatewaySlabsSubscriber};
|
||||
use drk::util::join_config_path;
|
||||
|
||||
use async_executor::Executor;
|
||||
use easy_parallel::Parallel;
|
||||
@@ -343,8 +347,9 @@ mod test {
|
||||
let rnd: u32 = rng.gen();
|
||||
let path_str = format!("database_{}.db", rnd);
|
||||
|
||||
let database_path = Path::new(path_str.as_str());
|
||||
let rocks = Rocks::new(database_path.clone()).unwrap();
|
||||
let database_path = PathBuf::from(path_str.as_str());
|
||||
let database_path = join_config_path(&database_path).unwrap();
|
||||
let rocks = Rocks::new(&database_path).unwrap();
|
||||
|
||||
let slabstore = RocksColumn::<columns::Slabs>::new(rocks.clone());
|
||||
|
||||
@@ -390,8 +395,9 @@ mod test {
|
||||
let rnd: u32 = rng.gen();
|
||||
let path_str = format!("database_{}.db", rnd);
|
||||
|
||||
let database_path = Path::new(path_str.as_str());
|
||||
let rocks = Rocks::new(database_path.clone()).unwrap();
|
||||
let database_path = PathBuf::from(path_str.as_str());
|
||||
let database_path = join_config_path(&database_path).unwrap();
|
||||
let rocks = Rocks::new(&database_path).unwrap();
|
||||
|
||||
let slabstore = RocksColumn::<columns::Slabs>::new(rocks.clone());
|
||||
|
||||
@@ -401,7 +407,7 @@ mod test {
|
||||
// start gateway client
|
||||
client.start().await.unwrap();
|
||||
|
||||
let slab = Slab::new( rnd.to_le_bytes().to_vec());
|
||||
let slab = Slab::new(rnd.to_le_bytes().to_vec());
|
||||
|
||||
client.put_slab(slab.clone()).await.unwrap();
|
||||
client.put_slab(slab.clone()).await.unwrap();
|
||||
@@ -435,8 +441,9 @@ mod test {
|
||||
let rnd: u32 = rng.gen();
|
||||
let path_str = format!("database_{}.db", rnd);
|
||||
|
||||
let database_path = Path::new(path_str.as_str());
|
||||
let rocks = Rocks::new(database_path.clone()).unwrap();
|
||||
let database_path = PathBuf::from(path_str.as_str());
|
||||
let database_path = join_config_path(&database_path).unwrap();
|
||||
let rocks = Rocks::new(&database_path).unwrap();
|
||||
|
||||
let slabstore = RocksColumn::<columns::Slabs>::new(rocks.clone());
|
||||
|
||||
@@ -485,8 +492,9 @@ mod test {
|
||||
let rnd: u32 = rng.gen();
|
||||
let path_str = format!("database_{}.db", rnd);
|
||||
|
||||
let database_path = Path::new(path_str.as_str());
|
||||
let rocks = Rocks::new(database_path.clone()).unwrap();
|
||||
let database_path = PathBuf::from(path_str.as_str());
|
||||
let database_path = join_config_path(&database_path).unwrap();
|
||||
let rocks = Rocks::new(&database_path).unwrap();
|
||||
|
||||
let slabstore = RocksColumn::<columns::Slabs>::new(rocks.clone());
|
||||
|
||||
@@ -530,8 +538,9 @@ mod test {
|
||||
let rnd: u32 = rng.gen();
|
||||
let path_str = format!("database_{}.db", rnd);
|
||||
|
||||
let database_path = Path::new(path_str.as_str());
|
||||
let rocks = Rocks::new(database_path.clone()).unwrap();
|
||||
let database_path = PathBuf::from(path_str.as_str());
|
||||
let database_path = join_config_path(&database_path).unwrap();
|
||||
let rocks = Rocks::new(&database_path).unwrap();
|
||||
|
||||
let slabstore = RocksColumn::<columns::Slabs>::new(rocks.clone());
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::sync::Arc;
|
||||
use drk::blockchain::{rocks::columns, Rocks, RocksColumn};
|
||||
use drk::service::{GatewayService, ProgramOptions};
|
||||
use drk::Result;
|
||||
use drk::util::join_config_path;
|
||||
|
||||
extern crate clap;
|
||||
use async_executor::Executor;
|
||||
@@ -19,9 +20,10 @@ fn setup_addr(address: Option<SocketAddr>, default: SocketAddr) -> SocketAddr {
|
||||
async fn start(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<()> {
|
||||
let accept_addr: SocketAddr = setup_addr(options.accept_addr, "127.0.0.1:3333".parse()?);
|
||||
let pub_addr: SocketAddr = setup_addr(options.pub_addr, "127.0.0.1:4444".parse()?);
|
||||
let database_path = options.database_path.as_path();
|
||||
let database_path = options.database_path.clone();
|
||||
|
||||
let rocks = Rocks::new(database_path)?;
|
||||
let database_path = join_config_path(&(*database_path))?;
|
||||
let rocks = Rocks::new(&database_path)?;
|
||||
let rocks_slabstore_column = RocksColumn::<columns::Slabs>::new(rocks);
|
||||
|
||||
let gateway = GatewayService::new(accept_addr, pub_addr, rocks_slabstore_column)?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use async_std::sync::Arc;
|
||||
use std::marker::PhantomData;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::serial::{deserialize, serialize, Decodable, Encodable};
|
||||
use crate::{Error, Result};
|
||||
@@ -39,7 +39,7 @@ pub struct Rocks {
|
||||
}
|
||||
|
||||
impl Rocks {
|
||||
pub fn new(path: &Path) -> Result<Arc<Self>> {
|
||||
pub fn new(path: &PathBuf) -> Result<Arc<Self>> {
|
||||
// column family options
|
||||
let cf_opts = Options::default();
|
||||
|
||||
@@ -99,7 +99,7 @@ impl Rocks {
|
||||
self.db.iterator_cf(cf, iterator_mode)
|
||||
}
|
||||
|
||||
pub fn destroy(path: &Path) -> Result<()> {
|
||||
pub fn destroy(path: &PathBuf) -> Result<()> {
|
||||
DB::destroy(&Options::default(), path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
use crate::crypto::{coin::Coin, merkle::IncrementalWitness, merkle_node::MerkleNode, note::Note};
|
||||
use crate::serial;
|
||||
use crate::serial::{deserialize, serialize, Decodable, Encodable};
|
||||
use crate::Error;
|
||||
use crate::Result;
|
||||
use crate::util::join_config_path;
|
||||
|
||||
use async_std::sync::{Arc, Mutex};
|
||||
use ff::Field;
|
||||
use log::*;
|
||||
use rand::rngs::OsRng;
|
||||
use rusqlite::{named_params, Connection};
|
||||
use std::path::{PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub type WalletPtr = Arc<WalletDB>;
|
||||
|
||||
@@ -26,7 +27,7 @@ pub struct WalletDB {
|
||||
impl WalletDB {
|
||||
pub fn new(wallet: &str) -> Result<Self> {
|
||||
debug!(target: "walletdb", "new() Constructor called");
|
||||
let path = Self::create_path(wallet)?;
|
||||
let path = join_config_path(&PathBuf::from(wallet))?;
|
||||
let cashier_secret = jubjub::Fr::random(&mut OsRng);
|
||||
let secret = jubjub::Fr::random(&mut OsRng);
|
||||
let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
|
||||
@@ -88,15 +89,7 @@ impl WalletDB {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_path(wallet: &str) -> Result<PathBuf> {
|
||||
let mut path = dirs::home_dir()
|
||||
.ok_or(Error::PathNotFound)?
|
||||
.as_path()
|
||||
.join(".config/darkfi/");
|
||||
path.push(wallet);
|
||||
debug!(target: "walletdb", "CREATE PATH {:?}", path);
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
|
||||
pub async fn key_gen(&self) -> (Vec<u8>, Vec<u8>) {
|
||||
debug!(target: "key_gen", "Generating keys...");
|
||||
|
||||
Reference in New Issue
Block a user