From c19d636d7d5a0091e66354262bd75afc89c1beff Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 13:18:32 +0500 Subject: [PATCH] added all|open|close opt param to priceslist, mypriceslist --- src/cc/CCPrices.h | 2 +- src/cc/prices.cpp | 21 ++++++++++++++++++--- src/wallet/rpcwallet.cpp | 32 +++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index c7f3961d5..900ee7505 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -46,7 +46,7 @@ UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid); UniValue PricesRekt(int64_t txfee,uint256 bettxid,int32_t rektheight); UniValue PricesCashout(int64_t txfee,uint256 bettxid); UniValue PricesInfo(uint256 bettxid,int32_t refheight); -UniValue PricesList(CPubKey mypk); +UniValue PricesList(uint32_t filter, CPubKey mypk); #endif diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 425b125c1..06e64b739 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1054,7 +1054,8 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - if (refheight > 0 && refheight < firstheight) { + // check acceptable refheight: + if (refheight < 0 || refheight > 0 && refheight < firstheight) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "incorrect height")); return(result); @@ -1113,7 +1114,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) return(result); } -UniValue PricesList(CPubKey mypk) +UniValue PricesList(uint32_t filter, CPubKey mypk) { UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp, C; @@ -1133,7 +1134,21 @@ UniValue PricesList(CPubKey mypk) if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size() - 1].scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B' && (mypk == CPubKey() || mypk == pk)) // if only mypubkey to list { - result.push_back(txid.GetHex()); + bool bAppend = false; + if (filter == 0) + bAppend = true; + else { + int32_t vini; + int32_t height; + uint256 finaltxid; + + int32_t spent = CCgetspenttxid(finaltxid, vini, height, txid, 2); + if (filter == 1 && spent < 0 || + filter == 2 && spent == 0) + bAppend = true; + } + if (bAppend) + result.push_back(txid.GetHex()); } } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8c6e4530f..a25c879e2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6919,24 +6919,46 @@ UniValue faucetget(const UniValue& params, bool fHelp) return(result); } +uint32_t pricesGetParam(UniValue param) { + uint32_t filter = 0; + if (strcmpi(param.get_str().c_str(), "all") == 0) + filter = 0; + if (strcmpi(param.get_str().c_str(), "open") == 0) + filter = 1; + if (strcmpi(param.get_str().c_str(), "closed") == 0) + filter = 2; + else + throw runtime_error("incorrect parameter\n"); +} + UniValue priceslist(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() > 0 ) - throw runtime_error("priceslist\n"); + if ( fHelp || params.size() != 0 || params.size() != 1) + throw runtime_error("priceslist [all|open|closed]\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + uint32_t filter = 0; + if (params.size() == 1) + filter = pricesGetParam(params[0]); + CPubKey emptypk; - return(PricesList(emptypk)); + + return(PricesList(filter, emptypk)); } UniValue mypriceslist(const UniValue& params, bool fHelp) { if (fHelp || params.size() > 0) - throw runtime_error("priceslist\n"); + throw runtime_error("mypriceslist [all|open|closed]\n"); if (ensure_CCrequirements(EVAL_PRICES) < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + uint32_t filter = 0; + if (params.size() == 1) + filter = pricesGetParam(params[0]); CPubKey mypk = pubkey2pk(Mypubkey()); - return(PricesList(mypk)); + + return(PricesList(filter, mypk)); } UniValue pricesinfo(const UniValue& params, bool fHelp)