github.com/onflow/flow-go@v0.33.17/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/rs/zerolog" 7 otelTrace "go.opentelemetry.io/otel/trace" 8 9 reusableRuntime "github.com/onflow/flow-go/fvm/runtime" 10 "github.com/onflow/flow-go/fvm/tracing" 11 "github.com/onflow/flow-go/model/flow" 12 "github.com/onflow/flow-go/module/trace" 13 ) 14 15 // Environment implements the accounts business logic and exposes cadence 16 // runtime interface methods for the runtime. 17 type Environment interface { 18 runtime.Interface 19 20 // Tracer 21 StartChildSpan( 22 name trace.SpanName, 23 options ...otelTrace.SpanStartOption, 24 ) tracing.TracerSpan 25 26 Meter 27 28 // Runtime 29 BorrowCadenceRuntime() *reusableRuntime.ReusableCadenceRuntime 30 ReturnCadenceRuntime(*reusableRuntime.ReusableCadenceRuntime) 31 32 TransactionInfo 33 34 // ProgramLogger 35 Logger() zerolog.Logger 36 Logs() []string 37 38 // EventEmitter 39 Events() flow.EventsList 40 ServiceEvents() flow.EventsList 41 ConvertedServiceEvents() flow.ServiceEventList 42 43 // SystemContracts 44 AccountsStorageCapacity( 45 addresses []flow.Address, 46 payer flow.Address, 47 maxTxFees uint64, 48 ) ( 49 cadence.Value, 50 error, 51 ) 52 CheckPayerBalanceAndGetMaxTxFees( 53 payer flow.Address, 54 inclusionEffort uint64, 55 executionEffort uint64, 56 ) ( 57 cadence.Value, 58 error, 59 ) 60 DeductTransactionFees( 61 payer flow.Address, 62 inclusionEffort uint64, 63 executionEffort uint64, 64 ) ( 65 cadence.Value, 66 error, 67 ) 68 69 // AccountInfo 70 GetAccount(address flow.Address) (*flow.Account, error) 71 72 // RandomSourceHistory is the current block's derived random source. 73 // This source is only used by the core-contract that tracks the random source 74 // history for commit-reveal schemes. 75 RandomSourceHistory() ([]byte, error) 76 77 // FlushPendingUpdates flushes pending updates from the stateful environment 78 // modules (i.e., ContractUpdater) to the state transaction, and return 79 // the updated contract keys. 80 FlushPendingUpdates() ( 81 ContractUpdates, 82 error, 83 ) 84 85 // Reset resets all stateful environment modules (e.g., ContractUpdater, 86 // EventEmitter) to initial state. 87 Reset() 88 } 89 90 type EnvironmentParams struct { 91 Chain flow.Chain 92 93 // NOTE: The ServiceAccountEnabled option is used by the playground 94 // https://github.com/onflow/flow-playground-api/blob/1ad967055f31db8f1ce88e008960e5fc14a9fbd1/compute/computer.go#L76 95 ServiceAccountEnabled bool 96 97 RuntimeParams 98 99 ProgramLoggerParams 100 101 EventEmitterParams 102 103 BlockInfoParams 104 TransactionInfoParams 105 ScriptInfoParams 106 107 EntropyProvider 108 109 ContractUpdaterParams 110 } 111 112 func DefaultEnvironmentParams() EnvironmentParams { 113 return EnvironmentParams{ 114 Chain: flow.Mainnet.Chain(), 115 ServiceAccountEnabled: true, 116 117 RuntimeParams: DefaultRuntimeParams(), 118 ProgramLoggerParams: DefaultProgramLoggerParams(), 119 EventEmitterParams: DefaultEventEmitterParams(), 120 BlockInfoParams: DefaultBlockInfoParams(), 121 TransactionInfoParams: DefaultTransactionInfoParams(), 122 ContractUpdaterParams: DefaultContractUpdaterParams(), 123 } 124 } 125 126 func (env *EnvironmentParams) SetScriptInfoParams(info *ScriptInfoParams) { 127 env.ScriptInfoParams = *info 128 }