Просмотр исходного кода

Merge branch 'master' of github.com:darkrenaissance/darkfi

ghassmo 5 лет назад
Родитель
Сommit
dd6135fd30

+ 4 - 1
src/bin/cashierd.rs

@@ -6,6 +6,7 @@ use std::{path::Path, path::PathBuf};
 
 use drk::blockchain::{rocks::columns, Rocks, RocksColumn};
 use drk::cli::{CashierdCli, CashierdConfig, Config};
+use drk::rpc::adapters::cashier_adapter::CashierAdapter;
 use drk::service::CashierService;
 use drk::service::GatewayClient;
 use drk::util::join_config_path;
@@ -36,8 +37,10 @@ async fn start(executor: Arc<Executor<'_>>, config: Arc<&CashierdConfig>) -> Res
     gateway.start().await?;
 
     debug!(target: "cashierd", "starting cashier service");
-    let cashier = CashierService::new(accept_addr, btc_endpoint, wallet, gateway)?;
+    let cashier = CashierService::new(accept_addr, btc_endpoint, wallet.clone(), gateway)?;
     cashier.start(executor.clone()).await?;
+
+    let adapter = Arc::new(CashierAdapter::new(wallet.clone())?);
     Ok(())
 }
 

+ 4 - 4
src/bin/darkfid.rs

@@ -1,6 +1,6 @@
 use drk::blockchain::{rocks::columns, Rocks, RocksColumn, Slab};
-use drk::cli::{Config, DarkfidCli, DarkfidConfig};
 use drk::cli::TransferParams;
+use drk::cli::{Config, DarkfidCli, DarkfidConfig};
 use drk::crypto::{
     load_params,
     merkle::{CommitmentTree, IncrementalWitness},
@@ -221,7 +221,7 @@ pub async fn futures_broker(
     }
 }
 
