Skip to content

Commit

Permalink
neorpc: add error codes and response errors
Browse files Browse the repository at this point in the history
Close nspcc-dev#2248

Signed-off-by: Tatiana Nesterenko <tatiana@nspcc.io>
  • Loading branch information
tatiana-nspcc committed Aug 8, 2023
1 parent d381cd1 commit f75fc3b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 166 deletions.
47 changes: 24 additions & 23 deletions pkg/neorpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
// container (a block or transaction) as a part of its job can't find it
// (this error generalizes -101 and -103 in cases where it's needed).
ErrUnknownScriptContainerCode = -105
// ErrUnknownStateRootCode is returned on from a call that accepts as a parameter or searches for a state root
// ErrUnknownStateRootCode is returned from a call that accepts as a parameter or searches for a state root
// as a part of its job can't find it.
ErrUnknownStateRootCode = -106
// ErrUnknownSessionCode is returned from a call that accepts as a parameter or searches for an iterator session
Expand All @@ -62,20 +62,20 @@ const (
// Codes for calls that use a wallet (-300...-304) can be returned by the C# RPC server only,
// see the https://github.com/nspcc-dev/neo-go/blob/master/docs/rpc.md#unsupported-methods.
const (
// ErrInsufficientFundsWalletCode is returned on RPC request processing error: Insufficient funds.
// Transaction that sends some assets can't be created because it fails. Can be returned only by the C# RPC server.
// ErrInsufficientFundsWalletCode is returned if transaction that sends some assets can't be created
// because it fails. Can be returned only by the C# RPC server.
ErrInsufficientFundsWalletCode = -300
// ErrWalletFeeLimitCode is returned on RPC request processing error: Fee limit exceeded.
// Transaction requires more network fee to be paid than is allowed by settings. Can be returned only by the C# RPC server.
// ErrWalletFeeLimitCode is returned if transaction requires more network fee to be paid
// than is allowed by settings. Can be returned only by the C# RPC server.
ErrWalletFeeLimitCode = -301
// ErrNoOpenedWalletCode is returned on RPC request processing error: No opened wallet.
// Server doesn't have any opened wallet to operate with. Can be returned only by the C# RPC server.
// ErrNoOpenedWalletCode is returned if server doesn't have any opened wallet to operate with.
// Can be returned only by the C# RPC server.
ErrNoOpenedWalletCode = -302
// ErrWalletNotFoundCode is returned on RPC request processing error: Wallet not found.
// Specified (or configured) wallet file path is invalid. Can be returned only by the C# RPC server.
// ErrWalletNotFoundCode is returned if specified (or configured) wallet file path is invalid.
// Can be returned only by the C# RPC server.
ErrWalletNotFoundCode = -303
// ErrWalletNotSupportedCode is returned on RPC request processing error: Wallet not supported.
// Specified (or configured) file can't be opened as a wallet. Can be returned only by the C# RPC server.
// ErrWalletNotSupportedCode is returned if specified (or configured) file can't be opened as a wallet.
// Can be returned only by the C# RPC server.
ErrWalletNotSupportedCode = -304
)

Expand All @@ -84,19 +84,19 @@ const (
// ErrVerificationFailedCode is returned on anything that can't be expressed by other codes.
// It is an unclassified inventory verification error.
ErrVerificationFailedCode = -500
// ErrAlreadyExistsCode is returned if block or transaction is already accepted and processed.
// ErrAlreadyExistsCode is returned if block or transaction is already accepted and processed on chain.
ErrAlreadyExistsCode = -501
// ErrMempoolCapReachedCode is returned if no more transactions can be accepted into the memory pool
// (unless they have a priority) as its full capacity is reached.
ErrMempoolCapReachedCode = -502
// ErrTxAlreadyInPoolCode is returned if transaction is already pooled, but not yet accepted into a block.
ErrTxAlreadyInPoolCode = -503
// ErrAlreadyInPoolCode is returned if transaction is already pooled, but not yet accepted into a block.
ErrAlreadyInPoolCode = -503
// ErrInsufficientNetworkFeeCode is returned if transaction has incorrect (too small per Policy setting)
// network fee value.
ErrInsufficientNetworkFeeCode = -504
// ErrPolicyFailCode is returned from a call denied by the Policy contract (one of signers is blocked) or
// ErrPolicyFailedCode is returned from a call denied by the Policy contract (one of signers is blocked) or
// if one of the Policy filters failed.
ErrPolicyFailCode = -505
ErrPolicyFailedCode = -505
// ErrInvalidScriptCode is returned if transaction contains incorrect executable script.
ErrInvalidScriptCode = -506
// ErrInvalidAttributeCode is returned if transaction contains an invalid attribute.
Expand All @@ -121,6 +121,7 @@ const (
// ErrOracleDisabledCode is returned if Oracle service is not enabled in the configuration (service is not running).
ErrOracleDisabledCode = -602
// ErrOracleRequestFinishedCode is returned if Oracle request submitted is already completely processed.
// Can be returned only by the C# RPC server.
ErrOracleRequestFinishedCode = -603
// ErrOracleRequestNotFoundCode is returned if Oracle request submitted is not known to this node.
// Can be returned only by the C# RPC server.
Expand All @@ -133,12 +134,12 @@ const (
ErrUnsupportedStateCode = -606
// ErrInvalidProofCode is returned if state proof verification failed.
ErrInvalidProofCode = -607
// ErrExecutionFailedCode is returned from s call made a VM execution, but it has failed.
// ErrExecutionFailedCode is returned from a call made a VM execution, but it has failed.
ErrExecutionFailedCode = -608
)

var (
// ErrInvalidParams represents a generic 'invalid parameters' error.
// ErrInvalidParams represents a generic "Invalid params" error.
ErrInvalidParams = NewInvalidParamsError("Invalid params")

// ErrUnknownBlock represents an error with code -101.
Expand Down Expand Up @@ -175,20 +176,20 @@ var (
// Any verification error that can't be expressed by other codes.
ErrVerificationFailed = NewErrorWithCode(ErrVerificationFailedCode, "Unclassified inventory verification error")
// ErrAlreadyExists represents an error with code -501.
// Block or transaction is already accepted and processed.
// Block or transaction is already accepted and processed on chain.
ErrAlreadyExists = NewErrorWithCode(ErrAlreadyExistsCode, "Inventory already exists on chain")
// ErrMempoolCapReached represents an error with code -502.
// No more transactions can be accepted into the memory pool (unless they have a priority) as its full capacity is reached.
ErrMempoolCapReached = NewErrorWithCode(ErrMempoolCapReachedCode, "The memory pool is full and no more transactions can be sent")
// ErrTxAlreadyInPool represents an error with code -503.
// ErrAlreadyInPool represents an error with code -503.
// Transaction is already pooled, but not yet accepted into a block.
ErrTxAlreadyInPool = NewErrorWithCode(ErrTxAlreadyInPoolCode, "Transaction already exists in the memory pool")
ErrAlreadyInPool = NewErrorWithCode(ErrAlreadyInPoolCode, "Transaction already exists in the memory pool")
// ErrInsufficientNetworkFee represents an error with code -504.
// Transaction has incorrect (too small per Policy setting) network fee value.
ErrInsufficientNetworkFee = NewErrorWithCode(ErrInsufficientNetworkFeeCode, "Insufficient network fee")
// ErrPolicyFail represents an error with code -505.
// ErrPolicyFailed represents an error with code -505.
// Denied by the Policy contract (one of signers is blocked).
ErrPolicyFail = NewErrorWithCode(ErrPolicyFailCode, "One of the Policy filters failed")
ErrPolicyFailed = NewErrorWithCode(ErrPolicyFailedCode, "One of the Policy filters failed")
// ErrInvalidScript represents an error with code -506.
// Transaction contains incorrect executable script.
ErrInvalidScript = NewErrorWithCode(ErrInvalidScriptCode, "Invalid script")
Expand Down
10 changes: 5 additions & 5 deletions pkg/services/rpcsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ func (s *Server) getrawtransaction(reqParams params.Params) (any, *neorpc.Error)
_header := s.chain.GetHeaderHash(height)
header, err := s.chain.GetHeader(_header)
if err != nil {
return nil, neorpc.NewInvalidParamsError(fmt.Sprintf("Failed to get header for the transaction: %s", err.Error()))
return nil, neorpc.NewInternalServerError(fmt.Sprintf("Failed to get header for the transaction: %s", err.Error()))
}
aers, err := s.chain.GetAppExecResults(txHash, trigger.Application)
if err != nil {
Expand Down Expand Up @@ -2101,7 +2101,7 @@ func (s *Server) getInvokeContractVerifyParams(reqParams params.Params) (util.Ui
if len(args) > 0 {
err := params.ExpandArrayIntoScript(bw.BinWriter, args)
if err != nil {
return util.Uint160{}, nil, nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidVerificationFunction, fmt.Sprintf("can't create witness invocation script: %s", err))
return util.Uint160{}, nil, nil, neorpc.NewInternalServerError(fmt.Sprintf("can't create witness invocation script: %s", err))
}
}
}
Expand Down Expand Up @@ -2448,14 +2448,14 @@ func getRelayResult(err error, hash util.Uint256) (any, *neorpc.Error) {
}, nil
case errors.Is(err, core.ErrTxExpired):
return nil, neorpc.WrapErrorWithData(neorpc.ErrExpiredTransaction, err.Error())
case errors.Is(err, core.ErrAlreadyExists) || errors.Is(err, core.ErrHasConflicts) || errors.Is(err, core.ErrInvalidBlockIndex):
case errors.Is(err, core.ErrAlreadyExists) || errors.Is(err, core.ErrInvalidBlockIndex):
return nil, neorpc.WrapErrorWithData(neorpc.ErrAlreadyExists, err.Error())
case errors.Is(err, core.ErrAlreadyExistsMemPool):
return nil, neorpc.WrapErrorWithData(neorpc.ErrTxAlreadyInPool, err.Error())
return nil, neorpc.WrapErrorWithData(neorpc.ErrAlreadyInPool, err.Error())
case errors.Is(err, core.ErrOOM):
return nil, neorpc.WrapErrorWithData(neorpc.ErrMempoolCapReached, err.Error())
case errors.Is(err, core.ErrPolicy):
return nil, neorpc.WrapErrorWithData(neorpc.ErrPolicyFail, err.Error())
return nil, neorpc.WrapErrorWithData(neorpc.ErrPolicyFailed, err.Error())
case errors.Is(err, core.ErrInvalidScript):
return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidScript, err.Error())
case errors.Is(err, core.ErrTxTooBig):
Expand Down
Loading

0 comments on commit f75fc3b

Please sign in to comment.