From 027f460bae0045d6bd0ad4b835be63011f5e3de8 Mon Sep 17 00:00:00 2001 From: miketout Date: Tue, 25 Jun 2024 20:18:57 -0700 Subject: [PATCH 01/14] Add volume pairs for getcurrency state, misc. --- src/init.cpp | 1 + src/miner.cpp | 4 +- src/pbaas/reserves.cpp | 1 - src/rpc/misc.cpp | 22 ++- src/rpc/pbaasrpc.cpp | 321 ++++++++++++++++++++++++++++++++++------- 5 files changed, 283 insertions(+), 66 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 99147aaa1b0..2827e4069a6 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1362,6 +1362,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // initialization, and this is the first time we can get it. store the Sapling address here extern boost::optional defaultSaplingDest; VERUS_DEFAULT_ZADDR = GetArg("-cheatcatcher", ""); + VERUS_DEFAULT_ZADDR = GetArg("-stakeguard", VERUS_DEFAULT_ZADDR); // TODO: should separate stakeguard/cheatcatcher from the default change address VERUS_DEFAULT_ZADDR = GetArg("-defaultzaddr", VERUS_DEFAULT_ZADDR); libzcash::PaymentAddress addr = DecodePaymentAddress(VERUS_DEFAULT_ZADDR); if (VERUS_DEFAULT_ZADDR.size() > 0 && IsValidPaymentAddress(addr)) diff --git a/src/miner.cpp b/src/miner.cpp index bd074332255..b30724784e1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -4483,7 +4483,7 @@ void static BitcoinMiner_noeq() bool tryAgain = true; int retryCount = 0; - while (tryAgain && retryCount++ < 2) + while (tryAgain && retryCount++ < 5) { tryAgain = false; params.push_back(EncodeHexBlk(*pblock)); @@ -4495,8 +4495,8 @@ void static BitcoinMiner_noeq() { ConnectedChains.lastSubmissionFailed = false; params = RPCCallRoot("addmergedblock", params); - params = find_value(params, "result"); error = find_value(params, "error"); + params = find_value(params, "result"); } catch (std::exception e) { LogPrintf("Failed to connect to %s chain\n", ConnectedChains.FirstNotaryChain().chainDefinition.name.c_str()); diff --git a/src/pbaas/reserves.cpp b/src/pbaas/reserves.cpp index dae9663ea24..c5583161163 100644 --- a/src/pbaas/reserves.cpp +++ b/src/pbaas/reserves.cpp @@ -2789,7 +2789,6 @@ CReserveTransactionDescriptor::CReserveTransactionDescriptor(const CTransaction { if (p.evalCode == EVAL_IDENTITY_ADVANCEDRESERVATION && identity.name == anr.name && identity.parent == anr.parent) { - // TDOD: HARDENING potentially finish validating the fees according to the currency flags |= IS_IDENTITY_DEFINITION + IS_HIGH_FEE; reservationValid = advancedReservationValid = true; } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 5f5793fe986..3fe9fefbd20 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -107,9 +107,12 @@ UniValue getinfo(const UniValue& params, bool fHelp) proxyType proxy; GetProxy(NET_IPV4, proxy); - notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); + + //notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); //fprintf(stderr,"after notarized_height %u\n",(uint32_t)time(NULL)); + CProofRoot confirmedRoot = ConnectedChains.FinalizedChainRoot(); + UniValue obj(UniValue::VOBJ); obj.push_back(Pair("VRSCversion", VERUS_VERSION)); obj.push_back(Pair("version", CLIENT_VERSION)); @@ -120,18 +123,11 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("notarychainid", EncodeDestination(CIdentityID(ConnectedChains.FirstNotaryChain().GetID())))); } obj.push_back(Pair("name", ConnectedChains.GetFriendlyCurrencyName(ASSETCHAINS_CHAINID))); - obj.push_back(Pair("notarized", notarized_height)); - obj.push_back(Pair("prevMoMheight", prevMoMheight)); - obj.push_back(Pair("notarizedhash", notarized_hash.ToString())); - obj.push_back(Pair("notarizedtxid", notarized_desttxid.ToString())); - txid_height = notarizedtxid_height(ASSETCHAINS_SYMBOL[0] != 0 ? (char *)"KMD" : (char *)"BTC",(char *)notarized_desttxid.ToString().c_str(),&kmdnotarized_height); - if ( txid_height > 0 ) - obj.push_back(Pair("notarizedtxid_height", txid_height)); - else obj.push_back(Pair("notarizedtxid_height", "mempool")); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - obj.push_back(Pair("KMDnotarized_height", kmdnotarized_height)); - obj.push_back(Pair("notarized_confirms", txid_height < kmdnotarized_height ? (kmdnotarized_height - txid_height + 1) : 0)); - //fprintf(stderr,"after notarized_confirms %u\n",(uint32_t)time(NULL)); + if (confirmedRoot.IsValid()) + { + obj.push_back(Pair("notarizedroot", confirmedRoot.ToUniValue())); + } + #ifdef ENABLE_WALLET if (pwalletMain) { obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index f7c35698b3e..15efc35eea8 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -11558,19 +11558,73 @@ UniValue getinitialcurrencystate(const UniValue& params, bool fHelp) return ConnectedChains.GetCurrencyState(chainDef.GetID(), chainDef.startBlock - 1, true).ToUniValue(); } +size_t GetImports(const uint160 ¤cyID, uint32_t fromHeight, uint32_t toHeight, std::map, std::tuple>> &importMap) +{ + // which transaction are we in this block? + std::vector> addressIndex; + uint160 searchKey = CCrossChainRPCData::GetConditionID(currencyID, CCrossChainImport::CurrencyImportKey()); + CBlockIndex *pIndex; + CChainNotarizationData cnd; + + size_t initialSize = importMap.size(); + + // get all import transactions including and since this one up to the confirmed height + if (GetAddressIndex(searchKey, CScript::P2IDX, addressIndex, fromHeight, toHeight)) + { + for (auto &idx : addressIndex) + { + uint256 blkHash; + CTransaction importTx; + if (!idx.first.spending && myGetTransaction(idx.first.txhash, importTx, blkHash)) + { + CCrossChainExport ccx; + CCrossChainImport cci; + int32_t sysCCIOut; + CPBaaSNotarization importNotarization; + int32_t importNotOut; + int32_t evidenceOutStart, evidenceOutEnd; + std::vector reserveTransfers; + uint32_t importHeight = 0; + + auto importBlockIdxIt = mapBlockIndex.find(blkHash); + if (importBlockIdxIt != mapBlockIndex.end() && chainActive.Contains(importBlockIdxIt->second)) + { + importHeight = importBlockIdxIt->second->GetHeight(); + } + else + { + continue; + } + + /* UniValue scrOut(UniValue::VOBJ); + ScriptPubKeyToUniv(importTx.vout[idx.first.index].scriptPubKey, scrOut, false); + printf("%s: scriptOut: %s\n", __func__, scrOut.write(1,2).c_str()); */ + + CCrossChainImport sysCCI; + if ((cci = CCrossChainImport(importTx.vout[idx.first.index].scriptPubKey)).IsValid() && + cci.GetImportInfo(importTx, importHeight, idx.first.index, ccx, sysCCI, sysCCIOut, importNotarization, importNotOut, evidenceOutStart, evidenceOutEnd, reserveTransfers)) + { + importMap[{idx.first.blockHeight, importHeight}] = {importTx, (int)idx.first.index, cci, importNotarization, reserveTransfers}; + } + } + } + } + return importMap.size() - initialSize; +} + UniValue getcurrencystate(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 3) { throw runtime_error( - "getcurrencystate \"currencynameorid\" (\"n\") (\"connectedsystemid\")\n" + "getcurrencystate \"currencynameorid\" (\"n\") (\"conversiondatacurrency\")\n" "\nReturns the currency state(s) on the blockchain for any specified currency, either with all changes on this chain or relative to another system.\n" "\nArguments\n" " \"currencynameorid\" (string) name or i-address of currency in question" " \"n\" or \"m,n\" or \"m,n,o\" (int or string, optional) height or inclusive range with optional step at which to get the currency state\n" " If not specified, the latest currency state and height is returned\n" - " (\"connectedchainid\") (string) optional\n" + " \"conversiondatacurrency\" (string) optional - if present, market data with prices expressed in given currency are returned\n" "\nResult:\n" " [\n" @@ -11585,7 +11639,31 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) " \"supply\" : n,\n" " \"reserve\" : n,\n" " \"currentratio\" : n,\n" - " \"}\n" + " }\n" + " \"conversiondata\": {\n" + " \"reserve1_basketcurrency\" : {\n" + " \"volume\":n,\n" + " \"open\":n,\n" + " \"high\":n,\n" + " \"low\":n,\n" + " \"close\":n,\n" + " },\n" + " \"reserve1_reserve2\" : {\n" + " ...\n" + " },\n" + " \"reserve1_reserve3\" : {\n" + " ...\n" + " },\n" + " \"reserve2_basketcurrency\" : {\n" + " ...\n" + " },\n" + " \"reserve2_reserve3\" : {\n" + " ...\n" + " },\n" + " \"reserve3_basketcurrency\" : {\n" + " ...\n" + " },\n" + " }\n" " },\n" " ]\n" @@ -11599,82 +11677,225 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) CCurrencyDefinition currencyToCheck; std::string currencyStr = uni_get_str(params[0]); - if (currencyStr.empty() || ValidateCurrencyName(currencyStr, true, ¤cyToCheck).IsNull()) - { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid currency specified"); - } - uint160 currencyID = currencyToCheck.GetID(); - - LOCK(cs_main); + uint160 currencyID; uint64_t lStart; uint64_t startEnd[3] = {0}; + uint32_t start = 0, end = 0, step = 0; - lStart = startEnd[1] = startEnd[0] = chainActive.LastTip() ? chainActive.LastTip()->GetHeight() : 1; + // if we're supposed to get market data + uint160 volumePriceCurrencyID; + CCurrencyDefinition volumePriceCurrency; + std::map, std::tuple>> importMap; - if (params.size() > 1) { - if (params[1].isStr()) + LOCK2(cs_main, mempool.cs); + + if (currencyStr.empty() || (currencyID = ValidateCurrencyName(currencyStr, true, ¤cyToCheck)).IsNull()) { - std::vector retNames; - boost::split(retNames, uni_get_str(params[1]), boost::is_any_of(",")); - Split(params[1].get_str(), startEnd, startEnd[0], 3); - if (retNames.size() == 2) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid currency specified"); + } + + lStart = startEnd[1] = startEnd[0] = chainActive.LastTip() ? chainActive.LastTip()->GetHeight() : 1; + + if (params.size() > 1) + { + if (params[1].isStr()) { - int64_t step = 1; - int64_t delta = startEnd[1] - startEnd[0]; - while ((delta / step) > 100) + std::vector retNames; + boost::split(retNames, uni_get_str(params[1]), boost::is_any_of(",")); + Split(params[1].get_str(), startEnd, startEnd[0], 3); + if (retNames.size() == 2) { - step *= 10; + int64_t step = 1; + int64_t delta = startEnd[1] - startEnd[0]; + while ((delta / step) > 100) + { + step *= 10; + } + // default to step 1 + startEnd[2] = step; } - // default to step 1 - startEnd[2] = step; + } + else if (uni_get_int(params[1], -1) != -1) + { + lStart = startEnd[1] = startEnd[0] = uni_get_int(params[1], lStart); } } - else if (uni_get_int(params[1], -1) != -1) + + if (startEnd[0] > startEnd[1]) { - lStart = startEnd[1] = startEnd[0] = uni_get_int(params[1], lStart); + startEnd[0] = startEnd[1]; } - } - if (startEnd[0] > startEnd[1]) - { - startEnd[0] = startEnd[1]; - } + if (startEnd[1] > lStart) + { + startEnd[1] = lStart; + } - if (startEnd[1] > lStart) - { - startEnd[1] = lStart; - } + if (startEnd[1] < startEnd[0]) + { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block range for currency state"); + } - if (startEnd[1] < startEnd[0]) - { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block range for currency state"); - } + if (startEnd[2] == 0) + { + startEnd[2] = 1; + } - if (startEnd[2] == 0) - { - startEnd[2] = 1; - } + if (startEnd[2] > INT_MAX) + { + startEnd[2] = INT_MAX; + } - if (startEnd[2] > INT_MAX) - { - startEnd[2] = INT_MAX; - } + start = startEnd[0]; + end = startEnd[1]; + step = startEnd[2]; - uint32_t start = startEnd[0], end = startEnd[1], step = startEnd[2]; + if (params.size() > 2 && currencyToCheck.IsFractional()) + { + if (currencyToCheck.systemID != ASSETCHAINS_CHAINID) + { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Can only return conversion data for currencies with a systemID of the current chain."); + } + // get currency parameter + volumePriceCurrencyID = ValidateCurrencyName(uni_get_str(params[2]), true, &volumePriceCurrency); + + // ensure it is a reserve or the basket currency name + if (volumePriceCurrencyID != currencyID && + !currencyToCheck.GetCurrenciesMap().count(volumePriceCurrencyID)) + { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Volume and pricing must be calculated in a reserve or the basket currency itself. " + uni_get_str(params[2]) + " is neither."); + } + + // get all imports + GetImports(currencyID, start, end, importMap); + } + } UniValue ret(UniValue::VARR); + // currencySource, currencyDest, volume in volume/price currency, starting price, highest during period, lowest during period, final price (all prices in volume/price currency) + std::map,std::tuple> pairVolumePrice; + CAmount totalVolumeInVolumeCurrency = 0; + for (int i = start; i <= end; i += step) { - LOCK(cs_main); - CCoinbaseCurrencyState currencyState = ConnectedChains.GetCurrencyState(currencyID, i, (i + step) > end); + pairVolumePrice.clear(); + + int queryEnd = (i + step) > end ? end : i + step; + auto importIt = importMap.lower_bound({i, 0}); + auto importNextIt = importIt == importMap.end() ? importMap.end() : importMap.upper_bound({queryEnd, 0}); + auto it = importIt; + CCoinbaseCurrencyState currencyState; + if (importIt != importMap.end() && it != importNextIt) + { + // if we have imports, calculate aggregated volumes, pair volumes, and OHLC in specified currency + // last import has final currency state for this interval + for (; it != importNextIt; it++) + { + currencyState = std::get<3>(it->second).currencyState; + + // get volume and price conversion rates + CCurrencyValueMap prices(currencyState.currencies, currencyState.conversionPrice); + CCurrencyValueMap viaPrices(currencyState.currencies, currencyState.viaConversionPrice); + prices.valueMap[currencyID] = volumePriceCurrencyID == currencyID ? SATOSHIDEN : currencyState.ReserveToNativeRaw(SATOSHIDEN, prices.valueMap[volumePriceCurrencyID]); + viaPrices.valueMap[currencyID] = volumePriceCurrencyID == currencyID ? SATOSHIDEN : currencyState.ReserveToNativeRaw(SATOSHIDEN, viaPrices.valueMap[volumePriceCurrencyID]); + CCurrencyValueMap conversionRates(currencyState.TargetConversionPrices(volumePriceCurrencyID, prices, viaPrices)); + + for (auto &oneRT : std::get<4>(it->second)) + { + if (oneRT.IsConversion()) + { + uint160 sourceCur = oneRT.FirstCurrency(); + uint160 destCur = oneRT.IsReserveToReserve() ? oneRT.secondReserveID : oneRT.destCurrencyID; + + CCurrencyValueMap currentRates(volumePriceCurrencyID == destCur ? conversionRates : currencyState.TargetConversionPrices(destCur, prices, viaPrices)); + + CCurrencyValueMap conversionFee = oneRT.ConversionFee(); + totalVolumeInVolumeCurrency += currencyState.ReserveToNativeRaw(oneRT.FirstValue() - conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); + + std::get<0>(pairVolumePrice[{sourceCur,destCur}]) += currencyState.ReserveToNativeRaw(oneRT.FirstValue() - conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); + + // save open, high, low, close + if (std::get<1>(pairVolumePrice[{sourceCur,destCur}]) == 0) + { + std::get<1>(pairVolumePrice[{sourceCur,destCur}]) = currentRates.valueMap[sourceCur]; + } + std::get<2>(pairVolumePrice[{sourceCur,destCur}]) = std::max(std::get<2>(pairVolumePrice[{sourceCur,destCur}]), currentRates.valueMap[sourceCur]); + if (std::get<3>(pairVolumePrice[{sourceCur,destCur}]) == 0) + { + std::get<3>(pairVolumePrice[{sourceCur,destCur}]) = currentRates.valueMap[sourceCur]; + } + else + { + std::get<3>(pairVolumePrice[{sourceCur,destCur}]) = std::min(std::get<3>(pairVolumePrice[{sourceCur,destCur}]), currentRates.valueMap[sourceCur]); + } + std::get<4>(pairVolumePrice[{sourceCur,destCur}]) = currentRates.valueMap[sourceCur]; + + // conversion fee is converted to native currency, unless source is already native + if (sourceCur != ASSETCHAINS_CHAINID) + { + totalVolumeInVolumeCurrency += currencyState.ReserveToNativeRaw(conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); + + CCurrencyValueMap feeRates(volumePriceCurrencyID == ASSETCHAINS_CHAINID ? conversionRates : (destCur == ASSETCHAINS_CHAINID ? currentRates : currencyState.TargetConversionPrices(ASSETCHAINS_CHAINID, prices, viaPrices))); + + std::get<0>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]) += currencyState.ReserveToNativeRaw(conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); + + // save open, high, low, close for fees, in case it isn't there + if (std::get<1>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]) == 0) + { + std::get<1>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]) = feeRates.valueMap[sourceCur]; + } + std::get<2>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]) = std::max(std::get<2>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]), feeRates.valueMap[sourceCur]); + if (std::get<3>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]) == 0) + { + std::get<3>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]) = feeRates.valueMap[sourceCur]; + } + else + { + std::get<3>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]) = std::min(std::get<3>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]), feeRates.valueMap[sourceCur]); + } + std::get<4>(pairVolumePrice[{sourceCur,ASSETCHAINS_CHAINID}]) = feeRates.valueMap[sourceCur]; + } + } + } + } + } + else + { + LOCK(cs_main); + currencyState = ConnectedChains.GetCurrencyState(currencyID, i, (i + step) > end); + } UniValue entry(UniValue::VOBJ); entry.push_back(Pair("height", i)); entry.push_back(Pair("blocktime", (uint64_t)chainActive.LastTip()->nTime)); - CAmount price; entry.push_back(Pair("currencystate", currencyState.ToUniValue())); + + if (pairVolumePrice.size()) + { + UniValue conversionData(UniValue::VOBJ); + UniValue pairArray(UniValue::VARR); + + conversionData.pushKV("pricingcurrency", ConnectedChains.GetFriendlyCurrencyName(volumePriceCurrencyID)); + + // output conversions as source, destination, volume, open, high, low, close + for (auto &oneVolPrice : pairVolumePrice) + { + UniValue onePairEntry(UniValue::VOBJ); + onePairEntry.pushKV("currency", ConnectedChains.GetFriendlyCurrencyName(oneVolPrice.first.first)); + onePairEntry.pushKV("convertto", ConnectedChains.GetFriendlyCurrencyName(oneVolPrice.first.second)); + onePairEntry.pushKV("volume", ValueFromAmount(std::get<0>(oneVolPrice.second))); + onePairEntry.pushKV("open", ValueFromAmount(std::get<1>(oneVolPrice.second))); + onePairEntry.pushKV("high", ValueFromAmount(std::get<2>(oneVolPrice.second))); + onePairEntry.pushKV("low", ValueFromAmount(std::get<3>(oneVolPrice.second))); + onePairEntry.pushKV("close", ValueFromAmount(std::get<4>(oneVolPrice.second))); + pairArray.push_back(onePairEntry); + } + conversionData.pushKV("volumepairs", pairArray); + entry.pushKV("conversiondata",conversionData); + } + ret.push_back(entry); } return ret; From 1a6220481c0c9d240a81dee9d795c35f53eb7404 Mon Sep 17 00:00:00 2001 From: miketout Date: Tue, 25 Jun 2024 20:21:31 -0700 Subject: [PATCH 02/14] Rename "pricingcurrency" to "volumecurrency" --- src/rpc/pbaasrpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index 15efc35eea8..df2b590f577 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -11877,7 +11877,7 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) UniValue conversionData(UniValue::VOBJ); UniValue pairArray(UniValue::VARR); - conversionData.pushKV("pricingcurrency", ConnectedChains.GetFriendlyCurrencyName(volumePriceCurrencyID)); + conversionData.pushKV("volumecurrency", ConnectedChains.GetFriendlyCurrencyName(volumePriceCurrencyID)); // output conversions as source, destination, volume, open, high, low, close for (auto &oneVolPrice : pairVolumePrice) From eef8243b4458b8111f0a3c5ef473dc9127241f92 Mon Sep 17 00:00:00 2001 From: miketout Date: Tue, 25 Jun 2024 20:30:00 -0700 Subject: [PATCH 03/14] Add total volume output to getcurrencystate --- src/rpc/pbaasrpc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index df2b590f577..48e52bca422 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -11878,6 +11878,7 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) UniValue pairArray(UniValue::VARR); conversionData.pushKV("volumecurrency", ConnectedChains.GetFriendlyCurrencyName(volumePriceCurrencyID)); + conversionData.pushKV("totalvolume", totalVolumeInVolumeCurrency); // output conversions as source, destination, volume, open, high, low, close for (auto &oneVolPrice : pairVolumePrice) From 03d9125cc675153eae0147f44ab28256cd95251b Mon Sep 17 00:00:00 2001 From: Asher Dawes Date: Tue, 25 Jun 2024 20:49:51 -0700 Subject: [PATCH 04/14] set deprecation height --- src/deprecation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deprecation.h b/src/deprecation.h index db468ece5cf..a2157b011e5 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -9,7 +9,7 @@ // * Shut down 52 weeks' worth of blocks after the estimated release block height. // * A warning is shown during the 2 months' worth of blocks prior to shut down. -static const int APPROX_RELEASE_HEIGHT = 3090000; +static const int APPROX_RELEASE_HEIGHT = 3108000; static const int WEEKS_UNTIL_DEPRECATION = 52; static const int DEPRECATION_HEIGHT = APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 60 * 24); From a3da4fc1bcfbb276b5fc63da15d6a182406ccaad Mon Sep 17 00:00:00 2001 From: Asher Dawes Date: Tue, 25 Jun 2024 20:50:48 -0700 Subject: [PATCH 05/14] set version --- .gitlab-ci.yml | 2 +- README.md | 2 +- doc/man/verus-cli/linux/README.txt | 2 +- doc/man/verus-cli/mac/README.txt | 2 +- doc/man/verus-cli/windows/README.txt | 2 +- src/version.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ff8cbafc3a3..d0eced3eb41 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,7 @@ stages: ######################################################################################################################## variables: - VERSION: 1.2.3-2 + VERSION: 1.2.3-3 VERUS_CLI_ARM64_LINUX: Verus-CLI-Linux-v${VERSION}-arm64.tar.gz VERUS_CLI_LINUX_X86_64: Verus-CLI-Linux-v${VERSION}-x86_64.tar.gz diff --git a/README.md b/README.md index e513f20feda..fd03927b52b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -## VerusCoin version 1.2.3-2 +## VerusCoin version 1.2.3-3 Arguably the world's most advanced technology, zero knowledge privacy enabled, multi-chain blockchain protocol, Verus Public Blockchains as a Service (PBaaS) combines Sapling zero knowledge technology with an intelligent, multi-chain, provable protocol, using interchain smart transactions. Verus PBaaS also enables merge mining and cross-chain staking with a completely original, combined proof of stake/proof of work consensus algorithm, Proof of Power, that can be mined on CPUs and mobile phones, and also solves the nothing at stake problem. With this and its approach towards CPU mining and ASICs, Verus Coin strives to be one of the most naturally decentralizing and attack resistant blockchain networks in existence. diff --git a/doc/man/verus-cli/linux/README.txt b/doc/man/verus-cli/linux/README.txt index 22d27d87e2b..542de30bc28 100644 --- a/doc/man/verus-cli/linux/README.txt +++ b/doc/man/verus-cli/linux/README.txt @@ -1,5 +1,5 @@ -VerusCoin Command Line Tools v1.2.3-2 +VerusCoin Command Line Tools v1.2.3-3 Contents: verusd - VerusCoin daemon diff --git a/doc/man/verus-cli/mac/README.txt b/doc/man/verus-cli/mac/README.txt index d497af0d226..8d594b6d28e 100644 --- a/doc/man/verus-cli/mac/README.txt +++ b/doc/man/verus-cli/mac/README.txt @@ -1,5 +1,5 @@ -VerusCoin Command Line Tools v1.2.3-2 +VerusCoin Command Line Tools v1.2.3-3 Contents: verusd - VerusCoin daemon. diff --git a/doc/man/verus-cli/windows/README.txt b/doc/man/verus-cli/windows/README.txt index 664be3d4417..5016ac2ea16 100644 --- a/doc/man/verus-cli/windows/README.txt +++ b/doc/man/verus-cli/windows/README.txt @@ -1,5 +1,5 @@ -VerusCoin Command Line Tools v1.2.3-2 +VerusCoin Command Line Tools v1.2.3-3 Contents: verusd.exe - VerusCoin daemon diff --git a/src/version.h b/src/version.h index 2a88651c637..1c5cbdb9e42 100644 --- a/src/version.h +++ b/src/version.h @@ -36,6 +36,6 @@ static const int MEMPOOL_GD_VERSION = 60002; static const int NO_BLOOM_VERSION = 170004; #define KOMODO_VERSION "0.2.1" -#define VERUS_VERSION "1.2.3-2" +#define VERUS_VERSION "1.2.3-3" #endif // BITCOIN_VERSION_H From 9ee05ce94e82007d3b033a9a7f6da69dcb53a85c Mon Sep 17 00:00:00 2001 From: miketout Date: Tue, 25 Jun 2024 21:01:44 -0700 Subject: [PATCH 06/14] Display volume as value vs. amount --- src/rpc/pbaasrpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index 48e52bca422..738b7c6d589 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -11878,7 +11878,7 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) UniValue pairArray(UniValue::VARR); conversionData.pushKV("volumecurrency", ConnectedChains.GetFriendlyCurrencyName(volumePriceCurrencyID)); - conversionData.pushKV("totalvolume", totalVolumeInVolumeCurrency); + conversionData.pushKV("totalvolume", ValueFromAmount(totalVolumeInVolumeCurrency)); // output conversions as source, destination, volume, open, high, low, close for (auto &oneVolPrice : pairVolumePrice) From f6101aafd9cbc2c62dbc2a9c35a846f08c724bb9 Mon Sep 17 00:00:00 2001 From: miketout Date: Tue, 25 Jun 2024 22:17:41 -0700 Subject: [PATCH 07/14] Group volume into matching currency state --- src/rpc/pbaasrpc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index 738b7c6d589..6e21716476a 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -11783,9 +11783,9 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) { pairVolumePrice.clear(); - int queryEnd = (i + step) > end ? end : i + step; - auto importIt = importMap.lower_bound({i, 0}); - auto importNextIt = importIt == importMap.end() ? importMap.end() : importMap.upper_bound({queryEnd, 0}); + int queryStart = i == start ? i : i - (step - 1); + auto importIt = importMap.lower_bound({queryStart, 0}); + auto importNextIt = importIt == importMap.end() ? importMap.end() : importMap.upper_bound({i, 0}); auto it = importIt; CCoinbaseCurrencyState currencyState; if (importIt != importMap.end() && it != importNextIt) From 1ce560763137f51d2461906fdc6f931e0c81265b Mon Sep 17 00:00:00 2001 From: miketout Date: Wed, 26 Jun 2024 17:01:54 -0700 Subject: [PATCH 08/14] Volume calculation fix --- src/pbaas/reserves.cpp | 2 +- src/rpc/pbaasrpc.cpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pbaas/reserves.cpp b/src/pbaas/reserves.cpp index c5583161163..3296ae9f617 100644 --- a/src/pbaas/reserves.cpp +++ b/src/pbaas/reserves.cpp @@ -863,7 +863,7 @@ CCurrencyValueMap CCoinbaseCurrencyState::TargetConversionPrices(const uint160 & } else { - retVal.valueMap[GetID()] = NativeToReserveRaw(SATOSHIDEN, prices.valueMap.find(targetCurrencyID)->second); + retVal.valueMap[GetID()] = ReserveToNativeRaw(SATOSHIDEN, prices.valueMap.find(targetCurrencyID)->second); for (auto &oneCur : currencies) { diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index 6e21716476a..92c84dd5bd2 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -11624,7 +11624,7 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) " \"currencynameorid\" (string) name or i-address of currency in question" " \"n\" or \"m,n\" or \"m,n,o\" (int or string, optional) height or inclusive range with optional step at which to get the currency state\n" " If not specified, the latest currency state and height is returned\n" - " \"conversiondatacurrency\" (string) optional - if present, market data with prices expressed in given currency are returned\n" + " \"conversiondatacurrency\" (string) optional - if present, market data with volumes in given currency are returned\n" "\nResult:\n" " [\n" @@ -11799,8 +11799,6 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) // get volume and price conversion rates CCurrencyValueMap prices(currencyState.currencies, currencyState.conversionPrice); CCurrencyValueMap viaPrices(currencyState.currencies, currencyState.viaConversionPrice); - prices.valueMap[currencyID] = volumePriceCurrencyID == currencyID ? SATOSHIDEN : currencyState.ReserveToNativeRaw(SATOSHIDEN, prices.valueMap[volumePriceCurrencyID]); - viaPrices.valueMap[currencyID] = volumePriceCurrencyID == currencyID ? SATOSHIDEN : currencyState.ReserveToNativeRaw(SATOSHIDEN, viaPrices.valueMap[volumePriceCurrencyID]); CCurrencyValueMap conversionRates(currencyState.TargetConversionPrices(volumePriceCurrencyID, prices, viaPrices)); for (auto &oneRT : std::get<4>(it->second)) From ffc3f21db3d338e1ac91c90600e12cedae9488fd Mon Sep 17 00:00:00 2001 From: miketout Date: Wed, 26 Jun 2024 22:31:38 -0700 Subject: [PATCH 09/14] Volume output improvements --- src/rpc/pbaasrpc.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index 92c84dd5bd2..986e858d6fc 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -11778,10 +11778,12 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) // currencySource, currencyDest, volume in volume/price currency, starting price, highest during period, lowest during period, final price (all prices in volume/price currency) std::map,std::tuple> pairVolumePrice; CAmount totalVolumeInVolumeCurrency = 0; + CAmount stepVolumeInVolumeCurrency = 0; for (int i = start; i <= end; i += step) { pairVolumePrice.clear(); + stepVolumeInVolumeCurrency = 0; int queryStart = i == start ? i : i - (step - 1); auto importIt = importMap.lower_bound({queryStart, 0}); @@ -11811,9 +11813,10 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) CCurrencyValueMap currentRates(volumePriceCurrencyID == destCur ? conversionRates : currencyState.TargetConversionPrices(destCur, prices, viaPrices)); CCurrencyValueMap conversionFee = oneRT.ConversionFee(); - totalVolumeInVolumeCurrency += currencyState.ReserveToNativeRaw(oneRT.FirstValue() - conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); - - std::get<0>(pairVolumePrice[{sourceCur,destCur}]) += currencyState.ReserveToNativeRaw(oneRT.FirstValue() - conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); + CAmount thisVolume = currencyState.ReserveToNativeRaw(oneRT.FirstValue() - conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); + totalVolumeInVolumeCurrency += thisVolume; + stepVolumeInVolumeCurrency += thisVolume; + std::get<0>(pairVolumePrice[{sourceCur,destCur}]) += thisVolume; // save open, high, low, close if (std::get<1>(pairVolumePrice[{sourceCur,destCur}]) == 0) @@ -11834,7 +11837,9 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) // conversion fee is converted to native currency, unless source is already native if (sourceCur != ASSETCHAINS_CHAINID) { - totalVolumeInVolumeCurrency += currencyState.ReserveToNativeRaw(conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); + CAmount feeVolume = currencyState.ReserveToNativeRaw(conversionFee.valueMap[sourceCur], conversionRates.valueMap[sourceCur]); + totalVolumeInVolumeCurrency += feeVolume; + stepVolumeInVolumeCurrency += feeVolume; CCurrencyValueMap feeRates(volumePriceCurrencyID == ASSETCHAINS_CHAINID ? conversionRates : (destCur == ASSETCHAINS_CHAINID ? currentRates : currencyState.TargetConversionPrices(ASSETCHAINS_CHAINID, prices, viaPrices))); @@ -11876,7 +11881,7 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) UniValue pairArray(UniValue::VARR); conversionData.pushKV("volumecurrency", ConnectedChains.GetFriendlyCurrencyName(volumePriceCurrencyID)); - conversionData.pushKV("totalvolume", ValueFromAmount(totalVolumeInVolumeCurrency)); + conversionData.pushKV("volumethisinterval", ValueFromAmount(stepVolumeInVolumeCurrency)); // output conversions as source, destination, volume, open, high, low, close for (auto &oneVolPrice : pairVolumePrice) @@ -11897,6 +11902,12 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) ret.push_back(entry); } + if (totalVolumeInVolumeCurrency) + { + UniValue entry(UniValue::VOBJ); + entry.pushKV("totalvolume", ValueFromAmount(totalVolumeInVolumeCurrency)); + ret.push_back(entry); + } return ret; } From 9f6e2a0f94d64b6b5f26ac359015902d9b9b28d5 Mon Sep 17 00:00:00 2001 From: miketout Date: Thu, 27 Jun 2024 16:39:56 -0700 Subject: [PATCH 10/14] Query limiting parameters for RPC APIs --- src/init.cpp | 1 + src/rpc/pbaasrpc.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 2827e4069a6..fb623e6ba1a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -405,6 +405,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-maxconnections=", strprintf(_("Maintain at most connections to peers (default: %u)"), DEFAULT_MAX_PEER_CONNECTIONS)); strUsage += HelpMessageOpt("-maxreceivebuffer=", strprintf(_("Maximum per-connection receive buffer, *1000 bytes (default: %u)"), 5000)); strUsage += HelpMessageOpt("-maxsendbuffer=", strprintf(_("Maximum per-connection send buffer, *1000 bytes (default: %u)"), 1000)); + strUsage += HelpMessageOpt("-maximumimportrange=", strprintf(_("Maximum number of blocks for an import range query or getcurrencystate with volume, (default: unlimited)"))); strUsage += HelpMessageOpt("-onion=", strprintf(_("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: %s)"), "-proxy")); strUsage += HelpMessageOpt("-onlynet=", _("Only connect to nodes in network (ipv4, ipv6 or onion)")); strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1)); diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index 986e858d6fc..b95a3cc41a0 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -2768,6 +2768,11 @@ UniValue getimports(const UniValue& params, bool fHelp) toHeight = proofHeight; } + if ((toHeight ? toHeight : nHeight) - fromHeight > GetArg("-maximumimportrange", chainActive.Height())) + { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid range for currency state volume and rate information. Maximum range limited to " + std::to_string(GetArg("-maximportrange", chainActive.Height()))); + } + if (GetCurrencyDefinition(chainID, chainDef, &defHeight)) { // which transaction are we in this block? @@ -11782,6 +11787,7 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) for (int i = start; i <= end; i += step) { + LOCK(cs_main); pairVolumePrice.clear(); stepVolumeInVolumeCurrency = 0; @@ -11792,6 +11798,11 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) CCoinbaseCurrencyState currencyState; if (importIt != importMap.end() && it != importNextIt) { + if (end - start > GetArg("-maximumimportrange", chainActive.Height())) + { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid range for currency state volume and rate information. Maximum range limited to " + std::to_string(GetArg("-maximumimportrange", chainActive.Height()))); + } + // if we have imports, calculate aggregated volumes, pair volumes, and OHLC in specified currency // last import has final currency state for this interval for (; it != importNextIt; it++) @@ -11867,7 +11878,6 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) } else { - LOCK(cs_main); currencyState = ConnectedChains.GetCurrencyState(currencyID, i, (i + step) > end); } UniValue entry(UniValue::VOBJ); From db77603b5128ae9e08f81f213b5b0ce8b1d5d0de Mon Sep 17 00:00:00 2001 From: miketout Date: Fri, 28 Jun 2024 14:04:32 -0700 Subject: [PATCH 11/14] getimports range fix --- src/rpc/pbaasrpc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index b95a3cc41a0..0576413d675 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -2764,9 +2764,9 @@ UniValue getimports(const UniValue& params, bool fHelp) if (params.size() > 2) { toHeight = uni_get_int64(params[2]); - proofHeight = toHeight < nHeight ? toHeight : nHeight; - toHeight = proofHeight; } + proofHeight = toHeight < nHeight ? toHeight : nHeight; + toHeight = proofHeight; if ((toHeight ? toHeight : nHeight) - fromHeight > GetArg("-maximumimportrange", chainActive.Height())) { From c3fa197f8143440fd00e96c851f6e4c850469eeb Mon Sep 17 00:00:00 2001 From: miketout Date: Fri, 28 Jun 2024 14:16:47 -0700 Subject: [PATCH 12/14] Earlier import range check --- src/rpc/pbaasrpc.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index 0576413d675..11808cd5619 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -2756,6 +2756,7 @@ UniValue getimports(const UniValue& params, bool fHelp) uint32_t fromHeight = 0, toHeight = INT32_MAX; uint32_t proofHeight = 0; uint32_t nHeight = chainActive.Height(); + uint32_t maximumImportRange = GetArg("-maximumimportrange", chainActive.Height()); if (params.size() > 1) { @@ -2765,10 +2766,14 @@ UniValue getimports(const UniValue& params, bool fHelp) { toHeight = uni_get_int64(params[2]); } + else if (fromHeight == 0 && maximumImportRange < nHeight) + { + fromHeight = nHeight - maximumImportRange; + } proofHeight = toHeight < nHeight ? toHeight : nHeight; toHeight = proofHeight; - if ((toHeight ? toHeight : nHeight) - fromHeight > GetArg("-maximumimportrange", chainActive.Height())) + if ((toHeight ? toHeight : nHeight) - fromHeight > maximumImportRange) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid range for currency state volume and rate information. Maximum range limited to " + std::to_string(GetArg("-maximportrange", chainActive.Height()))); } @@ -11701,7 +11706,9 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid currency specified"); } - lStart = startEnd[1] = startEnd[0] = chainActive.LastTip() ? chainActive.LastTip()->GetHeight() : 1; + uint32_t nHeight = chainActive.Height(); + + lStart = startEnd[1] = startEnd[0] = nHeight; if (params.size() > 1) { @@ -11759,6 +11766,11 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) if (params.size() > 2 && currencyToCheck.IsFractional()) { + if (end - start > GetArg("-maximumimportrange", chainActive.Height())) + { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid range for currency state volume and rate information. Maximum range limited to " + std::to_string(GetArg("-maximumimportrange", chainActive.Height()))); + } + if (currencyToCheck.systemID != ASSETCHAINS_CHAINID) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Can only return conversion data for currencies with a systemID of the current chain."); @@ -11798,11 +11810,6 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) CCoinbaseCurrencyState currencyState; if (importIt != importMap.end() && it != importNextIt) { - if (end - start > GetArg("-maximumimportrange", chainActive.Height())) - { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid range for currency state volume and rate information. Maximum range limited to " + std::to_string(GetArg("-maximumimportrange", chainActive.Height()))); - } - // if we have imports, calculate aggregated volumes, pair volumes, and OHLC in specified currency // last import has final currency state for this interval for (; it != importNextIt; it++) From bf93804ec7eff19138b0952648f987f9c5e8ea88 Mon Sep 17 00:00:00 2001 From: miketout Date: Fri, 28 Jun 2024 16:20:37 -0700 Subject: [PATCH 13/14] Testing for pricing change --- src/pbaas/reserves.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pbaas/reserves.cpp b/src/pbaas/reserves.cpp index 3296ae9f617..8c024478845 100644 --- a/src/pbaas/reserves.cpp +++ b/src/pbaas/reserves.cpp @@ -830,7 +830,7 @@ CCurrencyValueMap CCoinbaseCurrencyState::TargetConversionPrices(const uint160 & } else { - retVal.valueMap[GetID()] = NativeToReserveRaw(SATOSHIDEN, currencyMap.valueMap[targetCurrencyID]); + retVal.valueMap[GetID()] = ReserveToNativeRaw(SATOSHIDEN, currencyMap.valueMap[targetCurrencyID]); for (auto &oneCur : currencies) { @@ -906,7 +906,7 @@ CCurrencyValueMap CCoinbaseCurrencyState::TargetLastConversionPrices(const uint1 SATOSHIDEN : NativeToReserveRaw(ReserveToNativeRaw(SATOSHIDEN, viaCurrencyMap.valueMap[targetCurrencyID]), currencyMap.valueMap[oneCur]); } - retVal.valueMap[GetID()] = NativeToReserveRaw(SATOSHIDEN, currencyMap.valueMap[targetCurrencyID]); + retVal.valueMap[GetID()] = ReserveToNativeRaw(SATOSHIDEN, currencyMap.valueMap[targetCurrencyID]); } return retVal; } From fa88350bbedf9e3580e421ae80e4ceea2f0c1fde Mon Sep 17 00:00:00 2001 From: miketout Date: Fri, 28 Jun 2024 18:22:51 -0700 Subject: [PATCH 14/14] Add remaining blocks on last getcurrencystate step --- src/rpc/pbaasrpc.cpp | 45 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/rpc/pbaasrpc.cpp b/src/rpc/pbaasrpc.cpp index 11808cd5619..46f553029ca 100644 --- a/src/rpc/pbaasrpc.cpp +++ b/src/rpc/pbaasrpc.cpp @@ -11651,29 +11651,21 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) " \"currentratio\" : n,\n" " }\n" " \"conversiondata\": {\n" - " \"reserve1_basketcurrency\" : {\n" - " \"volume\":n,\n" - " \"open\":n,\n" - " \"high\":n,\n" - " \"low\":n,\n" - " \"close\":n,\n" - " },\n" - " \"reserve1_reserve2\" : {\n" - " ...\n" - " },\n" - " \"reserve1_reserve3\" : {\n" - " ...\n" - " },\n" - " \"reserve2_basketcurrency\" : {\n" - " ...\n" - " },\n" - " \"reserve2_reserve3\" : {\n" - " ...\n" - " },\n" - " \"reserve3_basketcurrency\" : {\n" - " ...\n" - " },\n" - " }\n" + " \"volumecurrency\": \"reserveorbasket\",\n" + " \"volumethisinterval\": n,\n" + " \"volumepairs\": [\n" + " {\n" + " \"currency\": \"sourcecurrency\", // Currency converting from\n" + " \"convertto\": \"destinationcurrency\", // Currency converting to\n" + " \"volume\": n, // Volume denominated in \"volumecurrency\"\n" + " \"open\": n, // Conversion rates of source currency in destination\n" + " \"high\": n,\n" + " \"low\": n,\n" + " \"close\": n\n" + " },\n" + " ...,\n" + " ]\n" + " },\n" " },\n" " ]\n" @@ -11796,14 +11788,17 @@ UniValue getcurrencystate(const UniValue& params, bool fHelp) std::map,std::tuple> pairVolumePrice; CAmount totalVolumeInVolumeCurrency = 0; CAmount stepVolumeInVolumeCurrency = 0; + int lastEnd = start; - for (int i = start; i <= end; i += step) + for (int i = start; i <= end; i += ((i + step <= end || i == end) ? step : end - i)) { LOCK(cs_main); pairVolumePrice.clear(); stepVolumeInVolumeCurrency = 0; - int queryStart = i == start ? i : i - (step - 1); + int queryStart = lastEnd; + lastEnd = (i + 1); + auto importIt = importMap.lower_bound({queryStart, 0}); auto importNextIt = importIt == importMap.end() ? importMap.end() : importMap.upper_bound({i, 0}); auto it = importIt;