Răsfoiți Sursa

cashierd: truncate received_balance to 8 digits

ghassmo 4 ani în urmă
părinte
comite
3ba34fe2ae
2 a modificat fișierele cu 12 adăugiri și 5 ștergeri
  1. 8 1
      src/bin/cashierd.rs
  2. 4 4
      src/client.rs

+ 8 - 1
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<char> = 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,
                         )

+ 4 - 4
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?;