소스 검색

drk, darkfid: changed f64 to str for amounts

lunar-mining 4 년 전
부모
커밋
5325fe7d3c
2개의 변경된 파일10개의 추가작업 그리고 10개의 파일을 삭제
  1. 6 6
      src/bin/darkfid.rs
  2. 4 4
      src/bin/drk.rs

+ 6 - 6
src/bin/darkfid.rs

@@ -346,11 +346,11 @@ impl Darkfid {
 
         let network = network.as_str().unwrap();
 
-        if amount.as_f64().is_none() {
-            return JsonResult::Err(jsonerr(InvalidAmountParam, None, id));
+        if amount.as_str().is_none() {
+            return JsonResult::Err(jsonerr(InvalidNetworkParam, None, id));
         }
 
-        let amount = amount.as_f64().unwrap();
+        let amount = amount.as_str().unwrap();
 
         let decimals = match decimals(network, token, &self.sol_tokenlist) {
             Ok(d) => d,
@@ -359,7 +359,7 @@ impl Darkfid {
             }
         };
 
-        let amount_in_apo = match decode_base10(&amount.to_string(), decimals, true) {
+        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));
@@ -452,7 +452,7 @@ impl Darkfid {
 
         let token = &args[0].as_str();
         let address = &args[1].as_str();
-        let amount = &args[2].as_f64();
+        let amount = &args[2].as_str();
 
         if token.is_none() {
             return JsonResult::Err(jsonerr(InvalidTokenIdParam, None, id));
@@ -485,7 +485,7 @@ impl Darkfid {
             let drk_address: jubjub::SubgroupPoint = deserialize(&drk_address)?;
 
             let decimals: usize = 8;
-            let amount = decode_base10(&amount.to_string(), decimals, true)?;
+            let amount = decode_base10(&amount, decimals, true)?;
 
             self.client
                 .lock()

+ 4 - 4
src/bin/drk.rs

@@ -129,7 +129,7 @@ impl Drk {
         network: &str,
         asset: &str,
         address: &str,
-        amount: f64,
+        amount: &str,
     ) -> Result<Value> {
         let req = jsonrpc::request(json!("withdraw"), json!([network, asset, address, amount]));
         Ok(self.request(req).await?)
@@ -138,7 +138,7 @@ impl Drk {
     // --> {"jsonrpc": "2.0", "method": "transfer",
     //      "params": ["dusdc", "vdNS7oBj7KvsMWWmo9r96SV4SqATLrGsH2a3PGpCfJC", 13.37], "id": 42}
     // <-- {"jsonrpc": "2.0", "result": "txID", "id": 42}
-    async fn transfer(&self, asset: &str, address: &str, amount: f64) -> Result<Value> {
+    async fn transfer(&self, asset: &str, address: &str, amount: &str) -> Result<Value> {
         let req = jsonrpc::request(json!("transfer"), json!([asset, address, amount]));
         Ok(self.request(req).await?)
     }
@@ -236,7 +236,7 @@ async fn start(config: &DrkConfig, options: ArgMatches<'_>) -> Result<()> {
         let network = matches.value_of("network").unwrap().to_lowercase();
         let token_sym = matches.value_of("TOKENSYM").unwrap();
         let address = matches.value_of("ADDRESS").unwrap();
-        let amount = matches.value_of("AMOUNT").unwrap().parse::<f64>()?;
+        let amount = matches.value_of("AMOUNT").unwrap();
 
         client
             .check_network(&NetworkName::from_str(&network)?)
@@ -254,7 +254,7 @@ async fn start(config: &DrkConfig, options: ArgMatches<'_>) -> Result<()> {
     if let Some(matches) = options.subcommand_matches("transfer") {
         let token_sym = matches.value_of("TOKENSYM").unwrap();
         let address = matches.value_of("ADDRESS").unwrap();
-        let amount = matches.value_of("AMOUNT").unwrap().parse::<f64>()?;
+        let amount = matches.value_of("AMOUNT").unwrap();
 
         let reply = client.transfer(&token_sym, &address, amount).await?;