mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Improve sub and unsub errors (RIPD-702)
This commit is contained in:
@@ -110,6 +110,7 @@ enum error_code_i
|
|||||||
rpcSRC_AMT_MALFORMED,
|
rpcSRC_AMT_MALFORMED,
|
||||||
rpcSRC_CUR_MALFORMED,
|
rpcSRC_CUR_MALFORMED,
|
||||||
rpcSRC_ISR_MALFORMED,
|
rpcSRC_ISR_MALFORMED,
|
||||||
|
rpcSTREAM_MALFORMED,
|
||||||
rpcATX_DEPRECATED,
|
rpcATX_DEPRECATED,
|
||||||
|
|
||||||
// Internal error (should never happen)
|
// Internal error (should never happen)
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ public:
|
|||||||
add (rpcSRC_ISR_MALFORMED, "srcIsrMalformed", "Source issuer is malformed.");
|
add (rpcSRC_ISR_MALFORMED, "srcIsrMalformed", "Source issuer is malformed.");
|
||||||
add (rpcSRC_MISSING, "srcMissing", "Source is missing.");
|
add (rpcSRC_MISSING, "srcMissing", "Source is missing.");
|
||||||
add (rpcSRC_UNCLAIMED, "srcUnclaimed", "Source account is not claimed.");
|
add (rpcSRC_UNCLAIMED, "srcUnclaimed", "Source account is not claimed.");
|
||||||
|
add (rpcSTREAM_MALFORMED, "malformedStream", "Stream malformed.");
|
||||||
add (rpcTOO_BUSY, "tooBusy", "The server is too busy to help you now.");
|
add (rpcTOO_BUSY, "tooBusy", "The server is too busy to help you now.");
|
||||||
add (rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found.");
|
add (rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found.");
|
||||||
add (rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method.");
|
add (rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method.");
|
||||||
|
|||||||
@@ -39,19 +39,17 @@ Json::Value doSubscribe (RPC::Context& context)
|
|||||||
InfoSub::pointer ispSub;
|
InfoSub::pointer ispSub;
|
||||||
Json::Value jvResult (Json::objectValue);
|
Json::Value jvResult (Json::objectValue);
|
||||||
|
|
||||||
if (!context.infoSub && !context.params.isMember (jss::url))
|
if (! context.infoSub && ! context.params.isMember(jss::url))
|
||||||
{
|
{
|
||||||
// Must be a JSON-RPC call.
|
// Must be a JSON-RPC call.
|
||||||
JLOG (context.j.info)
|
JLOG(context.j.info) << "doSubscribe: RPC subscribe requires a url";
|
||||||
<< "doSubscribe: RPC subscribe requires a url";
|
|
||||||
|
|
||||||
return rpcError (rpcINVALID_PARAMS);
|
return rpcError (rpcINVALID_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.params.isMember (jss::url))
|
if (context.params.isMember(jss::url))
|
||||||
{
|
{
|
||||||
if (context.role != Role::ADMIN)
|
if (context.role != Role::ADMIN)
|
||||||
return rpcError (rpcNO_PERMISSION);
|
return rpcError(rpcNO_PERMISSION);
|
||||||
|
|
||||||
std::string strUrl = context.params[jss::url].asString ();
|
std::string strUrl = context.params[jss::url].asString ();
|
||||||
std::string strUsername = context.params.isMember (jss::url_username) ?
|
std::string strUsername = context.params.isMember (jss::url_username) ?
|
||||||
@@ -67,9 +65,8 @@ Json::Value doSubscribe (RPC::Context& context)
|
|||||||
if (context.params.isMember (jss::password))
|
if (context.params.isMember (jss::password))
|
||||||
strPassword = context.params[jss::password].asString ();
|
strPassword = context.params[jss::password].asString ();
|
||||||
|
|
||||||
ispSub = context.netOps.findRpcSub (strUrl);
|
ispSub = context.netOps.findRpcSub(strUrl);
|
||||||
|
if (! ispSub)
|
||||||
if (!ispSub)
|
|
||||||
{
|
{
|
||||||
JLOG (context.j.debug)
|
JLOG (context.j.debug)
|
||||||
<< "doSubscribe: building: " << strUrl;
|
<< "doSubscribe: building: " << strUrl;
|
||||||
@@ -103,24 +100,21 @@ Json::Value doSubscribe (RPC::Context& context)
|
|||||||
ispSub = context.infoSub;
|
ispSub = context.infoSub;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.params.isMember (jss::streams))
|
if (context.params.isMember (jss::streams))
|
||||||
{
|
{
|
||||||
}
|
if (! context.params[jss::streams].isArray ())
|
||||||
else if (!context.params[jss::streams].isArray ())
|
|
||||||
{
|
{
|
||||||
JLOG (context.j.info)
|
JLOG (context.j.info)
|
||||||
<< "doSubscribe: streams requires an array.";
|
<< "doSubscribe: streams requires an array.";
|
||||||
|
|
||||||
return rpcError (rpcINVALID_PARAMS);
|
return rpcError (rpcINVALID_PARAMS);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto& it: context.params[jss::streams])
|
|
||||||
{
|
|
||||||
if (it.isString ())
|
|
||||||
{
|
|
||||||
std::string streamName = it.asString ();
|
|
||||||
|
|
||||||
|
for (auto const& it: context.params[jss::streams])
|
||||||
|
{
|
||||||
|
if (! it.isString())
|
||||||
|
return rpcError(rpcSTREAM_MALFORMED);
|
||||||
|
|
||||||
|
std::string streamName = it.asString ();
|
||||||
if (streamName == "server")
|
if (streamName == "server")
|
||||||
{
|
{
|
||||||
context.netOps.subServer (ispSub, jvResult,
|
context.netOps.subServer (ispSub, jvResult,
|
||||||
@@ -134,8 +128,8 @@ Json::Value doSubscribe (RPC::Context& context)
|
|||||||
{
|
{
|
||||||
context.netOps.subTransactions (ispSub);
|
context.netOps.subTransactions (ispSub);
|
||||||
}
|
}
|
||||||
else if (streamName == "transactions_proposed"
|
else if (streamName == "transactions_proposed" ||
|
||||||
|| streamName == "rt_transactions") // DEPRECATED
|
streamName == "rt_transactions") // DEPRECATED
|
||||||
{
|
{
|
||||||
context.netOps.subRTTransactions (ispSub);
|
context.netOps.subRTTransactions (ispSub);
|
||||||
}
|
}
|
||||||
@@ -146,75 +140,46 @@ Json::Value doSubscribe (RPC::Context& context)
|
|||||||
else if (streamName == "peer_status")
|
else if (streamName == "peer_status")
|
||||||
{
|
{
|
||||||
if (context.role != Role::ADMIN)
|
if (context.role != Role::ADMIN)
|
||||||
jvResult[jss::error] = "noPermission";
|
return rpcError(rpcNO_PERMISSION);
|
||||||
else
|
|
||||||
context.netOps.subPeerStatus (ispSub);
|
context.netOps.subPeerStatus (ispSub);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jvResult[jss::error] = "unknownStream";
|
return rpcError(rpcSTREAM_MALFORMED);
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
jvResult[jss::error] = "malformedStream";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto strAccountsProposed =
|
auto accountsProposed = context.params.isMember(jss::accounts_proposed)
|
||||||
context.params.isMember (jss::accounts_proposed)
|
|
||||||
? jss::accounts_proposed : jss::rt_accounts; // DEPRECATED
|
? jss::accounts_proposed : jss::rt_accounts; // DEPRECATED
|
||||||
|
if (context.params.isMember(accountsProposed))
|
||||||
|
{
|
||||||
|
if (! context.params[accountsProposed].isArray())
|
||||||
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
if (!context.params.isMember (strAccountsProposed))
|
auto ids = RPC::parseAccountIds(context.params[accountsProposed]);
|
||||||
{
|
if (ids.empty())
|
||||||
|
return rpcError(rpcACT_MALFORMED);
|
||||||
|
context.netOps.subAccount(ispSub, ids, true);
|
||||||
}
|
}
|
||||||
else if (!context.params[strAccountsProposed].isArray ())
|
|
||||||
|
if (context.params.isMember(jss::accounts))
|
||||||
{
|
{
|
||||||
|
if (! context.params[jss::accounts].isArray())
|
||||||
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
|
auto ids = RPC::parseAccountIds(context.params[jss::accounts]);
|
||||||
|
if (ids.empty())
|
||||||
|
return rpcError(rpcACT_MALFORMED);
|
||||||
|
context.netOps.subAccount(ispSub, ids, false);
|
||||||
|
JLOG(context.j.debug) << "doSubscribe: accounts: " << ids.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.params.isMember(jss::books))
|
||||||
|
{
|
||||||
|
if (! context.params[jss::books].isArray())
|
||||||
return rpcError (rpcINVALID_PARAMS);
|
return rpcError (rpcINVALID_PARAMS);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto ids = RPC::parseAccountIds (context.params[strAccountsProposed]);
|
|
||||||
|
|
||||||
if (ids.empty ())
|
|
||||||
jvResult[jss::error] = "malformedAccount";
|
|
||||||
else
|
|
||||||
context.netOps.subAccount (ispSub, ids, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!context.params.isMember (jss::accounts))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else if (!context.params[jss::accounts].isArray ())
|
|
||||||
{
|
|
||||||
return rpcError (rpcINVALID_PARAMS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto ids = RPC::parseAccountIds (context.params[jss::accounts]);
|
|
||||||
|
|
||||||
if (ids.empty ())
|
|
||||||
{
|
|
||||||
jvResult[jss::error] = "malformedAccount";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.netOps.subAccount (ispSub, ids, false);
|
|
||||||
JLOG (context.j.debug)
|
|
||||||
<< "doSubscribe: accounts: " << ids.size ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!context.params.isMember (jss::books))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else if (!context.params[jss::books].isArray ())
|
|
||||||
{
|
|
||||||
return rpcError (rpcINVALID_PARAMS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto& j: context.params[jss::books])
|
for (auto& j: context.params[jss::books])
|
||||||
{
|
{
|
||||||
if (!j.isObject ()
|
if (!j.isObject ()
|
||||||
|
|||||||
@@ -37,21 +37,20 @@ Json::Value doUnsubscribe (RPC::Context& context)
|
|||||||
InfoSub::pointer ispSub;
|
InfoSub::pointer ispSub;
|
||||||
Json::Value jvResult (Json::objectValue);
|
Json::Value jvResult (Json::objectValue);
|
||||||
|
|
||||||
if (!context.infoSub && !context.params.isMember (jss::url))
|
if (! context.infoSub && ! context.params.isMember(jss::url))
|
||||||
{
|
{
|
||||||
// Must be a JSON-RPC call.
|
// Must be a JSON-RPC call.
|
||||||
return rpcError (rpcINVALID_PARAMS);
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.params.isMember (jss::url))
|
if (context.params.isMember(jss::url))
|
||||||
{
|
{
|
||||||
if (context.role != Role::ADMIN)
|
if (context.role != Role::ADMIN)
|
||||||
return rpcError (rpcNO_PERMISSION);
|
return rpcError(rpcNO_PERMISSION);
|
||||||
|
|
||||||
std::string strUrl = context.params[jss::url].asString ();
|
std::string strUrl = context.params[jss::url].asString ();
|
||||||
ispSub = context.netOps.findRpcSub (strUrl);
|
ispSub = context.netOps.findRpcSub (strUrl);
|
||||||
|
if (! ispSub)
|
||||||
if (!ispSub)
|
|
||||||
return jvResult;
|
return jvResult;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -61,74 +60,76 @@ Json::Value doUnsubscribe (RPC::Context& context)
|
|||||||
|
|
||||||
if (context.params.isMember (jss::streams))
|
if (context.params.isMember (jss::streams))
|
||||||
{
|
{
|
||||||
|
if (! context.params[jss::streams].isArray ())
|
||||||
|
return rpcError (rpcINVALID_PARAMS);
|
||||||
|
|
||||||
for (auto& it: context.params[jss::streams])
|
for (auto& it: context.params[jss::streams])
|
||||||
{
|
{
|
||||||
if (it.isString ())
|
if (! it.isString())
|
||||||
{
|
return rpcError(rpcSTREAM_MALFORMED);
|
||||||
|
|
||||||
std::string streamName = it.asString ();
|
std::string streamName = it.asString ();
|
||||||
|
|
||||||
if (streamName == "server")
|
if (streamName == "server")
|
||||||
|
{
|
||||||
context.netOps.unsubServer (ispSub->getSeq ());
|
context.netOps.unsubServer (ispSub->getSeq ());
|
||||||
|
}
|
||||||
else if (streamName == "ledger")
|
else if (streamName == "ledger")
|
||||||
|
{
|
||||||
context.netOps.unsubLedger (ispSub->getSeq ());
|
context.netOps.unsubLedger (ispSub->getSeq ());
|
||||||
|
}
|
||||||
else if (streamName == "transactions")
|
else if (streamName == "transactions")
|
||||||
|
{
|
||||||
context.netOps.unsubTransactions (ispSub->getSeq ());
|
context.netOps.unsubTransactions (ispSub->getSeq ());
|
||||||
|
}
|
||||||
else if (streamName == "transactions_proposed"
|
else if (streamName == "transactions_proposed"
|
||||||
|| streamName == "rt_transactions") // DEPRECATED
|
|| streamName == "rt_transactions") // DEPRECATED
|
||||||
|
{
|
||||||
context.netOps.unsubRTTransactions (ispSub->getSeq ());
|
context.netOps.unsubRTTransactions (ispSub->getSeq ());
|
||||||
|
}
|
||||||
else if (streamName == "validations")
|
else if (streamName == "validations")
|
||||||
|
{
|
||||||
context.netOps.unsubValidations (ispSub->getSeq ());
|
context.netOps.unsubValidations (ispSub->getSeq ());
|
||||||
|
}
|
||||||
else if (streamName == "peer_status")
|
else if (streamName == "peer_status")
|
||||||
|
{
|
||||||
context.netOps.unsubPeerStatus (ispSub->getSeq ());
|
context.netOps.unsubPeerStatus (ispSub->getSeq ());
|
||||||
|
|
||||||
else
|
|
||||||
jvResult[jss::error] = "Unknown stream: " + streamName;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jvResult[jss::error] = "malformedSteam";
|
return rpcError(rpcSTREAM_MALFORMED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.params.isMember (jss::accounts_proposed)
|
auto accountsProposed = context.params.isMember(jss::accounts_proposed)
|
||||||
|| context.params.isMember (jss::rt_accounts))
|
? jss::accounts_proposed : jss::rt_accounts; // DEPRECATED
|
||||||
|
if (context.params.isMember(accountsProposed))
|
||||||
{
|
{
|
||||||
auto accounts = RPC::parseAccountIds (
|
if (! context.params[accountsProposed].isArray())
|
||||||
context.params.isMember (jss::accounts_proposed)
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
? context.params[jss::accounts_proposed]
|
|
||||||
: context.params[jss::rt_accounts]); // DEPRECATED
|
|
||||||
|
|
||||||
if (accounts.empty ())
|
auto ids = RPC::parseAccountIds(context.params[accountsProposed]);
|
||||||
jvResult[jss::error] = "malformedAccount";
|
if (ids.empty())
|
||||||
else
|
return rpcError(rpcACT_MALFORMED);
|
||||||
context.netOps.unsubAccount (ispSub, accounts, true);
|
context.netOps.unsubAccount(ispSub, ids, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.params.isMember (jss::accounts))
|
if (context.params.isMember(jss::accounts))
|
||||||
{
|
{
|
||||||
auto accounts = RPC::parseAccountIds (context.params[jss::accounts]);
|
if (! context.params[jss::accounts].isArray())
|
||||||
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
if (accounts.empty ())
|
auto ids = RPC::parseAccountIds(context.params[jss::accounts]);
|
||||||
jvResult[jss::error] = "malformedAccount";
|
if (ids.empty())
|
||||||
else
|
return rpcError(rpcACT_MALFORMED);
|
||||||
context.netOps.unsubAccount (ispSub, accounts, false);
|
context.netOps.unsubAccount(ispSub, ids, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.params.isMember (jss::books))
|
if (context.params.isMember(jss::books))
|
||||||
{
|
|
||||||
}
|
|
||||||
else if (!context.params[jss::books].isArray ())
|
|
||||||
{
|
|
||||||
return rpcError (rpcINVALID_PARAMS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
if (! context.params[jss::books].isArray())
|
||||||
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
for (auto& jv: context.params[jss::books])
|
for (auto& jv: context.params[jss::books])
|
||||||
{
|
{
|
||||||
if (!jv.isObject ()
|
if (!jv.isObject ()
|
||||||
|
|||||||
Reference in New Issue
Block a user