mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
core: support System.Runtime.GetAddressVersion syscall
This commit is contained in:
parent
4775705f00
commit
d942940a82
6 changed files with 30 additions and 0 deletions
|
@ -71,6 +71,7 @@ func TestSyscallExecution(t *testing.T) {
|
|||
"runtime.BurnGas": {interopnames.SystemRuntimeBurnGas, []string{"1"}, true},
|
||||
"runtime.CheckWitness": {interopnames.SystemRuntimeCheckWitness, []string{b}, false},
|
||||
"runtime.GasLeft": {interopnames.SystemRuntimeGasLeft, nil, false},
|
||||
"runtime.GetAddressVersion": {interopnames.SystemRuntimeGetAddressVersion, nil, false},
|
||||
"runtime.GetCallingScriptHash": {interopnames.SystemRuntimeGetCallingScriptHash, nil, false},
|
||||
"runtime.GetEntryScriptHash": {interopnames.SystemRuntimeGetEntryScriptHash, nil, false},
|
||||
"runtime.GetExecutingScriptHash": {interopnames.SystemRuntimeGetExecutingScriptHash, nil, false},
|
||||
|
|
|
@ -16,6 +16,7 @@ const (
|
|||
SystemRuntimeBurnGas = "System.Runtime.BurnGas"
|
||||
SystemRuntimeCheckWitness = "System.Runtime.CheckWitness"
|
||||
SystemRuntimeGasLeft = "System.Runtime.GasLeft"
|
||||
SystemRuntimeGetAddressVersion = "System.Runtime.GetAddressVersion"
|
||||
SystemRuntimeGetCallingScriptHash = "System.Runtime.GetCallingScriptHash"
|
||||
SystemRuntimeGetEntryScriptHash = "System.Runtime.GetEntryScriptHash"
|
||||
SystemRuntimeGetExecutingScriptHash = "System.Runtime.GetExecutingScriptHash"
|
||||
|
@ -51,6 +52,7 @@ var names = []string{
|
|||
SystemRuntimeBurnGas,
|
||||
SystemRuntimeCheckWitness,
|
||||
SystemRuntimeGasLeft,
|
||||
SystemRuntimeGetAddressVersion,
|
||||
SystemRuntimeGetCallingScriptHash,
|
||||
SystemRuntimeGetEntryScriptHash,
|
||||
SystemRuntimeGetExecutingScriptHash,
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
|
@ -72,6 +73,12 @@ func GetInvocationCounter(ic *interop.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetAddressVersion returns the address version of the current protocol.
|
||||
func GetAddressVersion(ic *interop.Context) error {
|
||||
ic.VM.Estack().PushItem(stackitem.NewBigInteger(big.NewInt(int64(address.NEO3Prefix))))
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetNetwork returns chain network number.
|
||||
func GetNetwork(ic *interop.Context) error {
|
||||
m := ic.Chain.GetConfig().Magic
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
||||
|
@ -207,6 +208,16 @@ func TestSystemRuntimeGetNetwork(t *testing.T) {
|
|||
e.InvokeScriptCheckHALT(t, w.Bytes(), []neotest.Signer{acc}, stackitem.NewBigInteger(big.NewInt(int64(bc.GetConfig().Magic))))
|
||||
}
|
||||
|
||||
func TestSystemRuntimeGetAddressVersion(t *testing.T) {
|
||||
bc, acc := chain.NewSingle(t)
|
||||
e := neotest.NewExecutor(t, bc, acc, acc)
|
||||
w := io.NewBufBinWriter()
|
||||
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemRuntimeGetAddressVersion)
|
||||
require.NoError(t, w.Err)
|
||||
e.InvokeScriptCheckHALT(t, w.Bytes(), []neotest.Signer{acc}, stackitem.NewBigInteger(big.NewInt(int64(address.NEO3Prefix))))
|
||||
}
|
||||
|
||||
func TestSystemRuntimeBurnGas(t *testing.T) {
|
||||
bc, acc := chain.NewSingle(t)
|
||||
e := neotest.NewExecutor(t, bc, acc, acc)
|
||||
|
|
|
@ -46,6 +46,7 @@ var systemInterops = []interop.Function{
|
|||
{Name: interopnames.SystemRuntimeCheckWitness, Func: runtime.CheckWitness, Price: 1 << 10,
|
||||
RequiredFlags: callflag.NoneFlag, ParamCount: 1},
|
||||
{Name: interopnames.SystemRuntimeGasLeft, Func: runtime.GasLeft, Price: 1 << 4},
|
||||
{Name: interopnames.SystemRuntimeGetAddressVersion, Func: runtime.GetAddressVersion, Price: 1 << 3},
|
||||
{Name: interopnames.SystemRuntimeGetCallingScriptHash, Func: runtime.GetCallingScriptHash, Price: 1 << 4},
|
||||
{Name: interopnames.SystemRuntimeGetEntryScriptHash, Func: runtime.GetEntryScriptHash, Price: 1 << 4},
|
||||
{Name: interopnames.SystemRuntimeGetExecutingScriptHash, Func: runtime.GetExecutingScriptHash, Price: 1 << 4},
|
||||
|
|
|
@ -46,6 +46,14 @@ func Notify(name string, args ...interface{}) {
|
|||
neogointernal.Syscall2NoReturn("System.Runtime.Notify", name, args)
|
||||
}
|
||||
|
||||
// GetAddressVersion returns the address version of the current protocol. The
|
||||
// address version represents the byte used to prepend to Neo addresses when
|
||||
// encoding them. The default value for Neo3 is 53 (0x35). This function uses
|
||||
// `System.Runtime.GetAddressVersion` syscall.
|
||||
func GetAddressVersion() int {
|
||||
return neogointernal.Syscall0("System.Runtime.GetAddressVersion").(int)
|
||||
}
|
||||
|
||||
// GetNetwork returns network magic number. This function uses
|
||||
// `System.Runtime.GetNetwork` syscall.
|
||||
func GetNetwork() int {
|
||||
|
|
Loading…
Reference in a new issue