aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Halpern <matthalp@google.com>2019-02-20 01:49:24 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-02-20 01:49:24 +0800
commit8af6c9e6a2880437ea93f1588cbe1f599d07a250 (patch)
treeb8d38e41fda0ca095263bb35f173d7a1eb67b6c7
parent514a9472ad32b98897f1f4a7391eb21ac05aa609 (diff)
downloadgo-tangerine-8af6c9e6a2880437ea93f1588cbe1f599d07a250.tar
go-tangerine-8af6c9e6a2880437ea93f1588cbe1f599d07a250.tar.gz
go-tangerine-8af6c9e6a2880437ea93f1588cbe1f599d07a250.tar.bz2
go-tangerine-8af6c9e6a2880437ea93f1588cbe1f599d07a250.tar.lz
go-tangerine-8af6c9e6a2880437ea93f1588cbe1f599d07a250.tar.xz
go-tangerine-8af6c9e6a2880437ea93f1588cbe1f599d07a250.tar.zst
go-tangerine-8af6c9e6a2880437ea93f1588cbe1f599d07a250.zip
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.
-rw-r--r--eth/api_tracer.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/eth/api_tracer.go b/eth/api_tracer.go
index 7aa48b256..a529ea118 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.