Skip to content

Commit

Permalink
update resource exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Feb 17, 2024
1 parent 2c0857a commit e662a7f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/resource-exporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub fn export(

use std::time::Instant;
let now = Instant::now();
let mut sum: u128 = 0;
for (address_bytes, account_state_bytes) in global_states.iter() {
let account: AccountAddress = bcs_ext::from_bytes(address_bytes)?;
let account_state: AccountState = account_state_bytes.as_slice().try_into()?;
Expand All @@ -96,12 +97,22 @@ pub fn export(
}
};
if let Some(res) = resource {
let balance = res.get("token").unwrap().get("value").unwrap();
writeln!(file, "{} {}", account, balance)?;
let balance = (res
.get("token")
.unwrap()
.get("value")
.unwrap()
.as_f64()
.unwrap()
/ 1000000000.0) as u128;
if balance > 0 {
writeln!(file, "{} {}", account, balance)?;
sum += balance;
}
}
}
println!("t2: {}", now.elapsed().as_millis());
// flush csv writer
writeln!(file, "total {}", sum)?;
file.flush()?;
Ok(())
}
Expand Down

0 comments on commit e662a7f

Please sign in to comment.