Răsfoiți Sursa

cashierd: truncate received tokens amount to 8 decimals

ghassmo 4 ani în urmă
părinte
comite
54edda9a9e
1 a modificat fișierele cu 6 adăugiri și 7 ștergeri
  1. 6 7
      src/bin/cashierd.rs

+ 6 - 7
src/bin/cashierd.rs

@@ -1,6 +1,5 @@
 use async_std::sync::{Arc, Mutex};
 use async_std::sync::{Arc, Mutex};
 use std::collections::HashMap;
 use std::collections::HashMap;
-use std::iter::FromIterator;
 use std::path::PathBuf;
 use std::path::PathBuf;
 use std::str::FromStr;
 use std::str::FromStr;
 
 
@@ -25,7 +24,7 @@ use drk::{
     },
     },
     serial::{deserialize, serialize},
     serial::{deserialize, serialize},
     service::{bridge, bridge::Bridge},
     service::{bridge, bridge::Bridge},
-    util::{expand_path, generate_id, join_config_path, NetworkName},
+    util::{expand_path, generate_id, join_config_path, parse::truncate, NetworkName},
     wallet::{CashierDb, WalletDb},
     wallet::{CashierDb, WalletDb},
     Error, Result,
     Error, Result,
 };
 };
@@ -572,11 +571,11 @@ impl Cashierd {
 
 
                     let token_notification = token_notification?;
                     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(9);
-                    let received_balance = u64::from_str(&String::from_iter(rv))?;
+                    let received_balance = truncate(
+                        token_notification.received_balance,
+                        8,
+                        token_notification.decimals,
+                    )?;
 
 
                     client
                     client
                         .send(
                         .send(