diff --git a/src/cpp/ripple/RPCErr.cpp b/src/cpp/ripple/RPCErr.cpp new file mode 100644 index 000000000..cc0e6ba17 --- /dev/null +++ b/src/cpp/ripple/RPCErr.cpp @@ -0,0 +1,81 @@ + +#include "Log.h" + +#include "RPCErr.h" +#include "utils.h" + +#include "../json/writer.h" + +SETUP_LOG(); + +Json::Value rpcError(int iError, Json::Value jvResult) +{ + static struct { + int iError; + const char* pToken; + const char* pMessage; + } errorInfoA[] = { + { rpcACT_EXISTS, "actExists", "Account already exists." }, + { rpcACT_MALFORMED, "actMalformed", "Account malformed." }, + { rpcACT_NOT_FOUND, "actNotFound", "Account not found." }, + { rpcBAD_SEED, "badSeed", "Disallowed seed." }, + { rpcBAD_SYNTAX, "badSyntax", "Syntax error." }, + { rpcDST_ACT_MALFORMED, "dstActMalformed", "Destination account is malformed." }, + { rpcDST_ACT_MISSING, "dstActMissing", "Destination account does not exists." }, + { rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency/issuer is malformed." }, + { rpcFAIL_GEN_DECRPYT, "failGenDecrypt", "Failed to decrypt generator." }, + { rpcGETS_ACT_MALFORMED, "getsActMalformed", "Gets account malformed." }, + { rpcGETS_AMT_MALFORMED, "getsAmtMalformed", "Gets amount malformed." }, + { rpcHOST_IP_MALFORMED, "hostIpMalformed", "Host IP is malformed." }, + { rpcINSUF_FUNDS, "insufFunds", "Insufficient funds." }, + { rpcINTERNAL, "internal", "Internal error." }, + { rpcINVALID_PARAMS, "invalidParams", "Invalid parameters." }, + { rpcLGR_IDXS_INVALID, "lgrIdxsInvalid", "Ledger indexes invalid." }, + { rpcLGR_IDX_MALFORMED, "lgrIdxMalformed", "Ledger index malformed." }, + { rpcLGR_NOT_FOUND, "lgrNotFound", "Ledger not found." }, + { rpcNICKNAME_MALFORMED, "nicknameMalformed","Nickname is malformed." }, + { rpcNICKNAME_MISSING, "nicknameMissing", "Nickname does not exist." }, + { rpcNICKNAME_PERM, "nicknamePerm", "Account does not control nickname." }, + { rpcNOT_IMPL, "notImpl", "Not implemented." }, + { rpcNO_ACCOUNT, "noAccount", "No such account." }, + { rpcNO_CLOSED, "noClosed", "Closed ledger is unavailable." }, + { rpcNO_CURRENT, "noCurrent", "Current ledger is unavailable." }, + { rpcNO_EVENTS, "noEvents", "Current transport does not support events." }, + { rpcNO_GEN_DECRPYT, "noGenDectypt", "Password failed to decrypt master public generator." }, + { rpcNO_NETWORK, "noNetwork", "Network not available." }, + { rpcNO_PATH, "noPath", "Unable to find a ripple path." }, + { rpcNO_PERMISSION, "noPermission", "You don't have permission for this command." }, + { rpcNOT_STANDALONE, "notStandAlone", "Operation valid in debug mode only." }, + { rpcPASSWD_CHANGED, "passwdChanged", "Wrong key, password changed." }, + { rpcPAYS_ACT_MALFORMED, "paysActMalformed", "Pays account malformed." }, + { rpcPAYS_AMT_MALFORMED, "paysAmtMalformed", "Pays amount malformed." }, + { rpcPORT_MALFORMED, "portMalformed", "Port is malformed." }, + { rpcPUBLIC_MALFORMED, "publicMalformed", "Public key is malformed." }, + { rpcQUALITY_MALFORMED, "qualityMalformed", "Quality malformed." }, + { rpcSRC_ACT_MALFORMED, "srcActMalformed", "Source account is malformed." }, + { rpcSRC_ACT_MISSING, "srcActMissing", "Source account does not exist." }, + { rpcSRC_AMT_MALFORMED, "srcAmtMalformed", "Source amount/currency/issuer is malformed." }, + { rpcSRC_UNCLAIMED, "srcUnclaimed", "Source account is not claimed." }, + { rpcSUCCESS, "success", "Success." }, + { rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found." }, + { rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown command." }, + { rpcWRONG_SEED, "wrongSeed", "The regular key does not point as the master key." }, + }; + + int i; + + for (i=NUMBER(errorInfoA); i-- && errorInfoA[i].iError != iError;) + ; + + jvResult["error"] = i >= 0 ? errorInfoA[i].pToken : lexical_cast_i(iError); + jvResult["error_message"] = i >= 0 ? errorInfoA[i].pMessage : lexical_cast_i(iError); + jvResult["error_code"] = iError; + + if (i >= 0) + cLog(lsDEBUG) << "rpcError: " + << errorInfoA[i].pToken << ": " << errorInfoA[i].pMessage << std::endl; + + return jvResult; +} + +// vim:ts=4 diff --git a/src/cpp/ripple/RPCErr.h b/src/cpp/ripple/RPCErr.h new file mode 100644 index 000000000..d22b66b02 --- /dev/null +++ b/src/cpp/ripple/RPCErr.h @@ -0,0 +1,71 @@ +#ifndef __RPCERR__ +#define __RPCERR__ + +#include "../json/value.h" + +enum { + rpcSUCCESS, + + rpcBAD_SYNTAX, // Must be 1 to print usage to command line. + + // Misc failure + rpcLOAD_FAILED, + rpcNO_PERMISSION, + rpcNO_EVENTS, + rpcNOT_STANDALONE, + + // Networking + rpcNO_CLOSED, + rpcNO_CURRENT, + rpcNO_NETWORK, + + // Ledger state + rpcACT_EXISTS, + rpcACT_NOT_FOUND, + rpcINSUF_FUNDS, + rpcLGR_NOT_FOUND, + rpcNICKNAME_MISSING, + rpcNO_ACCOUNT, + rpcNO_PATH, + rpcPASSWD_CHANGED, + rpcSRC_MISSING, + rpcSRC_UNCLAIMED, + rpcTXN_NOT_FOUND, + rpcWRONG_SEED, + + // Malformed command + rpcINVALID_PARAMS, + rpcUNKNOWN_COMMAND, + + // Bad parameter + rpcACT_MALFORMED, + rpcQUALITY_MALFORMED, + rpcBAD_SEED, + rpcDST_ACT_MALFORMED, + rpcDST_ACT_MISSING, + rpcDST_AMT_MALFORMED, + rpcGETS_ACT_MALFORMED, + rpcGETS_AMT_MALFORMED, + rpcHOST_IP_MALFORMED, + rpcLGR_IDXS_INVALID, + rpcLGR_IDX_MALFORMED, + rpcNICKNAME_MALFORMED, + rpcNICKNAME_PERM, + rpcPAYS_ACT_MALFORMED, + rpcPAYS_AMT_MALFORMED, + rpcPORT_MALFORMED, + rpcPUBLIC_MALFORMED, + rpcSRC_ACT_MALFORMED, + rpcSRC_ACT_MISSING, + rpcSRC_AMT_MALFORMED, + + // Internal error (should never happen) + rpcINTERNAL, // Generic internal error. + rpcFAIL_GEN_DECRPYT, + rpcNOT_IMPL, + rpcNO_GEN_DECRPYT, +}; + +Json::Value rpcError(int iError, Json::Value jvResult=Json::Value(Json::objectValue)); +#endif +// vim:ts=4