Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-cli.cpp
Show First 20 Lines • Show All 290 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
/** Process getinfo requests */ | /** Process getinfo requests */ | ||||
class GetinfoRequestHandler : public BaseRequestHandler { | class GetinfoRequestHandler : public BaseRequestHandler { | ||||
public: | public: | ||||
const int ID_NETWORKINFO = 0; | const int ID_NETWORKINFO = 0; | ||||
const int ID_BLOCKCHAININFO = 1; | const int ID_BLOCKCHAININFO = 1; | ||||
const int ID_WALLETINFO = 2; | const int ID_WALLETINFO = 2; | ||||
const int ID_BALANCES = 3; | |||||
/** Create a simulated `getinfo` request. */ | /** Create a simulated `getinfo` request. */ | ||||
UniValue PrepareRequest(const std::string &method, | UniValue PrepareRequest(const std::string &method, | ||||
const std::vector<std::string> &args) override { | const std::vector<std::string> &args) override { | ||||
if (!args.empty()) { | if (!args.empty()) { | ||||
throw std::runtime_error("-getinfo takes no arguments"); | throw std::runtime_error("-getinfo takes no arguments"); | ||||
} | } | ||||
UniValue result(UniValue::VARR); | UniValue result(UniValue::VARR); | ||||
result.push_back( | result.push_back( | ||||
JSONRPCRequestObj("getnetworkinfo", NullUniValue, ID_NETWORKINFO)); | JSONRPCRequestObj("getnetworkinfo", NullUniValue, ID_NETWORKINFO)); | ||||
result.push_back(JSONRPCRequestObj("getblockchaininfo", NullUniValue, | result.push_back(JSONRPCRequestObj("getblockchaininfo", NullUniValue, | ||||
ID_BLOCKCHAININFO)); | ID_BLOCKCHAININFO)); | ||||
result.push_back( | result.push_back( | ||||
JSONRPCRequestObj("getwalletinfo", NullUniValue, ID_WALLETINFO)); | JSONRPCRequestObj("getwalletinfo", NullUniValue, ID_WALLETINFO)); | ||||
result.push_back( | |||||
JSONRPCRequestObj("getbalances", NullUniValue, ID_BALANCES)); | |||||
return result; | return result; | ||||
} | } | ||||
/** Collect values from the batch and form a simulated `getinfo` reply. */ | /** Collect values from the batch and form a simulated `getinfo` reply. */ | ||||
UniValue ProcessReply(const UniValue &batch_in) override { | UniValue ProcessReply(const UniValue &batch_in) override { | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in, 3); | std::vector<UniValue> batch = | ||||
JSONRPCProcessBatchReply(batch_in, batch_in.size()); | |||||
// Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass | // Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass | ||||
// them on getwalletinfo() is allowed to fail in case there is no | // them on; getwalletinfo() and getbalances are allowed to fail if there | ||||
// wallet. | // is no wallet. | ||||
if (!batch[ID_NETWORKINFO]["error"].isNull()) { | if (!batch[ID_NETWORKINFO]["error"].isNull()) { | ||||
return batch[ID_NETWORKINFO]; | return batch[ID_NETWORKINFO]; | ||||
} | } | ||||
if (!batch[ID_BLOCKCHAININFO]["error"].isNull()) { | if (!batch[ID_BLOCKCHAININFO]["error"].isNull()) { | ||||
return batch[ID_BLOCKCHAININFO]; | return batch[ID_BLOCKCHAININFO]; | ||||
} | } | ||||
result.pushKV("version", batch[ID_NETWORKINFO]["result"]["version"]); | result.pushKV("version", batch[ID_NETWORKINFO]["result"]["version"]); | ||||
result.pushKV("blocks", batch[ID_BLOCKCHAININFO]["result"]["blocks"]); | result.pushKV("blocks", batch[ID_BLOCKCHAININFO]["result"]["blocks"]); | ||||
result.pushKV("headers", batch[ID_BLOCKCHAININFO]["result"]["headers"]); | result.pushKV("headers", batch[ID_BLOCKCHAININFO]["result"]["headers"]); | ||||
result.pushKV( | result.pushKV( | ||||
"verificationprogress", | "verificationprogress", | ||||
batch[ID_BLOCKCHAININFO]["result"]["verificationprogress"]); | batch[ID_BLOCKCHAININFO]["result"]["verificationprogress"]); | ||||
result.pushKV("timeoffset", | result.pushKV("timeoffset", | ||||
batch[ID_NETWORKINFO]["result"]["timeoffset"]); | batch[ID_NETWORKINFO]["result"]["timeoffset"]); | ||||
result.pushKV("connections", | result.pushKV("connections", | ||||
batch[ID_NETWORKINFO]["result"]["connections"]); | batch[ID_NETWORKINFO]["result"]["connections"]); | ||||
result.pushKV("proxy", | result.pushKV("proxy", | ||||
batch[ID_NETWORKINFO]["result"]["networks"][0]["proxy"]); | batch[ID_NETWORKINFO]["result"]["networks"][0]["proxy"]); | ||||
result.pushKV("difficulty", | result.pushKV("difficulty", | ||||
batch[ID_BLOCKCHAININFO]["result"]["difficulty"]); | batch[ID_BLOCKCHAININFO]["result"]["difficulty"]); | ||||
result.pushKV("chain", | result.pushKV("chain", | ||||
UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"])); | UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"])); | ||||
if (!batch[ID_WALLETINFO]["result"].isNull()) { | if (!batch[ID_WALLETINFO]["result"].isNull()) { | ||||
result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]); | |||||
result.pushKV("keypoolsize", | result.pushKV("keypoolsize", | ||||
batch[ID_WALLETINFO]["result"]["keypoolsize"]); | batch[ID_WALLETINFO]["result"]["keypoolsize"]); | ||||
if (!batch[ID_WALLETINFO]["result"]["unlocked_until"].isNull()) { | if (!batch[ID_WALLETINFO]["result"]["unlocked_until"].isNull()) { | ||||
result.pushKV("unlocked_until", | result.pushKV("unlocked_until", | ||||
batch[ID_WALLETINFO]["result"]["unlocked_until"]); | batch[ID_WALLETINFO]["result"]["unlocked_until"]); | ||||
} | } | ||||
result.pushKV("paytxfee", | result.pushKV("paytxfee", | ||||
batch[ID_WALLETINFO]["result"]["paytxfee"]); | batch[ID_WALLETINFO]["result"]["paytxfee"]); | ||||
} | } | ||||
if (!batch[ID_BALANCES]["result"].isNull()) { | |||||
result.pushKV("balance", | |||||
batch[ID_BALANCES]["result"]["mine"]["trusted"]); | |||||
} | |||||
result.pushKV("relayfee", batch[ID_NETWORKINFO]["result"]["relayfee"]); | result.pushKV("relayfee", batch[ID_NETWORKINFO]["result"]["relayfee"]); | ||||
result.pushKV("warnings", batch[ID_NETWORKINFO]["result"]["warnings"]); | result.pushKV("warnings", batch[ID_NETWORKINFO]["result"]["warnings"]); | ||||
return JSONRPCReplyObj(result, NullUniValue, 1); | return JSONRPCReplyObj(result, NullUniValue, 1); | ||||
} | } | ||||
}; | }; | ||||
/** Process default single requests */ | /** Process default single requests */ | ||||
class DefaultRequestHandler : public BaseRequestHandler { | class DefaultRequestHandler : public BaseRequestHandler { | ||||
▲ Show 20 Lines • Show All 342 Lines • Show Last 20 Lines |