|
|
@ -63,6 +63,7 @@ |
|
|
|
#include "komodo_defs.h" |
|
|
|
#include <string.h> |
|
|
|
#include "sietch.h" |
|
|
|
#include "rpchushwallet.h" |
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
@ -3025,6 +3026,301 @@ uint64_t komodo_interestsum() |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
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. \"hushaddress:\" (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 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; |
|
|
|
|
|
|
|
if (fHelp || params.size() > 5 || params.size() == 3) |
|
|
|
throw runtime_error( |
|
|
|
"z_listsentbyaddress\n" |
|
|
|
"\nReturns decrypted Hush outputs sent to a single address.\n" |
|
|
|
"\n" |
|
|
|
"This function only returns information on addresses sent from wallet addresses with full spending keys." |
|
|
|
"\n" |
|
|
|
"\nArguments:\n" |
|
|
|
"1. \"hushaddress:\" (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" |
|
|
|
" \"sends\": { A list of outputs of where funds were sent to in the transaction,\n" |
|
|
|
" only available if the transaction has valid sends (inputs) belonging to the wallet\n" |
|
|
|
" \"transparentSends\": [{ An Array of spends (outputs) for transparent addresses of the receipient\n" |
|
|
|
" \"address\": \"hushaddress\", (string) Hush transparent address (t-address)\n" |
|
|
|
" \"scriptPubKey\": \"script\", (string) Script for the Hush transparent address (t-address)\n" |
|
|
|
" \"amount\": x.xxxx, (numeric) Value of output being sent " + CURRENCY_UNIT + ", negative for sends\n" |
|
|
|
" \"vout\": : n, (numeric) the vout value\n" |
|
|
|
" }],\n" |
|
|
|
" \"saplingSends\": [{ An Array of spends (outputs) for sapling addresses\n" |
|
|
|
" \"address\": \"hushaddress\", (string) Hush sapling address (z-address) of the receipient\n" |
|
|
|
" \"amount\": x.xxxx, (numeric) Value of output being sent" + CURRENCY_UNIT + ", negative for sends\n" |
|
|
|
" \"memo\": xxxxx, (string) hexademical string representation of memo field\n" |
|
|
|
" \"memoStr\" : \"memo\", (string) Only returned if memo contains valid UTF-8 text.\n" |
|
|
|
" \"shieldedOutputIndex\": 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" |
|
|
|
" \"missingSaplingOVK\": true/false (string) True if the sapling outputs are not decryptable\n" |
|
|
|
" }\n" |
|
|
|
"\nExamples:\n" |
|
|
|
+ HelpExampleCli("z_listsentbyaddress", "t1KzZ5n2TPEGYXTZ3WYGL1AYEumEQaRoHaL") |
|
|
|
+ HelpExampleRpc("z_listsentbyaddress", "t1KzZ5n2TPEGYXTZ3WYGL1AYEumEQaRoHaL") |
|
|
|
); |
|
|
|
|
|
|
|
LOCK2(cs_main, pwalletMain->cs_wallet); |
|
|
|
|
|
|
|
UniValue ret(UniValue::VARR); |
|
|
|
|
|
|
|
//param values`
|
|
|
|
int64_t nMinConfirms = 0; |
|
|
|
int64_t nFilterType = 0; |
|
|
|
int64_t nFilter = 9999999; |
|
|
|
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; |
|
|
|
|
|
|
|
if (!CheckFinalTx(wtx)) |
|
|
|
continue; |
|
|
|
|
|
|
|
if (wtx.GetDepthInMainChain() < 0) |
|
|
|
continue; |
|
|
|
|
|
|
|
if (wtx.mapSaplingNoteData.size() == 0 && !wtx.IsTrusted()) |
|
|
|
continue; |
|
|
|
|
|
|
|
//Excude transactions with less confirmations than required
|
|
|
|
if (wtx.GetDepthInMainChain() < nMinConfirms) |
|
|
|
continue; |
|
|
|
|
|
|
|
//Exclude Transactions older that max days old
|
|
|
|
if (wtx.GetDepthInMainChain() > 0 && nFilterType == 1 && mapBlockIndex[wtx.hashBlock]->GetBlockTime() < (t - (nFilter * 60 * 60 * 24))) |
|
|
|
continue; |
|
|
|
|
|
|
|
//Exclude transactions with greater than max confirmations
|
|
|
|
if (nFilterType == 2 && wtx.GetDepthInMainChain() > nFilter) |
|
|
|
continue; |
|
|
|
|
|
|
|
zsWalletTxJSON(wtx, ret, "*", false, 0); |
|
|
|
|
|
|
|
|
|
|
|
if (ret.size() >= nCount) break; |
|
|
|
} |
|
|
|
|
|
|
|
vector<UniValue> arrTmp = ret.getValues(); |
|
|
|
|
|
|
|
std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
|
|
|
|
|
|
|
|
ret.clear(); |
|
|
|
ret.setArray(); |
|
|
|
ret.push_backV(arrTmp); |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
UniValue z_listunspent(const UniValue& params, bool fHelp, const CPubKey& mypk) |
|
|
|
{ |
|
|
@ -3953,6 +4249,15 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp, const CPubK |
|
|
|
obj.push_back(Pair("txid", entry.op.hash.ToString())); |
|
|
|
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.note.value())))); |
|
|
|
obj.push_back(Pair("memo", HexStr(entry.memo))); |
|
|
|
// give a string representation if valid utf8
|
|
|
|
auto memo = entry.memo; |
|
|
|
if (memo[0] <= 0xf4) { |
|
|
|
auto end = std::find_if(memo.rbegin(), memo.rend(), [](unsigned char v) { return v != 0; }); |
|
|
|
std::string memoStr(memo.begin(), end.base()); |
|
|
|
if (utf8::is_valid(memoStr)) { |
|
|
|
obj.push_back(Pair("memoStr", memoStr)); |
|
|
|
} |
|
|
|
} |
|
|
|
obj.push_back(Pair("outindex", (int)entry.op.n)); |
|
|
|
obj.push_back(Pair("rawconfirmations", entry.confirmations)); |
|
|
|
obj.push_back(Pair("confirmations", dpowconfs)); |
|
|
@ -8188,6 +8493,7 @@ static const CRPCCommand commands[] = |
|
|
|
{ "disclosure", "z_validatepaymentdisclosure", &z_validatepaymentdisclosure, true } |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void RegisterWalletRPCCommands(CRPCTable &tableRPC) |
|
|
|
{ |
|
|
|
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) |
|
|
|