Ejemplo n.º 1
0
static UniValue JSONRPCExecOne(Config &config, JSONRPCRequest jreq,
                               const UniValue &req) {
    UniValue rpc_result(UniValue::VOBJ);

    try {
        jreq.parse(req);

        UniValue result = tableRPC.execute(config, jreq);
        rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
    } catch (const UniValue &objError) {
        rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
    } catch (const std::exception &e) {
        rpc_result = JSONRPCReplyObj(
            NullUniValue, JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
    }

    return rpc_result;
}
Ejemplo n.º 2
0
 /** Collect values from the batch and form a simulated `getinfo` reply. */
 UniValue ProcessReply(const UniValue &batch_in) override
 {
     UniValue result(UniValue::VOBJ);
     std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in, 3);
     // Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass them on
     // getwalletinfo() is allowed to fail in case there is no wallet.
     if (!batch[ID_NETWORKINFO]["error"].isNull()) {
         return batch[ID_NETWORKINFO];
     }
     if (!batch[ID_BLOCKCHAININFO]["error"].isNull()) {
         return batch[ID_BLOCKCHAININFO];
     }
     result.pushKV("version", batch[ID_NETWORKINFO]["result"]["version"]);
     result.pushKV("protocolversion", batch[ID_NETWORKINFO]["result"]["protocolversion"]);
     if (!batch[ID_WALLETINFO].isNull()) {
         result.pushKV("walletversion", batch[ID_WALLETINFO]["result"]["walletversion"]);
         result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]);
     }
     result.pushKV("blocks", batch[ID_BLOCKCHAININFO]["result"]["blocks"]);
     result.pushKV("timeoffset", batch[ID_NETWORKINFO]["result"]["timeoffset"]);
     result.pushKV("connections", batch[ID_NETWORKINFO]["result"]["connections"]);
     result.pushKV("proxy", batch[ID_NETWORKINFO]["result"]["networks"][0]["proxy"]);
     result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
     result.pushKV("testnet", UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"].get_str() == "test"));
     if (!batch[ID_WALLETINFO].isNull()) {
         result.pushKV("walletversion", batch[ID_WALLETINFO]["result"]["walletversion"]);
         result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]);
         result.pushKV("keypoololdest", batch[ID_WALLETINFO]["result"]["keypoololdest"]);
         result.pushKV("keypoolsize", batch[ID_WALLETINFO]["result"]["keypoolsize"]);
         if (!batch[ID_WALLETINFO]["result"]["unlocked_until"].isNull()) {
             result.pushKV("unlocked_until", batch[ID_WALLETINFO]["result"]["unlocked_until"]);
         }
         result.pushKV("paytxfee", batch[ID_WALLETINFO]["result"]["paytxfee"]);
     }
     result.pushKV("relayfee", batch[ID_NETWORKINFO]["result"]["relayfee"]);
     result.pushKV("warnings", batch[ID_NETWORKINFO]["result"]["warnings"]);
     return JSONRPCReplyObj(result, NullUniValue, 1);
 }
Ejemplo n.º 3
0
std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id)
{
    UniValue reply = JSONRPCReplyObj(result, error, id);
    return reply.write() + "\n";
}
Ejemplo n.º 4
0
std::string JSONRPCReply(const json_spirit::Value& result, const json_spirit::Value& error, const json_spirit::Value& id)
{
    json_spirit::Object reply = JSONRPCReplyObj(result, error, id);
    return write_string(json_spirit::Value(reply), false) + "\n";
}