forked from TrueCloudLab/frostfs-node
[#474] morph/client: Add FaultException to error msg
If non-"HALT" `State` occurs after calling `InvokeFunction` NeoGo client method, add `FaultException` information to returning error. Add returning state check to `NotaryInvoke` method of the morph/client. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
f6f2e4d10f
commit
4a4aee82e0
2 changed files with 19 additions and 1 deletions
|
@ -2,6 +2,7 @@ package client
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||
|
@ -48,6 +49,18 @@ var ErrNilClient = errors.New("client is nil")
|
|||
// HaltState returned if TestInvoke function processed without panic.
|
||||
const HaltState = "HALT"
|
||||
|
||||
type NotHaltStateError struct {
|
||||
state, exception string
|
||||
}
|
||||
|
||||
func (e *NotHaltStateError) Error() string {
|
||||
return fmt.Sprintf(
|
||||
"chain/client: contract execution finished with state %s; exception: %s",
|
||||
e.state,
|
||||
e.exception,
|
||||
)
|
||||
}
|
||||
|
||||
var errEmptyInvocationScript = errors.New("got empty invocation script from neo node")
|
||||
|
||||
var errScriptDecode = errors.New("could not decode invocation script from neo node")
|
||||
|
@ -132,7 +145,7 @@ func (c *Client) TestInvoke(contract util.Uint160, method string, args ...interf
|
|||
}
|
||||
|
||||
if val.State != HaltState {
|
||||
return nil, errors.Errorf("chain/client: contract execution finished with state %s", val.State)
|
||||
return nil, &NotHaltStateError{state: val.State, exception: val.FaultException}
|
||||
}
|
||||
|
||||
return val.Stack, nil
|
||||
|
|
|
@ -222,6 +222,11 @@ func (c *Client) notaryInvoke(committee bool, contract util.Uint160, method stri
|
|||
return err
|
||||
}
|
||||
|
||||
// check invocation state
|
||||
if test.State != HaltState {
|
||||
return &NotHaltStateError{state: test.State, exception: test.FaultException}
|
||||
}
|
||||
|
||||
// if test invocation failed, then return error
|
||||
if len(test.Script) == 0 {
|
||||
return errEmptyInvocationScript
|
||||
|
|
Loading…
Reference in a new issue