rpc: detalize submit* RPC validation error

These changes do not break the compatibility with the C# node response.

It is useful for the end-user to be aware of the failed validation reason.
Also, the `cause` will be displayed at the running node log.
This commit is contained in:
Anna Shaleva 2021-02-25 12:08:41 +03:00
parent 492a89eb02
commit 2fbbadeb56
2 changed files with 12 additions and 6 deletions

View file

@ -1235,9 +1235,9 @@ func (s *Server) submitBlock(reqParams request.Params) (interface{}, *response.E
if err != nil {
switch {
case errors.Is(err, core.ErrInvalidBlockIndex) || errors.Is(err, core.ErrAlreadyExists):
return nil, response.ErrAlreadyExists
return nil, response.WrapErrorWithData(response.ErrAlreadyExists, err)
default:
return nil, response.ErrValidationFailed
return nil, response.WrapErrorWithData(response.ErrValidationFailed, err)
}
}
return &result.RelayResult{
@ -1273,13 +1273,13 @@ func getRelayResult(err error, hash util.Uint256) (interface{}, *response.Error)
Hash: hash,
}, nil
case errors.Is(err, core.ErrAlreadyExists):
return nil, response.ErrAlreadyExists
return nil, response.WrapErrorWithData(response.ErrAlreadyExists, err)
case errors.Is(err, core.ErrOOM):
return nil, response.ErrOutOfMemory
return nil, response.WrapErrorWithData(response.ErrOutOfMemory, err)
case errors.Is(err, core.ErrPolicy):
return nil, response.ErrPolicyFail
return nil, response.WrapErrorWithData(response.ErrPolicyFail, err)
default:
return nil, response.ErrValidationFailed
return nil, response.WrapErrorWithData(response.ErrValidationFailed, err)
}
}