Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional boolean to z_listreceivedbyaddress to decode memo field #84

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3042,13 +3042,14 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;

if (fHelp || params.size()==0 || params.size() >2)
if (fHelp || params.size()==0 || params.size() >3)
throw runtime_error(
"z_listreceivedbyaddress \"address\" ( minconf )\n"
"\nReturn a list of amounts received by a zaddr belonging to the node’s wallet.\n"
"\nArguments:\n"
"1. \"address\" (string) The private address.\n"
"2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n"
"3. decode (boolean, optional, default=False) Decode memo to Unicode text, if possible.\n"
"\nResult:\n"
"{\n"
" \"txid\": xxxxx, (string) the transaction id\n"
Expand All @@ -3060,9 +3061,14 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet);

int nMinDepth = 1;
bool bDecode = false;
if (params.size() > 1) {
nMinDepth = params[1].get_int();

if (params.size() > 2) {
bDecode = params[2].get_bool();
}

if (nMinDepth < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Minimum number of confirmations cannot be less than 0");
}
Expand Down Expand Up @@ -3091,7 +3097,12 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
obj.push_back(Pair("txid",entry.jsop.hash.ToString()));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value))));
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
obj.push_back(Pair("memo", HexStr(data)));
if (bDecode) {
// TODO: check for printable ascii/unicode vs binary data
obj.push_back(Pair("memo", data.ToString()));
} else {
obj.push_back(Pair("memo", HexStr(data)));
}
result.push_back(obj);
}
return result;
Expand Down