From 3ba34fe2ae376a1ca3496194ff656bb4a0806dfd Mon Sep 17 00:00:00 2001 From: ghassmo Date: Tue, 12 Oct 2021 12:14:09 +0300 Subject: [PATCH] cashierd: truncate received_balance to 8 digits --- src/bin/cashierd.rs | 9 ++++++++- src/client.rs | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/bin/cashierd.rs b/src/bin/cashierd.rs index 7fbcf9afb..2df0f9afe 100644 --- a/src/bin/cashierd.rs +++ b/src/bin/cashierd.rs @@ -8,6 +8,7 @@ use serde_json::{json, Value}; use std::collections::HashMap; use std::path::PathBuf; use std::str::FromStr; +use std::iter::FromIterator; use drk::{ blockchain::Rocks, @@ -566,10 +567,16 @@ impl Cashierd { let token_notification = token_notification?; + // truncate received_balance to 8 digits + let received_balance = token_notification.received_balance; + let mut rv: Vec = received_balance.to_string().chars().collect(); + rv.truncate(8); + let received_balance = u64::from_str(&String::from_iter(rv))?; + client .send( token_notification.drk_pub_key, - token_notification.received_balance, + received_balance, token_notification.token_id, true, ) diff --git a/src/client.rs b/src/client.rs index 76d15b07c..c9731e153 100644 --- a/src/client.rs +++ b/src/client.rs @@ -124,10 +124,6 @@ impl Client { ) -> ClientResult<()> { debug!(target: "CLIENT", "Start transfer {}", amount); - if amount == 0 { - return Err(ClientFailed::InvalidAmount(amount as u64)); - } - let token_id_exists = self.state.lock().await.wallet.token_id_exists(&token_id)?; if token_id_exists { @@ -150,6 +146,10 @@ impl Client { ) -> ClientResult<()> { debug!(target: "CLIENT", "Start send {}", amount); + if amount == 0 { + return Err(ClientFailed::InvalidAmount(amount as u64)); + } + let slab = self .build_slab_from_tx(pub_key, amount, token_id, clear_input) .await?;