Explorar o código

minor changes to cashierd

ghassmo %!s(int64=4) %!d(string=hai) anos
pai
achega
e2462d964c
Modificáronse 2 ficheiros con 18 adicións e 34 borrados
  1. 14 32
      src/bin/cashierd.rs
  2. 4 2
      src/bin/darkfid.rs

+ 14 - 32
src/bin/cashierd.rs

@@ -238,19 +238,17 @@ impl Cashierd {
     async fn deposit(&self, id: Value, params: Value) -> JsonResult {
         debug!(target: "CASHIER DAEMON", "RECEIVED DEPOSIT REQUEST");
 
-        let args: &Vec<serde_json::Value>;
+        let args: &Vec<serde_json::Value> = params.as_array().unwrap();
 
-        if let Some(ar) = params.as_array() {
-            args = ar;
-        } else {
+        if args.len() != 3 {
             return JsonResult::Err(jsonerr(InvalidParams, None, id));
         }
 
-        let network = &args[0].to_string();
+        let network = &args[0].as_str().unwrap();
         let token_id = &args[1];
-        let drk_pub_key = &args[2];
+        let drk_pub_key = &args[2].as_str().unwrap();
 
-        if !self.features.contains_key(network) {
+        if !self.features.contains_key(network.clone()) {
             return JsonResult::Err(jsonerr(
                 InvalidParams,
                 Some(format!("Cashier doesn't support this network: {}", network)),
@@ -261,7 +259,7 @@ impl Cashierd {
         let result: Result<String> = async {
             let asset_id = drk::util::parse_id(token_id)?;
 
-            let drk_pub_key = bs58::decode(&drk_pub_key.to_string()).into_vec()?;
+            let drk_pub_key = bs58::decode(&drk_pub_key).into_vec()?;
             let drk_pub_key: jubjub::SubgroupPoint = deserialize(&drk_pub_key)?;
 
             // TODO check if the drk public key is already exist
@@ -310,20 +308,18 @@ impl Cashierd {
     async fn withdraw(&self, id: Value, params: Value) -> JsonResult {
         debug!(target: "CASHIER DAEMON", "RECEIVED DEPOSIT REQUEST");
 
-        let args: &Vec<serde_json::Value>;
+        let args: &Vec<serde_json::Value> = params.as_array().unwrap();
 
-        if let Some(ar) = params.as_array() {
-            args = ar;
-        } else {
+        if args.len() != 4 {
             return JsonResult::Err(jsonerr(InvalidParams, None, id));
         }
 
-        let network = &args[0].to_string();
+        let network = &args[0].as_str().unwrap();
         let token = &args[1];
-        let address = &args[2];
+        let address = &args[2].as_str().unwrap();
         let _amount = &args[3];
 
-        if !self.features.contains_key(network) {
+        if !self.features.contains_key(network.clone()) {
             return JsonResult::Err(jsonerr(
                 InvalidParams,
                 Some(format!("Cashier doesn't support this network: {}", network)),
@@ -371,7 +367,8 @@ impl Cashierd {
     }
 }
 
-fn main() -> Result<()> {
+#[async_std::main]
+async fn main() -> Result<()> {
     let args = clap_app!(cashierd =>
         (@arg CONFIG: -c --config +takes_value "Sets a custom config file")
         (@arg verbose: -v --verbose "Increase verbosity")
@@ -408,20 +405,5 @@ fn main() -> Result<()> {
     ])
     .unwrap();
 
-    let (signal, shutdown) = async_channel::unbounded::<()>();
-
-    let cashierd2 = cashierd.clone();
-    let (_, _result) = Parallel::new()
-        // Run four executor threads.
-        .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv())))
-        // Run the main future on the current thread.
-        .finish(|| {
-            smol::future::block_on(async move {
-                cashierd2.start().await?;
-                drop(signal);
-                Ok::<(), Error>(())
-            })
-        });
-
-    Ok(())
+    cashierd.start().await
 }

+ 4 - 2
src/bin/darkfid.rs

@@ -196,7 +196,8 @@ impl Darkfid {
 
         // check if the token input is an ID
         // if not, find the associated ID
-        let _token_id = self.clone().parse_token(tkn_str);
+        // TODO 
+        //let _token_id = self.clone().parse_token(tkn_str);
 
         // TODO: Optional sanity checking here, but cashier *must* do so too.
 
@@ -204,7 +205,8 @@ impl Darkfid {
         match self.wallet.get_keypairs() {
             Ok(v) => {
                 let pk = v[0].public;
-                pubkey = bs58::encode(serialize(&pk)).into_string();
+                let pk = serialize(&pk);
+                pubkey = bs58::encode(pk).into_string();
             }
             Err(e) => {
                 return JsonResult::Err(jsonerr(ServerError(-32003), Some(e.to_string()), id))