From 90a268109538c1f5eae677348f7266f59ac98f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 22 Aug 2024 17:30:39 -0700 Subject: [PATCH] update implementations of RecoverProgram --- cmd/util/ledger/util/migration_runtime_interface.go | 4 ++-- fvm/environment/facade_env.go | 3 +-- fvm/environment/mock/environment.go | 10 +++++----- fvm/environment/program_recovery.go | 8 ++------ 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/cmd/util/ledger/util/migration_runtime_interface.go b/cmd/util/ledger/util/migration_runtime_interface.go index f91c4116096..7db157f860f 100644 --- a/cmd/util/ledger/util/migration_runtime_interface.go +++ b/cmd/util/ledger/util/migration_runtime_interface.go @@ -175,8 +175,8 @@ func (m *MigrationRuntimeInterface) GetOrLoadProgram( func (m *MigrationRuntimeInterface) RecoverProgram( program *ast.Program, location common.Location, -) (*ast.Program, error) { - return environment.RecoverProgram(nil, m.chainID, program, location) +) ([]byte, error) { + return environment.RecoverProgram(m.chainID, program, location) } type migrationTransactionPreparer struct { diff --git a/fvm/environment/facade_env.go b/fvm/environment/facade_env.go index 88812b4cec3..a9e558c5106 100644 --- a/fvm/environment/facade_env.go +++ b/fvm/environment/facade_env.go @@ -336,9 +336,8 @@ func (*facadeEnvironment) GetInterpreterSharedState() *interpreter.SharedState { return nil } -func (env *facadeEnvironment) RecoverProgram(program *ast.Program, location common.Location) (*ast.Program, error) { +func (env *facadeEnvironment) RecoverProgram(program *ast.Program, location common.Location) ([]byte, error) { return RecoverProgram( - env, env.chain.ChainID(), program, location, diff --git a/fvm/environment/mock/environment.go b/fvm/environment/mock/environment.go index c47f0713e8b..967095141bc 100644 --- a/fvm/environment/mock/environment.go +++ b/fvm/environment/mock/environment.go @@ -1407,23 +1407,23 @@ func (_m *Environment) RecordTrace(operation string, location common.Location, d } // RecoverProgram provides a mock function with given fields: program, location -func (_m *Environment) RecoverProgram(program *ast.Program, location common.Location) (*ast.Program, error) { +func (_m *Environment) RecoverProgram(program *ast.Program, location common.Location) ([]byte, error) { ret := _m.Called(program, location) if len(ret) == 0 { panic("no return value specified for RecoverProgram") } - var r0 *ast.Program + var r0 []byte var r1 error - if rf, ok := ret.Get(0).(func(*ast.Program, common.Location) (*ast.Program, error)); ok { + if rf, ok := ret.Get(0).(func(*ast.Program, common.Location) ([]byte, error)); ok { return rf(program, location) } - if rf, ok := ret.Get(0).(func(*ast.Program, common.Location) *ast.Program); ok { + if rf, ok := ret.Get(0).(func(*ast.Program, common.Location) []byte); ok { r0 = rf(program, location) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*ast.Program) + r0 = ret.Get(0).([]byte) } } diff --git a/fvm/environment/program_recovery.go b/fvm/environment/program_recovery.go index 9f2485c617d..439d6a46d02 100644 --- a/fvm/environment/program_recovery.go +++ b/fvm/environment/program_recovery.go @@ -5,7 +5,6 @@ import ( "github.com/onflow/cadence/runtime/ast" "github.com/onflow/cadence/runtime/common" - "github.com/onflow/cadence/runtime/parser" "github.com/onflow/cadence/runtime/sema" "github.com/onflow/flow-go/fvm/systemcontracts" @@ -13,12 +12,11 @@ import ( ) func RecoverProgram( - memoryGauge common.MemoryGauge, chainID flow.ChainID, program *ast.Program, location common.Location, ) ( - *ast.Program, + []byte, error, ) { addressLocation, ok := location.(common.AddressLocation) @@ -36,9 +34,7 @@ func RecoverProgram( contractName := addressLocation.Name - code := RecoveredFungibleTokenCode(fungibleTokenAddress, contractName) - - return parser.ParseProgram(memoryGauge, []byte(code), parser.Config{}) + return []byte(RecoveredFungibleTokenCode(fungibleTokenAddress, contractName)), nil } func RecoveredFungibleTokenCode(fungibleTokenAddress common.Address, contractName string) string {