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:
parent
2e84b05c28
commit
8c3382cea7
1 changed files with 3 additions and 2 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue