goas: remove found flag from balance insert helpers

This commit is contained in:
David Rusu 2024-08-23 13:39:36 +04:00
parent 7a706583dc
commit 30354a08bd
2 changed files with 13 additions and 21 deletions

View File

@ -67,42 +67,35 @@ impl BalanceWitness {
} }
pub fn insert_positive(&mut self, unit: Unit, value: Value) { pub fn insert_positive(&mut self, unit: Unit, value: Value) {
let mut found = false;
for unit_bal in self.balances.iter_mut() { for unit_bal in self.balances.iter_mut() {
if unit_bal.unit == unit { if unit_bal.unit == unit {
found = true;
unit_bal.pos += value; unit_bal.pos += value;
break; return;
} }
} }
if !found { // Unit was not found, so we must create one.
self.balances.push(UnitBalance { self.balances.push(UnitBalance {
unit, unit,
pos: value, pos: value,
neg: 0, neg: 0,
}); });
} }
}
pub fn insert_negative(&mut self, unit: Unit, value: Value) { pub fn insert_negative(&mut self, unit: Unit, value: Value) {
let mut found = false;
for unit_bal in self.balances.iter_mut() { for unit_bal in self.balances.iter_mut() {
if unit_bal.unit == unit { if unit_bal.unit == unit {
found = true;
unit_bal.neg += value; unit_bal.neg += value;
break; return;
} }
} }
if !found {
self.balances.push(UnitBalance { self.balances.push(UnitBalance {
unit, unit,
pos: 0, pos: 0,
neg: value, neg: value,
}); });
} }
}
pub fn clear_zeros(&mut self) { pub fn clear_zeros(&mut self) {
let mut i = 0usize; let mut i = 0usize;

View File

@ -36,7 +36,6 @@ fn test_simple_transfer() {
let bundle = cl::BundleWitness { let bundle = cl::BundleWitness {
partials: vec![ptx_witness], partials: vec![ptx_witness],
balance_blinding: BalanceWitness::random_blinding(&mut rng),
}; };
assert!(bundle.balance().is_zero()) assert!(bundle.balance().is_zero())