From 59fbfbcae7e42f3354a50b74524c6907e3eeea21 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 16 Apr 2019 00:19:10 +0500 Subject: [PATCH] pricesinfo height opt --- src/cc/prices.cpp | 13 +++++++++++++ src/wallet/rpcwallet.cpp | 10 ++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index dfed22378..486d97f8c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -397,6 +397,11 @@ int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t { int64_t price, profits = 0; + if (height < firstheight) { + fprintf(stderr, "requested height is lower than bet firstheight.%d\n", height); + return 0; + } + int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // if we are within 24h then use min or max value if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0) @@ -768,6 +773,14 @@ 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) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "incorrect height")); + return(result); + } + if (refheight == 0) + refheight = komodo_nextheight()-1; + costbasis = prices_costbasis(bettx); addedbets = prices_batontxid(batontxid, bettx, bettxid); if ((profits = prices_syntheticprofits(false, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 05283c0b9..8d6af20c2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6931,13 +6931,15 @@ UniValue priceslist(const UniValue& params, bool fHelp) UniValue pricesinfo(const UniValue& params, bool fHelp) { uint256 bettxid; int32_t height; - if ( fHelp || params.size() != 2 ) - throw runtime_error("pricesinfo fundingtxid height\n"); + if ( fHelp || params.size() != 1 && params.size() != 2) + throw runtime_error("pricesinfo fundingtxid [height]\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"); bettxid = Parseuint256((char *)params[0].get_str().c_str()); - height = atoi(params[1].get_str().c_str()); - return(PricesInfo(bettxid,height)); + height = 0; + if (params.size() == 2) + height = atoi(params[1].get_str().c_str()); + return(PricesInfo(bettxid, height)); } UniValue dicefund(const UniValue& params, bool fHelp)