interop: add runtime.LoadScript

This commit is contained in:
Roman Khimov 2022-09-29 23:49:31 +03:00
parent 4e26f4b26e
commit de2de986a7

View file

@ -6,6 +6,7 @@ package runtime
import ( import (
"github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
"github.com/nspcc-dev/neo-go/pkg/interop/neogointernal" "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
) )
@ -29,6 +30,21 @@ func CheckWitness(hashOrKey []byte) bool {
return neogointernal.Syscall1("System.Runtime.CheckWitness", hashOrKey).(bool) return neogointernal.Syscall1("System.Runtime.CheckWitness", hashOrKey).(bool)
} }
// LoadScript loads the given bytecode into the VM and executes it with the
// given call flags and arguments. This bytecode is executed as is from byte 0,
// it's not a deployed contract that can have methods. The execution context is
// limited to read only actions ([contract.ReadOnly]) irrespective of provided
// call flags (you can only restrict them further with this option). An item is
// always returned from this call, either it's the one returned from the script
// (and it can only return one) or it's a Null stack item if the script returns
// nothing. Note that this is somewhat similar to [contract.Call], so the
// script can ABORT the transaction or THROW an exception, make sure you
// appropriately handle exceptions if bytecode comes from untrusted source.
// This function uses `System.Runtime.LoadScript` syscall.
func LoadScript(script []byte, f contract.CallFlag, args ...interface{}) interface{} {
return neogointernal.Syscall3("System.Runtime.LoadScript", script, f, args)
}
// Log instructs VM to log the given message. It's mostly used for debugging // Log instructs VM to log the given message. It's mostly used for debugging
// purposes as these messages are not saved anywhere normally and usually are // purposes as these messages are not saved anywhere normally and usually are
// only visible in the VM logs. This function uses `System.Runtime.Log` syscall. // only visible in the VM logs. This function uses `System.Runtime.Log` syscall.