github.com/koko1123/flow-go-1@v0.29.6/fvm/environment/env.go (about)

     1  package environment
     2  
     3  import (
     4  	"github.com/onflow/cadence"
     5  	"github.com/onflow/cadence/runtime"
     6  	"github.com/onflow/cadence/runtime/common"
     7  	"github.com/rs/zerolog"
     8  	otelTrace "go.opentelemetry.io/otel/trace"
     9  
    10  	"github.com/koko1123/flow-go-1/fvm/derived"
    11  	reusableRuntime "github.com/koko1123/flow-go-1/fvm/runtime"
    12  	"github.com/koko1123/flow-go-1/fvm/tracing"
    13  	"github.com/koko1123/flow-go-1/model/flow"
    14  	"github.com/koko1123/flow-go-1/module/trace"
    15  )
    16  
    17  // Environment implements the accounts business logic and exposes cadence
    18  // runtime interface methods for the runtime.
    19  type Environment interface {
    20  	runtime.Interface
    21  
    22  	// Tracer
    23  	StartChildSpan(
    24  		name trace.SpanName,
    25  		options ...otelTrace.SpanStartOption,
    26  	) tracing.TracerSpan
    27  
    28  	Meter
    29  
    30  	// Runtime
    31  	BorrowCadenceRuntime() *reusableRuntime.ReusableCadenceRuntime
    32  	ReturnCadenceRuntime(*reusableRuntime.ReusableCadenceRuntime)
    33  
    34  	TransactionInfo
    35  
    36  	// ProgramLogger
    37  	Logger() *zerolog.Logger
    38  	Logs() []string
    39  
    40  	// EventEmitter
    41  	Events() []flow.Event
    42  	ServiceEvents() []flow.Event
    43  
    44  	// SystemContracts
    45  	AccountsStorageCapacity(
    46  		addresses []common.Address,
    47  		payer common.Address,
    48  		maxTxFees uint64,
    49  	) (
    50  		cadence.Value,
    51  		error,
    52  	)
    53  	CheckPayerBalanceAndGetMaxTxFees(
    54  		payer flow.Address,
    55  		inclusionEffort uint64,
    56  		executionEffort uint64,
    57  	) (
    58  		cadence.Value,
    59  		error,
    60  	)
    61  	DeductTransactionFees(
    62  		payer flow.Address,
    63  		inclusionEffort uint64,
    64  		executionEffort uint64,
    65  	) (
    66  		cadence.Value,
    67  		error,
    68  	)
    69  
    70  	// AccountInfo
    71  	GetAccount(address flow.Address) (*flow.Account, error)
    72  
    73  	AccountFreezer
    74  
    75  	// FlushPendingUpdates flushes pending updates from the stateful environment
    76  	// modules (i.e., ContractUpdater) to the state transaction, and return
    77  	// corresponding modified sets invalidator.
    78  	FlushPendingUpdates() (
    79  		derived.TransactionInvalidator,
    80  		error,
    81  	)
    82  
    83  	// Reset resets all stateful environment modules (e.g., ContractUpdater,
    84  	// EventEmitter, AccountFreezer) to initial state.
    85  	Reset()
    86  }
    87  
    88  type EnvironmentParams struct {
    89  	Chain flow.Chain
    90  
    91  	// NOTE: The ServiceAccountEnabled option is used by the playground
    92  	// https://github.com/onflow/flow-playground-api/blob/1ad967055f31db8f1ce88e008960e5fc14a9fbd1/compute/computer.go#L76
    93  	ServiceAccountEnabled bool
    94  
    95  	RuntimeParams
    96  
    97  	ProgramLoggerParams
    98  
    99  	EventEmitterParams
   100  
   101  	BlockInfoParams
   102  	TransactionInfoParams
   103  
   104  	ContractUpdaterParams
   105  }
   106  
   107  func DefaultEnvironmentParams() EnvironmentParams {
   108  	return EnvironmentParams{
   109  		Chain:                 flow.Mainnet.Chain(),
   110  		ServiceAccountEnabled: true,
   111  
   112  		RuntimeParams:         DefaultRuntimeParams(),
   113  		ProgramLoggerParams:   DefaultProgramLoggerParams(),
   114  		EventEmitterParams:    DefaultEventEmitterParams(),
   115  		BlockInfoParams:       DefaultBlockInfoParams(),
   116  		TransactionInfoParams: DefaultTransactionInfoParams(),
   117  		ContractUpdaterParams: DefaultContractUpdaterParams(),
   118  	}
   119  }