Skip to content

Commit

Permalink
Merge pull request #6258 from onflow/bastian/improve-runtime-interfac…
Browse files Browse the repository at this point in the history
…e-implementations

Use Cadence's empty and test runtime.Interface implementations
  • Loading branch information
turbolent authored Jul 25, 2024
2 parents 14f9fdd + 6b1c3b5 commit 608d9f5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1,035 deletions.
205 changes: 3 additions & 202 deletions cmd/util/ledger/util/migration_runtime_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ package util
import (
"errors"
"fmt"
"time"

"go.opentelemetry.io/otel/attribute"

"github.com/onflow/atree"
"github.com/onflow/cadence"
"github.com/onflow/cadence/runtime"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/interpreter"
Expand Down Expand Up @@ -39,12 +34,15 @@ type GerOrLoadProgramListenerFunc func(
// MigrationRuntimeInterface is a runtime interface that can be used in migrations.
// It only allows parsing and checking of contracts.
type MigrationRuntimeInterface struct {
runtime.EmptyRuntimeInterface
GetContractCodeFunc GetContractCodeFunc
GetContractNamesFunc GetContractNamesFunc
GetOrLoadProgramFunc GetOrLoadProgramFunc
GetOrLoadProgramListenerFunc GerOrLoadProgramListenerFunc
}

var _ runtime.Interface = &MigrationRuntimeInterface{}

func NewMigrationRuntimeInterface(
getCodeFunc GetContractCodeFunc,
getContractNamesFunc GetContractNamesFunc,
Expand Down Expand Up @@ -167,203 +165,6 @@ func (m *MigrationRuntimeInterface) GetOrLoadProgram(
return getOrLoadProgram(location, load)
}

func (m *MigrationRuntimeInterface) MeterMemory(_ common.MemoryUsage) error {
return nil
}

func (m *MigrationRuntimeInterface) MeterComputation(_ common.ComputationKind, _ uint) error {
return nil
}

func (m *MigrationRuntimeInterface) GetValue(_, _ []byte) (value []byte, err error) {
panic("unexpected GetValue call")
}

func (m *MigrationRuntimeInterface) SetValue(_, _, _ []byte) (err error) {
panic("unexpected SetValue call")
}

func (m *MigrationRuntimeInterface) CreateAccount(_ runtime.Address) (address runtime.Address, err error) {
panic("unexpected CreateAccount call")
}

func (m *MigrationRuntimeInterface) AddEncodedAccountKey(_ runtime.Address, _ []byte) error {
panic("unexpected AddEncodedAccountKey call")
}

func (m *MigrationRuntimeInterface) RevokeEncodedAccountKey(_ runtime.Address, _ int) (publicKey []byte, err error) {
panic("unexpected RevokeEncodedAccountKey call")
}

func (m *MigrationRuntimeInterface) AddAccountKey(
_ runtime.Address,
_ *runtime.PublicKey,
_ runtime.HashAlgorithm,
_ int,
) (*runtime.AccountKey, error) {
panic("unexpected AddAccountKey call")
}

func (m *MigrationRuntimeInterface) GetAccountKey(_ runtime.Address, _ uint32) (*runtime.AccountKey, error) {
panic("unexpected GetAccountKey call")
}

func (m *MigrationRuntimeInterface) RevokeAccountKey(_ runtime.Address, _ uint32) (*runtime.AccountKey, error) {
panic("unexpected RevokeAccountKey call")
}

func (m *MigrationRuntimeInterface) UpdateAccountContractCode(_ common.AddressLocation, _ []byte) (err error) {
panic("unexpected UpdateAccountContractCode call")
}

func (m *MigrationRuntimeInterface) RemoveAccountContractCode(common.AddressLocation) (err error) {
panic("unexpected RemoveAccountContractCode call")
}

func (m *MigrationRuntimeInterface) GetSigningAccounts() ([]runtime.Address, error) {
panic("unexpected GetSigningAccounts call")
}

func (m *MigrationRuntimeInterface) ProgramLog(_ string) error {
panic("unexpected ProgramLog call")
}

func (m *MigrationRuntimeInterface) EmitEvent(_ cadence.Event) error {
panic("unexpected EmitEvent call")
}

func (m *MigrationRuntimeInterface) ValueExists(_, _ []byte) (exists bool, err error) {
panic("unexpected ValueExists call")
}

func (m *MigrationRuntimeInterface) GenerateUUID() (uint64, error) {
panic("unexpected GenerateUUID call")
}

func (m *MigrationRuntimeInterface) GetComputationLimit() uint64 {
panic("unexpected GetComputationLimit call")
}

func (m *MigrationRuntimeInterface) SetComputationUsed(_ uint64) error {
panic("unexpected SetComputationUsed call")
}

func (m *MigrationRuntimeInterface) DecodeArgument(_ []byte, _ cadence.Type) (cadence.Value, error) {
panic("unexpected DecodeArgument call")
}

func (m *MigrationRuntimeInterface) GetCurrentBlockHeight() (uint64, error) {
panic("unexpected GetCurrentBlockHeight call")
}

func (m *MigrationRuntimeInterface) GetBlockAtHeight(_ uint64) (block runtime.Block, exists bool, err error) {
panic("unexpected GetBlockAtHeight call")
}

func (m *MigrationRuntimeInterface) ReadRandom([]byte) error {
panic("unexpected ReadRandom call")
}

func (m *MigrationRuntimeInterface) VerifySignature(
_ []byte,
_ string,
_ []byte,
_ []byte,
_ runtime.SignatureAlgorithm,
_ runtime.HashAlgorithm,
) (bool, error) {
panic("unexpected VerifySignature call")
}

func (m *MigrationRuntimeInterface) Hash(_ []byte, _ string, _ runtime.HashAlgorithm) ([]byte, error) {
panic("unexpected Hash call")
}

func (m *MigrationRuntimeInterface) GetAccountBalance(_ common.Address) (value uint64, err error) {
panic("unexpected GetAccountBalance call")
}

func (m *MigrationRuntimeInterface) GetAccountAvailableBalance(_ common.Address) (value uint64, err error) {
panic("unexpected GetAccountAvailableBalance call")
}

func (m *MigrationRuntimeInterface) GetStorageUsed(_ runtime.Address) (value uint64, err error) {
panic("unexpected GetStorageUsed call")
}

func (m *MigrationRuntimeInterface) GetStorageCapacity(_ runtime.Address) (value uint64, err error) {
panic("unexpected GetStorageCapacity call")
}

func (m *MigrationRuntimeInterface) ImplementationDebugLog(_ string) error {
panic("unexpected ImplementationDebugLog call")
}

func (m *MigrationRuntimeInterface) ValidatePublicKey(_ *runtime.PublicKey) error {
panic("unexpected ValidatePublicKey call")
}

func (m *MigrationRuntimeInterface) GetAccountContractNames(_ runtime.Address) ([]string, error) {
panic("unexpected GetAccountContractNames call")
}

func (m *MigrationRuntimeInterface) AllocateStorageIndex(_ []byte) (atree.StorageIndex, error) {
panic("unexpected AllocateStorageIndex call")
}

func (m *MigrationRuntimeInterface) ComputationUsed() (uint64, error) {
panic("unexpected ComputationUsed call")
}

func (m *MigrationRuntimeInterface) MemoryUsed() (uint64, error) {
panic("unexpected MemoryUsed call")
}

func (m *MigrationRuntimeInterface) InteractionUsed() (uint64, error) {
panic("unexpected InteractionUsed call")
}

func (m *MigrationRuntimeInterface) SetInterpreterSharedState(_ *interpreter.SharedState) {
panic("unexpected SetInterpreterSharedState call")
}

func (m *MigrationRuntimeInterface) GetInterpreterSharedState() *interpreter.SharedState {
panic("unexpected GetInterpreterSharedState call")
}

func (m *MigrationRuntimeInterface) AccountKeysCount(_ runtime.Address) (uint32, error) {
panic("unexpected AccountKeysCount call")
}

func (m *MigrationRuntimeInterface) BLSVerifyPOP(_ *runtime.PublicKey, _ []byte) (bool, error) {
panic("unexpected BLSVerifyPOP call")
}

func (m *MigrationRuntimeInterface) BLSAggregateSignatures(_ [][]byte) ([]byte, error) {
panic("unexpected BLSAggregateSignatures call")
}

func (m *MigrationRuntimeInterface) BLSAggregatePublicKeys(_ []*runtime.PublicKey) (*runtime.PublicKey, error) {
panic("unexpected BLSAggregatePublicKeys call")
}

func (m *MigrationRuntimeInterface) ResourceOwnerChanged(
_ *interpreter.Interpreter,
_ *interpreter.CompositeValue,
_ common.Address,
_ common.Address,
) {
panic("unexpected ResourceOwnerChanged call")
}

func (m *MigrationRuntimeInterface) GenerateAccountID(_ common.Address) (uint64, error) {
panic("unexpected GenerateAccountID call")
}

func (m *MigrationRuntimeInterface) RecordTrace(_ string, _ runtime.Location, _ time.Duration, _ []attribute.KeyValue) {
panic("unexpected RecordTrace call")
}

type migrationTransactionPreparer struct {
state.NestedTransactionPreparer
derived.DerivedTransactionPreparer
Expand Down
Loading

0 comments on commit 608d9f5

Please sign in to comment.