From 89ed00ddfb9b85438e04213e69f98f99cb4a3d1c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 3 Sep 2019 18:03:13 +0300 Subject: [PATCH] core: simplify GetTransationResults() based on golint suggestion Golint: pkg/core/blockchain.go:796:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) Refs. #213. --- pkg/core/blockchain.go | 64 ++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 4b4aa7b8d..864b10284 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -791,43 +791,41 @@ func (bc *Blockchain) GetTransationResults(t *transaction.Transaction) []*transa var results []*transaction.Result tempGroupResult := make(map[util.Uint256]util.Fixed8) - if references := bc.References(t); references == nil { + references := bc.References(t) + if references == nil { return nil - } else { - for _, output := range references { - tempResults = append(tempResults, &transaction.Result{ - AssetID: output.AssetID, - Amount: output.Amount, - }) + } + for _, output := range references { + tempResults = append(tempResults, &transaction.Result{ + AssetID: output.AssetID, + Amount: output.Amount, + }) + } + for _, output := range t.Outputs { + tempResults = append(tempResults, &transaction.Result{ + AssetID: output.AssetID, + Amount: -output.Amount, + }) + } + for _, r := range tempResults { + if amount, ok := tempGroupResult[r.AssetID]; ok { + tempGroupResult[r.AssetID] = amount.Add(r.Amount) + } else { + tempGroupResult[r.AssetID] = r.Amount } - for _, output := range t.Outputs { - tempResults = append(tempResults, &transaction.Result{ - AssetID: output.AssetID, - Amount: -output.Amount, - }) - } - for _, r := range tempResults { - if amount, ok := tempGroupResult[r.AssetID]; ok { - tempGroupResult[r.AssetID] = amount.Add(r.Amount) - } else { - tempGroupResult[r.AssetID] = r.Amount - } - } - - results = []*transaction.Result{} // this assignment is necessary. (Most of the time amount == 0 and results is the empty slice.) - for assetID, amount := range tempGroupResult { - if amount != util.Fixed8(0) { - results = append(results, &transaction.Result{ - AssetID: assetID, - Amount: amount, - }) - } - } - - return results - } + results = []*transaction.Result{} // this assignment is necessary. (Most of the time amount == 0 and results is the empty slice.) + for assetID, amount := range tempGroupResult { + if amount != util.Fixed8(0) { + results = append(results, &transaction.Result{ + AssetID: assetID, + Amount: amount, + }) + } + } + + return results } // GetScriptHashesForVerifying returns all the ScriptHashes of a transaction which will be use