Skip to content

Commit 991685d

Browse files
committed
Move getinfo to rpcnet.cpp
Where to place `getinfo` is a difficult issue as it shows information from the wallet, net and block chain. However, I moved it out of rpcwallet as the command needs also to be available without wallet.
1 parent bbb0936 commit 991685d

File tree

2 files changed

+59
-58
lines changed

2 files changed

+59
-58
lines changed

src/rpcnet.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "protocol.h"
99
#include "sync.h"
1010
#include "util.h"
11+
#include "wallet.h" // for getinfo
12+
#include "init.h" // for getinfo
13+
#include "main.h" // for getinfo
1114

1215
#include <inttypes.h>
1316

@@ -329,3 +332,59 @@ Value getnettotals(const Array& params, bool fHelp)
329332
obj.push_back(Pair("timemillis", static_cast<boost::int64_t>(GetTimeMillis())));
330333
return obj;
331334
}
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+
}

src/rpcwallet.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -66,64 +66,6 @@ string AccountFromValue(const Value& value)
6666
return strAccount;
6767
}
6868

69-
Value getinfo(const Array& params, bool fHelp)
70-
{
71-
if (fHelp || params.size() != 0)
72-
throw runtime_error(
73-
"getinfo\n"
74-
"Returns an object containing various state info.\n"
75-
"\nResult:\n"
76-
"{\n"
77-
" \"version\": xxxxx, (numeric) the server version\n"
78-
" \"protocolversion\": xxxxx, (numeric) the protocol version\n"
79-
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
80-
" \"balance\": xxxxxxx, (numeric) the total bitcoin balance of the wallet\n"
81-
" \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
82-
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
83-
" \"connections\": xxxxx, (numeric) the number of connections\n"
84-
" \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
85-
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
86-
" \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
87-
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
88-
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
89-
" \"paytxfee\": x.xxxx, (numeric) the transaction fee set in btc\n"
90-
" \"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"
91-
" \"errors\": \"...\" (string) any error messages\n"
92-
"}\n"
93-
"\nExamples:\n"
94-
+ HelpExampleCli("getinfo", "")
95-
+ HelpExampleRpc("getinfo", "")
96-
);
97-
98-
proxyType proxy;
99-
GetProxy(NET_IPV4, proxy);
100-
101-
Object obj;
102-
obj.push_back(Pair("version", (int)CLIENT_VERSION));
103-
obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
104-
if (pwalletMain) {
105-
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
106-
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
107-
}
108-
obj.push_back(Pair("blocks", (int)chainActive.Height()));
109-
obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset()));
110-
obj.push_back(Pair("connections", (int)vNodes.size()));
111-
obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
112-
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
113-
obj.push_back(Pair("testnet", TestNet()));
114-
if (pwalletMain) {
115-
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
116-
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
117-
}
118-
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
119-
if (pwalletMain && pwalletMain->IsCrypted())
120-
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
121-
obj.push_back(Pair("errors", GetWarnings("statusbar")));
122-
return obj;
123-
}
124-
125-
126-
12769
Value getnewaddress(const Array& params, bool fHelp)
12870
{
12971
if (fHelp || params.size() > 1)

0 commit comments

Comments
 (0)