drk, darkfid: changed f64 to str for amounts

This commit is contained in:
lunar-mining
2021-10-11 10:24:35 +02:00
parent e6f0e794cf
commit 5325fe7d3c
2 changed files with 10 additions and 10 deletions

View File

@@ -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()

View File

@@ -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?;