-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-eth-fee-history-endpoint
- Loading branch information
Showing
4 changed files
with
143 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/goccy/go-json" | ||
gethCommon "github.com/onflow/go-ethereum/common" | ||
"github.com/onflow/go-ethereum/eth/tracers" | ||
"github.com/onflow/go-ethereum/rpc" | ||
"github.com/rs/zerolog" | ||
|
||
"github.com/onflow/flow-evm-gateway/storage" | ||
) | ||
|
||
type DebugAPI struct { | ||
logger zerolog.Logger | ||
tracer storage.TraceIndexer | ||
blocks storage.BlockIndexer | ||
} | ||
|
||
func NewDebugAPI(tracer storage.TraceIndexer, blocks storage.BlockIndexer, logger zerolog.Logger) *DebugAPI { | ||
return &DebugAPI{ | ||
logger: logger, | ||
tracer: tracer, | ||
blocks: blocks, | ||
} | ||
} | ||
|
||
// TraceTransaction will return a debug execution trace of a transaction if it exists, | ||
// currently we only support CALL traces, so the config is ignored. | ||
func (d *DebugAPI) TraceTransaction( | ||
ctx context.Context, | ||
hash gethCommon.Hash, | ||
_ *tracers.TraceConfig, | ||
) (json.RawMessage, error) { | ||
res, err := d.tracer.GetTransaction(hash) | ||
if err != nil { | ||
return handleError[json.RawMessage](d.logger, err) | ||
} | ||
return res, nil | ||
} | ||
|
||
func (d *DebugAPI) TraceBlockByNumber( | ||
ctx context.Context, | ||
number rpc.BlockNumber, | ||
_ *tracers.TraceConfig, | ||
) ([]json.RawMessage, error) { | ||
block, err := d.blocks.GetByHeight(uint64(number.Int64())) | ||
if err != nil { | ||
return handleError[[]json.RawMessage](d.logger, err) | ||
} | ||
|
||
results := make([]json.RawMessage, len(block.TransactionHashes)) | ||
for i, h := range block.TransactionHashes { | ||
results[i], err = d.TraceTransaction(ctx, h, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return results, nil | ||
} | ||
|
||
func (d *DebugAPI) TraceBlockByHash( | ||
ctx context.Context, | ||
hash gethCommon.Hash, | ||
_ *tracers.TraceConfig, | ||
) ([]json.RawMessage, error) { | ||
block, err := d.blocks.GetByID(hash) | ||
if err != nil { | ||
return handleError[[]json.RawMessage](d.logger, err) | ||
} | ||
|
||
results := make([]json.RawMessage, len(block.TransactionHashes)) | ||
for i, h := range block.TransactionHashes { | ||
results[i], err = d.TraceTransaction(ctx, h, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return results, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters