Simplify a switch statement in OutputAmount.

Instead of using 3 fallthroughs with obscure cases, use a single
switch statement with just a one case.  This switch is only evaluated
if a previous if statement body is entered.  Functionally no
different, but imo this much easier to read, and removes two uses of !
to negate bools.
This commit is contained in:
Josh Rickmar 2014-05-07 22:48:18 -05:00
parent 2762d58a83
commit 2f0a9b1435

View file

@ -1262,16 +1262,13 @@ func (d *Debits) InputAmount() btcutil.Amount {
func (t *TxRecord) OutputAmount(ignoreChange bool) btcutil.Amount {
a := btcutil.Amount(0)
for i, txOut := range t.Tx().MsgTx().TxOut {
switch {
case !ignoreChange:
fallthrough
case len(t.credits) <= i:
fallthrough
case t.credits[i] == nil:
fallthrough
case !t.credits[i].change:
a += btcutil.Amount(txOut.Value)
if ignoreChange {
switch cs := t.credits; {
case i < len(cs) && cs[i] != nil && cs[i].change:
continue
}
}
a += btcutil.Amount(txOut.Value)
}
return a
}