|
8 | 8 | #include "protocol.h"
|
9 | 9 | #include "sync.h"
|
10 | 10 | #include "util.h"
|
| 11 | +#include "wallet.h" // for getinfo |
| 12 | +#include "init.h" // for getinfo |
| 13 | +#include "main.h" // for getinfo |
11 | 14 |
|
12 | 15 | #include <inttypes.h>
|
13 | 16 |
|
@@ -329,3 +332,59 @@ Value getnettotals(const Array& params, bool fHelp)
|
329 | 332 | obj.push_back(Pair("timemillis", static_cast<boost::int64_t>(GetTimeMillis())));
|
330 | 333 | return obj;
|
331 | 334 | }
|
| 335 | + |
| 336 | +Value getinfo(const Array& params, bool fHelp) |
| 337 | +{ |
| 338 | + if (fHelp || params.size() != 0) |
| 339 | + throw runtime_error( |
| 340 | + "getinfo\n" |
| 341 | + "Returns an object containing various state info.\n" |
| 342 | + "\nResult:\n" |
| 343 | + "{\n" |
| 344 | + " \"version\": xxxxx, (numeric) the server version\n" |
| 345 | + " \"protocolversion\": xxxxx, (numeric) the protocol version\n" |
| 346 | + " \"walletversion\": xxxxx, (numeric) the wallet version\n" |
| 347 | + " \"balance\": xxxxxxx, (numeric) the total bitcoin balance of the wallet\n" |
| 348 | + " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" |
| 349 | + " \"timeoffset\": xxxxx, (numeric) the time offset\n" |
| 350 | + " \"connections\": xxxxx, (numeric) the number of connections\n" |
| 351 | + " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n" |
| 352 | + " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" |
| 353 | + " \"testnet\": true|false, (boolean) if the server is using testnet or not\n" |
| 354 | + " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n" |
| 355 | + " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n" |
| 356 | + " \"paytxfee\": x.xxxx, (numeric) the transaction fee set in btc\n" |
| 357 | + " \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n" |
| 358 | + " \"errors\": \"...\" (string) any error messages\n" |
| 359 | + "}\n" |
| 360 | + "\nExamples:\n" |
| 361 | + + HelpExampleCli("getinfo", "") |
| 362 | + + HelpExampleRpc("getinfo", "") |
| 363 | + ); |
| 364 | + |
| 365 | + proxyType proxy; |
| 366 | + GetProxy(NET_IPV4, proxy); |
| 367 | + |
| 368 | + Object obj; |
| 369 | + obj.push_back(Pair("version", (int)CLIENT_VERSION)); |
| 370 | + obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); |
| 371 | + if (pwalletMain) { |
| 372 | + obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); |
| 373 | + obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); |
| 374 | + } |
| 375 | + obj.push_back(Pair("blocks", (int)chainActive.Height())); |
| 376 | + obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); |
| 377 | + obj.push_back(Pair("connections", (int)vNodes.size())); |
| 378 | + obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); |
| 379 | + obj.push_back(Pair("difficulty", (double)GetDifficulty())); |
| 380 | + obj.push_back(Pair("testnet", TestNet())); |
| 381 | + if (pwalletMain) { |
| 382 | + obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); |
| 383 | + obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); |
| 384 | + } |
| 385 | + obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); |
| 386 | + if (pwalletMain && pwalletMain->IsCrypted()) |
| 387 | + obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime)); |
| 388 | + obj.push_back(Pair("errors", GetWarnings("statusbar"))); |
| 389 | + return obj; |
| 390 | +} |
0 commit comments