Skip to content

Commit

Permalink
native: don't push void result in Call
Browse files Browse the repository at this point in the history
This was done in neo-project/neo#1693
for native calls. `OnPersist` script still uses `DROP` though
as value is pushed via `CheckReturn` logic for regular calls.
  • Loading branch information
fyrchik authored and AnnaShaleva committed Oct 1, 2020
1 parent debd1c5 commit c3fabdf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/core/interop/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Method = func(ic *Context, args []stackitem.Item) stackitem.Item
// MethodAndPrice is a native-contract method descriptor.
type MethodAndPrice struct {
Func Method
MD *manifest.Method
Price int64
RequiredFlags smartcontract.CallFlag
}
Expand Down Expand Up @@ -123,6 +124,7 @@ func NewContractMD(name string) *ContractMD {
// AddMethod adds new method to a native contract.
func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method, safe bool) {
c.Manifest.ABI.Methods = append(c.Manifest.ABI.Methods, *desc)
md.MD = desc
c.Methods[desc.Name] = *md
if safe {
c.Manifest.SafeMethods.Add(desc.Name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/interop/contract/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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)
if md != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/core/native/interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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/smartcontract"
)

// Deploy deploys native contract.
Expand Down Expand Up @@ -62,6 +63,8 @@ func Call(ic *interop.Context) error {
return errors.New("gas limit exceeded")
}
result := m.Func(ic, args)
ic.VM.Estack().PushVal(result)
if m.MD.ReturnType != smartcontract.VoidType {
ic.VM.Estack().PushVal(result)
}
return nil
}

0 comments on commit c3fabdf

Please sign in to comment.