Skip to content

Commit a63f8b7

Browse files
author
Jeff Garzik
committed
Merge pull request #3717 from djpnewton/wallet-txcount
add getwalletinfo RPC call with wallet transaction count
2 parents 0ffd87f + a00ebb5 commit a63f8b7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/rpcserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ static const CRPCCommand vRPCCommands[] =
295295
{ "lockunspent", &lockunspent, false, false, true },
296296
{ "listlockunspent", &listlockunspent, false, false, true },
297297
{ "settxfee", &settxfee, false, false, true },
298+
{ "getwalletinfo", &getwalletinfo, true, false, true },
298299

299300
/* Wallet-enabled mining */
300301
{ "getgenerate", &getgenerate, true, false, false },

src/rpcserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHel
163163
extern json_spirit::Value encryptwallet(const json_spirit::Array& params, bool fHelp);
164164
extern json_spirit::Value validateaddress(const json_spirit::Array& params, bool fHelp);
165165
extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp);
166+
extern json_spirit::Value getwalletinfo(const json_spirit::Array& params, bool fHelp);
166167

167168
extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
168169
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);

src/rpcwallet.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,4 +1888,36 @@ Value settxfee(const Array& params, bool fHelp)
18881888
return true;
18891889
}
18901890

1891+
Value getwalletinfo(const Array& params, bool fHelp)
1892+
{
1893+
if (fHelp || params.size() != 0)
1894+
throw runtime_error(
1895+
"getwalletinfo\n"
1896+
"Returns an object containing various wallet state info.\n"
1897+
"\nResult:\n"
1898+
"{\n"
1899+
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
1900+
" \"balance\": xxxxxxx, (numeric) the total bitcoin balance of the wallet\n"
1901+
" \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
1902+
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
1903+
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
1904+
" \"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"
1905+
"}\n"
1906+
"\nExamples:\n"
1907+
+ HelpExampleCli("getwalletinfo", "")
1908+
+ HelpExampleRpc("getwalletinfo", "")
1909+
);
1910+
1911+
Object obj;
1912+
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
1913+
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
1914+
obj.push_back(Pair("txcount", (int)pwalletMain->mapWallet.size()));
1915+
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
1916+
obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
1917+
if (pwalletMain->IsCrypted())
1918+
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
1919+
return obj;
1920+
}
1921+
1922+
18911923

0 commit comments

Comments
 (0)