]> Git Repo - VerusCoin.git/commitdiff
Fix for displaying reserve values in listtransactions
authormiketout <[email protected]>
Tue, 2 Jun 2020 23:45:19 +0000 (16:45 -0700)
committermiketout <[email protected]>
Tue, 2 Jun 2020 23:45:19 +0000 (16:45 -0700)
src/chainparams.cpp
src/pbaas/pbaas.cpp
src/pbaas/reserves.cpp
src/pbaas/reserves.h
src/rpc/pbaasrpc.cpp
src/wallet/rpcwallet.cpp

index d1fb91fac52e060b449926528d00f3d6836f4c9e..248f9aa3d0e74bc92158437aa3e4f7efaac64725 100644 (file)
@@ -202,7 +202,7 @@ public:
 
         vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
 
-        //fMiningRequiresPeers = true;
+        fMiningRequiresPeers = true;
         fDefaultConsistencyChecks = false;
         fRequireStandard = true;
         fMineBlocksOnDemand = false;
index 7de35a8c5fe030af442a767b1b64dcf082aca901..e8bac88b9e71c66e4d645e6d25883fc719f5920b 100644 (file)
@@ -1563,8 +1563,6 @@ void CConnectedChains::SignAndCommitImportTransactions(const CTransaction &lastI
     }
 }
 
