فهرست منبع

darkfid: fix amount bug when withdraw/transfer

ghassmo 4 سال پیش
والد
کامیت
f6c11bab25
1فایلهای تغییر یافته به همراه18 افزوده شده و 10 حذف شده
  1. 18 10
      src/bin/darkfid.rs

+ 18 - 10
src/bin/darkfid.rs

@@ -155,7 +155,7 @@ impl Darkfid {
                 let mut data_vec: Vec<String> = Vec::new();
 
                 if let Some(symbol) = self.drk_tokenlist.clone().symbol_from_id(id)? {
-                    let decimals = decimals(network, &symbol, &self.sol_tokenlist)?;
+                    let decimals = decimals(&symbol, &self.sol_tokenlist)?;
                     for amount in balances.values() {
                         let amount = encode_base10(amount.clone(), decimals);
                         data_vec.push(amount);
@@ -352,7 +352,7 @@ impl Darkfid {
 
         let amount = amount.as_str().unwrap();
 
-        let decimals = match decimals(network, token, &self.sol_tokenlist) {
+        let decimals = match decimals(token, &self.sol_tokenlist) {
             Ok(d) => d,
             Err(e) => {
                 return JsonResult::Err(jsonerr(InternalError, Some(e.to_string()), id));
@@ -402,13 +402,10 @@ impl Darkfid {
                 let cashier_public: jubjub::SubgroupPoint =
                     deserialize(&bs58::decode(cashier_public).into_vec()?)?;
 
-                let decimals: usize = 8;
-                let amount = decode_base10(&amount.to_string(), decimals, true)?;
-
                 self.client
                     .lock()
                     .await
-                    .transfer(token_id.clone(), cashier_public, amount)
+                    .transfer(token_id.clone(), cashier_public, amount_in_apo)
                     .await?;
 
                 Ok(())
@@ -471,6 +468,20 @@ impl Darkfid {
         }
         let amount = amount.unwrap();
 
+        let decimals = match decimals(token, &self.sol_tokenlist) {
+            Ok(d) => d,
+            Err(e) => {
+                return JsonResult::Err(jsonerr(InternalError, Some(e.to_string()), id));
+            }
+        };
+
+        let amount_in_apo = match decode_base10(&amount, decimals, true) {
+            Ok(a) => a,
+            Err(e) => {
+                return JsonResult::Err(jsonerr(InternalError, Some(e.to_string()), id));
+            }
+        };
+
         let token_id: &jubjub::Fr;
 
         // get the id for the token
@@ -484,13 +495,10 @@ impl Darkfid {
             let drk_address = bs58::decode(&address).into_vec()?;
             let drk_address: jubjub::SubgroupPoint = deserialize(&drk_address)?;
 
-            let decimals: usize = 8;
-            let amount = decode_base10(&amount, decimals, true)?;
-
             self.client
                 .lock()
                 .await
-                .transfer(token_id.clone(), drk_address, amount)
+                .transfer(token_id.clone(), drk_address, amount_in_apo)
                 .await?;
 
             Ok(())