Skip to content

Commit

Permalink
support multiple filters
Browse files Browse the repository at this point in the history
  • Loading branch information
alex v committed Nov 29, 2019
1 parent ab629ed commit 6c7c471
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3715,6 +3715,7 @@ UniValue listproposals(const UniValue& params, bool fHelp)
"\nArguments:\n"
"\n1. \"filter\" (string, optional) \"accepted\" | \"rejected\" | \"expired\" | \"pending\" | \"mine\"\n"
"\nExamples:\n"
+ HelpExampleCli("listproposal", "mine accepted")
+ HelpExampleCli("listproposal", "accepted")
+ HelpExampleRpc("listproposal", "")
);
Expand All @@ -3729,24 +3730,24 @@ UniValue listproposals(const UniValue& params, bool fHelp)
bool showExpired = false;
bool showPending = false;
bool showMine = false;
if(params.size() == 1) {
if(params[0].get_str() == "accepted") {
for(unsigned int i = 0; i < params.size(); i++) {
if(params[i].get_str() == "accepted") {
showAccepted = true;
showAll = false;
}
if(params[0].get_str() == "rejected") {
else if(params[i].get_str() == "rejected") {
showRejected = true;
showAll = false;
}
if(params[0].get_str() == "expired") {
else if(params[i].get_str() == "expired") {
showAll = false;
showExpired = true;
}
if(params[0].get_str() == "pending") {
else if(params[i].get_str() == "pending") {
showAll = false;
showPending = true;
}
if(params[0].get_str() == "mine") {
else if(params[i].get_str() == "mine") {
showAll = false;
showMine = true;
}
Expand All @@ -3762,27 +3763,25 @@ UniValue listproposals(const UniValue& params, bool fHelp)
if (!pcoinsTip->GetProposal(it->first, proposal))
continue;

flags fLastState = proposal.GetLastState();
flags fLastState = proposal.fState;

bool fIsMine = false;

if (showMine)
{
CTxDestination address(CNavCoinAddress(proposal.Address));
CTxDestination address(CNavCoinAddress(proposal.Address).Get());
isminefilter mine = IsMine(*pwalletMain, address);
if(mine & ISMINE_SPENDABLE)
fIsMine = true;
}


if((showAll && (!proposal.IsExpired(pindexBestHeader->GetBlockTime())
|| fLastState == CFund::PENDING_VOTING_PREQ
|| fLastState == CFund::PENDING_FUNDS))
if(showAll
|| (showMine && fIsMine)
|| (showPending && (fLastState == CFund::NIL || fLastState == CFund::PENDING_VOTING_PREQ
|| fLastState == CFund::PENDING_FUNDS))
|| (showAccepted && (fLastState == CFund::ACCEPTED || proposal.IsAccepted()))
|| (showRejected && (fLastState == CFund::REJECTED || proposal.IsRejected()))
|| (showAccepted && (fLastState == CFund::ACCEPTED))
|| (showRejected && (fLastState == CFund::REJECTED))
|| (showExpired && proposal.IsExpired(pindexBestHeader->GetBlockTime()))) {
UniValue o(UniValue::VOBJ);
proposal.ToJson(o, *pcoinsTip);
Expand Down

0 comments on commit 6c7c471

Please sign in to comment.