mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
rpc: add custom errors to sendrawtransaction
In case of unsuccessful relyReason sendRawTransaction should return errors with codes [-500, ..., -505] instead of error with code -32603
This commit is contained in:
parent
a746d8e6e6
commit
2031d8d103
1 changed files with 17 additions and 21 deletions
|
@ -854,28 +854,24 @@ func (s *Server) sendrawtransaction(reqParams request.Params) (interface{}, erro
|
|||
tx := &transaction.Transaction{}
|
||||
tx.DecodeBinary(r)
|
||||
if r.Err != nil {
|
||||
err = errors.Wrap(r.Err, "transaction DecodeBinary failed")
|
||||
} else {
|
||||
relayReason := s.coreServer.RelayTxn(tx)
|
||||
switch relayReason {
|
||||
case network.RelaySucceed:
|
||||
results = true
|
||||
case network.RelayAlreadyExists:
|
||||
err = errors.New("block or transaction already exists and cannot be sent repeatedly")
|
||||
case network.RelayOutOfMemory:
|
||||
err = errors.New("the memory pool is full and no more transactions can be sent")
|
||||
case network.RelayUnableToVerify:
|
||||
err = errors.New("the block cannot be validated")
|
||||
case network.RelayInvalid:
|
||||
err = errors.New("block or transaction validation failed")
|
||||
case network.RelayPolicyFail:
|
||||
err = errors.New("one of the Policy filters failed")
|
||||
default:
|
||||
err = errors.New("unknown error")
|
||||
}
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
if err != nil {
|
||||
resultsErr = response.NewInternalServerError(err.Error(), err)
|
||||
relayReason := s.coreServer.RelayTxn(tx)
|
||||
switch relayReason {
|
||||
case network.RelaySucceed:
|
||||
results = true
|
||||
case network.RelayAlreadyExists:
|
||||
resultsErr = response.ErrAlreadyExists
|
||||
case network.RelayOutOfMemory:
|
||||
resultsErr = response.ErrOutOfMemory
|
||||
case network.RelayUnableToVerify:
|
||||
resultsErr = response.ErrUnableToVerify
|
||||
case network.RelayInvalid:
|
||||
resultsErr = response.ErrValidationFailed
|
||||
case network.RelayPolicyFail:
|
||||
resultsErr = response.ErrPolicyFail
|
||||
default:
|
||||
resultsErr = response.ErrUnknown
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue