rpc: extend the list of predefined RPC errors
Add a few the most common ones.
This commit is contained in:
parent
ef9eca7cce
commit
6434404081
2 changed files with 16 additions and 6 deletions
|
@ -34,6 +34,16 @@ const (
|
||||||
var (
|
var (
|
||||||
// ErrInvalidParams represents a generic 'invalid parameters' error.
|
// ErrInvalidParams represents a generic 'invalid parameters' error.
|
||||||
ErrInvalidParams = NewInvalidParamsError("invalid params")
|
ErrInvalidParams = NewInvalidParamsError("invalid params")
|
||||||
|
// ErrUnknownBlock is returned if requested block is not found.
|
||||||
|
ErrUnknownBlock = NewError(RPCErrorCode, "Unknown block", "")
|
||||||
|
// ErrUnknownTransaction is returned if requested transaction is not found.
|
||||||
|
ErrUnknownTransaction = NewError(RPCErrorCode, "Unknown transaction", "")
|
||||||
|
// ErrUnknownHeader is returned when requested header is not found.
|
||||||
|
ErrUnknownHeader = NewError(RPCErrorCode, "Unknown header", "")
|
||||||
|
// ErrUnknownScriptContainer is returned when requested block or transaction is not found.
|
||||||
|
ErrUnknownScriptContainer = NewError(RPCErrorCode, "Unknown script container", "")
|
||||||
|
// ErrUnknownStateRoot is returned when requested state root is not found.
|
||||||
|
ErrUnknownStateRoot = NewError(RPCErrorCode, "Unknown state root", "")
|
||||||
// ErrAlreadyExists represents SubmitError with code -501.
|
// ErrAlreadyExists represents SubmitError with code -501.
|
||||||
ErrAlreadyExists = NewSubmitError(-501, "Block or transaction already exists and cannot be sent repeatedly.")
|
ErrAlreadyExists = NewSubmitError(-501, "Block or transaction already exists and cannot be sent repeatedly.")
|
||||||
// ErrOutOfMemory represents SubmitError with code -502.
|
// ErrOutOfMemory represents SubmitError with code -502.
|
||||||
|
|
|
@ -671,7 +671,7 @@ func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *resp
|
||||||
|
|
||||||
appExecResults, err := s.chain.GetAppExecResults(hash, trigger.All)
|
appExecResults, err := s.chain.GetAppExecResults(hash, trigger.All)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, response.NewRPCError("Unknown transaction or block", fmt.Sprintf("failed to locate application log: %s", err))
|
return nil, response.WrapErrorWithData(response.ErrUnknownScriptContainer, fmt.Sprintf("failed to locate application log: %s", err))
|
||||||
}
|
}
|
||||||
return result.NewApplicationLog(hash, appExecResults, trig), nil
|
return result.NewApplicationLog(hash, appExecResults, trig), nil
|
||||||
}
|
}
|
||||||
|
@ -1379,7 +1379,7 @@ func (s *Server) getStateRoot(ps request.Params) (interface{}, *response.Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, response.NewRPCError("Unknown state root", "")
|
return nil, response.ErrUnknownStateRoot
|
||||||
}
|
}
|
||||||
return rt, nil
|
return rt, nil
|
||||||
}
|
}
|
||||||
|
@ -1413,7 +1413,7 @@ func (s *Server) getrawtransaction(reqParams request.Params) (interface{}, *resp
|
||||||
}
|
}
|
||||||
tx, height, err := s.chain.GetTransaction(txHash)
|
tx, height, err := s.chain.GetTransaction(txHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, response.NewRPCError("Unknown transaction", "")
|
return nil, response.ErrUnknownTransaction
|
||||||
}
|
}
|
||||||
if v, _ := reqParams.Value(1).GetBoolean(); v {
|
if v, _ := reqParams.Value(1).GetBoolean(); v {
|
||||||
if height == math.MaxUint32 {
|
if height == math.MaxUint32 {
|
||||||
|
@ -1444,7 +1444,7 @@ func (s *Server) getTransactionHeight(ps request.Params) (interface{}, *response
|
||||||
|
|
||||||
_, height, err := s.chain.GetTransaction(h)
|
_, height, err := s.chain.GetTransaction(h)
|
||||||
if err != nil || height == math.MaxUint32 {
|
if err != nil || height == math.MaxUint32 {
|
||||||
return nil, response.NewRPCError("Unknown transaction", "")
|
return nil, response.ErrUnknownTransaction
|
||||||
}
|
}
|
||||||
|
|
||||||
return height, nil
|
return height, nil
|
||||||
|
@ -1478,7 +1478,7 @@ func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *respons
|
||||||
headerHash := s.chain.GetHeaderHash(num)
|
headerHash := s.chain.GetHeaderHash(num)
|
||||||
block, errBlock := s.chain.GetBlock(headerHash)
|
block, errBlock := s.chain.GetBlock(headerHash)
|
||||||
if errBlock != nil {
|
if errBlock != nil {
|
||||||
return 0, response.NewRPCError("Unknown block", "")
|
return 0, response.ErrUnknownBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockSysFee int64
|
var blockSysFee int64
|
||||||
|
@ -1500,7 +1500,7 @@ func (s *Server) getBlockHeader(reqParams request.Params) (interface{}, *respons
|
||||||
verbose, _ := reqParams.Value(1).GetBoolean()
|
verbose, _ := reqParams.Value(1).GetBoolean()
|
||||||
h, err := s.chain.GetHeader(hash)
|
h, err := s.chain.GetHeader(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, response.NewRPCError("Unknown header", "")
|
return nil, response.ErrUnknownHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
|
|
Loading…
Reference in a new issue