]> Git Repo - VerusCoin.git/blobdiff - src/pbaas/crosschainrpc.cpp
Build fix
[VerusCoin.git] / src / pbaas / crosschainrpc.cpp
index d2700e974e00dea45488190939d8398a9a84de41..1e35c23da7447a536f596a505120a4852ef37ef4 100644 (file)
@@ -222,7 +222,7 @@ UniValue RPCCallRoot(const string& strMethod, const UniValue& params, int timeou
     {
         return RPCCall(strMethod, params, PBAAS_USERPASS, PBAAS_PORT, PBAAS_HOST);
     }
-    else if (ReadConfigFile(PBAAS_TESTMODE ? "VRSCTEST" : "VRSC", settings, settingsmulti))
+    else if (ReadConfigFile(PBAAS_TESTMODE ? "vrsctest" : "VRSC", settings, settingsmulti))
     {
         PBAAS_USERPASS = settingsmulti.find("-rpcuser")->second[0] + ":" + settingsmulti.find("-rpcpassword")->second[0];
         PBAAS_PORT = atoi(settingsmulti.find("-rpcport")->second[0]);
@@ -267,16 +267,23 @@ CNodeData::CNodeData(std::string netAddr, std::string paymentAddr) :
 
 CIdentitySignature::CIdentitySignature(const UniValue &uni)
 {
-    version = uni_get_int(find_value(uni, "version"));
-    blockHeight = uni_get_int64(find_value(uni, "blockheight"));
-    UniValue sigs = find_value(uni, "signatures");
-    if (sigs.isArray() && sigs.size())
+    try
     {
-        for (int i = 0; i < sigs.size(); i++)
+        version = uni_get_int(find_value(uni, "version"));
+        blockHeight = uni_get_int64(find_value(uni, "blockheight"));
+        UniValue sigs = find_value(uni, "signatures");
+        if (sigs.isArray() && sigs.size())
         {
-            signatures.insert(ParseHex(uni_get_str(sigs[i])));
+            for (int i = 0; i < sigs.size(); i++)
+            {
+                signatures.insert(ParseHex(uni_get_str(sigs[i])));
+            }
         }
     }
+    catch(...)
+    {
+        version = VERSION_INVALID;
+    }
 }
 
 uint256 CIdentitySignature::IdentitySignatureHash(const std::vector<uint160> &vdxfCodes, 
@@ -378,26 +385,27 @@ CIdentitySignature::ESignatureVerification CIdentitySignature::CheckSignature(co
 
 uint160 DecodeCurrencyName(std::string currencyStr)
 {
-    std::string extraName;
     uint160 retVal;
     currencyStr = TrimSpaces(currencyStr);
     if (!currencyStr.size())
     {
         return retVal;
     }
-    ParseSubNames(currencyStr, extraName, true);
-    if (currencyStr.back() == '@' || (extraName != "" && boost::to_lower_copy(extraName) != boost::to_lower_copy(VERUS_CHAINNAME)))
+    if (currencyStr.back() == '@')
     {
         return retVal;
     }
-    if (CCurrencyDefinition::GetID(currencyStr) == ASSETCHAINS_CHAINID)
+    std::string copyStr = currencyStr;
+    uint160 parent;
+    currencyStr = CleanName(currencyStr, parent, true);
+    if (!parent.IsNull() && CCurrencyDefinition::GetID(currencyStr, parent) == ASSETCHAINS_CHAINID)
     {
         return ASSETCHAINS_CHAINID;
     }
     CTxDestination currencyDest = DecodeDestination(currencyStr);
     if (currencyDest.which() == COptCCParams::ADDRTYPE_INVALID)
     {
-        currencyDest = DecodeDestination(currencyStr + "@");
+        currencyDest = DecodeDestination(copyStr + "@");
     }
     if (currencyDest.which() != COptCCParams::ADDRTYPE_INVALID)
     {
@@ -408,11 +416,21 @@ uint160 DecodeCurrencyName(std::string currencyStr)
 
 CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
     preLaunchDiscount(0),
-    initialFractionalSupply(0)
+    initialFractionalSupply(0),
+    gatewayConverterIssuance(0),
+    minNotariesConfirm(0),
+    idRegistrationFees(IDENTITY_REGISTRATION_FEE),
+    idReferralLevels(DEFAULT_ID_REFERRAL_LEVELS),
+    idImportFees(IDENTITY_IMPORT_FEE),
+    currencyRegistrationFee(CURRENCY_REGISTRATION_FEE),
+    pbaasSystemLaunchFee(PBAAS_SYSTEM_LAUNCH_FEE),
+    currencyImportFee(CURRENCY_IMPORT_FEE),
+    transactionImportFee(TRANSACTION_TRANSFER_FEE >> 1),
+    transactionExportFee(TRANSACTION_TRANSFER_FEE >> 1)
 {
     try
     {
-        nVersion = uni_get_int64(find_value(obj, "version"), PBAAS_VERSION);
+        nVersion = uni_get_int64(find_value(obj, "version"), VERSION_CURRENT);
         options = (uint32_t)uni_get_int64(find_value(obj, "options"));
         name = std::string(uni_get_str(find_value(obj, "name")), 0, (KOMODO_ASSETCHAIN_MAXLEN - 1));
 
@@ -449,14 +467,30 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
         gatewayConverterName = uni_get_str(find_value(obj, "gatewayconvertername"));
         if (!gatewayConverterName.empty())
         {
-            if (!(IsPBaaSChain() || IsGateway()))
+            if (!(IsPBaaSChain() || IsGateway()) || (IsPBaaSChain() && IsGateway()))
             {
                 LogPrintf("%s: a gateway converter currency may only be defined as part of a gateway or PBaaS system definition\n", __func__);
                 nVersion = PBAAS_VERSION_INVALID;
                 return;
             }
-            uint160 gatewayParent = systemID;
-            gatewayID = GetID(gatewayConverterName, gatewayParent);
+            else if (IsGateway())
+            {
+                gatewayID = GetID();
+            }
+            uint160 parent = GetID();
+            std::string cleanGatewayName = CleanName(gatewayConverterName, parent, true);
+            uint160 converterID = GetID(cleanGatewayName, parent);
+            if (parent != GetID())
+            {
+                LogPrintf("%s: invalid name for gateway converter %s\n", __func__, cleanGatewayName.c_str());
+                nVersion = PBAAS_VERSION_INVALID;
+                return;
+            }
+        }
+
+        if (IsPBaaSChain() || IsGateway() || IsPBaaSConverter())
+        {
+            gatewayConverterIssuance = AmountFromValueNoErr(find_value(obj, "gatewayconverterissuance"));
         }
 
         notarizationProtocol = (ENotarizationProtocol)uni_get_int(find_value(obj, "notarizationprotocol"), (int32_t)NOTARIZATION_NOTARY_CONFIRM);
@@ -492,8 +526,8 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
             launchSystemID = parent;
         }
 
-        startBlock = uni_get_int(find_value(obj, "startblock"));
-        endBlock = uni_get_int(find_value(obj, "endblock"));
+        startBlock = (uint32_t)uni_get_int64(find_value(obj, "startblock"));
+        endBlock = (uint32_t)uni_get_int64(find_value(obj, "endblock"));
 
         int32_t totalReserveWeight = IsFractional() ? SATOSHIDEN : 0;
         UniValue currencyArr = find_value(obj, "currencies");
@@ -511,7 +545,6 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
             {
                 preLaunchDiscount = AmountFromValueNoErr(find_value(obj, "prelaunchdiscount"));
                 initialFractionalSupply = AmountFromValueNoErr(find_value(obj, "initialsupply"));
-                gatewayConverterIssuance = AmountFromValueNoErr(find_value(obj, "gatewayconverterissuance"));
 
                 if (!initialFractionalSupply)
                 {
@@ -520,50 +553,7 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
                     nVersion = PBAAS_VERSION_INVALID;
                 }
 
-                UniValue preLaunchCarveoutsUni = find_value(obj, "prelaunchcarveouts");
-                int32_t preLaunchCarveOutTotal = 0;
-                if (nVersion != PBAAS_VERSION_INVALID && preLaunchCarveoutsUni.isArray())
-                {
-                    for (int i = 0; i < preLaunchCarveoutsUni.size(); i++)
-                    {
-                        std::vector<std::string> preLaunchCarveOutKey = preLaunchCarveoutsUni[i].getKeys();
-                        std::vector<UniValue> preLaunchCarveOutValue = preLaunchCarveoutsUni[i].getValues();
-                        if (preLaunchCarveOutKey.size() != 1 || preLaunchCarveOutValue.size() != 1)
-                        {
-                            LogPrintf("%s: each prelaunchcarveouts entry must contain one destination identity and one amount\n", __func__);
-                            printf("%s: each prelaunchcarveouts entry must contain one destination identity and one amount\n", __func__);
-                            nVersion = PBAAS_VERSION_INVALID;
-                            break;
-                        }
-
-                        CTxDestination carveOutDest = DecodeDestination(preLaunchCarveOutKey[0]);
-
-                        if (carveOutDest.which() != COptCCParams::ADDRTYPE_ID && !(carveOutDest.which() == COptCCParams::ADDRTYPE_INVALID && preLaunchCarveoutsUni.size() == 1))
-                        {
-                            LogPrintf("%s: prelaunchcarveouts destination must be an identity\n", __func__);
-                            nVersion = PBAAS_VERSION_INVALID;
-                            break;
-                        }
-
-                        CAmount carveOutAmount = AmountFromValueNoErr(preLaunchCarveOutValue[0]);
-                        if (carveOutAmount <= 0)
-                        {
-                            LogPrintf("%s: prelaunchcarveouts values must be greater than zero\n", __func__);
-                            nVersion = PBAAS_VERSION_INVALID;
-                            break;
-                        }
-                        preLaunchCarveOutTotal += carveOutAmount;
-                        if (preLaunchDiscount < 0 || 
-                            preLaunchDiscount >= SATOSHIDEN ||
-                            CCurrencyDefinition::CalculateRatioOfValue((totalReserveWeight - preLaunchCarveOutTotal), SATOSHIDEN - preLaunchDiscount) >= SATOSHIDEN)
-                        {
-                            LogPrintf("%s: prelaunchcarveouts values and discounts must total less than 1\n", __func__);
-                            nVersion = PBAAS_VERSION_INVALID;
-                            break;
-                        }
-                        preLaunchCarveOuts.push_back(make_pair(CIdentityID(GetDestinationID(carveOutDest)), preLaunchCarveOutTotal));
-                    }
-                }
+                preLaunchCarveOut = AmountFromValueNoErr(find_value(obj, "prelaunchcarveout"));
 
                 // if weights are defined, use them as relative ratios of each member currency
                 if (weightArr.isArray() && weightArr.size())
@@ -637,13 +627,13 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
             {
                 // if we are fractional, explicit conversion values are not valid
                 // and are based on non-zero, initial contributions relative to supply
-                if ((conversionArr.isArray() && conversionArr.size()) ||
+                if ((conversionArr.isArray() && conversionArr.size() != currencyArr.size()) ||
                     !initialContributionArr.isArray() || 
                     initialContributionArr.size() != currencyArr.size() ||
                     weights.size() != currencyArr.size() ||
                     !IsFractional())
                 {
-                    LogPrintf("%s: reserve currencies must have weights, initial contributions in every currency, and no explicit conversion rates\n", __func__);
+                    LogPrintf("%s: reserve currencies must have weights, initial contributions in at least one currency\n", __func__);
                     nVersion = PBAAS_VERSION_INVALID;
                 }
             }
@@ -689,13 +679,7 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
             bool isInitialContributions = initialContributionArr.isArray() && initialContributionArr.size();
             bool isPreconvertMin = minPreconvertArr.isArray() && minPreconvertArr.size();
             bool isPreconvertMax = maxPreconvertArr.isArray() && maxPreconvertArr.size();
-            bool explicitConversions = conversionArr.isArray() && conversionArr.size();
-
-            if (IsFractional() && explicitConversions)
-            {
-                LogPrintf("%s: cannot specify explicit conversion values for reserve currencies\n", __func__);
-                nVersion = PBAAS_VERSION_INVALID;
-            }
+            bool explicitConversions = (!IsFractional() && conversionArr.isArray()) && conversionArr.size();
 
             for (int i = 0; nVersion != PBAAS_VERSION_INVALID && i < currencyArr.size(); i++)
             {
@@ -714,12 +698,6 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
                 if (isInitialContributions && i < initialContributionArr.size())
                 {
                     int64_t contrib = AmountFromValueNoErr(initialContributionArr[i]);
-                    if (IsFractional() && contrib < MIN_RESERVE_CONTRIBUTION)
-                    {
-                        LogPrintf("%s: all fractional reserve currencies must start with %s minimum initial contribution in each currency\n", __func__, ValueFromAmount(MIN_RESERVE_CONTRIBUTION).write().c_str());
-                        nVersion = PBAAS_VERSION_INVALID;
-                        break;
-                    }
                     contributions[i] = contrib;
                     preconverted[i] = contrib;
                 }
@@ -800,9 +778,6 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
             }
         }
 
-        idRegistrationFees = AmountFromValueNoErr(find_value(obj, "idregistrationprice"));
-        idReferralLevels = uni_get_int(find_value(obj, "idreferrallevels"));
-
         UniValue notaryArr = find_value(obj, "notaries");
         minNotariesConfirm = 0;
         if (notaryArr.isArray())
@@ -825,18 +800,42 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
             minNotariesConfirm = uni_get_int(find_value(obj, "minnotariesconfirm"));
         }
 
+        idRegistrationFees = uni_get_int64(find_value(obj, "idregistrationfees"), idRegistrationFees);
+        idReferralLevels = uni_get_int(find_value(obj, "idreferrallevels"), idReferralLevels);
+        idImportFees = uni_get_int64(find_value(obj, "idimportfees"), idImportFees);
+
         auto vEras = uni_getValues(find_value(obj, "eras"));
         if (vEras.size() > ASSETCHAINS_MAX_ERAS)
         {
             vEras.resize(ASSETCHAINS_MAX_ERAS);
         }
 
-        for (auto era : vEras)
+        if (vEras.size())
         {
-            rewards.push_back(uni_get_int64(find_value(era, "reward")));
-            rewardsDecay.push_back(uni_get_int64(find_value(era, "decay")));
-            halving.push_back(uni_get_int64(find_value(era, "halving")));
-            eraEnd.push_back(uni_get_int64(find_value(era, "eraend")));
+            currencyRegistrationFee = uni_get_int64(find_value(obj, "currencyregistrationfee"), currencyRegistrationFee);
+            pbaasSystemLaunchFee = uni_get_int64(find_value(obj, "pbaassystemregistrationfee"), pbaasSystemLaunchFee);
+            currencyImportFee = uni_get_int64(find_value(obj, "currencyimportfee"), currencyImportFee);
+            transactionImportFee = uni_get_int64(find_value(obj, "transactionimportfee"), transactionImportFee);
+            transactionExportFee = uni_get_int64(find_value(obj, "transactionexportfee"), transactionExportFee);
+
+            if (!gatewayID.IsNull())
+            {
+                gatewayConverterIssuance = uni_get_int64(find_value(obj, "gatewayconverterissuance"));
+            }
+
+            for (auto era : vEras)
+            {
+                rewards.push_back(uni_get_int64(find_value(era, "reward")));
+                rewardsDecay.push_back(uni_get_int64(find_value(era, "decay")));
+                halving.push_back(uni_get_int64(find_value(era, "halving")));
+                eraEnd.push_back(uni_get_int64(find_value(era, "eraend")));
+            }
+
+            if (!rewards.size())
+            {
+                LogPrintf("%s: PBaaS chain does not have valid rewards eras");
+                nVersion = PBAAS_VERSION_INVALID;
+            }
         }
     }
     catch (exception e)
@@ -869,16 +868,18 @@ int64_t CCurrencyDefinition::GetTotalPreallocation() const
 // this will only return an accurate result after total preconversion has been updated and before any emission
 int32_t CCurrencyDefinition::GetTotalCarveOut() const
 {
-    int32_t totalCarveOut = 0;
-    for (auto &oneCarveOut : preLaunchCarveOuts)
-    {
-        totalCarveOut += oneCarveOut.second;
-        if (oneCarveOut.second < 0 || oneCarveOut.second > SATOSHIDEN || totalCarveOut > SATOSHIDEN)
-        {
-            LogPrintf("%s: invalid carve out amount specified %d\n", __func__, oneCarveOut.second);
-            return 0;
-        }
-    }
-    return totalCarveOut;
+    return preLaunchCarveOut;
+}
+
+CAmount AmountFromValue(const UniValue& value)
+{
+    if (!value.isNum() && !value.isStr())
+        throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string");
+    CAmount amount;
+    if (!ParseFixedPoint(value.getValStr(), 8, &amount))
+        throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
+    if (!MoneyRange(amount))
+        throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range");
+    return amount;
 }
 
This page took 0.033625 seconds and 4 git commands to generate.