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:
parent
2762d58a83
commit
2f0a9b1435
1 changed files with 6 additions and 9 deletions
15
tx/tx.go
15
tx/tx.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue