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 {
let total = funding.iter().fold(0, |acc, output| acc + output.value);
spending.iter().fold(total, |acc, input| acc - input.value)
let funded_values = funding.iter().map(|output| output.value);
let spent_values = spending.iter().map(|input| input.value);
funded_values.sum::<u64>() - spent_values.sum::<u64>()
}
impl Status {