]> Git Repo - VerusCoin.git/commitdiff
Validate ID dest for sendtoaddress and z_sendmany
authormiketout <[email protected]>
Tue, 23 Jun 2020 06:35:38 +0000 (23:35 -0700)
committermiketout <[email protected]>
Tue, 23 Jun 2020 06:35:38 +0000 (23:35 -0700)
src/chainparams.cpp
src/key_io.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 87dcecffa34f7c4f371a3bca3f306ee137938cac..e3dfbe5ff9652ca9623c0622fa6e9ce4983d30a3 100644 (file)
@@ -35,6 +35,7 @@ std::string EncodeDestination(const CTxDestination& dest);
 std::vector<unsigned char> GetDestinationBytes(const CTxDestination& dest);
 uint160 GetDestinationID(const CTxDestination dest);
 CTxDestination DecodeDestination(const std::string& str);
+CTxDestination ValidateDestination(const std::string &destStr);
 bool IsValidDestinationString(const std::string& str);
 bool IsValidDestinationString(const std::string& str, const CChainParams& params);
 
index b0cdc9096ffa4e599854cb748224604e27648c9b..f9c774702bb440cab453c1d88e1c8645f1cb2744 100644 (file)
@@ -174,6 +174,21 @@ bool GetCurrencyDefinition(string &name, CCurrencyDefinition &chainDef)
     return GetCurrencyDefinition(CCrossChainRPCData::GetID(name), chainDef);
 }
 
+CTxDestination ValidateDestination(const std::string &destStr)
+{
+    CTxDestination destination = DecodeDestination(destStr);
+    CTransferDestination transferDestination;
+    if (destination.which() == COptCCParams::ADDRTYPE_ID)
+    {
+        AssertLockHeld(cs_main);
+        if (!CIdentity::LookupIdentity(GetDestinationID(destination)).IsValid())
+        {
+            return CTxDestination();
+        }
+    }
+    return destination;
+}
+
 // set default peer nodes in the current connected chains
 bool SetPeerNodes(const UniValue &nodes)
 {
@@ -3196,7 +3211,7 @@ UniValue sendcurrency(const UniValue& params, bool fHelp)
                 throw JSONRPCError(RPC_INVALID_PARAMETER, "Only the ID of a mintable currency can mint such a currency. Minting cannot be combined with conversion.");
             }
 
-            CTxDestination destination = DecodeDestination(destStr);
+            CTxDestination destination = ValidateDestination(destStr);
             CTransferDestination transferDestination;
             if (destination.which() == COptCCParams::ADDRTYPE_INVALID)
             {
@@ -3211,6 +3226,10 @@ UniValue sendcurrency(const UniValue& params, bool fHelp)
                         }
                         rawDestBytes.insert(rawDestBytes.end(), subNames[i].begin(), subNames[i].end());
                     }
+                    if (!rawDestBytes.size())
+                    {
+                        throw JSONRPCError(RPC_INVALID_PARAMETER, "Specified destination must be valid.");
+                    }
                     transferDestination = CTransferDestination(CTransferDestination::DEST_RAW, rawDestBytes);
                 }
                 else
@@ -3218,13 +3237,6 @@ UniValue sendcurrency(const UniValue& params, bool fHelp)
                     throw JSONRPCError(RPC_INVALID_PARAMETER, "Specified destination must be valid.");
                 }
             }
-            else if (destination.which() == COptCCParams::ADDRTYPE_ID)
-            {
-                if (!CIdentity::LookupIdentity(GetDestinationID(destination)).IsValid())
-                {
-                    throw JSONRPCError(RPC_INVALID_PARAMETER, "When sending to an ID, the ID must be valid.");
-                }
-            }
 
             CTxDestination refundDestination = DecodeDestination(refundToStr);
             if (refundDestination.which() == COptCCParams::ADDRTYPE_ID &&
index 39c88433a7f86c682ee641afe50643514848b8c4..7324f332427bbfce9e5c5eb5563bc29e60b2dc1b 100644 (file)
@@ -472,7 +472,8 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp)
 
     LOCK2(cs_main, pwalletMain->cs_wallet);
 
-    CTxDestination dest = DecodeDestination(params[0].get_str());
+    CTxDestination dest = ValidateDestination(params[0].get_str());
+
     if (!IsValidDestination(dest)) {
         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Verus address");
     }
@@ -4871,7 +4872,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
 
         string address = find_value(o, "address").get_str();
         bool isZaddr = false;
-        CTxDestination taddr = DecodeDestination(address);
+        CTxDestination taddr = ValidateDestination(address);
         if (!IsValidDestination(taddr)) {
             auto res = DecodePaymentAddress(address);
             if (IsValidPaymentAddress(res, branchId)) {
This page took 0.042718 seconds and 4 git commands to generate.