add and pass needed config params to cashierd

This commit is contained in:
ghassmo
2021-09-01 15:46:29 +03:00
parent 13519a7302
commit a362e6aff5
3 changed files with 58 additions and 32 deletions

View File

@@ -6,7 +6,7 @@ use std::{path::Path, path::PathBuf};
use drk::cli::{CashierdCli, CashierdConfig, Config};
use drk::service::CashierService;
use drk::util::join_config_path;
use drk::wallet::CashierDb;
use drk::wallet::{WalletDb, CashierDb};
use drk::{Error, Result};
use log::*;
@@ -21,13 +21,13 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<CashierdConfig>) -> Resu
let btc_endpoint: String = config.btc_endpoint.clone();
let database_path = config.database_path.clone();
let database_path = config.client_database_path.clone();
let database_path = join_config_path(&PathBuf::from(database_path))?;
let wallet = Arc::new(CashierDb::new("cashier.db", config.password.clone())?);
// TODO add to config
let client_wallet_path = "cashier_client_wallet.db";
let wallet = Arc::new(CashierDb::new(
&config.cashierdb_path,
config.password.clone(),
)?);
debug!(target: "cashierd", "starting cashier service");
let mut cashier = CashierService::new(
@@ -40,11 +40,16 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<CashierdConfig>) -> Resu
PathBuf::from("cashier_mint.params"),
PathBuf::from("cashier_spend.params"),
),
PathBuf::from(client_wallet_path),
PathBuf::from(&config.client_walletdb_path),
)
.await?;
cashier.start(ex.clone()).await?;
let client_wallet = Arc::new(WalletDb::new(
&PathBuf::from(&config.client_walletdb_path),
config.client_password.clone()
)?);
cashier.start(ex.clone(), client_wallet.clone()).await?;
//let rpc_url: std::net::SocketAddr = config.rpc_url.parse()?;
//let adapter = Arc::new(CashierAdapter::new(wallet.clone())?);

View File

@@ -106,21 +106,13 @@ impl Default for DarkfidConfig {
let database_path = String::from("database_client.db");
let database_path = join_config_path(&PathBuf::from(database_path))
.expect("error during join database_path to config path");
let database_path = String::from(
database_path
.to_str()
.expect("error convert Path to String"),
);
.expect("join database_path to config path");
let database_path = String::from(database_path.to_str().expect("convert Path to String"));
let walletdb_path = String::from("walletdb.db");
let walletdb_path = join_config_path(&PathBuf::from(walletdb_path))
.expect("error during join walletdb_path to config path");
let walletdb_path = String::from(
walletdb_path
.to_str()
.expect("error convert Path to String"),
);
.expect("join walletdb_path to config path");
let walletdb_path = String::from(walletdb_path.to_str().expect("convert Path to String"));
let mut lp = PathBuf::new();
lp.push(env::temp_dir());
@@ -192,8 +184,8 @@ pub struct CashierdConfig {
pub rpc_url: String,
#[serde(default)]
#[serde(rename = "database_path")]
pub database_path: String,
#[serde(rename = "client_database_path")]
pub client_database_path: String,
#[serde(default)]
#[serde(rename = "btc_endpoint")]
@@ -207,9 +199,21 @@ pub struct CashierdConfig {
#[serde(rename = "log_path")]
pub log_path: String,
#[serde(default)]
#[serde(rename = "cashierdb_path")]
pub cashierdb_path: String,
#[serde(default)]
#[serde(rename = "client_walletdb_path")]
pub client_walletdb_path: String,
#[serde(default)]
#[serde(rename = "password")]
pub password: String,
#[serde(default)]
#[serde(rename = "client_password")]
pub client_password: String,
}
impl Default for CashierdConfig {
@@ -217,22 +221,41 @@ impl Default for CashierdConfig {
let accept_url = String::from("127.0.0.1:7777");
let rpc_url = String::from("http://127.0.0.1:8000");
let gateway_url = String::from("127.0.0.1:3333");
let database_path = String::from("cashierd.db");
let client_database_path = String::from("cashier_client_database.db");
let btc_endpoint = String::from("tcp://electrum.blockstream.info:50001");
let mut lp = PathBuf::new();
lp.push(env::temp_dir());
lp.push("cashierd.log");
let log_path = String::from(lp.to_str().unwrap());
let cashierdb_path = String::from("cashier.db");
let cashierdb_path = join_config_path(&PathBuf::from(cashierdb_path))
.expect("join walletdb_path to config path");
let cashierdb_path = String::from(cashierdb_path.to_str().expect("convert Path to String"));
let client_walletdb_path = String::from("cashier_client_walletdb.db");
let client_walletdb_path = join_config_path(&PathBuf::from(client_walletdb_path))
.expect("join walletdb_path to config path");
let client_walletdb_path = String::from(
client_walletdb_path
.to_str()
.expect("convert Path to String"),
);
let password = String::new();
let client_password = String::new();
Self {
accept_url,
rpc_url,
database_path,
client_database_path,
btc_endpoint,
gateway_url,
log_path,
cashierdb_path,
client_walletdb_path,
password,
client_password,
}
}
}

View File

@@ -3,7 +3,7 @@ use super::reqrep::{PeerId, RepProtocol, Reply, ReqProtocol, Request};
use crate::blockchain::Rocks;
use crate::client::Client;
use crate::serial::{deserialize, serialize};
use crate::wallet::{CashierDbPtr, WalletDb};
use crate::wallet::{CashierDbPtr, WalletPtr};
use crate::{Error, Result};
use ff::Field;
@@ -77,7 +77,11 @@ impl CashierService {
client,
})
}
pub async fn start(&mut self, executor: Arc<Executor<'_>>) -> Result<()> {
pub async fn start(
&mut self,
executor: Arc<Executor<'_>>,
client_wallet: WalletPtr,
) -> Result<()> {
debug!(target: "Cashier", "Start Cashier");
let service_name = String::from("CASHIER DAEMON");
@@ -98,12 +102,6 @@ impl CashierService {
self.client.lock().await.start().await?;
// this for test
let client_wallet = Arc::new(WalletDb::new(
&PathBuf::from("cashier_client_wallet.db"),
"123".into(),
)?);
let cashier_client_subscriber_task = executor.spawn(Client::connect_to_subscriber(
self.client.clone(),
executor.clone(),