core: add System.Contract.GetCallFlags interop

Part of #1055.

It returns calling flags of the current context.
This commit is contained in:
Anna Shaleva 2020-07-16 12:13:55 +03:00
parent 842feb2533
commit f31ce9289d
5 changed files with 23 additions and 0 deletions

View file

@ -25,6 +25,7 @@ var syscalls = map[string]map[string]Syscall{
"CreateStandardAccount": {"System.Contract.CreateStandardAccount", false},
"Destroy": {"System.Contract.Destroy", false},
"IsStandard": {"System.Contract.IsStandard", false},
"GetCallFlags": {"System.Contract.GetCallFlags", false},
"Update": {"System.Contract.Update", false},
},
"crypto": {

View file

@ -530,3 +530,9 @@ func contractCreateStandardAccount(ic *interop.Context, v *vm.VM) error {
v.Estack().PushVal(p.GetScriptHash().BytesBE())
return nil
}
// contractGetCallFlags returns current context calling flags.
func contractGetCallFlags(_ *interop.Context, v *vm.VM) error {
v.Estack().PushVal(v.Context().GetCallFlags())
return nil
}

View file

@ -582,3 +582,12 @@ func TestContractUpdate(t *testing.T) {
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())
}

View file

@ -93,6 +93,7 @@ var systemInterops = []interop.Function{
{Name: "System.Contract.Destroy", Func: contractDestroy, Price: 1000000,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
{Name: "System.Contract.IsStandard", Func: contractIsStandard, Price: 30000},
{Name: "System.Contract.GetCallFlags", Func: contractGetCallFlags, Price: 30000},
{Name: "System.Contract.Update", Func: contractUpdate, Price: 0,
AllowedTriggers: trigger.Application, RequiredFlags: smartcontract.AllowModifyStates},
{Name: "System.Enumerator.Concat", Func: enumerator.Concat, Price: 400},

View file

@ -49,3 +49,9 @@ func IsStandard(h []byte) bool {
func CreateStandardAccount(pub []byte) []byte {
return nil
}
// GetCallFlags returns calling flags which execution context was created with.
// This function uses `System.Contract.GetCallFlags` syscall.
func GetCallFlags() int64 {
return 0
}