From c87e2262c3cf78ebb906370571870c078e392cd3 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 7 Aug 2020 16:58:09 +0300 Subject: [PATCH] core: remove ScriptHashGetter from interop context We have VM inside the context, so don't need ScriptHashGetter anymore. --- pkg/core/interop/context.go | 2 -- pkg/core/interop/runtime/witness.go | 4 ++-- pkg/core/native/native_nep5.go | 2 +- pkg/vm/vm.go | 7 ------- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index 045fc5246..ad1dbb958 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -35,7 +35,6 @@ type Context struct { Notifications []state.NotificationEvent Log *zap.Logger Invocations map[util.Uint160]int - ScriptGetter vm.ScriptHashGetter VM *vm.VM Functions [][]Function } @@ -176,7 +175,6 @@ func (ic *Context) SpawnVM() *vm.VM { v := vm.NewWithTrigger(ic.Trigger) v.GasLimit = -1 v.SyscallHandler = ic.SyscallHandler - ic.ScriptGetter = v ic.VM = v return v } diff --git a/pkg/core/interop/runtime/witness.go b/pkg/core/interop/runtime/witness.go index 727a8427e..0005300b5 100644 --- a/pkg/core/interop/runtime/witness.go +++ b/pkg/core/interop/runtime/witness.go @@ -16,13 +16,13 @@ import ( // for verifying in the interop context. func CheckHashedWitness(ic *interop.Context, hash util.Uint160) (bool, error) { if tx, ok := ic.Container.(*transaction.Transaction); ok { - return checkScope(ic.DAO, tx, ic.ScriptGetter, hash) + return checkScope(ic.DAO, tx, ic.VM, hash) } return false, errors.New("script container is not a transaction") } -func checkScope(d dao.DAO, tx *transaction.Transaction, v vm.ScriptHashGetter, hash util.Uint160) (bool, error) { +func checkScope(d dao.DAO, tx *transaction.Transaction, v *vm.VM, hash util.Uint160) (bool, error) { for _, c := range tx.Signers { if c.Account == hash { if c.Scopes == transaction.Global { diff --git a/pkg/core/native/native_nep5.go b/pkg/core/native/native_nep5.go index dd64acb02..b24b83125 100644 --- a/pkg/core/native/native_nep5.go +++ b/pkg/core/native/native_nep5.go @@ -175,7 +175,7 @@ func (c *nep5TokenNative) transfer(ic *interop.Context, from, to util.Uint160, a return errors.New("negative amount") } - caller := ic.ScriptGetter.GetCallingScriptHash() + caller := ic.VM.GetCallingScriptHash() if caller.Equals(util.Uint160{}) || !from.Equals(caller) { ok, err := runtime.CheckHashedWitness(ic, from) if err != nil { diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index a1cd02358..49ed636fa 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -40,13 +40,6 @@ func newError(ip int, op opcode.Opcode, err interface{}) *errorAtInstruct { // StateMessage is a vm state message which could be used as additional info for example by cli. type StateMessage string -// ScriptHashGetter defines an interface for getting calling, entry and current script hashes. -type ScriptHashGetter interface { - GetCallingScriptHash() util.Uint160 - GetEntryScriptHash() util.Uint160 - GetCurrentScriptHash() util.Uint160 -} - const ( // MaxInvocationStackSize is the maximum size of an invocation stack. MaxInvocationStackSize = 1024