1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-25 07:17:41 +01:00

Refactor balance calculation

This commit is contained in:
Roman Zeyde 2018-05-31 12:55:50 +03:00
parent 2e84b05c28
commit 8c3382cea7
No known key found for this signature in database
GPG key ID: 87CAE5FA46917CBB

View file

@ -34,8 +34,9 @@ pub struct Status {
} }
fn calc_balance((funding, spending): &(Vec<FundingOutput>, Vec<SpendingInput>)) -> u64 { fn calc_balance((funding, spending): &(Vec<FundingOutput>, Vec<SpendingInput>)) -> u64 {
let total = funding.iter().fold(0, |acc, output| acc + output.value); let funded_values = funding.iter().map(|output| output.value);
spending.iter().fold(total, |acc, input| acc - input.value) let spent_values = spending.iter().map(|input| input.value);
funded_values.sum::<u64>() - spent_values.sum::<u64>()
} }
impl Status { impl Status {