Merge pull request #1271 from nspcc-dev/core/call_from_native

core: contractCall from native contracts
This commit is contained in:
Roman Khimov 2020-08-07 21:24:50 +03:00 committed by GitHub
commit f5131491b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 558 additions and 394 deletions

View file

@ -11,18 +11,18 @@ import (
)
// GasLeft returns remaining amount of GAS.
func GasLeft(_ *interop.Context, v *vm.VM) error {
if v.GasLimit == -1 {
v.Estack().PushVal(v.GasLimit)
func GasLeft(ic *interop.Context) error {
if ic.VM.GasLimit == -1 {
ic.VM.Estack().PushVal(ic.VM.GasLimit)
} else {
v.Estack().PushVal(v.GasLimit - v.GasConsumed())
ic.VM.Estack().PushVal(ic.VM.GasLimit - ic.VM.GasConsumed())
}
return nil
}
// GetNotifications returns notifications emitted by current contract execution.
func GetNotifications(ic *interop.Context, v *vm.VM) error {
item := v.Estack().Pop().Item()
func GetNotifications(ic *interop.Context) error {
item := ic.VM.Estack().Pop().Item()
notifications := ic.Notifications
if _, ok := item.(stackitem.Null); !ok {
b, err := item.TryBytes()
@ -52,16 +52,16 @@ func GetNotifications(ic *interop.Context, v *vm.VM) error {
})
arr.Append(ev)
}
v.Estack().PushVal(arr)
ic.VM.Estack().PushVal(arr)
return nil
}
// GetInvocationCounter returns how many times current contract was invoked during current tx execution.
func GetInvocationCounter(ic *interop.Context, v *vm.VM) error {
count, ok := ic.Invocations[v.GetCurrentScriptHash()]
func GetInvocationCounter(ic *interop.Context) error {
count, ok := ic.Invocations[ic.VM.GetCurrentScriptHash()]
if !ok {
return errors.New("current contract wasn't invoked from others")
}
v.Estack().PushVal(count)
ic.VM.Estack().PushVal(count)
return nil
}