-bool RefundFailedLaunch(uint160 currencyID, CTransaction &lastImportTx, std::vector<CTransaction> &newRefunds, std::string &errorReason);
-
 CCurrencyValueMap CalculatePreconversions(const CCurrencyDefinition &chainDef, int32_t definitionHeight, CCurrencyValueMap &fees)
 {
     // if we are getting information on the current chain, we assume that preconverted amounts have been
@@ -1575,7 +1573,7 @@ CCurrencyValueMap CalculatePreconversions(const CCurrencyDefinition &chainDef, i
         std::multimap<uint160, pair<CInputDescriptor, CReserveTransfer>> transferInputs;
         CCurrencyValueMap preconvertedAmounts;
 
-        if (GetChainTransfers(transferInputs, chainDef.GetID(), definitionHeight, chainDef.startBlock, CReserveTransfer::PRECONVERT | CReserveTransfer::VALID))
+        if (GetChainTransfers(transferInputs, chainDef.GetID(), definitionHeight, chainDef.startBlock - 1, CReserveTransfer::PRECONVERT | CReserveTransfer::VALID))
         {
             auto curMap = chainDef.GetCurrenciesMap();
             for (auto &transfer : transferInputs)
@@ -1646,6 +1644,31 @@ bool CConnectedChains::NewImportNotarization(const CCurrencyDefinition &_curDef,
         }
     }
 
+    int32_t definitionHeight = exportHeight;
+    CChainNotarizationData cnd;
+    if (isDefinition)
+    {
+        CTransaction dummyTx;
+        uint256 blkHash;
+
+        if (!myGetTransaction(lastImportTx.GetHash(), dummyTx, blkHash) || blkHash.IsNull())
+        {
+            LogPrintf("%s: invalid last import transaction for %s\n", __func__, curDef.name.c_str());
+            return false;
+        }
+        definitionHeight = mapBlockIndex[blkHash]->GetHeight();
+    }
+    else if (GetNotarizationData(curDef.GetID(), EVAL_ACCEPTEDNOTARIZATION, cnd) && cnd.vtx.size())
+    {
+        lastNotarization = cnd.vtx[cnd.forks[cnd.bestChain].back()].second;
+    }
+    else
+    {
+        LogPrintf("%s: cannot get last notarization for %s\n", __func__, curDef.name.c_str());
+        return false;
+    }
+    
+
     CBlockIndex *pindex;
     CTxDestination notarizationID = VERUS_DEFAULTID.IsNull() ? CTxDestination(CIdentityID(currencyID)) : CTxDestination(VERUS_DEFAULTID);
 
@@ -1659,7 +1682,7 @@ bool CConnectedChains::NewImportNotarization(const CCurrencyDefinition &_curDef,
 
         // check if the chain is qualified for a refund
         CCurrencyValueMap minPreMap, preConvertedMap, fees;
-        preConvertedMap = CalculatePreconversions(curDef, pindex->GetHeight(), fees).CanonicalMap();
+        preConvertedMap = CalculatePreconversions(curDef, definitionHeight, fees).CanonicalMap();
         curDef.preconverted = preConvertedMap.AsCurrencyVector(curDef.currencies);
 
         CCoinbaseCurrencyState initialCur = GetInitialCurrencyState(curDef);
@@ -1677,6 +1700,7 @@ bool CConnectedChains::NewImportNotarization(const CCurrencyDefinition &_curDef,
             // the result of the supply cannot be zero, enabling us to easily determine that this
             // represents a failed launch
             newCurState.supply = 0;
+            newCurState.SetRefunding(true);
             refunding = true;
         }
         else if (curDef.IsFractional() &&
@@ -1716,14 +1740,13 @@ bool CConnectedChains::NewImportNotarization(const CCurrencyDefinition &_curDef,
         CCoinbaseCurrencyState initialCur = lastNotarization.currencyState;
         newCurState = initialCur;
 
-
         if (curDef.minPreconvert.size() && curDef.minPreconvert.size() == curDef.currencies.size())
         {
             minPreMap = CCurrencyValueMap(curDef.currencies, curDef.minPreconvert).CanonicalMap();
         }
 
-        // we don't need any more notarizations after failure to launch, if success, continue
-        if (!(minPreMap.valueMap.size() && lastNotarization.currencyState.supply == 0))
+        // we won't change currency state in notarizations after failure to launch, if success, recalculate as needed
+        if (!(lastNotarization.currencyState.IsRefunding()))
         {
             // calculate new currency state from this import
             // we are not refunding, and it is possible that we also have
@@ -1812,7 +1835,7 @@ bool CConnectedChains::NewImportNotarization(const CCurrencyDefinition &_curDef,
     indexDests = std::vector<CTxDestination>({CKeyID(curDef.GetConditionID(EVAL_FINALIZE_NOTARIZATION))});
 
     // update crypto condition with final notarization output data
-    mnewTx.vout.push_back(CTxOut(PBAAS_MINNOTARIZATIONOUTPUT
+    mnewTx.vout.push_back(CTxOut(0
             MakeMofNCCScript(CConditionObj<CTransactionFinalization>(EVAL_FINALIZE_NOTARIZATION, dests, 1, &nf), &indexDests)));
 
     return true;
@@ -1833,7 +1856,7 @@ void CConnectedChains::ProcessLocalImports()
     std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>> unspentOutputs;
     std::map<uint160, std::pair<uint32_t, CTransaction>> currenciesToImport;    // height of earliest tx
     CCurrencyDefinition oneCurrency;
-    printf("%s: Searching for %s\n", __func__, ConnectedChains.ThisChain().GetConditionID(EVAL_FINALIZE_EXPORT).GetHex().c_str());
+    //printf("%s: Searching for %s\n", __func__, ConnectedChains.ThisChain().GetConditionID(EVAL_FINALIZE_EXPORT).GetHex().c_str());
     if (GetAddressUnspent(ConnectedChains.ThisChain().GetConditionID(EVAL_FINALIZE_EXPORT), 1, unspentOutputs))
     {
         CCrossChainExport ccx, ccxDummy;
@@ -1852,7 +1875,7 @@ void CConnectedChains::ProcessLocalImports()
                 myGetTransaction(oneOut.first.txhash, txOut, blkHash) &&
                 (ccx = CCrossChainExport(txOut)).IsValid() &&
                 (oneCurrency = GetCachedCurrency(ccx.systemID)).IsValid() &&
-                oneCurrency.startBlock < nHeight &&
+                oneCurrency.startBlock <= nHeight &&
                 !currenciesToImport.count(ccx.systemID) &&
                 GetLastImport(ccx.systemID, txImport, lastExport, cci, ccxDummy))
             {
index c793d8dbe191061f094efeb0a9f4522d89291e24..d5c825cb81e235466920617e75c5e61fa2961755 100644 (file)
@@ -156,7 +156,7 @@ CCurrencyState::CCurrencyState(const UniValue &obj)
 {
     flags = uni_get_int(find_value(obj, "flags"));
 
-    if (flags & ISFRACTIONAL)
+    if (flags & FLAG_FRACTIONAL)
     {
         auto CurrenciesArr = find_value(obj, "reservecurrencies");
         size_t numCurrencies;
@@ -164,7 +164,7 @@ CCurrencyState::CCurrencyState(const UniValue &obj)
             !(numCurrencies = CurrenciesArr.size()) ||
             numCurrencies > MAX_RESERVE_CURRENCIES)
         {
-            flags &= ~VALID;
+            flags &= ~FLAG_VALID;
             LogPrintf("Failed to proplerly specify currencies in reserve currency definition\n");
         }
         else
@@ -178,7 +178,7 @@ CCurrencyState::CCurrencyState(const UniValue &obj)
                     if (currencyID.IsNull())
                     {
                         LogPrintf("Invalid currency ID\n");
-                        flags &= ~VALID;
+                        flags &= ~FLAG_VALID;
                         break;
                     }
                     currencies[i] = currencyID;
@@ -189,13 +189,13 @@ CCurrencyState::CCurrencyState(const UniValue &obj)
             catch(const std::exception& e)
             {
                 std::cerr << e.what() << '\n';
-                flags &= ~VALID;
+                flags &= ~FLAG_VALID;
                 LogPrintf("Invalid specification of currencies, weights, and/or reserves in initial definition of reserve currency\n");
             }
         }
     }
 
-    if (!(flags & VALID))
+    if (!(flags & FLAG_VALID))
     {
         printf("Invalid currency specification, see debug.log for reason other than invalid flags\n");
         LogPrintf("Invalid currency specification\n");
@@ -211,7 +211,7 @@ CCurrencyState::CCurrencyState(const UniValue &obj)
         catch(const std::exception& e)
         {
             std::cerr << e.what() << '\n';
-            flags &= ~VALID;
+            flags &= ~FLAG_VALID;
         }
     }
 }
@@ -677,7 +677,7 @@ CAmount CCurrencyState::ConvertAmounts(CAmount inputReserve, CAmount inputFracti
     int64_t totalReserveOut = 0;        // how much reserve goes to sellers
 
     // if both conversions are zero, nothing to do but return current price
-    if ((!inputReserve && !inputFractional) || !(flags & ISFRACTIONAL))
+    if ((!inputReserve && !inputFractional) || !(flags & FLAG_FRACTIONAL))
     {
         return conversionPrice;
     }
@@ -2304,7 +2304,7 @@ CCoinbaseCurrencyState CCoinbaseCurrencyState::MatchOrders(const std::vector<CRe
     int64_t totalSerializedSize = pInOutTotalSerializeSize ? *pInOutTotalSerializeSize + CCurrencyState::CONVERSION_TX_SIZE_MIN : CCurrencyState::CONVERSION_TX_SIZE_MIN;
     int64_t conversionSizeOverhead = 0;
 
-    if (!(flags & ISFRACTIONAL))
+    if (!(flags & FLAG_FRACTIONAL))
     {
         return CCoinbaseCurrencyState();
     }
index d951b84da163a163de61e10aa91d9a494ef14524..bd52e20b1f290ee5ba634a44c1f0e3bb2250adaf 100644 (file)
@@ -340,9 +340,12 @@ public:
 class CCurrencyState
 {
 public:
-    enum {
-        VALID = 1,
-        ISFRACTIONAL = 2,
+    enum FLAGS {
+        FLAG_VALID = 1,
+        FLAG_FRACTIONAL = 2,
+        FLAG_REFUNDING = 4
+    };
+    enum CONSTANTS {
         MIN_RESERVE_RATIO = 1000000,        // we will not start a chain with less than 1% reserve ratio in any single currency
         MAX_RESERVE_RATIO = 100000000,      // we will not start a chain with greater than 100% reserve ratio
         SHUTDOWN_RESERVE_RATIO = 500000,    // if we hit this reserve ratio in any currency, initiate chain shutdown
@@ -370,7 +373,7 @@ public:
                       CAmount InitialSupply, 
                       CAmount Emitted, 
                       CAmount Supply, 
-                      uint32_t Flags=VALID) : 
+                      uint32_t Flags=FLAG_VALID) : 
         flags(Flags), supply(Supply), initialSupply(InitialSupply), emitted(Emitted), weights(Weights), reserves(Reserves)
     {}
 
@@ -520,12 +523,29 @@ public:
 
     bool IsValid() const
     {
-        return flags & CCurrencyState::VALID;
+        return flags & FLAG_VALID;
     }
 
     bool IsFractional() const
     {
-        return flags & CCurrencyState::ISFRACTIONAL;
+        return flags & FLAG_FRACTIONAL;
+    }
+
+    bool IsRefunding() const
+    {
+        return flags & FLAG_REFUNDING;
+    }
+
+    void SetRefunding(bool newState=true)
+    {
+        if (newState)
+        {
+            flags |= FLAG_REFUNDING;
+        }
+        else
+        {
+            flags &= ~FLAG_REFUNDING;
+        }
     }
 
     std::map<uint160, int32_t> GetReserveMap() const
index 36f51ba8e3b49ebe18e079ba38ab33935e4e0d4b..3ad50180ac1e0313a5ff89390e2c634879f029af 100644 (file)
@@ -641,7 +641,7 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &currencyDe
         GetAddressIndex(CCrossChainRPCData::GetConditionID(systemID, EVAL_CROSSCHAIN_EXPORT), 1, addressIndex, blkHeight, lastConfirmed.notarizationHeight))
     {
         // find this export, then check the next one that spends it and use it if also valid
-        bool found = false;
+        found = false;
         uint256 lastHash = lastExportHash;
 
         // indexed by input hash
@@ -1551,6 +1551,12 @@ bool GetChainTransfers(multimap<uint160, pair<CInputDescriptor, CReserveTransfer
 
             if (myGetTransaction(it->first.txhash, ntx, blkHash))
             {
+                /*
+                uint256 hashBlk;
+                UniValue univTx(UniValue::VOBJ);
+                TxToUniv(ntx, hashBlk, univTx);
+                printf("tx: %s\n", univTx.write(1,2).c_str());
+                */
                 for (int i = 0; i < ntx.vout.size(); i++)
                 {
                     // if this is a transfer output, optionally to this chain, add it to the input vector
@@ -2975,7 +2981,7 @@ CCoinbaseCurrencyState GetInitialCurrencyState(const CCurrencyDefinition &chainD
     {
         cState = CCurrencyState(chainDef.currencies,
                                 chainDef.weights,
-                                std::vector<int64_t>(chainDef.currencies.size()), 0, 0, 0, CCurrencyState::VALID + CCurrencyState::ISFRACTIONAL);
+                                std::vector<int64_t>(chainDef.currencies.size()), 0, 0, 0, CCurrencyState::FLAG_VALID + CCurrencyState::FLAG_FRACTIONAL);
         CCurrencyState tmpState;
         conversions = cState.ConvertAmounts(chainDef.preconverted, std::vector<int64_t>(chainDef.currencies.size()), tmpState);
         cState = tmpState;
@@ -2991,7 +2997,7 @@ CCoinbaseCurrencyState GetInitialCurrencyState(const CCurrencyDefinition &chainD
                                 0, 
                                 PreconvertedNative,
                                 PreconvertedNative, 
-                                CCurrencyState::VALID);
+                                CCurrencyState::FLAG_VALID);
     }
 
     cState.UpdateWithEmission(chainDef.GetTotalPreallocation());
index 7994798330b24af4d19baf7219e282b0a94de6d9..05d4abafce0dfc09b5d2a8be5c09291560cc1fde 100644 (file)
@@ -2114,14 +2114,15 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
             entry.push_back(Pair("category", bIsStake ? "stake" : "send"));
             entry.push_back(Pair("amount", ValueFromAmount(-s.amount)));
 
-
-            CCurrencyValueMap tokenAmounts = wtx.vout[s.vout].scriptPubKey.ReserveOutValue();
-            if (tokenAmounts.valueMap.size())
+            if (wtx.vout.size() > s.vout)
             {
-                entry.push_back(Pair("tokenamounts", tokenAmounts.ToUniValue()));
+                CCurrencyValueMap tokenAmounts = wtx.vout[s.vout].scriptPubKey.ReserveOutValue();
+                if (tokenAmounts.valueMap.size())
+                {
+                    entry.push_back(Pair("tokenamounts", tokenAmounts.ToUniValue()));
+                }
             }
 
-
             entry.push_back(Pair("vout", s.vout));
             entry.push_back(Pair("fee", ValueFromAmount(-nFee)));
             if (fLong)
@@ -2179,7 +2180,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
                 }
 
                 entry.push_back(Pair("amount", ValueFromAmount(r.amount)));
-                if (rtxd.IsReserve())
+                if (wtx.vout.size() > r.vout && rtxd.IsReserve())
                 {
                     entry.push_back(Pair("reserveamount", wtx.vout[r.vout].scriptPubKey.ReserveOutValue().ToUniValue()));
                 }
This page took 0.051085 seconds and 4 git commands to generate.