-async fn start(executor: Arc<Executor<'_>>, config: Arc<&DarkfidConfig>) -> Result<()> {
+async fn start(executor: Arc<Executor<'_>>, config: Arc<DarkfidConfig>) -> Result<()> {
     let connect_addr: SocketAddr = config.connect_url.parse()?;
     let sub_addr: SocketAddr = config.subscriber_url.parse()?;
     let cashier_addr: SocketAddr = config.cashier_url.parse()?;
@@ -358,7 +358,7 @@ fn main() -> Result<()> {
         Config::<DarkfidConfig>::load_default(config_path)?
     };
 
-    let config_ptr = Arc::new(&config);
+    let config = Arc::new(config);
 
     let ex = Arc::new(Executor::new());
     let (signal, shutdown) = async_channel::unbounded::<()>();
@@ -393,7 +393,7 @@ fn main() -> Result<()> {
         // Run the main future on the current thread.
         .finish(|| {
             smol::future::block_on(async move {
-                start(ex2, config_ptr).await?;
+                start(ex2, config).await?;
                 drop(signal);
                 Ok::<(), drk::Error>(())
             })

+ 81 - 0
src/rpc/adapters/cashier_adapter.rs

@@ -0,0 +1,81 @@
+use crate::wallet::CashierDb;
+use crate::{Error, Result};
+use async_std::sync::Arc;
+use log::*;
+
+pub struct CashierAdapter {
+    pub wallet: Arc<CashierDb>,
+}
+
+impl CashierAdapter {
+    pub fn new(wallet: Arc<CashierDb>) -> Result<Self> {
+        Ok(Self { wallet })
+    }
+
+    pub fn handle_input(
+        self: Arc<Self>,
+        mut io: jsonrpc_core::IoHandler,
+    ) -> Result<jsonrpc_core::IoHandler> {
+        io.add_sync_method("cashier_hello", |_| {
+            Ok(jsonrpc_core::Value::String("hello world!".into()))
+        });
+        Ok(io)
+        //    let self1 = self.clone();
+        //    io.add_method("get_key", move |_| {
+        //        let self2 = self1.clone();
+        //        async move {
+        //            let pub_key = self2.get_key()?;
+        //            Ok(jsonrpc_core::Value::String(pub_key))
+        //        }
+        //    });
+
+        //    let self1 = self.clone();
+        //    io.add_method("get_cash_public", move |_| {
+        //        let self2 = self1.clone();
+        //        async move {
+        //            let cash_key = self2.get_cash_public()?;
+        //            Ok(jsonrpc_core::Value::String(cash_key))
+        //        }
+        //    });
+
+        //    let self1 = self.clone();
+        //    io.add_method("get_info", move |_| {
+        //        let self2 = self1.clone();
+        //        async move {
+        //            self2.get_info();
+        //            Ok(jsonrpc_core::Value::Null)
+        //        }
+        //    });
+
+        //    let self1 = self.clone();
+        //    io.add_method("stop", move |_| {
+        //        let self2 = self1.clone();
+        //        async move {
+        //            self2.stop();
+        //            Ok(jsonrpc_core::Value::Null)
+        //        }
+        //    });
+        //    let self1 = self.clone();
+
+        //    io.add_method("create_wallet", move |_| {
+        //        let self2 = self1.clone();
+        //        async move {
+        //            self2.init_db()?;
+        //            Ok(jsonrpc_core::Value::String(
+        //                "wallet creation successful".into(),
+        //            ))
+        //        }
+        //    });
+
+        //    let self1 = self.clone();
+        //    io.add_method("key_gen", move |_| {
+        //        let self2 = self1.clone();
+        //        async move {
+        //            self2.key_gen()?;
+        //            Ok(jsonrpc_core::Value::String(
+        //                "key generation successful".into(),
+        //            ))
+        //        }
+        //    });
+    }
+}

+ 1 - 1
src/rpc/adapters/mod.rs

@@ -1,4 +1,4 @@
 pub mod cashier_adapter;
 pub mod user_adapter;
 
-pub use user_adapter::{UserAdapterPtr, UserAdapter};
+pub use user_adapter::{UserAdapter, UserAdapterPtr};

+ 4 - 1
src/rpc/adapters/user_adapter.rs

@@ -42,7 +42,10 @@ impl UserAdapter {
         })
     }
 
-    pub fn handle_input(self: Arc<Self>, mut io: jsonrpc_core::IoHandler) -> Result<jsonrpc_core::IoHandler> {
+    pub fn handle_input(
+        self: Arc<Self>,
+        mut io: jsonrpc_core::IoHandler,
+    ) -> Result<jsonrpc_core::IoHandler> {
         io.add_sync_method("say_hello", |_| {
             Ok(jsonrpc_core::Value::String("hello world!".into()))
         });

+ 4 - 3
src/rpc/jsonserver.rs

@@ -1,6 +1,6 @@
 use crate::cli::DarkfidConfig;
-use crate::cli::{TransferParams, WithdrawParams};
-use crate::rpc::adapters::user_adapter::UserAdapter;
+//use crate::cli::{TransferParams, WithdrawParams};
+use crate::rpc::adapters::UserAdapter;
 use crate::{Error, Result};
 
 use async_executor::Executor;
@@ -76,7 +76,7 @@ pub async fn listen(
 
 pub async fn start(
     executor: Arc<Executor<'_>>,
-    config: Arc<&DarkfidConfig>,
+    config: Arc<DarkfidConfig>,
     adapter: Arc<UserAdapter>,
 ) -> Result<()> {
     let rpc = RpcInterface::new(adapter)?;
@@ -98,6 +98,7 @@ pub async fn start(
 
     Ok(())
 }
+
 // json RPC server goes here
 #[allow(dead_code)]
 pub struct RpcInterface {

+ 1 - 2
src/rpc/mod.rs

@@ -1,4 +1,3 @@
+pub mod adapters;
 pub mod jsonrpc;
 pub mod jsonserver;
-pub mod adapters;
-