From 8af6c9e6a2880437ea93f1588cbe1f599d07a250 Mon Sep 17 00:00:00 2001 From: Matthew Halpern Date: Tue, 19 Feb 2019 09:49:24 -0800 Subject: [PATCH] eth: extract check for tracing transaction in block file (#19107) Simplifies the transaction presense check to use a function to determine if the transaction is present in the block provided to trace, which originally had a redundant parenthesis and used a `exist` flag to dictate control flow. --- eth/api_tracer.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/eth/api_tracer.go b/eth/api_tracer.go index 7aa48b2563..a529ea118e 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -526,13 +526,7 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block, func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block *types.Block, config *StdTraceConfig) ([]string, error) { // If we're tracing a single transaction, make sure it's present if config != nil && config.TxHash != (common.Hash{}) { - var exists bool - for _, tx := range block.Transactions() { - if exists = (tx.Hash() == config.TxHash); exists { - break - } - } - if !exists { + if !containsTx(block, config.TxHash) { return nil, fmt.Errorf("transaction %#x not found in block", config.TxHash) } } @@ -625,6 +619,17 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block return dumps, nil } +// containsTx reports whether the transaction with a certain hash +// is contained within the specified block. +func containsTx(block *types.Block, hash common.Hash) bool { + for _, tx := range block.Transactions() { + if tx.Hash() == hash { + return true + } + } + return false +} + // computeStateDB retrieves the state database associated with a certain block. // If no state is locally available for the given block, a number of blocks are // attempted to be reexecuted to generate the desired state.