From 9f4ea3d03fef13ed8bb392ca1b4c60d06f94f912 Mon Sep 17 00:00:00 2001 From: instagibbs Date: Mon, 15 Aug 2016 11:06:05 -0400 Subject: [PATCH] Add parent genesis hash to chainparams, simplify checks --- src/chainparams.cpp | 6 ++++-- src/chainparams.h | 2 ++ src/validation.cpp | 8 ++------ src/wallet/rpcwallet.cpp | 8 +++++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 4552dc0180..ec16b29843 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -107,8 +107,8 @@ public: CScript scriptChallenge(CScript() << OP_2 << ParseHex("03206b45265ae687dfdc602b8faa7dd749d7865b0e51f986e12c532229f0c998be") << ParseHex("0204c6be425356d9200a3303d95f2c39078cc9473ca49619da1e0ec233f27516ca") << ParseHex("02cc276552e180061f64dc16e2a02e7f9ecbcc744dea84eddbe991721824df825c") << OP_3 << OP_CHECKMULTISIG); - uint256 genesisBlockHash(uint256S("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943")); - CScript scriptDestination(CScript() << std::vector(genesisBlockHash.begin(), genesisBlockHash.end()) << OP_WITHDRAWPROOFVERIFY); + parentGenesisBlockHash = uint256S("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"); + CScript scriptDestination(CScript() << std::vector(parentGenesisBlockHash.begin(), parentGenesisBlockHash.end()) << OP_WITHDRAWPROOFVERIFY); genesis = CreateGenesisBlock(strNetworkID.c_str(), scriptDestination, 1231006505, scriptChallenge, 1, MAX_MONEY, 100); consensus.hashGenesisBlock = genesis.GetHash(); @@ -206,6 +206,8 @@ public: genesis = CreateGenesisBlock(strNetworkID.c_str(), scriptDestination, 1296688602, scriptDestination, 1, MAX_MONEY, 100); consensus.hashGenesisBlock = genesis.GetHash(); + parentGenesisBlockHash = uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"); + scriptCoinbaseDestination = CScript(); // Allow any coinbase destination vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds. diff --git a/src/chainparams.h b/src/chainparams.h index 94512722bf..6e8d5054ef 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -68,6 +68,7 @@ public: int GetDefaultPort() const { return nDefaultPort; } const CBlock& GenesisBlock() const { return genesis; } + const uint256 ParentGenesisBlockHash() const { return parentGenesisBlockHash; } /** Make miner wait to have peers to avoid wasting work */ bool MiningRequiresPeers() const { return fMiningRequiresPeers; } /** Default value for -checkmempool and -checkblockindex argument */ @@ -98,6 +99,7 @@ protected: std::vector base58Prefixes[MAX_BASE58_TYPES]; std::string strNetworkID; CBlock genesis; + uint256 parentGenesisBlockHash; std::vector vFixedSeeds; bool fMiningRequiresPeers; bool fDefaultConsistencyChecks; diff --git a/src/validation.cpp b/src/validation.cpp index d84cfdb188..6651d953e9 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2091,12 +2091,8 @@ bool BitcoindRPCCheck(bool init) return false; } UniValue result = reply["result"]; - if (GetBoolArg("-testnet", false) && result.isStr() && result.get_str() != "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943") { //FIXME: Stick parent chain(s) genesis in chainparams - LogPrintf("ERROR: Invalid parent genesis block hash response via RPC. Contacting wrong parent daemon?"); - return false; - } - if (GetBoolArg("-regtest", false) && result.isStr() && result.get_str() != "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206") { - LogPrintf("ERROR: Invalid parent genesis block hash response via RPC. Contacting wrong parent daemon?"); + if (!result.isStr() || result.get_str() != Params().ParentGenesisBlockHash().GetHex()) { + LogPrintf("ERROR: Invalid parent genesis block hash response via RPC. Contacting wrong parent daemon?\n"); return false; } } catch (const std::runtime_error& re) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 61a9eb9dfa..b3f405db51 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -24,7 +24,7 @@ #include "wallet.h" #include "walletdb.h" #include "merkleblock.h" - +#include "chainparams.h" #include #include @@ -41,8 +41,6 @@ static CCriticalSection cs_nWalletUnlockTime; //Redeemscript template for alpha fedpeg static const CScript fedRedeemScript(CScript() << OP_2 << ParseHex("02d51090b27ca8f1cc04984614bd749d8bab6f2a3681318d3fd0dd43b2a39dd774") << ParseHex("034c55bede1bce8e486080f8ebb7a0e8f106b49efb295a8314da0e1b1723738c66") << ParseHex("03a75bd7ac458b19f98047c76a6ffa442e592148c5d23a1ec82d379d5d558f4fd8") << OP_3 << OP_CHECKMULTISIG); -static uint256 genesisBlockHash(uint256S("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943")); - std::string HelpRequiringPassphrase() { return pwalletMain && pwalletMain->IsCrypted() @@ -3284,6 +3282,8 @@ UniValue sendtomainchain(const JSONRPCRequest& request) hex.push_back((unsigned char)'H'); hex.insert(hex.end(), vData.begin(), vData.end()); + uint256 genesisBlockHash = Params().ParentGenesisBlockHash(); + scriptPubKey << hex; scriptPubKey << OP_DROP; scriptPubKey << std::vector(genesisBlockHash.begin(), genesisBlockHash.end()); @@ -3381,6 +3381,8 @@ UniValue claimpegin(const JSONRPCRequest& request) throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to find output in bitcoinTx to the mainaddress from getpeginaddress"); CAmount value = txBTC.vout[nOut].nValue.GetAmount(); + uint256 genesisBlockHash = Params().ParentGenesisBlockHash(); + //Output we're re-locking CScript relock_spk; relock_spk << std::vector(genesisBlockHash.begin(), genesisBlockHash.end());