From 2f0a9b1435971d2fad62c99b59aa15f13e3b1baa Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 7 May 2014 22:48:18 -0500 Subject: [PATCH] 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. --- tx/tx.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tx/tx.go b/tx/tx.go index 84abc95..d3b15ee 100644 --- a/tx/tx.go +++ b/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 }