Merge pull request #1462 from nspcc-dev/rpc/exceptions

rpc, core: add FaultException to AppExecResult and Invoke* results
This commit is contained in:
Roman Khimov 2020-10-08 16:20:38 +03:00 committed by GitHub
commit 8c2fd91c5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 190 additions and 75 deletions

View file

@ -541,12 +541,17 @@ func (c *Client) AddNetworkFee(tx *transaction.Transaction, extraFee int64, accs
for i, cosigner := range tx.Signers {
if accs[i].Contract.Deployed {
res, err := c.InvokeFunction(cosigner.Account, manifest.MethodVerify, []smartcontract.Parameter{}, tx.Signers)
if err == nil && res.State == "HALT" && len(res.Stack) == 1 {
r, err := topIntFromStack(res.Stack)
if err != nil || r == 0 {
return core.ErrVerificationFailed
}
} else {
if err != nil {
return fmt.Errorf("failed to invoke verify: %w", err)
}
if res.State != "HALT" {
return fmt.Errorf("invalid VM state %s due to an error: %s", res.State, res.FaultException)
}
if l := len(res.Stack); l != 1 {
return fmt.Errorf("result stack length should be equal to 1, got %d", l)
}
r, err := topIntFromStack(res.Stack)
if err != nil || r == 0 {
return core.ErrVerificationFailed
}
tx.NetworkFee += res.GasConsumed