Improved error message on mistyped command [RIPD-1527]:

Previously if you mistyped the "submit_multisigned" command as
"submit_multisign", the returned message was "Internal error".  Not
very helpful.  It turns out this was caused by a small amount of
code in RPCCall.cpp.  Removing that code improves two situations:

1. It improves the situation with a mistyped command.  Now the
   command returns "Unknown method" and provides the string of
   the mistyped command.

2. The "transaction_entry", if properly entered in its command
   line form, would fire an assert.  That assert is now removed.

In the process, it was discovered that the command line form of
the "transaction_entry" command has not worked correctly for at
least a year.  Therefore support for that the command line form
of "transaction_entry" is added along with appropriate unit
tests.
This commit is contained in:
Scott Schurr
2017-11-22 18:39:08 -08:00
committed by seelabs
parent 8a02b76d73
commit 722917e9a6
3 changed files with 139 additions and 19 deletions

View File

@@ -879,6 +879,31 @@ private:
return rpcError (rpcINVALID_PARAMS);
}
// transaction_entry <tx_hash> <ledger_hash/ledger_index>
Json::Value parseTransactionEntry (Json::Value const& jvParams)
{
// Parameter count should have already been verified.
assert (jvParams.size() == 2);
std::string const txHash = jvParams[0u].asString();
if (txHash.length() != 64)
return rpcError (rpcINVALID_PARAMS);
Json::Value jvRequest;
jvRequest[jss::tx_hash] = txHash;
jvParseLedger (jvRequest, jvParams[1u].asString());
// jvParseLedger inserts a "ledger_index" of 0 if it doesn't
// find a match.
if (jvRequest.isMember(jss::ledger_index) &&
jvRequest[jss::ledger_index] == 0)
return rpcError (rpcINVALID_PARAMS);
return jvRequest;
}
// tx <transaction_id>
Json::Value parseTx (Json::Value const& jvParams)
{
@@ -1073,7 +1098,7 @@ public:
{ "server_info", &RPCParser::parseAsIs, 0, 0 },
{ "server_state", &RPCParser::parseAsIs, 0, 0 },
{ "stop", &RPCParser::parseAsIs, 0, 0 },
// { "transaction_entry", &RPCParser::parseTransactionEntry, -1, -1 },
{ "transaction_entry", &RPCParser::parseTransactionEntry, 2, 2 },
{ "tx", &RPCParser::parseTx, 1, 2 },
{ "tx_account", &RPCParser::parseTxAccount, 1, 7 },
{ "tx_history", &RPCParser::parseTxHistory, 1, 1 },
@@ -1323,12 +1348,6 @@ rpcClient(std::vector<std::string> const& args,
jvParams.append(jvRequest[i]);
}
if (jvRequest.isMember(jss::params))
{
auto const& params = jvRequest[jss::params];
assert(params.size() == 1);
jvParams.append(params[0u]);
}
{
boost::asio::io_service isService;
RPCCall::fromNetwork (