]> Git Repo - VerusCoin.git/commitdiff
New currency state member for preconverted output record
authormiketout <[email protected]>
Sun, 21 Feb 2021 02:46:21 +0000 (18:46 -0800)
committermiketout <[email protected]>
Sun, 21 Feb 2021 02:46:21 +0000 (18:46 -0800)
src/pbaas/notarization.cpp
src/pbaas/pbaas.cpp
src/pbaas/reserves.cpp
src/pbaas/reserves.h
src/primitives/transaction.cpp
src/rpc/pbaasrpc.cpp
src/script/script.cpp
src/transaction_builder.cpp
src/wallet/wallet.cpp

index 99fb8c59895e3f66f3c5fbfa9bdaa6c20949b048..45d5483f43f5eaa65e76ff4a6d7bb9b2c900374c 100644 (file)
@@ -416,6 +416,7 @@ bool CPBaaSNotarization::NextNotarizationInfo(const CCurrencyDefinition &sourceS
     uint160 sourceSystemID = sourceSystem.GetID();
 
     newNotarization = *this;
+    newNotarization.SetDefinitionNotarization(false);
     newNotarization.prevNotarization = CUTXORef();
     newNotarization.prevHeight = newNotarization.notarizationHeight;
     newNotarization.notarizationHeight = currentHeight;
@@ -457,7 +458,7 @@ bool CPBaaSNotarization::NextNotarizationInfo(const CCurrencyDefinition &sourceS
                 CCurrencyValueMap newReserveIn = CCurrencyValueMap(std::vector<uint160>({reserveTransfer.FirstCurrency()}), 
                                                                    std::vector<int64_t>({reserveTransfer.FirstValue() - fees.valueMap[reserveTransfer.FirstCurrency()]}));
                 CCurrencyValueMap newTotalReserves = CCurrencyValueMap(destCurrency.currencies, newNotarization.currencyState.reserves) + newReserveIn;
-                if (newTotalReserves <= CCurrencyValueMap(destCurrency.currencies, destCurrency.maxPreconvert))
+                if (!destCurrency.maxPreconvert.size() || newTotalReserves <= CCurrencyValueMap(destCurrency.currencies, destCurrency.maxPreconvert))
                 {
                     newNotarization.currencyState.reserveIn = 
                         (CCurrencyValueMap(destCurrency.currencies, newNotarization.currencyState.reserveIn) + newReserveIn).AsCurrencyVector(destCurrency.currencies);
@@ -492,48 +493,50 @@ bool CPBaaSNotarization::NextNotarizationInfo(const CCurrencyDefinition &sourceS
     // if this is the clear launch notarization after start, make the notarization and determine if we should launch or refund
     if (destCurrency.launchSystemID == sourceSystemID && currentHeight == (destCurrency.startBlock - 1))
     {
-        // we get one pre-launch coming through here
-        bool launchClear = false;
-        if (newNotarization.IsPreLaunch() && !newNotarization.currencyState.IsLaunchClear())
+        // we get one pre-launch coming through here, initial supply is set and ready for pre-convert
+        // don't revert or emit initial supply, it will be emitted for valid pre-conversions, which must already
+        // be included in the currency state
+        if (newNotarization.IsPreLaunch() && !newNotarization.IsLaunchCleared())
         {
             newNotarization.SetPreLaunch(false);
+            newNotarization.SetLaunchCleared();
+
+            // do not revert initial fixed supply on a currency
+            assert(newNotarization.currencyState.nativeOut >= newNotarization.currencyState.initialSupply);
+
             newNotarization.currencyState.RevertReservesAndSupply();
             newNotarization.currencyState.SetPrelaunch(false);
             newNotarization.currencyState.SetLaunchClear();
-            // first time through is export, second is import, then we finish clearing the launch
-        }
-        else if (newNotarization.currencyState.IsLaunchClear())
-        {
-            launchClear = true;
-            newNotarization.currencyState.SetLaunchClear(false);
-            newNotarization.currencyState.SetPrelaunch(true);
-            newNotarization.currencyState.ClearForNextBlock();
-        }
 
-        bool refunding = false;
-
-        // check if the chain is qualified for a refund
-        CCurrencyValueMap minPreMap, fees;
-        CCurrencyValueMap preConvertedMap = CCurrencyValueMap(destCurrency.currencies, newNotarization.currencyState.reserves).CanonicalMap();
+            // first time through is export, second is import, then we finish clearing the launch
+            // check if the chain is qualified to launch or should refund
+            CCurrencyValueMap minPreMap, fees;
+            CCurrencyValueMap preConvertedMap = CCurrencyValueMap(destCurrency.currencies, newNotarization.currencyState.reserves).CanonicalMap();
 
-        if (destCurrency.minPreconvert.size() && destCurrency.minPreconvert.size() == destCurrency.currencies.size())
-        {
-            minPreMap = CCurrencyValueMap(destCurrency.currencies, destCurrency.minPreconvert).CanonicalMap();
-        }
+            if (destCurrency.minPreconvert.size() && destCurrency.minPreconvert.size() == destCurrency.currencies.size())
+            {
+                minPreMap = CCurrencyValueMap(destCurrency.currencies, destCurrency.minPreconvert).CanonicalMap();
+            }
 
-        if (minPreMap.valueMap.size() && preConvertedMap < minPreMap)
-        {
-            // we force the supply to zero
-            // in any case where there was less than minimum participation,
-            newNotarization.currencyState.supply = 0;
-            newNotarization.currencyState.SetRefunding(true);
-            newNotarization.SetRefunding(true);
-            refunding = true;
+            if (minPreMap.valueMap.size() && preConvertedMap < minPreMap)
+            {
+                // we force the supply to zero
+                // in any case where there was less than minimum participation,
+                newNotarization.currencyState.supply = 0;
+                newNotarization.currencyState.SetRefunding(true);
+                newNotarization.SetRefunding(true);
+            }
+            else
+            {
+                newNotarization.SetLaunchConfirmed();
+                newNotarization.currencyState.SetLaunchConfirmed();
+            }
         }
-        else
+        else if (newNotarization.IsLaunchCleared())
         {
-            newNotarization.SetLaunchConfirmed();
-            newNotarization.currencyState.SetLaunchConfirmed();
+            newNotarization.currencyState.SetPrelaunch(false);
+            newNotarization.currencyState.SetLaunchClear(false);
+            newNotarization.currencyState.ClearForNextBlock();
         }
 
         CCurrencyDefinition destSystem = ConnectedChains.GetCachedCurrency(destCurrency.systemID);
@@ -549,21 +552,24 @@ bool CPBaaSNotarization::NextNotarizationInfo(const CCurrencyDefinition &sourceS
                                                            gatewayDepositsUsed, 
                                                            spentCurrencyOut,
                                                            &tempState);
-        
+
         newNotarization.currencyState = tempState;
-        if (launchClear)
-        {
-            newNotarization.currencyState.SetPrelaunch(false);
-            newNotarization.currencyState.SetLaunchClear(false);
-        }
         return retVal;
     }
-    else if (lastExportHeight >= destCurrency.startBlock)
+    else
     {
-        newNotarization.currencyState.SetLaunchClear(false);
-        if (destCurrency.systemID != ASSETCHAINS_CHAINID)
+        if (lastExportHeight >= destCurrency.startBlock)
+        {
+            newNotarization.currencyState.SetLaunchCompleteMarker();
+            newNotarization.currencyState.SetLaunchClear(false);
+            if (destCurrency.systemID != ASSETCHAINS_CHAINID)
+            {
+                newNotarization.SetSameChain(false);
+            }
+        }
+        else
         {
-            newNotarization.SetSameChain(false);
+            newNotarization.currencyState.SetPrelaunch();
         }
 
         // calculate new state from processing all transfers
@@ -580,7 +586,7 @@ bool CPBaaSNotarization::NextNotarizationInfo(const CCurrencyDefinition &sourceS
                                                                   gatewayDepositsUsed, 
                                                                   spentCurrencyOut,
                                                                   &newNotarization.currencyState);
-        if (isValidExport && destCurrency.IsFractional())
+        if (!newNotarization.currencyState.IsPrelaunch() && isValidExport && destCurrency.IsFractional())
         {
             // we want the new price and the old state as a starting point to ensure no rounding error impact
             // on reserves
index 8aac5b4c943e7eb1e11c6e90ee760b6a8f903793..c24c6c625130f53a36a59a237ead1ebc4b2c7f1e 100644 (file)
@@ -1159,7 +1159,7 @@ CCoinbaseCurrencyState CConnectedChains::GetCurrencyState(CCurrencyDefinition &c
         currencyState = GetInitialCurrencyState(thisChain);
     }
     // if this is a token on this chain, it will be simply notarized
-    else if (curDef.systemID == ASSETCHAINS_CHAINID)
+    else if (curDef.systemID == ASSETCHAINS_CHAINID || (curDef.launchSystemID == ASSETCHAINS_CHAINID && curDef.startBlock > height))
     {
         // get the last notarization in the height range for this currency, which is valid by definition for a token
         CPBaaSNotarization notarization;
@@ -1174,9 +1174,10 @@ CCoinbaseCurrencyState CConnectedChains::GetCurrencyState(CCurrencyDefinition &c
             else
             {
                 currencyState = GetInitialCurrencyState(curDef);
+                currencyState.SetPrelaunch();
             }
         }
-        if (!currencyState.IsValid() || notarization.notarizationHeight < (curDef.startBlock - 1))
+        if (currencyState.IsValid() && notarization.notarizationHeight < (curDef.startBlock - 1))
         {
             // pre-launch
             currencyState.SetPrelaunch(true);
@@ -1845,7 +1846,7 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
 
         // if not the initial import in the thread, it should have a valid prior notarization as well
         // the notarization of the initial import may be superceded by pre-launch exports
-        if (nHeight && lastCCI.IsInitialLaunchImport() || lastCCI.IsPostLaunch())
+        if (nHeight && lastCCI.IsPostLaunch())
         {
             if (!lastCCI.GetImportInfo(lastImportTx,
                                        outputNum,
@@ -1928,7 +1929,7 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
         std::vector<CReserveTransfer> exportTransfers = oneIT.second;
         std::vector<CTxOut> newOutputs;
         CCurrencyValueMap importedCurrency, gatewayDepositsUsed, spentCurrencyOut;
-        // if we are transisitioning from export to import, allow the function to set launch clear on the currency
+        // if we are transitioning from export to import, allow the function to set launch clear on the currency
         if (lastNotarization.currencyState.IsLaunchClear() && !lastCCI.IsInitialLaunchImport())
         {
             lastNotarization.SetPreLaunch();
@@ -2207,10 +2208,17 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
             // dust rules don't apply
             if (oneChangeVal.second)
             {
-                CReserveDeposit rd = CReserveDeposit(sourceSystemID, CCurrencyValueMap(std::vector<uint160>({oneChangeVal.first}), 
-                                                                                            std::vector<int64_t>({oneChangeVal.second})));
-                tb.AddTransparentOutput(MakeMofNCCScript(CConditionObj<CReserveDeposit>(EVAL_RESERVE_DEPOSIT, dests, 1, &rd)), 
-                                                                                        oneChangeVal.first == ASSETCHAINS_CHAINID ? oneChangeVal.second : 0);
+                CReserveDeposit rd = CReserveDeposit(sourceSystemID, CCurrencyValueMap());;
+                CAmount nativeOutput = 0;
+                if (oneChangeVal.first == ASSETCHAINS_CHAINID)
+                {
+                    nativeOutput = oneChangeVal.second;
+                }
+                else
+                {
+                    rd.reserveValues.valueMap[oneChangeVal.first] = oneChangeVal.second;
+                }
+                tb.AddTransparentOutput(MakeMofNCCScript(CConditionObj<CReserveDeposit>(EVAL_RESERVE_DEPOSIT, dests, 1, &rd)), nativeOutput);
             }
         }
 
@@ -2221,10 +2229,17 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
             // dust rules don't apply
             if (oneChangeVal.second)
             {
-                CReserveDeposit rd = CReserveDeposit(ccx.destCurrencyID, CCurrencyValueMap(std::vector<uint160>({oneChangeVal.first}), 
-                                                                                            std::vector<int64_t>({oneChangeVal.second})));
-                tb.AddTransparentOutput(MakeMofNCCScript(CConditionObj<CReserveDeposit>(EVAL_RESERVE_DEPOSIT, dests, 1, &rd)), 
-                                                                                        oneChangeVal.first == ASSETCHAINS_CHAINID ? oneChangeVal.second : 0);
+                CReserveDeposit rd = CReserveDeposit(ccx.destCurrencyID, CCurrencyValueMap());;
+                CAmount nativeOutput = 0;
+                if (oneChangeVal.first == ASSETCHAINS_CHAINID)
+                {
+                    nativeOutput = oneChangeVal.second;
+                }
+                else
+                {
+                    rd.reserveValues.valueMap[oneChangeVal.first] = oneChangeVal.second;
+                }
+                tb.AddTransparentOutput(MakeMofNCCScript(CConditionObj<CReserveDeposit>(EVAL_RESERVE_DEPOSIT, dests, 1, &rd)), nativeOutput);
             }
         }
 
@@ -2715,6 +2730,8 @@ bool CConnectedChains::CreateNextExport(const CCurrencyDefinition &_curDef,
         return false;
     }
 
+    //printf("%s: num transfers %ld\n", __func__, exportTransfers.size());
+
     newNotarization.prevNotarization = lastNotarizationUTXO;
 
     CCurrencyValueMap totalExports;
@@ -2819,7 +2836,7 @@ bool CConnectedChains::CreateNextExport(const CCurrencyDefinition &_curDef,
                           addHeight,
                           destSystemID, 
                           currencyID, 
-                          txInputs.size(), 
+                          exportTransfers.size(), 
                           totalExports.CanonicalMap(), 
                           totalTransferFees.CanonicalMap(),
                           transferHash,
@@ -3091,7 +3108,7 @@ void CConnectedChains::AggregateChainTransfers(const CTxDestination &feeOutput,
             auto outputIt = transferOutputs.begin();
             bool checkLaunchCurrencies = false;
             for (int outputsDone = 0; 
-                 outputsDone < transferOutputs.size() || launchCurrencies.size();
+                 outputsDone <= transferOutputs.size() || launchCurrencies.size();
                  outputsDone++)
             {
                 if (outputIt != transferOutputs.end())
index 70e5280bbd034dd8d87b0aad7bf9fd8e5779ec17..bbc8e7a86bc1e6e4f28ce13ff7fc2ae49a355b67 100644 (file)
@@ -1827,7 +1827,10 @@ bool CReserveTransfer::GetTxOut(const CCurrencyValueMap &reserves, int64_t nativ
         if (!reserves.valueMap.size() && nativeAmount)
         {
             CTxDestination dest = TransferDestinationToDestination(destination);
-            if (dest.which() == CScript::P2ID || dest.which() == CScript::P2PK || dest.which() == CScript::P2PKH || dest.which() == CScript::P2SH)
+            if (dest.which() == COptCCParams::ADDRTYPE_ID || 
+                dest.which() == COptCCParams::ADDRTYPE_PK ||
+                dest.which() == COptCCParams::ADDRTYPE_PKH ||
+                dest.which() == COptCCParams::ADDRTYPE_SH)
             {
                 txOut = CTxOut(nativeAmount, GetScriptForDestination(dest));
                 return true;
@@ -1836,7 +1839,7 @@ bool CReserveTransfer::GetTxOut(const CCurrencyValueMap &reserves, int64_t nativ
         else
         {
             CTxDestination dest = TransferDestinationToDestination(destination);
-            if (dest.which() == CScript::P2ID || dest.which() == CScript::P2PK || dest.which() == CScript::P2PKH)
+            if (dest.which() == COptCCParams::ADDRTYPE_ID || dest.which() == COptCCParams::ADDRTYPE_PK || dest.which() == COptCCParams::ADDRTYPE_PKH)
             {
                 std::vector<CTxDestination> dests = std::vector<CTxDestination>({TransferDestinationToDestination(destination)});
                 CTokenOutput ro = CTokenOutput(reserves);
@@ -2330,7 +2333,7 @@ bool CReserveTransactionDescriptor::AddReserveTransferImportOutputs(const CCurre
                     return false;
                 }
 
-                if (!importCurrencyState.IsPrelaunch())
+                if (importCurrencyState.IsLaunchCompleteMarker())
                 {
                     printf("%s: Invalid preconversion after launch %s\n", __func__, curTransfer.ToUniValue().write().c_str());
                     LogPrintf("%s: Invalid preconversion after launch %s\n", __func__, curTransfer.ToUniValue().write().c_str());
@@ -2341,7 +2344,7 @@ bool CReserveTransactionDescriptor::AddReserveTransferImportOutputs(const CCurre
                 // remove initialCurrencyState when not needed
                 if (!initialCurrencyState.IsValid())
                 {
-                    initialCurrencyState = GetInitialCurrencyState(importCurrencyDef);
+                    initialCurrencyState = ConnectedChains.GetCurrencyState(importCurrencyID, importCurrencyDef.startBlock - 1);
                 }
 
                 // either the destination currency must be fractional or the source currency
@@ -2404,43 +2407,49 @@ bool CReserveTransactionDescriptor::AddReserveTransferImportOutputs(const CCurre
                 transferFees.valueMap[systemDestID] += preConversionFee;
 
                 newCurrencyConverted = initialCurrencyState.ReserveToNativeRaw(valueOut, initialCurrencyState.conversionPrice[curIdx]);
+                if (newCurrencyConverted == -1)
+                {
+                    // if we have an overflow, this isn't going to work
+                    newCurrencyConverted = 0;
+                }
 
                 if (!carveOutSet)
                 {
                     totalCarveOut = importCurrencyDef.GetTotalCarveOut();
                     carveOutSet = true;
                 }
-                if (totalCarveOut > 0 && totalCarveOut < SATOSHIDEN)
-                {
-                    CAmount newReserveIn = CCurrencyState::NativeToReserveRaw(valueOut, SATOSHIDEN - totalCarveOut);
-                    totalCarveOuts.valueMap[curTransfer.FirstCurrency()] += valueOut - newReserveIn;
-                    valueOut = newReserveIn;
-                }
 
-                if (curTransfer.FirstCurrency() != systemDestID)
+                if (newCurrencyConverted)
                 {
-                    // if this is a fractional currency, everything but fees and carveouts stay in reserve deposit
-                    // else all that would be reserves is sent to chain ID
-                    if (!isFractional)
+                    if (totalCarveOut > 0 && totalCarveOut < SATOSHIDEN)
                     {
-                        AddReserveOutput(curTransfer.FirstCurrency(), valueOut);
-                        std::vector<CTxDestination> dests({CIdentityID(importCurrencyID)});
-                        CTokenOutput ro = CTokenOutput(curTransfer.FirstCurrency(), valueOut);
-                        vOutputs.push_back(CTxOut(0, MakeMofNCCScript(CConditionObj<CTokenOutput>(EVAL_RESERVE_OUTPUT, dests, 1, &ro))));
+                        CAmount newReserveIn = CCurrencyState::NativeToReserveRaw(valueOut, SATOSHIDEN - totalCarveOut);
+                        totalCarveOuts.valueMap[curTransfer.FirstCurrency()] += valueOut - newReserveIn;
+                        valueOut = newReserveIn;
                     }
-                }
-                else
-                {
-                    // if it is not fractional, send to currency ID, else leave it in reserve deposit
-                    if (!isFractional)
+
+                    if (curTransfer.FirstCurrency() != systemDestID)
                     {
-                        nativeOut += valueOut;
-                        vOutputs.push_back(CTxOut(valueOut, GetScriptForDestination(CIdentityID(importCurrencyID))));
+                        // if this is a fractional currency, everything but fees and carveouts stay in reserve deposit
+                        // else all that would be reserves is sent to chain ID
+                        if (!isFractional)
+                        {
+                            AddReserveOutput(curTransfer.FirstCurrency(), valueOut);
+                            std::vector<CTxDestination> dests({CIdentityID(importCurrencyID)});
+                            CTokenOutput ro = CTokenOutput(curTransfer.FirstCurrency(), valueOut);
+                            vOutputs.push_back(CTxOut(0, MakeMofNCCScript(CConditionObj<CTokenOutput>(EVAL_RESERVE_OUTPUT, dests, 1, &ro))));
+                        }
+                    }
+                    else
+                    {
+                        // if it is not fractional, send to currency ID, else leave it in reserve deposit
+                        if (!isFractional)
+                        {
+                            nativeOut += valueOut;
+                            vOutputs.push_back(CTxOut(valueOut, GetScriptForDestination(CIdentityID(importCurrencyID))));
+                        }
                     }
-                }
 
-                if (newCurrencyConverted)
-                {
                     preConvertedOutput.valueMap[curTransfer.FirstCurrency()] += newCurrencyConverted;
                     AddNativeOutConverted(curTransfer.FirstCurrency(), newCurrencyConverted);
                     AddNativeOutConverted(curTransfer.destCurrencyID, newCurrencyConverted);
@@ -2455,7 +2464,7 @@ bool CReserveTransactionDescriptor::AddReserveTransferImportOutputs(const CCurre
                         AddReserveOutConverted(curTransfer.destCurrencyID, newCurrencyConverted);
                         AddReserveOutput(curTransfer.destCurrencyID, newCurrencyConverted);
                         AddReserveInput(curTransfer.destCurrencyID, newCurrencyConverted);
-                        curTransfer.GetTxOut(CCurrencyValueMap(std::vector<uint160>({curTransfer.destCurrencyID}), std::vector<int64_t>(newCurrencyConverted)), 
+                        curTransfer.GetTxOut(CCurrencyValueMap(std::vector<uint160>({curTransfer.destCurrencyID}), std::vector<int64_t>({newCurrencyConverted})), 
                                              0, newOut);
                     }
                 }
@@ -2756,6 +2765,11 @@ bool CReserveTransactionDescriptor::AddReserveTransferImportOutputs(const CCurre
     }
 
     newCurrencyState.supply += preAllocTotal;
+    newCurrencyState.preConvertedOut = 0;
+    for (auto &oneVal : preConvertedOutput.valueMap)
+    {
+        newCurrencyState.preConvertedOut += oneVal.second;
+    }
 
     if (totalMinted)
     {
index ea6ab84227f1c84a5fa4e5985942baba5f5fa5bc..a8d7f7d57ef40a457e8bb915aad009bf92f4160b 100644 (file)
@@ -726,6 +726,18 @@ public:
         return flags & FLAG_INITIALLAUNCHIMPORT;
     }
 
+    void SetInitialLaunchImport(bool isInitialLaunchImport=true)
+    {
+        if (isInitialLaunchImport)
+        {
+            flags |= FLAG_INITIALLAUNCHIMPORT;
+        }
+        else
+        {
+            flags &= ~FLAG_INITIALLAUNCHIMPORT;
+        }
+    }
+
     UniValue ToUniValue() const;
 
     static std::string CurrencyImportKeyName()
@@ -1308,6 +1320,7 @@ class CCoinbaseCurrencyState : public CCurrencyState
 {
 public:
     CAmount nativeOut;                      // converted native output, emitted is stored in parent class
+    CAmount preConvertedOut;                // how much of the currency out was pre-converted, which is asynchronously added to supply
     CAmount nativeFees;
     CAmount nativeConversionFees;
     std::vector<CAmount> reserveIn;         // reserve currency converted to native
@@ -1318,7 +1331,7 @@ public:
     std::vector<CAmount> fees;              // fee values in native (or reserve if specified) coins for reserve transaction fees for the block
     std::vector<CAmount> conversionFees;    // total of only conversion fees, which will accrue to the conversion transaction
 
-    CCoinbaseCurrencyState() : nativeOut(0), nativeFees(0), nativeConversionFees(0) {}
+    CCoinbaseCurrencyState() : nativeOut(0), preConvertedOut(0), nativeFees(0), nativeConversionFees(0) {}
 
     CCoinbaseCurrencyState(const CCurrencyState &CurrencyState,
                            CAmount NativeOut=0, CAmount NativeFees=0, CAmount NativeConversionFees=0,
@@ -1328,7 +1341,8 @@ public:
                            const std::vector<CAmount> &ConversionPrice=std::vector<CAmount>(), 
                            const std::vector<CAmount> &ViaConversionPrice=std::vector<CAmount>(), 
                            const std::vector<CAmount> &Fees=std::vector<CAmount>(), 
-                           const std::vector<CAmount> &ConversionFees=std::vector<CAmount>()) : 
+                           const std::vector<CAmount> &ConversionFees=std::vector<CAmount>(),
+                           CAmount PreConvertedOut=0) : 
         CCurrencyState(CurrencyState), nativeOut(NativeOut), nativeFees(NativeFees), nativeConversionFees(NativeConversionFees),
         reserveIn(ReserveIn),
         nativeIn(NativeIn),
@@ -1336,7 +1350,8 @@ public:
         conversionPrice(ConversionPrice),
         viaConversionPrice(ViaConversionPrice),
         fees(Fees),
-        conversionFees(ConversionFees)        
+        conversionFees(ConversionFees),
+        preConvertedOut(PreConvertedOut)
     {
         if (!reserveIn.size()) reserveIn = std::vector<CAmount>(currencies.size());
         if (!nativeIn.size()) nativeIn = std::vector<CAmount>(currencies.size());
@@ -1362,6 +1377,7 @@ public:
     inline void SerializationOp(Stream& s, Operation ser_action) {
         READWRITE(*(CCurrencyState *)this);
         READWRITE(nativeOut);
+        READWRITE(preConvertedOut);
         READWRITE(nativeFees);
         READWRITE(nativeConversionFees);
         READWRITE(reserveIn);
@@ -1384,6 +1400,7 @@ public:
     {
         emitted = 0;
         nativeOut = 0;
+        preConvertedOut = 0;
         nativeFees = 0;
         nativeConversionFees = 0;
         reserveIn = std::vector<CAmount>(currencies.size());
@@ -1414,7 +1431,7 @@ public:
             reserves[oneCur.second] += (reserveOut[oneCur.second] - reserveIn[oneCur.second]);
             supply += nativeIn[oneCur.second];
         }
-        supply -= (nativeOut + emitted);
+        supply -= ((nativeOut + emitted) - preConvertedOut);
     }
 
     CCoinbaseCurrencyState MatchOrders(const std::vector<CReserveTransactionDescriptor> &orders, 
index 2e03c5dfb6009f68a5807b8f1aaa92c56f79b60a..405c6df7bd8524c682110cf8a4afbde2674b52b2 100644 (file)
@@ -415,8 +415,8 @@ CCurrencyValueMap CTransaction::GetReserveValueOut() const
                 reserveIt->second += oneCur.second;
                 if (reserveIt->second < 0)
                 {
-                    printf("CTransaction::GetReserveValueOut(): currency value overflow total: %ld, adding: %ld\n", reserveIt->second, oneCur.second);
-                    LogPrintf("CTransaction::GetReserveValueOut(): value overflow\n");
+                    printf("%s: currency value overflow total: %ld, adding: %ld\n", __func__, reserveIt->second, oneCur.second);
+                    LogPrintf("%s: currency value overflow total: %ld, adding: %ld\n", __func__, reserveIt->second, oneCur.second);
                     return std::map<uint160, CAmount>();
                 }
             }
index 7d125ee869e6be3bb00a705ebe5c34e90c31c09c..343ed433c9479a871a5bbedef924e276ea291a02 100644 (file)
@@ -1395,7 +1395,7 @@ bool GetChainTransfers(multimap<uint160, pair<CInputDescriptor, CReserveTransfer
 
     LOCK2(cs_main, mempool.cs);
 
-    if (!GetAddressIndex(CCrossChainRPCData::GetConditionID(ASSETCHAINS_CHAINID, CReserveTransfer::ReserveTransferKey()), 
+    if (!GetAddressIndex(CReserveTransfer::ReserveTransferKey(), 
                          CScript::P2IDX, 
                          addressIndex, 
                          start, 
index ac423f27ab22eb188b1aa882ed629e7b7982b992..13bebf23e12d1819ac808715fa9435e3649f5e76 100644 (file)
@@ -689,6 +689,7 @@ CCurrencyValueMap CScript::ReserveOutValue(COptCCParams &p, bool spendableOnly)
             {
                 CReserveDeposit rd(p.vData[0]);
                 retVal = rd.reserveValues;
+                retVal.valueMap.erase(ASSETCHAINS_CHAINID);
                 break;
             }
 
index 06db2b2409767e8b3e1b90d426f068e86da1ca6b..e5ad4a4c458690d30546b7c36e2365723394a327 100644 (file)
@@ -255,7 +255,7 @@ TransactionBuilderResult TransactionBuilder::Build()
 
         CReserveTransactionDescriptor rtxd(mtx, view, chainActive.Height());
         reserveChange = rtxd.ReserveInputMap() - rtxd.ReserveOutputMap();
-        //printf("%s: reserve input:\n%s\noutput:\n%s\nchange:\n%s\n", __func__, rtxd.ReserveInputMap().ToUniValue().write(1,2).c_str(), rtxd.ReserveOutputMap().ToUniValue().write(1,2).c_str(), reserveChange.ToUniValue().write(1,2).c_str());
+        printf("%s: reserve input:\n%s\noutput:\n%s\nchange:\n%s\n", __func__, rtxd.ReserveInputMap().ToUniValue().write(1,2).c_str(), rtxd.ReserveOutputMap().ToUniValue().write(1,2).c_str(), reserveChange.ToUniValue().write(1,2).c_str());
         bool hasReserveChange = false;
 
         // Valid change
index 5316b82bfa855f5f563ddeaa047f3c7d65c57d34..a953d47ee44d5783dc173c664ebfc26eb990f2ea 100644 (file)
@@ -5685,7 +5685,7 @@ bool CWallet::SelectReserveCoinsMinConf(const CCurrencyValueMap& targetValues,
             continue;
         }
 
-        printf("nTotal: %s\n", nTotal.ToUniValue().write().c_str());
+        //printf("nTotal: %s\n", nTotal.ToUniValue().write().c_str());
 
         CReserveOutSelectionInfo coin(pcoin, i, nAll);
 
@@ -5772,11 +5772,11 @@ bool CWallet::SelectReserveCoinsMinConf(const CCurrencyValueMap& targetValues,
     // if our lower total + larger total are not enough, no way we have enough
     if ((lowerTotal + largerTotal) < nTotalTarget)
     {
-        printf("AVAILABLE < nTotalTarget:\nlowerTotal:\n%s\nlargerTotal:\n%s\nnewLargerTotal:\n%s\nTotalTarget:\n%s\n", lowerTotal.ToUniValue().write().c_str(), largerTotal.ToUniValue().write().c_str(), newLargerTotal.ToUniValue().write().c_str(), nTotalTarget.ToUniValue().write().c_str());
+        //printf("AVAILABLE < nTotalTarget:\nlowerTotal:\n%s\nlargerTotal:\n%s\nnewLargerTotal:\n%s\nTotalTarget:\n%s\n", lowerTotal.ToUniValue().write().c_str(), largerTotal.ToUniValue().write().c_str(), newLargerTotal.ToUniValue().write().c_str(), nTotalTarget.ToUniValue().write().c_str());
         return false;
     }
 
-    printf("\nlowerTotal:\n%s\nlargerTotal:\n%s\nnewLargerTotal:\n%s\nTotalTarget:\n%s\n", lowerTotal.ToUniValue().write().c_str(), largerTotal.ToUniValue().write().c_str(), newLargerTotal.ToUniValue().write().c_str(), nTotalTarget.ToUniValue().write().c_str());
+    //printf("\nlowerTotal:\n%s\nlargerTotal:\n%s\nnewLargerTotal:\n%s\nTotalTarget:\n%s\n", lowerTotal.ToUniValue().write().c_str(), largerTotal.ToUniValue().write().c_str(), newLargerTotal.ToUniValue().write().c_str(), nTotalTarget.ToUniValue().write().c_str());
 
     for (auto &lowerOut : lowerOuts)
     {
This page took 0.054434 seconds and 4 git commands to generate.