core: introduce CheckReturnState constants
At the moment we should have 3 possible options to check return state during vm context unloading: * no check * ensure the stack is empty * ensure the stack is not empty It is necessary to distinguish them because new _deploy method shouldn't left anything on stack. Example: if we use _deploy method before some ordinary contract method which returns one value. Without these changes the contract invocation will fail due to 2 elements on stack left after invocation (the first `null` element is from _deploy, the second element is return-value from the ordinary contract method).
This commit is contained in:
parent
659fb89beb
commit
fe1f0a7245
5 changed files with 29 additions and 9 deletions
|
@ -46,9 +46,22 @@ type Context struct {
|
|||
callFlag smartcontract.CallFlag
|
||||
|
||||
// CheckReturn specifies if amount of return values needs to be checked.
|
||||
CheckReturn bool
|
||||
CheckReturn CheckReturnState
|
||||
}
|
||||
|
||||
// CheckReturnState represents possible states of stack after opcode.RET was processed.
|
||||
type CheckReturnState byte
|
||||
|
||||
const (
|
||||
// NoCheck performs no return values check.
|
||||
NoCheck CheckReturnState = 0
|
||||
// EnsureIsEmpty checks that stack is empty and panics if not.
|
||||
EnsureIsEmpty CheckReturnState = 1
|
||||
// EnsureNotEmpty checks that stack contains not more than 1 element and panics if not.
|
||||
// It pushes stackitem.Null on stack in case if there's no elements.
|
||||
EnsureNotEmpty CheckReturnState = 2
|
||||
)
|
||||
|
||||
var errNoInstParam = errors.New("failed to read instruction parameter")
|
||||
|
||||
// NewContext returns a new Context object.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue