Submit Env transactions through RPC interface

This commit is contained in:
Vinnie Falco
2015-12-21 13:57:23 -05:00
committed by Edward Hennis
parent 8f74ee1d96
commit d5363d1a85
6 changed files with 84 additions and 35 deletions

View File

@@ -1079,18 +1079,18 @@ struct RPCCallImp
};
//------------------------------------------------------------------------------
namespace RPCCall {
int fromCommandLine (
Config const& config,
const std::vector<std::string>& vCmd,
Logs& logs)
std::pair<int, Json::Value>
rpcClient(std::vector<std::string> const& args,
Config const& config, Logs& logs)
{
if (vCmd.empty ())
return 1; // 1 = print usage.
static_assert(rpcBAD_SYNTAX == 1 && rpcSUCCESS == 0,
"Expect specific rpc enum values.");
if (args.empty ())
return { rpcBAD_SYNTAX, {} }; // rpcBAD_SYNTAX = print usage
int nRet = rpcSUCCESS;
Json::Value jvOutput;
int nRet = 0;
Json::Value jvRequest (Json::objectValue);
auto rpcJ = logs.journal ("RPCParser");
@@ -1099,15 +1099,15 @@ int fromCommandLine (
RPCParser rpParser (rpcJ);
Json::Value jvRpcParams (Json::arrayValue);
for (int i = 1; i != vCmd.size (); i++)
jvRpcParams.append (vCmd[i]);
for (int i = 1; i != args.size (); i++)
jvRpcParams.append (args[i]);
Json::Value jvRpc = Json::Value (Json::objectValue);
jvRpc["method"] = vCmd[0];
jvRpc["method"] = args[0];
jvRpc[jss::params] = jvRpcParams;
jvRequest = rpParser.parseCommand (vCmd[0], jvRpcParams, true);
jvRequest = rpParser.parseCommand (args[0], jvRpcParams, true);
JLOG (rpcJ.trace) << "RPC Request: " << jvRequest << std::endl;
@@ -1147,7 +1147,7 @@ int fromCommandLine (
{
boost::asio::io_service isService;
fromNetwork (
RPCCall::fromNetwork (
isService,
setup.client.ip,
setup.client.port,
@@ -1155,7 +1155,7 @@ int fromCommandLine (
setup.client.password,
"",
jvRequest.isMember ("method") // Allow parser to rewrite method.
? jvRequest["method"].asString () : vCmd[0],
? jvRequest["method"].asString () : args[0],
jvParams, // Parsed, execute.
setup.client.secure != 0, // Use SSL
config.QUIET,
@@ -1196,7 +1196,7 @@ int fromCommandLine (
nRet = jvOutput.isMember (jss::error_code)
? beast::lexicalCast <int> (jvOutput[jss::error_code].asString ())
: 1;
: rpcBAD_SYNTAX;
}
// YYY We could have a command line flag for single line output for scripts.
@@ -1209,9 +1209,24 @@ int fromCommandLine (
nRet = rpcINTERNAL;
}
std::cout << jvOutput.toStyledString ();
return { nRet, std::move(jvOutput) };
}
return nRet;
//------------------------------------------------------------------------------
namespace RPCCall {
int fromCommandLine (
Config const& config,
const std::vector<std::string>& vCmd,
Logs& logs)
{
auto const result = rpcClient(vCmd, config, logs);
if (result.first != rpcBAD_SYNTAX)
std::cout << result.second.toStyledString ();
return result.first;
}
//------------------------------------------------------------------------------