|
6 | 6 | "github.com/onflow/cadence/runtime/common" |
7 | 7 | "github.com/onflow/cadence/runtime/interpreter" |
8 | 8 |
|
| 9 | + "github.com/onflow/flow-go/engine/execution/state/delta" |
9 | 10 | "github.com/onflow/flow-go/fvm/derived" |
10 | 11 | "github.com/onflow/flow-go/fvm/state" |
11 | 12 | "github.com/onflow/flow-go/fvm/storage" |
@@ -157,6 +158,34 @@ func NewScriptEnvironment( |
157 | 158 | }) |
158 | 159 | } |
159 | 160 |
|
| 161 | +// This is mainly used by command line tools, the emulator, and cadence tools |
| 162 | +// testing. |
| 163 | +func NewScriptEnvironmentFromStorageSnapshot( |
| 164 | + params EnvironmentParams, |
| 165 | + storageSnapshot state.StorageSnapshot, |
| 166 | +) *facadeEnvironment { |
| 167 | + derivedBlockData := derived.NewEmptyDerivedBlockData() |
| 168 | + derivedTxn, err := derivedBlockData.NewSnapshotReadDerivedTransactionData( |
| 169 | + derived.EndOfBlockExecutionTime, |
| 170 | + derived.EndOfBlockExecutionTime) |
| 171 | + if err != nil { |
| 172 | + panic(err) |
| 173 | + } |
| 174 | + |
| 175 | + txn := storage.SerialTransaction{ |
| 176 | + NestedTransaction: state.NewTransactionState( |
| 177 | + delta.NewDeltaView(storageSnapshot), |
| 178 | + state.DefaultParameters()), |
| 179 | + DerivedTransactionCommitter: derivedTxn, |
| 180 | + } |
| 181 | + |
| 182 | + return NewScriptEnv( |
| 183 | + context.Background(), |
| 184 | + tracing.NewTracerSpan(), |
| 185 | + params, |
| 186 | + txn) |
| 187 | +} |
| 188 | + |
160 | 189 | func NewScriptEnv( |
161 | 190 | ctx context.Context, |
162 | 191 | tracer tracing.TracerSpan, |
|
0 commit comments