Skip to content

Commit

Permalink
api(debug): minor improvement, rename traceTx to trace clause
Browse files Browse the repository at this point in the history
  • Loading branch information
libotony committed Jul 21, 2023
1 parent 60242bd commit ac69a25
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions api/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func New(repo *chain.Repository, stater *state.Stater, forkConfig thor.ForkConfi
}
}

func (d *Debug) handleTxEnv(ctx context.Context, blockID thor.Bytes32, txIndex uint64, clauseIndex uint64) (*runtime.Runtime, *runtime.TransactionExecutor, thor.Bytes32, error) {
func (d *Debug) prepareClauseEnv(ctx context.Context, blockID thor.Bytes32, txIndex uint64, clauseIndex uint64) (*runtime.Runtime, *runtime.TransactionExecutor, thor.Bytes32, error) {
block, err := d.repo.GetBlock(blockID)
if err != nil {
if d.repo.IsNotFound(err) {
Expand Down Expand Up @@ -100,9 +100,9 @@ func (d *Debug) handleTxEnv(ctx context.Context, blockID thor.Bytes32, txIndex u
return nil, nil, thor.Bytes32{}, utils.Forbidden(errors.New("early reverted"))
}

// trace an existed transaction
func (d *Debug) traceTransaction(ctx context.Context, tracer tracers.Tracer, blockID thor.Bytes32, txIndex uint64, clauseIndex uint64) (interface{}, error) {
rt, txExec, txID, err := d.handleTxEnv(ctx, blockID, txIndex, clauseIndex)
// trace an existed clause
func (d *Debug) traceClause(ctx context.Context, tracer tracers.Tracer, blockID thor.Bytes32, txIndex uint64, clauseIndex uint64) (interface{}, error) {
rt, txExec, txID, err := d.prepareClauseEnv(ctx, blockID, txIndex, clauseIndex)
if err != nil {
return nil, err
}
Expand All @@ -123,7 +123,7 @@ func (d *Debug) traceTransaction(ctx context.Context, tracer tracers.Tracer, blo
return tracer.GetResult()
}

func (d *Debug) handleTraceTransaction(w http.ResponseWriter, req *http.Request) error {
func (d *Debug) handleTraceClause(w http.ResponseWriter, req *http.Request) error {
var opt *TracerOption
if err := utils.ParseJSON(req.Body, &opt); err != nil {
return utils.BadRequest(errors.WithMessage(err, "body"))
Expand Down Expand Up @@ -153,15 +153,15 @@ func (d *Debug) handleTraceTransaction(w http.ResponseWriter, req *http.Request)
if err != nil {
return err
}
res, err := d.traceTransaction(req.Context(), tracer, blockID, txIndex, clauseIndex)
res, err := d.traceClause(req.Context(), tracer, blockID, txIndex, clauseIndex)
if err != nil {
return err
}
return utils.WriteJSON(w, res)
}

func (d *Debug) debugStorage(ctx context.Context, contractAddress thor.Address, blockID thor.Bytes32, txIndex uint64, clauseIndex uint64, keyStart []byte, maxResult int) (*StorageRangeResult, error) {
rt, _, _, err := d.handleTxEnv(ctx, blockID, txIndex, clauseIndex)
rt, _, _, err := d.prepareClauseEnv(ctx, blockID, txIndex, clauseIndex)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (d *Debug) parseTarget(target string) (blockID thor.Bytes32, txIndex uint64
func (d *Debug) Mount(root *mux.Router, pathPrefix string) {
sub := root.PathPrefix(pathPrefix).Subrouter()

sub.Path("/tracers").Methods(http.MethodPost).HandlerFunc(utils.WrapHandlerFunc(d.handleTraceTransaction))
sub.Path("/tracers").Methods(http.MethodPost).HandlerFunc(utils.WrapHandlerFunc(d.handleTraceClause))
sub.Path("/storage-range").Methods(http.MethodPost).HandlerFunc(utils.WrapHandlerFunc(d.handleDebugStorage))

}

0 comments on commit ac69a25

Please sign in to comment.