Browse Source

Add WalletDb to CashierService

Janus 5 years ago
parent
commit
9c6c8d0e82
3 changed files with 13 additions and 2 deletions
  1. 3 1
      src/bin/cashierd.rs
  2. 6 1
      src/cli/cli_config.rs
  3. 4 0
      src/service/bitcoin_bridge.rs

+ 3 - 1
src/bin/cashierd.rs

@@ -9,6 +9,7 @@ use toml;
 
 
 use drk::blockchain::{rocks::columns, Rocks, RocksColumn};
 use drk::blockchain::{rocks::columns, Rocks, RocksColumn};
 use drk::cli::{CashierdCli, CashierdConfig};
 use drk::cli::{CashierdCli, CashierdConfig};
+use drk::wallet::{WalletDb, WalletPtr};
 use drk::service::CashierService;
 use drk::service::CashierService;
 
 
 use drk::util::join_config_path;
 use drk::util::join_config_path;
@@ -36,8 +37,9 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<&CashierdConfig>) -> Res
     let rocks_cashierstore_column = RocksColumn::<columns::CashierKeys>::new(rocks);
     let rocks_cashierstore_column = RocksColumn::<columns::CashierKeys>::new(rocks);
     // Use pw: PASSWORD for now
     // Use pw: PASSWORD for now
     //let cashier_wallet = Arc::new(WalletDB::new("cashier.db", "PASSWORD")?);
     //let cashier_wallet = Arc::new(WalletDB::new("cashier.db", "PASSWORD")?);
+    let wallet = Arc::new(WalletDb::new("cashier.db", config.password.clone())?);
 
 
-    let cashier = CashierService::new(accept_addr, rocks_cashierstore_column)?;
+    let cashier = CashierService::new(accept_addr, rocks_cashierstore_column, wallet)?;
 
 
     cashier.start(executor.clone()).await?;
     cashier.start(executor.clone()).await?;
     Ok(())
     Ok(())

+ 6 - 1
src/cli/cli_config.rs

@@ -174,6 +174,10 @@ pub struct CashierdConfig {
     #[serde(default)]
     #[serde(default)]
     #[serde(rename = "log_path")]
     #[serde(rename = "log_path")]
     pub log_path: String,
     pub log_path: String,
+
+    #[serde(default)]
+    #[serde(rename = "password")]
+    pub password: String,
 }
 }
 
 
 impl CashierdConfig {
 impl CashierdConfig {
@@ -197,6 +201,7 @@ impl Default for CashierdConfig {
         let accept_url = String::from("127.0.0.1:7777");
         let accept_url = String::from("127.0.0.1:7777");
         let database_path = String::from("cashierd.db");
         let database_path = String::from("cashierd.db");
         let log_path = String::from("/tmp/cashierd.log");
         let log_path = String::from("/tmp/cashierd.log");
-        Self { accept_url, database_path, log_path }
+        let password = String::new();
+        Self { accept_url, database_path, log_path, password }
     }
     }
 }
 }

+ 4 - 0
src/service/bitcoin_bridge.rs

@@ -9,6 +9,7 @@ use bitcoin::network::constants::Network;
 use super::reqrep::{PeerId, RepProtocol, Reply, ReqProtocol, Request};
 use super::reqrep::{PeerId, RepProtocol, Reply, ReqProtocol, Request};
 use crate::blockchain::{rocks::columns, RocksColumn, CashierKeypair, CashierStore};
 use crate::blockchain::{rocks::columns, RocksColumn, CashierKeypair, CashierStore};
 use crate::{serial::deserialize, serial::serialize, Error, Result};
 use crate::{serial::deserialize, serial::serialize, Error, Result};
+use crate::wallet::{WalletDb, WalletPtr};
 use std::net::SocketAddr;
 use std::net::SocketAddr;
 use async_std::sync::Arc;
 use async_std::sync::Arc;
 use async_executor::Executor;
 use async_executor::Executor;
@@ -77,18 +78,21 @@ impl BitcoinKeys {
 pub struct CashierService {
 pub struct CashierService {
     addr: SocketAddr,
     addr: SocketAddr,
     cashierstore: Arc<CashierStore>,
     cashierstore: Arc<CashierStore>,
+    wallet: Arc<WalletDb>,
 }
 }
 
 
 impl CashierService {
 impl CashierService {
     pub fn new(
     pub fn new(
         addr: SocketAddr,
         addr: SocketAddr,
         rocks: RocksColumn<columns::CashierKeys>,
         rocks: RocksColumn<columns::CashierKeys>,
+        wallet: Arc<WalletDb>,
     )-> Result<Arc<CashierService>> {
     )-> Result<Arc<CashierService>> {
         let cashierstore = CashierStore::new(rocks)?;
         let cashierstore = CashierStore::new(rocks)?;
 
 
         Ok(Arc::new(CashierService {
         Ok(Arc::new(CashierService {
             cashierstore,
             cashierstore,
             addr,
             addr,
+            wallet,
         }))
         }))
     }
     }
     pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
     pub async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {