Add z_listreceivedbyaddress from ZER
This commit is contained in:
@@ -477,6 +477,147 @@ void zsWalletTxJSON(const CWalletTx& wtx, UniValue& ret, const std::string strAd
|
||||
|
||||
}
|
||||
|
||||
UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) {
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 5 || params.size() == 3)
|
||||
throw runtime_error(
|
||||
"z_listreceivedbyaddress\n"
|
||||
"\nReturns received outputs for a single address.\n"
|
||||
"\n"
|
||||
"This function only returns information on addresses with full spending keys."
|
||||
"\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"zeroaddress:\" (string, required) \n"
|
||||
"\n"
|
||||
"2. \"Minimum Confimations:\" (numeric, optional, default=0) \n"
|
||||
"\n"
|
||||
"3. \"Filter Type:\" (numeric, optional, default=0) \n"
|
||||
" Value of 0: Returns all transactions in the wallet\n"
|
||||
" Value of 1: Returns the last x days of transactions\n"
|
||||
" Value of 2: Returns transactions with confimations less than x\n"
|
||||
"\n"
|
||||
"4. \"Filter:\" (numeric, optional, default=999999) \n"
|
||||
" Filter Type equal 0: paramater ignored\n"
|
||||
" Filter Type equal 1: number represents the number of days returned\n"
|
||||
" Filter Type equal 2: number represents the max confirmations for transaction to be returned\n"
|
||||
"\n"
|
||||
"5. \"Count:\" (numeric, optional, default=9999999) \n"
|
||||
" Last n number of transactions returned\n"
|
||||
"\n"
|
||||
"Default Parameters:\n"
|
||||
"2. 0 - O confimations required\n"
|
||||
"3. 0 - Returns all transactions\n"
|
||||
"4. 9999999 - Ignored\n"
|
||||
"5. 9999999 - Return the last 9,999,999 transactions.\n"
|
||||
"\n"
|
||||
"\nResult:\n"
|
||||
" \"txid\": \"transactionid\", (string) The transaction id.\n"
|
||||
" \"coinbase\": \"coinbase\", (string) Coinbase transaction, true or false\n"
|
||||
" \"category\": \"category\", (string) orphan (coinbase), immature (coinbase), generate (coinbase), regular\n"
|
||||
" \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction\n"
|
||||
" \"blockindex\": n, (numeric) The block index containing the transaction\n"
|
||||
" \"blocktime\": n, (numeric) The block time in seconds of the block containing the transaction, 0 for unconfirmed transactions\n"
|
||||
" \"expiryheight\": n, (numeric) The expiry height of the transaction\n"
|
||||
" \"confirmations\": n, (numeric) The number of confirmations for the transaction\n"
|
||||
" \"time\": xxx, (numeric) The transaction time in seconds of the transaction\n"
|
||||
" \"size\": xxx, (numeric) The transaction size\n"
|
||||
" \"walletconflicts\": [conflicts], An array of wallet conflicts\n"
|
||||
" \"recieved\": { A list of receives from the transaction\n"
|
||||
" \"transparentReceived\": [{ An Array of txos received for transparent addresses\n"
|
||||
" \"address\": \"zeroaddress\", (string) Hush transparent address (t-address)\n"
|
||||
" \"scriptPubKey\": \"script\", (string) Script for the Zero transparent address (t-address)\n"
|
||||
" \"amount\": x.xxxx, (numeric) Value of output being received " + CURRENCY_UNIT + ", positive for receives\n"
|
||||
" \"vout\": : n, (numeric) the vout value\n"
|
||||
" }],\n"
|
||||
" \"saplingReceived\": [{ An Array of utxos/notes received for sapling addresses\n"
|
||||
" \"address\": \"zeroaddress\", (string) Shielded address (z-address)\n"
|
||||
" \"amount\": x.xxxx, (numeric) Value of output being received " + CURRENCY_UNIT + ", positive for receives\n"
|
||||
" \"sheildedOutputIndex\": n, (numeric) The index of the ShieledOutput\n"
|
||||
" \"change\": true/false (string) The note is change. This can result from sending funds\n"
|
||||
" to the same address they came from, or incomplete useage\n"
|
||||
" resulting in the remainder of the note used being sent back to the\n"
|
||||
" same z-address.\n"
|
||||
" }],\n"
|
||||
" },\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_listreceivedbyaddress", "R...")
|
||||
+ HelpExampleRpc("z_listreceivedbyaddress", "R...")
|
||||
);
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
|
||||
//param values`
|
||||
int64_t nMinConfirms = 0;
|
||||
int64_t nFilterType = 0;
|
||||
int64_t nFilter = 999999;
|
||||
int64_t nCount = 9999999;
|
||||
|
||||
if (params.size() >= 2)
|
||||
nMinConfirms = params[1].get_int64();
|
||||
|
||||
if (params.size() >= 4) {
|
||||
nFilterType = params[2].get_int64();
|
||||
nFilter = params[3].get_int64();
|
||||
}
|
||||
|
||||
if (params.size() == 5) {
|
||||
nCount = params[4].get_int64();
|
||||
}
|
||||
|
||||
if (nMinConfirms < 0)
|
||||
throw runtime_error("Minimum confimations must be greater that 0");
|
||||
|
||||
if (nFilterType < 0 || nFilterType > 2)
|
||||
throw runtime_error("Filter type must be 0, 1 or 2.");
|
||||
|
||||
if (nFilter < 0)
|
||||
throw runtime_error("Filter must be greater that 0.");
|
||||
|
||||
//Created Ordered Transaction Map
|
||||
map<int64_t,CWalletTx> orderedTxs;
|
||||
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
|
||||
const CWalletTx& wtx = (*it).second;
|
||||
orderedTxs.insert(std::pair<int64_t,CWalletTx>(wtx.nOrderPos, wtx));
|
||||
}
|
||||
|
||||
|
||||
uint64_t t = GetTime();
|
||||
//Reverse Iterate thru transactions
|
||||
for (map<int64_t,CWalletTx>::reverse_iterator it = orderedTxs.rbegin(); it != orderedTxs.rend(); ++it) {
|
||||
const CWalletTx& wtx = (*it).second;
|
||||
bool includeTransaction = true;
|
||||
|
||||
//Excude transactions with less confirmations than required
|
||||
if (wtx.GetDepthInMainChain() < nMinConfirms) {
|
||||
includeTransaction = false;
|
||||
}
|
||||
|
||||
//Exclude Transactions older that max days old
|
||||
if (wtx.GetDepthInMainChain() > 0) {
|
||||
if (nFilterType == 1 && mapBlockIndex[wtx.hashBlock]->GetBlockTime() < (t - (nFilter * 60 * 60 * 24))) {
|
||||
includeTransaction = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Exclude transactions with greater than max confirmations
|
||||
if (nFilterType == 2 && wtx.GetDepthInMainChain() > nFilter){
|
||||
includeTransaction = false;
|
||||
}
|
||||
|
||||
if (includeTransaction) {
|
||||
zsWalletTxJSON(wtx, ret, params[0].get_str() , true, 2);
|
||||
}
|
||||
|
||||
if (ret.size() > nCount) break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue z_listsentbyaddress(const UniValue& params, bool fHelp,const CPubKey&) {
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
@@ -631,15 +772,3 @@ UniValue z_listsentbyaddress(const UniValue& params, bool fHelp,const CPubKey&)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const CRPCCommand commands[] =
|
||||
{ // category name actor (function) okSafeMode
|
||||
// --------------------- ------------------------ ----------------------- ----------
|
||||
{ "Hush Exclusive", "z_listsentbyaddress", &z_listsentbyaddress, true },
|
||||
};
|
||||
|
||||
void RegisterHushExclusiveRPCCommands(CRPCTable &tableRPC)
|
||||
{
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
|
||||
@@ -8181,6 +8181,8 @@ static const CRPCCommand commands[] =
|
||||
{ "wallet", "z_exportwallet", &z_exportwallet, true },
|
||||
{ "wallet", "z_importwallet", &z_importwallet, true },
|
||||
{ "wallet", "z_viewtransaction", &z_viewtransaction, true },
|
||||
{ "wallet", "z_listsentbyaddress", &z_listsentbyaddress, true },
|
||||
{ "wallet", "z_listreceivedbyaddress", &z_listreceivedbyaddress, true },
|
||||
// TODO: rearrange into another category
|
||||
{ "disclosure", "z_getpaymentdisclosure", &z_getpaymentdisclosure, true },
|
||||
{ "disclosure", "z_validatepaymentdisclosure", &z_validatepaymentdisclosure, true }
|
||||
|
||||
Reference in New Issue
Block a user