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