Skip to content

[api] archive APIs implementation #4654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
16 changes: 16 additions & 0 deletions action/protocol/execution/evm/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ package evm
import (
"context"

"github.com/iotexproject/iotex-core/v2/action"
"github.com/iotexproject/iotex-core/v2/action/protocol"
"github.com/iotexproject/iotex-core/v2/pkg/log"
)

type (
helperContextKey struct{}

tracerContextKey struct{}

// HelperContext is the context for EVM helper
HelperContext struct {
GetBlockHash GetBlockHash
GetBlockTime GetBlockTime
DepositGasFunc protocol.DepositGas
}

TracerContext struct {
CaptureTx func([]byte, *action.Receipt)
}
)

// WithHelperCtx returns a new context with helper context
Expand All @@ -31,3 +38,12 @@ func mustGetHelperCtx(ctx context.Context) HelperContext {
}
return hc
}

func WithTracerCtx(ctx context.Context, tctx TracerContext) context.Context {
return context.WithValue(ctx, tracerContextKey{}, tctx)
}

func GetTracerCtx(ctx context.Context) (TracerContext, bool) {
tc, ok := ctx.Value(tracerContextKey{}).(TracerContext)
return tc, ok
}
10 changes: 10 additions & 0 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ func ExecuteContract(
receipt.SetExecutionRevertMsg(revertMsg)
}
log.S().Debugf("Receipt: %+v, %v", receipt, err)
if tCtx, ok := GetTracerCtx(ctx); ok && tCtx.CaptureTx != nil {
tCtx.CaptureTx(retval, receipt)
}
return retval, receipt, nil
}

Expand Down Expand Up @@ -513,6 +516,13 @@ func executeInEVM(ctx context.Context, evmParams *Params, stateDB stateDB) ([]by
refund uint64
amount = uint256.MustFromBig(evmParams.amount)
)
debug := evm.Config.Tracer != nil
if debug {
evm.Config.Tracer.CaptureTxStart(remainingGas)
defer func() {
evm.Config.Tracer.CaptureTxEnd(remainingGas)
}()
}
if evmParams.contract == nil {
// create contract
var evmContractAddress common.Address
Expand Down
5 changes: 5 additions & 0 deletions action/protocol/managers.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ type (
DelState(...StateOption) (uint64, error)
WriteView(string, View) error
}

StateManagerWithCloser interface {
StateManager
Close()
}
)

type (
Expand Down
Loading
Loading