Browse Source

added all|open|close opt param to priceslist, mypriceslist

z_createrawtransaction
dimxy 5 years ago
parent
commit
c19d636d7d
  1. 2
      src/cc/CCPrices.h
  2. 21
      src/cc/prices.cpp
  3. 32
      src/wallet/rpcwallet.cpp

2
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

21
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<std::pair<CAddressIndexKey, CAmount> > 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());
}
}
}

32
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)

Loading…
Cancel
Save