core: add System.Contract.GetCallFlags interop
Part of #1055. It returns calling flags of the current context.
This commit is contained in:
parent
842feb2533
commit
f31ce9289d
5 changed files with 23 additions and 0 deletions
|
@ -25,6 +25,7 @@ var syscalls = map[string]map[string]Syscall{
|
||||||
"CreateStandardAccount": {"System.Contract.CreateStandardAccount", false},
|
"CreateStandardAccount": {"System.Contract.CreateStandardAccount", false},
|
||||||
"Destroy": {"System.Contract.Destroy", false},
|
"Destroy": {"System.Contract.Destroy", false},
|
||||||
"IsStandard": {"System.Contract.IsStandard", false},
|
"IsStandard": {"System.Contract.IsStandard", false},
|
||||||
|
"GetCallFlags": {"System.Contract.GetCallFlags", false},
|
||||||
"Update": {"System.Contract.Update", false},
|
"Update": {"System.Contract.Update", false},
|
||||||
},
|
},
|
||||||
"crypto": {
|
"crypto": {
|
||||||
|
|
|
@ -530,3 +530,9 @@ func contractCreateStandardAccount(ic *interop.Context, v *vm.VM) error {
|
||||||
v.Estack().PushVal(p.GetScriptHash().BytesBE())
|
v.Estack().PushVal(p.GetScriptHash().BytesBE())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// contractGetCallFlags returns current context calling flags.
|
||||||
|
func contractGetCallFlags(_ *interop.Context, v *vm.VM) error {
|
||||||
|
v.Estack().PushVal(v.Context().GetCallFlags())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -582,3 +582,12 @@ func TestContractUpdate(t *testing.T) {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContractGetCallFlags(t *testing.T) {
|
||||||
|
v, ic, bc := createVM(t)
|
||||||
|
defer bc.Close()
|
||||||
|
|
||||||
|
v.LoadScriptWithHash([]byte{byte(opcode.RET)}, util.Uint160{1, 2, 3}, smartcontract.All)
|
||||||
|
require.NoError(t, contractGetCallFlags(ic, v))
|
||||||
|
require.Equal(t, int64(smartcontract.All), v.Estack().Pop().Value().(*big.Int).Int64())
|
||||||
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ var systemInterops = []interop.Function{
|
||||||
{Name: "System.Contract.Destroy", Func: contractDestroy, Price: 1000000,
|
{Name: "System.Contract.Destroy", Func: contractDestroy, Price: 1000000,
|
||||||
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
|
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
|
||||||
{Name: "System.Contract.IsStandard", Func: contractIsStandard, Price: 30000},
|
{Name: "System.Contract.IsStandard", Func: contractIsStandard, Price: 30000},
|
||||||
|
{Name: "System.Contract.GetCallFlags", Func: contractGetCallFlags, Price: 30000},
|
||||||
{Name: "System.Contract.Update", Func: contractUpdate, Price: 0,
|
{Name: "System.Contract.Update", Func: contractUpdate, Price: 0,
|
||||||
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
|
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
|
||||||
{Name: "System.Enumerator.Concat", Func: enumerator.Concat, Price: 400},
|
{Name: "System.Enumerator.Concat", Func: enumerator.Concat, Price: 400},
|
||||||
|
|
|
@ -49,3 +49,9 @@ func IsStandard(h []byte) bool {
|
||||||
func CreateStandardAccount(pub []byte) []byte {
|
func CreateStandardAccount(pub []byte) []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCallFlags returns calling flags which execution context was created with.
|
||||||
|
// This function uses `System.Contract.GetCallFlags` syscall.
|
||||||
|
func GetCallFlags() int64 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue