core: optimize contractCallEx

Provide script hash upon script load.
This commit is contained in:
Evgenii Stratonikov 2020-06-11 10:32:55 +03:00
parent 61edc8705e
commit 55ab7535be
2 changed files with 10 additions and 1 deletions

View file

@ -442,7 +442,7 @@ func contractCallExInternal(ic *interop.Context, v *vm.VM, h []byte, method stac
return errors.New("disallowed method call")
}
}
v.LoadScript(cs.Script)
v.LoadScriptWithHash(cs.Script, u)
v.Estack().PushVal(args)
v.Estack().PushVal(method)
return nil

View file

@ -268,6 +268,15 @@ func (v *VM) LoadScript(b []byte) {
v.istack.PushVal(ctx)
}
// LoadScriptWithHash if similar to the LoadScript method, but it also loads
// given script hash directly into the Context to avoid its recalculations. It's
// up to user of this function to make sure the script and hash match each other.
func (v *VM) LoadScriptWithHash(b []byte, hash util.Uint160) {
v.LoadScript(b)
ctx := v.Context()
ctx.scriptHash = hash
}
// Context returns the current executed context. Nil if there is no context,
// which implies no program is loaded.
func (v *VM) Context() *Context {