Переглянути джерело

added 'deposit' subcommand to drk_cli

lunar-mining 5 роки тому
батько
коміт
1ad24f8e05
6 змінених файлів з 50 додано та 21 видалено
  1. 2 2
      src/bin/darkfid.rs
  2. 11 4
      src/bin/drk.rs
  3. 6 1
      src/cli/cli_config.rs
  4. 22 0
      src/cli/drk_cli.rs
  5. 9 13
      src/rpc/jsonserver.rs
  6. 0 1
      src/util.rs

+ 2 - 2
src/bin/darkfid.rs

@@ -8,6 +8,8 @@ use drk::crypto::{
     nullifier::Nullifier,
     nullifier::Nullifier,
     save_params, setup_mint_prover, setup_spend_prover,
     save_params, setup_mint_prover, setup_spend_prover,
 };
 };
+use drk::rpc::adapter::RpcAdapter;
+use drk::rpc::jsonserver;
 use drk::serial::Decodable;
 use drk::serial::Decodable;
 use drk::service::{GatewayClient, GatewaySlabsSubscriber};
 use drk::service::{GatewayClient, GatewaySlabsSubscriber};
 use drk::state::{state_transition, ProgramState, StateUpdate};
 use drk::state::{state_transition, ProgramState, StateUpdate};
@@ -15,8 +17,6 @@ use drk::util::join_config_path;
 use drk::wallet::{WalletDb, WalletPtr};
 use drk::wallet::{WalletDb, WalletPtr};
 use drk::{tx, Result};
 use drk::{tx, Result};
 use log::*;
 use log::*;
-use drk::rpc::adapter::RpcAdapter;
-use drk::rpc::jsonserver;
 
 
 use async_executor::Executor;
 use async_executor::Executor;
 use bellman::groth16;
 use bellman::groth16;

+ 11 - 4
src/bin/drk.rs

@@ -70,6 +70,12 @@ impl Drk {
         self.request().await
         self.request().await
     }
     }
 
 
+    pub async fn deposit(&mut self) -> Result<()> {
+        self.payload
+            .insert(String::from("method"), Value::String("deposit".into()));
+        self.request().await
+    }
+
     pub async fn transfer(&mut self, address: String, amount: String) -> Result<()> {
     pub async fn transfer(&mut self, address: String, amount: String) -> Result<()> {
         let mut params = Map::new();
         let mut params = Map::new();
         params.insert("amount".into(), Value::String(amount));
         params.insert("amount".into(), Value::String(amount));
@@ -81,7 +87,6 @@ impl Drk {
         self.payload
         self.payload
             .insert(String::from("params"), Value::Object(params));
             .insert(String::from("params"), Value::Object(params));
 
 
-
         self.request().await
         self.request().await
     }
     }
 
 
@@ -89,9 +94,7 @@ impl Drk {
         let payload = surf::Body::from_json(&self.payload)?;
         let payload = surf::Body::from_json(&self.payload)?;
         let payload = payload.into_string().await?;
         let payload = payload.into_string().await?;
 
 
-        let mut res = surf::post(&self.url)
-            .body(payload)
-            .await?;
+        let mut res = surf::post(&self.url).body(payload).await?;
 
 
         if res.status() == 200 {
         if res.status() == 200 {
             let response = res.take_body();
             let response = res.take_body();
@@ -130,6 +133,10 @@ async fn start(config: &DrkConfig, options: DrkCli) -> Result<()> {
         client.transfer(transfer.pub_key, transfer.amount).await?;
         client.transfer(transfer.pub_key, transfer.amount).await?;
     }
     }
 
 
+    if let Some(_deposit) = options.deposit {
+        client.deposit().await?;
+    }
+
     if options.stop {
     if options.stop {
         client.stop().await?;
         client.stop().await?;
     }
     }

+ 6 - 1
src/cli/cli_config.rs

@@ -152,6 +152,11 @@ impl Default for GatewaydConfig {
         let publisher_url = String::from("127.0.0.1:4444");
         let publisher_url = String::from("127.0.0.1:4444");
         let database_path = String::from("gatewayd.db");
         let database_path = String::from("gatewayd.db");
         let log_path = String::from("/tmp/gatewayd.log");
         let log_path = String::from("/tmp/gatewayd.log");
-        Self { accept_url, publisher_url, database_path, log_path }
+        Self {
+            accept_url,
+            publisher_url,
+            database_path,
+            log_path,
+        }
     }
     }
 }
 }

+ 22 - 0
src/cli/drk_cli.rs

@@ -29,6 +29,17 @@ impl Transfer {
     }
     }
 }
 }
 
 
+pub struct Deposit {
+    pub asset: String,
+}
+
+impl Deposit {
+    pub fn new() -> Self {
+        Self {
+            asset: String::new(),
+        }
+    }
+}
 pub struct DrkCli {
 pub struct DrkCli {
     //pub change_config: bool,
     //pub change_config: bool,
     pub verbose: bool,
     pub verbose: bool,
@@ -39,6 +50,7 @@ pub struct DrkCli {
     pub hello: bool,
     pub hello: bool,
     pub stop: bool,
     pub stop: bool,
     pub transfer: Option<Transfer>,
     pub transfer: Option<Transfer>,
+    pub deposit: Option<Deposit>,
 }
 }
 
 
 impl DrkCli {
 impl DrkCli {
@@ -115,6 +127,7 @@ impl DrkCli {
                             .required(true),
                             .required(true),
                     ),
                     ),
             )
             )
