Skip to content

Commit

Permalink
Add listaddresses RPC call
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLTZ committed Sep 10, 2024
1 parent a6770b3 commit 29fa24f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,36 @@ UniValue getrawchangeaddress(const UniValue& params, bool fHelp)
return EncodeDestination(keyID);
}

UniValue listaddresses(const UniValue& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;

if (fHelp || params.size() != 0)
throw runtime_error(
"listaddresses\n"
"\nReturns the list of transparent addresses belonging to the wallet.\n"
"\nResult:\n"
"[ (json array of string)\n"
" \"address\" (string) a transparent address belonging to the wallet\n"
" ,...\n"
"]\n"
"\nExamples:\n"
+ HelpExampleCli("listaddresses", "")
+ HelpExampleRpc("listaddresses", "")
);

LOCK2(cs_main, pwalletMain->cs_wallet);

// Find all addresses
UniValue ret(UniValue::VARR);
for (const std::pair<CTxDestination, CAddressBookData>& item : pwalletMain->mapAddressBook) {
const CTxDestination& dest = item.first;
ret.push_back(EncodeDestination(dest));
}
return ret;
}

static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, CWalletTx& wtxNew)
{
CAmount curBalance = pwalletMain->GetBalance();
Expand Down Expand Up @@ -4387,6 +4417,7 @@ static const CRPCCommand commands[] =
{ "wallet", "importaddress", &importaddress, true },
{ "wallet", "importpubkey", &importpubkey, true },
{ "wallet", "keypoolrefill", &keypoolrefill, true },
{ "wallet", "listaddresses", &listaddresses, true },
{ "wallet", "listaddressgroupings", &listaddressgroupings, false },
{ "wallet", "listlockunspent", &listlockunspent, false },
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false },
Expand Down
6 changes: 6 additions & 0 deletions src/wallet/test/rpc_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
/* Correct address, message and signature*/
BOOST_CHECK(CallRPC("verifymessage " + EncodeDestination(demoAddress) + " " + retValue.get_str() + " mymessage").get_bool() == true);

/*********************************
* listaddresses
*********************************/
BOOST_CHECK_THROW(CallRPC("listaddresses true"), runtime_error);
BOOST_CHECK_NO_THROW(retValue = CallRPC("listaddresses"));

/*********************************
* fundrawtransaction
*********************************/
Expand Down

0 comments on commit 29fa24f

Please sign in to comment.