Skip to content

Commit

Permalink
Merge #2: Add extended balance RPC call
Browse files Browse the repository at this point in the history
209f82f Add extended balance RPC call (Fornax)

Pull request description:

  Allows you to pull the following balances via RPC call:

  - Available coins
  - Immature coins
  - Locked coins
  - Total coins

Tree-SHA512: 4ba3447769bcd607ce0a6249a50fa8a637a1d33a9aafcd6ee1092e32b697317838d668f98a0865f9f5f11523ec1260dce8dde4043ec117122540bce50b91a574
  • Loading branch information
MitchellCash committed Oct 3, 2018
2 parents bf1e046 + 209f82f commit 18d86e6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{"listreceivedbyaccount", 2},
{"getbalance", 1},
{"getbalance", 2},
{"getextendedbalance", 0},
{"getblockhash", 0},
{"move", 2},
{"move", 3},
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ static const CRPCCommand vRPCCommands[] =
{"wallet", "getaccount", &getaccount, true, false, true},
{"wallet", "getaddressesbyaccount", &getaddressesbyaccount, true, false, true},
{"wallet", "getbalance", &getbalance, false, false, true},
{"wallet", "getextendedbalance", &getextendedbalance, false, false, true},
{"wallet", "getnewaddress", &getnewaddress, true, false, true},
{"wallet", "getrawchangeaddress", &getrawchangeaddress, true, false, true},
{"wallet", "getreceivedbyaccount", &getreceivedbyaccount, false, false, true},
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ extern UniValue signmessage(const UniValue& params, bool fHelp);
extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
extern UniValue getbalance(const UniValue& params, bool fHelp);
extern UniValue getextendedbalance(const UniValue& params, bool fHelp);
extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
extern UniValue movecmd(const UniValue& params, bool fHelp);
extern UniValue sendfrom(const UniValue& params, bool fHelp);
Expand Down
42 changes: 42 additions & 0 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,48 @@ UniValue getbalance(const UniValue& params, bool fHelp)
return ValueFromAmount(nBalance);
}

UniValue getextendedbalance(const UniValue& params, bool fHelp)
{
if (fHelp || (params.size() > 0))
throw runtime_error(
"getextendedbalance\n"
"\nGet extended balance information.\n"
"\nResult:\n"
"{\n"
" \"blocks\": \"xxx\", (string) The current block height\n"
" \"balance\": \"xxx\", (string) The total ION balance\n"
" \"balance_locked\": \"xxx\", (string) The locked ION balance\n"
" \"balance_unlocked\": \"xxx\", (string) The unlocked ION balance\n"
" \"balance_unconfirmed\": \"xxx\", (string) The unconfirmed ION balance\n"
" \"balance_immature\": \"xxx\", (string) The immature ION balance\n"
" \"zerocoin_balance\": \"xxx\", (string) The total xION balance\n"
" \"zerocoin_balance_mature\": \"xxx\", (string) The mature xION balance\n"
" \"zerocoin_balance_immature\": \"xxx\", (string) The immature xION balance\n"
" \"watchonly_balance\": \"xxx\", (string) The total watch-only ION balance\n"
" \"watchonly_balance_unconfirmed\": \"xxx\", (string) The unconfirmed watch-only ION balance\n"
" \"watchonly_balance_immature\": \"xxx\", (string) The immature watch-only ION balance\n"
" \"watchonly_balance_locked\": \"xxx\", (string) The locked watch-only ION balance\n"
"}\n"
"\nExamples:\n" +
HelpExampleCli("getextendedbalance", "") + HelpExampleRpc("getextendedbalance", ""));
LOCK2(cs_main, pwalletMain->cs_wallet);
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("blocks", (int)chainActive.Height()));
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
obj.push_back(Pair("balance_locked", ValueFromAmount(pwalletMain->GetLockedCoins())));
obj.push_back(Pair("balance_unlocked", ValueFromAmount(pwalletMain->GetUnlockedCoins())));
obj.push_back(Pair("balance_unconfirmed", ValueFromAmount(pwalletMain->GetUnconfirmedBalance())));
obj.push_back(Pair("balance_immature", ValueFromAmount(pwalletMain->GetImmatureBalance())));
obj.push_back(Pair("zerocoin_balance", ValueFromAmount(pwalletMain->GetZerocoinBalance(false))));
obj.push_back(Pair("zerocoin_balance_mature", ValueFromAmount(pwalletMain->GetZerocoinBalance(true))));
obj.push_back(Pair("zerocoin_balance_immature", ValueFromAmount(pwalletMain->GetImmatureZerocoinBalance())));
obj.push_back(Pair("watchonly_balance", ValueFromAmount(pwalletMain->GetWatchOnlyBalance())));
obj.push_back(Pair("watchonly_balance_unconfirmed", ValueFromAmount(pwalletMain->GetUnconfirmedWatchOnlyBalance())));
obj.push_back(Pair("watchonly_balance_immature", ValueFromAmount(pwalletMain->GetImmatureWatchOnlyBalance())));
obj.push_back(Pair("watchonly_balance_locked", ValueFromAmount(pwalletMain->GetLockedWatchOnlyBalance())));
return obj;
}

UniValue getunconfirmedbalance(const UniValue &params, bool fHelp)
{
if (fHelp || params.size() > 0)
Expand Down

0 comments on commit 18d86e6

Please sign in to comment.