native: don't push void result in Call

This was done in https://github.com/neo-project/neo/pull/1693
for native calls. `OnPersist` script still uses `DROP` though
as value is pushed via `CheckReturn` logic for regular calls.
This commit is contained in:
Evgenii Stratonikov 2020-09-21 17:34:40 +03:00
parent 877b8ece63
commit 30526046e7
3 changed files with 7 additions and 2 deletions

View file

@ -82,6 +82,7 @@ type Method = func(ic *Context, args []stackitem.Item) stackitem.Item
// MethodAndPrice is a native-contract method descriptor. // MethodAndPrice is a native-contract method descriptor.
type MethodAndPrice struct { type MethodAndPrice struct {
Func Method Func Method
MD *manifest.Method
Price int64 Price int64
RequiredFlags smartcontract.CallFlag RequiredFlags smartcontract.CallFlag
} }
@ -123,6 +124,7 @@ func NewContractMD(name string) *ContractMD {
// AddMethod adds new method to a native contract. // AddMethod adds new method to a native contract.
func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method, safe bool) { func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method, safe bool) {
c.Manifest.ABI.Methods = append(c.Manifest.ABI.Methods, *desc) c.Manifest.ABI.Methods = append(c.Manifest.ABI.Methods, *desc)
md.MD = desc
c.Methods[desc.Name] = *md c.Methods[desc.Name] = *md
if safe { if safe {
c.Manifest.SafeMethods.Add(desc.Name) c.Manifest.SafeMethods.Add(desc.Name)

View file

@ -77,8 +77,8 @@ func callExInternal(ic *interop.Context, h []byte, name string, args []stackitem
} }
// use Jump not Call here because context was loaded in LoadScript above. // use Jump not Call here because context was loaded in LoadScript above.
ic.VM.Jump(ic.VM.Context(), md.Offset) ic.VM.Jump(ic.VM.Context(), md.Offset)
ic.VM.Context().CheckReturn = true
} }
ic.VM.Context().CheckReturn = true
md = cs.Manifest.ABI.GetMethod(manifest.MethodInit) md = cs.Manifest.ABI.GetMethod(manifest.MethodInit)
if md != nil { if md != nil {

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/interop" "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/core/state"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
) )
// Deploy deploys native contract. // Deploy deploys native contract.
@ -62,6 +63,8 @@ func Call(ic *interop.Context) error {
return errors.New("gas limit exceeded") return errors.New("gas limit exceeded")
} }
result := m.Func(ic, args) result := m.Func(ic, args)
ic.VM.Estack().PushVal(result) if m.MD.ReturnType != smartcontract.VoidType {
ic.VM.Estack().PushVal(result)
}
return nil return nil
} }