forked from neo-project/neo-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemente RPC errors proposal neo-project#156
- Loading branch information
Showing
13 changed files
with
250 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright (C) 2015-2023 The Neo Project. | ||
// | ||
// The Neo.Network.RPC is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System.Collections.Generic; | ||
namespace Neo.Plugins; | ||
|
||
public class RpcError | ||
{ | ||
public int Code { get; set; } | ||
public string Message { get; set; } | ||
public string Data { get; set; } | ||
public RpcError(int code, string message, string data = "") | ||
{ | ||
Code = code; | ||
Message = message; | ||
Data = data; | ||
} | ||
|
||
public static RpcError ParseError(string data) => new RpcError(RpcErrorCode.BadRequest, "Parse RpcError", data); | ||
|
||
// Missing helper methods | ||
public static RpcError InvalidRequestError(string data) => new RpcError(RpcErrorCode.InvalidRequest, "Invalid request", data); | ||
|
||
public static RpcError MethodNotFoundError(string data) => new RpcError(RpcErrorCode.MethodNotFound, "Method not found", data); | ||
|
||
public static RpcError InvalidParamsError(string data) => new RpcError(RpcErrorCode.InvalidParams, "Invalid params", data); | ||
|
||
public static RpcError InternalServerError(string data) => new RpcError(RpcErrorCode.InternalServerError, "Internal RpcError", data); | ||
|
||
public static RpcError ErrorWithCode(int code, string message) => new RpcError(code, message); | ||
|
||
// Helper to wrap an existing RpcError with data | ||
public static RpcError WrapErrorWithData(RpcError error, string data) => new RpcError(error.Code, error.Message, data); | ||
|
||
|
||
public override string ToString() | ||
{ | ||
if (string.IsNullOrEmpty(Data)) | ||
{ | ||
return $"{Message} ({Code})"; | ||
} | ||
return $"{Message} ({Code}) - {Data}"; | ||
} | ||
|
||
public string ErrorMessage => string.IsNullOrEmpty(Data) ? $"{Message}" : $"{Message} - {Data}"; | ||
|
||
} | ||
|
||
public static class RpcErrorFactor | ||
{ | ||
private static readonly Dictionary<int, string> DefaultMessages = new Dictionary<int, string> { | ||
|
||
{RpcErrorCode.InternalServerError, "Internal server RpcError"}, | ||
{RpcErrorCode.BadRequest, "Bad request"}, | ||
{RpcErrorCode.InvalidRequest, "Invalid request"}, | ||
{RpcErrorCode.MethodNotFound, "Method not found"}, | ||
{RpcErrorCode.InvalidParams, "Invalid params"}, | ||
|
||
{RpcErrorCode.UnknownBlock, "Unknown block"}, | ||
{RpcErrorCode.UnknownContract, "Unknown contract"}, | ||
{RpcErrorCode.UnknownTransaction, "Unknown transaction"}, | ||
{RpcErrorCode.UnknownStorageItem, "Unknown storage item"}, | ||
{RpcErrorCode.UnknownScriptContainer, "Unknown script container"}, | ||
{RpcErrorCode.UnknownStateRoot, "Unknown state root"}, | ||
{RpcErrorCode.UnknownSession, "Unknown session"}, | ||
{RpcErrorCode.UnknownIterator, "Unknown iterator"}, | ||
{RpcErrorCode.UnknownHeight, "Unknown height"}, | ||
|
||
{RpcErrorCode.InsufficientFundsWallet, "Insufficient funds in wallet"}, | ||
{RpcErrorCode.WalletFeeLimit, "Wallet fee limit exceeded"}, | ||
{RpcErrorCode.NoOpenedWallet, "No opened wallet"}, | ||
{RpcErrorCode.WalletNotFound, "Wallet not found"}, | ||
{RpcErrorCode.WalletNotSupported, "Wallet not supported"}, | ||
|
||
{ RpcErrorCode.AccessDenied, "Access denied"}, | ||
|
||
{RpcErrorCode.VerificationFailed, "Inventory verification failed"}, | ||
{RpcErrorCode.AlreadyExists, "Inventory already exists"}, | ||
{RpcErrorCode.MempoolCapReached, "Memory pool capacity reached"}, | ||
{RpcErrorCode.AlreadyInPool, "Already in transaction pool"}, | ||
{RpcErrorCode.InsufficientNetworkFee, "Insufficient network fee"}, | ||
{RpcErrorCode.PolicyFailed, "Policy check failed"}, | ||
{RpcErrorCode.InvalidScript, "Invalid transaction script"}, | ||
{RpcErrorCode.InvalidAttribute, "Invalid transaction attribute"}, | ||
{RpcErrorCode.InvalidSignature, "Invalid transaction signature"}, | ||
{RpcErrorCode.InvalidSize, "Invalid inventory size"}, | ||
{RpcErrorCode.ExpiredTransaction, "Expired transaction"}, | ||
{RpcErrorCode.InsufficientFunds, "Insufficient funds for fee"}, | ||
{RpcErrorCode.InvalidVerificationFunction, "Invalid contract verification"}, | ||
|
||
{RpcErrorCode.SessionsDisabled, "State iterator sessions disabled"}, | ||
{RpcErrorCode.OracleDisabled, "Oracle service disabled"}, | ||
{RpcErrorCode.OracleRequestFinished, "Oracle request already finished"}, | ||
{RpcErrorCode.OracleRequestNotFound, "Oracle request not found"}, | ||
{RpcErrorCode.OracleNotDesignatedNode, "Not a designated oracle node"}, | ||
{RpcErrorCode.UnsupportedState, "Old state not supported"}, | ||
{RpcErrorCode.InvalidProof, "Invalid state proof"}, | ||
{RpcErrorCode.ExecutionFailed, "Contract execution failed"} | ||
|
||
}; | ||
|
||
public static RpcError NewError(int code, string message = null, string data = "") | ||
{ | ||
message ??= DefaultMessages[code]; | ||
return new RpcError(code, message, data); | ||
} | ||
|
||
public static RpcError NewCustomError(int code, string message) | ||
{ | ||
return new RpcError(code, message, null); | ||
} | ||
|
||
public static bool Contains(int code) | ||
{ | ||
return DefaultMessages.ContainsKey(code); | ||
} | ||
|
||
public static readonly RpcError ErrInvalidParams = NewError(RpcErrorCode.InvalidParams); | ||
|
||
public static readonly RpcError ErrUnknownBlock = NewError(RpcErrorCode.UnknownBlock); | ||
|
||
public static readonly RpcError ErrUnknownContract = NewError(RpcErrorCode.UnknownContract); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (C) 2015-2023 The Neo Project. | ||
// | ||
// The Neo.Network.RPC is free software distributed under the MIT software license, | ||
// see the accompanying file LICENSE in the main directory of the | ||
// project or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using System.Collections.Generic; | ||
namespace Neo.Plugins; | ||
public static class RpcErrorCode | ||
{ | ||
|
||
public const int InternalServerError = -32603; | ||
public const int BadRequest = -32700; | ||
public const int InvalidRequest = -32600; | ||
public const int MethodNotFound = -32601; | ||
public const int InvalidParams = -32602; | ||
|
||
public const int UnknownBlock = -101; | ||
public const int UnknownContract = -102; | ||
public const int UnknownTransaction = -103; | ||
public const int UnknownStorageItem = -104; | ||
public const int UnknownScriptContainer = -105; | ||
public const int UnknownStateRoot = -106; | ||
public const int UnknownSession = -107; | ||
public const int UnknownIterator = -108; | ||
public const int UnknownHeight = -109; | ||
|
||
public const int InsufficientFundsWallet = -300; | ||
public const int WalletFeeLimit = -301; | ||
public const int NoOpenedWallet = -302; | ||
public const int WalletNotFound = -303; | ||
public const int WalletNotSupported = -304; | ||
|
||
public const int AccessDenied = -400; | ||
|
||
public const int VerificationFailed = -500; | ||
public const int AlreadyExists = -501; | ||
public const int MempoolCapReached = -502; | ||
public const int AlreadyInPool = -503; | ||
public const int InsufficientNetworkFee = -504; | ||
public const int PolicyFailed = -505; | ||
public const int InvalidScript = -506; | ||
public const int InvalidAttribute = -507; | ||
public const int InvalidSignature = -508; | ||
public const int InvalidSize = -509; | ||
public const int ExpiredTransaction = -510; | ||
public const int InsufficientFunds = -511; | ||
public const int InvalidVerificationFunction = -512; | ||
|
||
public const int SessionsDisabled = -601; | ||
public const int OracleDisabled = -602; | ||
public const int OracleRequestFinished = -603; | ||
public const int OracleRequestNotFound = -604; | ||
public const int OracleNotDesignatedNode = -605; | ||
public const int UnsupportedState = -606; | ||
public const int InvalidProof = -607; | ||
public const int ExecutionFailed = -608; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.