+            .subcommand(App::new("deposit").about("Deposit BTC for dBTC"))
             //.subcommand(
             //.subcommand(
             //    App::new("config")
             //    App::new("config")
             //        .about("Configuration settings")
             //        .about("Configuration settings")
@@ -149,6 +162,14 @@ impl DrkCli {
         let hello = app.is_present("hello");
         let hello = app.is_present("hello");
         let stop = app.is_present("stop");
         let stop = app.is_present("stop");
 
 
+        let deposit = None;
+        match app.subcommand_matches("deposit") {
+            Some(_) => {
+                //let deposit = Deposit::new();
+            }
+            None => {}
+        }
+
         let mut transfer = None;
         let mut transfer = None;
         match app.subcommand_matches("transfer") {
         match app.subcommand_matches("transfer") {
             Some(transfer_sub) => {
             Some(transfer_sub) => {
@@ -200,6 +221,7 @@ impl DrkCli {
             info,
             info,
             hello,
             hello,
             stop,
             stop,
+            deposit,
             transfer,
             transfer,
         })
         })
     }
     }

+ 9 - 13
src/rpc/jsonserver.rs

@@ -7,20 +7,18 @@ use async_native_tls::TlsAcceptor;
 use async_std::sync::Mutex;
 use async_std::sync::Mutex;
 use http_types::{Request, Response, StatusCode};
 use http_types::{Request, Response, StatusCode};
 use log::*;
 use log::*;
-use smol::Async;
 use serde::Deserialize;
 use serde::Deserialize;
+use smol::Async;
 
 
 use std::net::TcpListener;
 use std::net::TcpListener;
 use std::sync::Arc;
 use std::sync::Arc;
 
 
-
 #[derive(Deserialize, Debug)]
 #[derive(Deserialize, Debug)]
 pub struct TransferParams {
 pub struct TransferParams {
     address: String,
     address: String,
     amount: String,
     amount: String,
 }
 }
 
 
-
 /// Listens for incoming connections and serves them.
 /// Listens for incoming connections and serves them.
 pub async fn listen(
 pub async fn listen(
     executor: Arc<Executor<'_>>,
     executor: Arc<Executor<'_>>,
@@ -64,8 +62,8 @@ pub async fn listen(
                         let _stream = async_dup::Arc::new(async_dup::Mutex::new(stream));
                         let _stream = async_dup::Arc::new(async_dup::Mutex::new(stream));
                         executor.spawn(async move {
                         executor.spawn(async move {
                             /*if let Err(err) = async_h1::accept(stream, serve).await {
                             /*if let Err(err) = async_h1::accept(stream, serve).await {
-                              println!("Connection error: {:#?}", err);
-                              }*/
+                            println!("Connection error: {:#?}", err);
+                            }*/
                             unimplemented!();
                             unimplemented!();
                         })
                         })
                     }
                     }
@@ -205,7 +203,7 @@ impl RpcInterface {
                 println!("Key generation method called...");
                 println!("Key generation method called...");
                 self2.adapter.key_gen()?;
                 self2.adapter.key_gen()?;
                 Ok(jsonrpc_core::Value::String(
                 Ok(jsonrpc_core::Value::String(
-                        "Key generation successful".into(),
+                    "Key generation successful".into(),
                 ))
                 ))
             }
             }
         });
         });
@@ -216,7 +214,7 @@ impl RpcInterface {
                 println!("Key generation method called...");
                 println!("Key generation method called...");
                 self2.adapter.cash_key_gen()?;
                 self2.adapter.cash_key_gen()?;
                 Ok(jsonrpc_core::Value::String(
                 Ok(jsonrpc_core::Value::String(
-                        "Attempted key generation".into(),
+                    "Attempted key generation".into(),
                 ))
                 ))
             }
             }
         });
         });
@@ -244,15 +242,13 @@ impl RpcInterface {
             let parsed: TransferParams = params.parse().unwrap();
             let parsed: TransferParams = params.parse().unwrap();
             println!("test transfer params:  {:?}", parsed);
             println!("test transfer params:  {:?}", parsed);
             Ok(jsonrpc_core::Value::String("Transfer To... ".into()))
             Ok(jsonrpc_core::Value::String("Transfer To... ".into()))
-
         });
         });
 
 
-
         debug!(target: "rpc", "JsonRpcInterface::handle_input() [END]");
         debug!(target: "rpc", "JsonRpcInterface::handle_input() [END]");
         Ok(io)
         Ok(io)
-}
+    }
 
 
-pub async fn wait_for_quit(self: Arc<Self>) -> Result<()> {
-    Ok(self.stop_recv.recv().await?)
-}
+    pub async fn wait_for_quit(self: Arc<Self>) -> Result<()> {
+        Ok(self.stop_recv.recv().await?)
+    }
 }
 }

+ 0 - 1
src/util.rs

@@ -11,4 +11,3 @@ pub fn join_config_path(file: &PathBuf) -> Result<PathBuf> {
     path.push(file);
     path.push(file);
     Ok(path)
     Ok(path)
 }
 }
-