mirror of
https://codeberg.org/JasterV/transactions-processor.git
synced 2026-04-26 18:10:06 +00:00
display moved to function
This commit is contained in:
parent
cc9eacbeec
commit
86ae78bd83
2 changed files with 29 additions and 8 deletions
27
src/main.rs
27
src/main.rs
|
|
@ -23,7 +23,7 @@ async fn main() -> Result<()> {
|
|||
|
||||
while let Some(record) = records.next().await {
|
||||
let transaction = record?;
|
||||
|
||||
|
||||
if addr_map.contains_key(&transaction.client) {
|
||||
addr_map.get(&transaction.client).unwrap().do_send::<Command>(transaction.into());
|
||||
} else {
|
||||
|
|
@ -33,12 +33,23 @@ async fn main() -> Result<()> {
|
|||
addr.do_send::<Command>(transaction.into());
|
||||
}
|
||||
}
|
||||
|
||||
let mut result: Vec<Account> = vec![];
|
||||
for addr in addr_map.values() {
|
||||
let account: Account = addr.send(Stop).await?;
|
||||
result.push(account);
|
||||
}
|
||||
|
||||
|
||||
fetch_and_display_accounts(&addr_map).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn fetch_and_display_accounts(actors: &AccountActors) -> Result<()> {
|
||||
println!("client,available,held,total,locked");
|
||||
for addr in actors.values() {
|
||||
let account: Account = addr.send(Stop).await?;
|
||||
println!(
|
||||
"{},{},{},{},{}",
|
||||
account.get_client(),
|
||||
account.get_available(),
|
||||
account.get_held(),
|
||||
account.get_total(),
|
||||
account.get_locked()
|
||||
)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,16 @@ impl Account {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_client(&self) -> u16 { self.client }
|
||||
|
||||
pub fn get_available(&self) -> f32 { self.available }
|
||||
|
||||
pub fn get_held(&self) -> f32 { self.held }
|
||||
|
||||
pub fn get_total(&self) -> f32 { self.total }
|
||||
|
||||
pub fn get_locked(&self) -> bool { self.locked }
|
||||
|
||||
pub fn deposit(&mut self, amount: f32) -> Result<()> {
|
||||
self.assert_lock()?;
|
||||
self.available += amount;
|
||||
|
|
|
|||
Loading…
Reference in a new issue