text: // Copyright (c) 2010 Satoshi Nakamoto
  // Copyright (c) 2009-2015 The Bitcoin Core developers
  // Distributed under the MIT software license, see the accompanying
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  
  #include "chainparams.h"
  #include "consensus/merkle.h"
  
  #include "tinyformat.h"
  #include "util.h"
  #include "utilstrencodings.h"
  
  #include <assert.h>
  
  #include <boost/assign/list_of.hpp>
  
  #include "chainparamsseeds.h"
  
  static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
  {
      CMutableTransaction txNew;
      txNew.nVersion = 1;
      txNew.vin.resize(1);
      txNew.vout.resize(1);
      txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
      txNew.vout[0].nValue = genesisReward;
      txNew.vout[0].scriptPubKey = genesisOutputScript;
  
      CBlock genesis;
      genesis.nTime    = nTime;
      genesis.nBits    = nBits;
      genesis.nNonce   = nNonce;
      genesis.nVersion = nVersion;
      genesis.vtx.push_back(txNew);
      genesis.hashPrevBlock.SetNull();
      genesis.hashMerkleRoot = BlockMerkleRoot(genesis);
      return genesis;
  }
  
  /**
   * Build the genesis block. Note that the output of its generation
   * transaction cannot be spent since it did not originally exist in the
   * database.
   *
   * CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
   *   CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
   *     CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
   *     CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
   *   vMerkleTree: 4a5e1e
   */
  static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
  {
      const char* pszTimestamp = "Mtgox is down";
      const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
      return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
  }
  
  /**
   * Main network
   */
  /**
   * What makes a good checkpoint block?
   * + Is surrounded by blocks with reasonable timestamps
   *   (no blocks before with a timestamp after, none after with
   *    timestamp before)
   * + Contains no strange transactions
   */
  
  class CMainParams : public CChainParams {
  public:
      CMainParams() {
          strNetworkID = "main";
          consensus.nSubsidyHalvingInterval = 150000;
          consensus.nMajorityEnforceBlockUpgrade = 4750;
          consensus.nMajorityRejectBlockOutdated = 5750; // 4 days=5760 blocks - 10 possible v2//
          consensus.nMajorityWindow = 1000;
          consensus.BIP34Height = 1;
          consensus.BIP34Hash = uint256S("0x0000000008ac706f854f85867e7056561218ef6564016143187f86f5190d6431");
          consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
          consensus.nPowTargetTimespan1 = 18000; 
  	consensus.nPowTargetTimespan2 = 120;
  	consensus.nPowRetargetBlockStart = 1086560;
          consensus.nPowTargetSpacing = 60;
          consensus.fPowAllowMinDifficultyBlocks = false;
          consensus.fPowNoRetargeting = false;
          /** 
           * The message start string is designed to be unlikely to occur in normal data.
           * The characters are rarely used upper ASCII, not valid as UTF-8, and produce
           * a large 32-bit integer with any alignment.
           */
          pchMessageStart[0] = 0xf9;
          pchMessageStart[1] = 0xbe;
          pchMessageStart[2] = 0xb4;
          pchMessageStart[3] = 0xd9;
          vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
          nDefaultPort = 11080;
          nMaxTipAge = 24 * 60 * 60;
          nPruneAfterHeight = 100000;
  
          genesis = CreateGenesisBlock(1411421930, 2552177790, 0x1d00ffff, 1, 50 * COIN);
          consensus.hashGenesisBlock = genesis.GetHash();
          assert(consensus.hashGenesisBlock == uint256S("0x0000000040a867146dcc50bee85f69ac20addc33080c2a769c01200920251955"));
          assert(genesis.hashMerkleRoot == uint256S("0xa99c7c572f07503bb52506cc6bcc18a0653d78c9c34fd7b576fe093723554bac"));
  
          vSeeds.push_back(CDNSSeedData("seed.cointech.net", "seed.cointech.net"));
          vSeeds.push_back(CDNSSeedData("seed.aurumcoin-au.com", "seed.aurumcoin-au.com")); 
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
          base58Prefixes[SECRET_KEY] =     std::vector<unsigned char>(1,128);
          base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >();
          base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();
  
          vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
  
          fMiningRequiresPeers = true;
          fDefaultConsistencyChecks = false;
          fRequireStandard = true;
          fMineBlocksOnDemand = false;
          fTestnetToBeDeprecatedFieldRPC = false;
  
          checkpointData = (CCheckpointData) {
              boost::assign::map_list_of
              ( 0, uint256S("0x0000000040a867146dcc50bee85f69ac20addc33080c2a769c01200920251955"))
              ( 11111, uint256S("0x0000000000000d6b76dde5f12fdac760ec311594f768d2fe5aea29c613bf7ee8"))
              ( 44444, uint256S("0x000000000000453b26bdf521d4c0a209d914f9400d1f91fdada6eb2c121efddd"))
              ( 333333, uint256S("0x000000000008192966bcd41ea78df8758f85c529f7b5d298f4dd64e8df8c839f"))
              ( 777777, uint256S("0x00000000000155f34faa2798bbbb32f9446a993064a682f1326625ce205e54be"))
              ( 1079955, uint256S("0x000000000000006e986566d60f6d46ec1cbf2888967bc8ed0395b73170198511")), 
              1525602406, // * UNIX timestamp of last checkpoint block
              1182376,   // * total number of transactions between genesis and last checkpoint
                          //   (the tx=... number in the SetBestChain debug.log lines)
              60000.0     // * estimated number of transactions per day after checkpoint
          };
      }
  };
  static CMainParams mainParams;
  
  /**
   * Testnet (v3)
   */
  class CTestNetParams : public CChainParams {
  public:
      CTestNetParams() {
          strNetworkID = "test";
          consensus.nSubsidyHalvingInterval = 150000;
          consensus.nMajorityEnforceBlockUpgrade = 51;
          consensus.nMajorityRejectBlockOutdated = 75;
          consensus.nMajorityWindow = 100;
          consensus.BIP34Height = -1;
          consensus.BIP34Hash = uint256();
          consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
          consensus.nPowTargetTimespan1 = 18000; // 
          consensus.nPowTargetTimespan2 = 18000; // 
          consensus.nPowRetargetBlockStart = 1086560;
          consensus.nPowTargetSpacing =  60;
          consensus.fPowAllowMinDifficultyBlocks = true;
          consensus.fPowNoRetargeting = false;
          pchMessageStart[0] = 0x0b;
          pchMessageStart[1] = 0x11;
          pchMessageStart[2] = 0x09;
          pchMessageStart[3] = 0x07;
          vAlertPubKey = ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");
          nDefaultPort = 5744;
          nMaxTipAge = 0x7fffffff;
          nPruneAfterHeight = 1000;
  
          genesis = CreateGenesisBlock(1411421930, 2552177790, 0x1d00ffff, 1, 50 * COIN);
          consensus.hashGenesisBlock = genesis.GetHash();
          assert(consensus.hashGenesisBlock == uint256S("0x0000000040a867146dcc50bee85f69ac20addc33080c2a769c01200920251955"));
          assert(genesis.hashMerkleRoot == uint256S("0xa99c7c572f07503bb52506cc6bcc18a0653d78c9c34fd7b576fe093723554bac"));
  
          vFixedSeeds.clear();
          vSeeds.clear();
          vSeeds.push_back(CDNSSeedData("zetool.cointech.net", "zetool.cointech.net"));
          vSeeds.push_back(CDNSSeedData("seed.cointech.net", "seed.cointech.net"));
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
          base58Prefixes[SECRET_KEY] =     std::vector<unsigned char>(1,239);
          base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
          base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
  
          vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
  
          fMiningRequiresPeers = true;
          fDefaultConsistencyChecks = false;
          fRequireStandard = false;
          fMineBlocksOnDemand = false;
          fTestnetToBeDeprecatedFieldRPC = true;
  
          checkpointData = (CCheckpointData) {
              boost::assign::map_list_of
              ( 546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")),
              1337966069,
              1488,
              300
          };
  
      }
  };
  static CTestNetParams testNetParams;
  
  /**
   * Regression test
   */
  class CRegTestParams : public CChainParams {
  public:
      CRegTestParams() {
          strNetworkID = "regtest";
          consensus.nSubsidyHalvingInterval = 150;
          consensus.nMajorityEnforceBlockUpgrade = 750;
          consensus.nMajorityRejectBlockOutdated = 950;
          consensus.nMajorityWindow = 1000;
          consensus.BIP34Height = -1; // BIP34 has not necessarily activated on regtest
          consensus.BIP34Hash = uint256();
          consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
          consensus.nPowTargetTimespan1 = 18000; 
          consensus.nPowTargetTimespan2 = 18000;
          consensus.nPowRetargetBlockStart = 1086560;
          consensus.nPowTargetSpacing = 60;
          consensus.fPowAllowMinDifficultyBlocks = true;
          consensus.fPowNoRetargeting = true;
  
          pchMessageStart[0] = 0xfa;
          pchMessageStart[1] = 0xbf;
          pchMessageStart[2] = 0xb5;
          pchMessageStart[3] = 0xda;
          nMaxTipAge = 24 * 60 * 60;
          nDefaultPort = 5744;
          nPruneAfterHeight = 1000;
  
          genesis = CreateGenesisBlock(1411421930, 2552177790, 0x1d00ffff, 1, 50 * COIN);
          consensus.hashGenesisBlock = genesis.GetHash();
          assert(consensus.hashGenesisBlock == uint256S("0x0000000040a867146dcc50bee85f69ac20addc33080c2a769c01200920251955"));
          assert(genesis.hashMerkleRoot == uint256S("0xa99c7c572f07503bb52506cc6bcc18a0653d78c9c34fd7b576fe093723554bac"));
  
          vFixedSeeds.clear(); //! Regtest mode doesn't have any fixed seeds.
          vSeeds.clear();  //! Regtest mode doesn't have any DNS seeds.
  
          fMiningRequiresPeers = false;
          fDefaultConsistencyChecks = true;
          fRequireStandard = false;
          fMineBlocksOnDemand = true;
          fTestnetToBeDeprecatedFieldRPC = false;
  
          checkpointData = (CCheckpointData){
              boost::assign::map_list_of
              ( 0, uint256S("0000000040a867146dcc50bee85f69ac20addc33080c2a769c01200920251955")),
              0,
              0,
              0
          };
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
          base58Prefixes[SECRET_KEY] =     std::vector<unsigned char>(1,239);
          base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
          base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
      }
  };
  static CRegTestParams regTestParams;
  
  static CChainParams *pCurrentParams = 0;
  
  const CChainParams &Params() {
      assert(pCurrentParams);
      return *pCurrentParams;
  }
  
  CChainParams& Params(const std::string& chain)
  {
      if (chain == CBaseChainParams::MAIN)
              return mainParams;
      else if (chain == CBaseChainParams::TESTNET)
              return testNetParams;
      else if (chain == CBaseChainParams::REGTEST)
              return regTestParams;
      else
          throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
  }
  
  void SelectParams(const std::string& network)
  {
      SelectBaseParams(network);
      pCurrentParams = &Params(network);
  }
  