github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/evm/context.go (about)

     1  package evm
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/iotexproject/iotex-core/pkg/log"
     7  )
     8  
     9  type (
    10  	helperContextKey struct{}
    11  
    12  	// HelperContext is the context for EVM helper
    13  	HelperContext struct {
    14  		GetBlockHash   GetBlockHash
    15  		GetBlockTime   GetBlockTime
    16  		DepositGasFunc DepositGasWithSGD
    17  		// TODO: sgd should be moved into depositGasFunc
    18  		Sgd SGDRegistry
    19  	}
    20  )
    21  
    22  // WithHelperCtx returns a new context with helper context
    23  func WithHelperCtx(ctx context.Context, hctx HelperContext) context.Context {
    24  	return context.WithValue(ctx, helperContextKey{}, hctx)
    25  }
    26  
    27  // mustGetHelperCtx returns the helper context from the context
    28  func mustGetHelperCtx(ctx context.Context) HelperContext {
    29  	hc, ok := ctx.Value(helperContextKey{}).(HelperContext)
    30  	if !ok {
    31  		log.S().Panic("Miss evm helper context")
    32  	}
    33  	return hc
    34  }