text: // Copyright (c) 2010 Satoshi Nakamoto
  // Copyright (c) 2009-2012 The Bitcoin developers
  // Distributed under the MIT/X11 software license, see the accompanying
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  
  #include "assert.h"
  
  #include "chainparams.h"
  #include "main.h"
  #include "util.h"
  
  #include <boost/assign/list_of.hpp>
  
  using namespace boost::assign;
  
  struct SeedSpec6 {
      uint8_t addr[16];
      uint16_t port;
  };
  
  #include "chainparamsseeds.h"
  
  //
  // Main network
  //
  
  // Convert the pnSeeds6 array into usable address objects.
  static void convertSeed6(std::vector<CAddress> &vSeedsOut, const SeedSpec6 *data, unsigned int count)
  {
      // It'll only connect to one or two seed nodes because once it connects,
      // it'll get a pile of addresses with newer timestamps.
      // Seed nodes are given a random 'last seen time' of between one and two
      // weeks ago.
      const int64_t nOneWeek = 7*24*60*60;
      for (unsigned int i = 0; i < count; i++)
      {
          struct in6_addr ip;
          memcpy(&ip, data[i].addr, sizeof(ip));
          CAddress addr(CService(ip, data[i].port));
          addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
          vSeedsOut.push_back(addr);
      }
  }
  
  class CMainParams : public CChainParams {
  public:
      CMainParams() {
          // 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 4-byte int at any alignment.
          pchMessageStart[0] = 0xa3;
          pchMessageStart[1] = 0x82;
          pchMessageStart[2] = 0xf5;
          pchMessageStart[3] = 0x53;
          vAlertPubKey = ParseHex("04cdd273904fee60d22ac8b52ebbb77e82b9acb37a134c83531987f3f0ee4291d0047ae55edeb2609d57e0200aba8297bf343384db4ed2cbaff1668921109ed8e0");
          nDefaultPort = 48200;
          nRPCPort = 48210;
          bnProofOfWorkLimit = CBigNum(~uint256(0) >> 20);
  
          const char* pszTimestamp = "yeee harrrr, The revolution of PoW/PoS";
          std::vector<CTxIn> vin;
          std::vector<CTxOut> vout;
          vin.resize(1);
          vout.resize(1);
          vin[0].scriptSig = CScript() << 0 << CBigNum(42) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
          vout[0].nValue = 0;
          vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
          CTransaction txNew(1, 1528305090, vin, vout, 0);
          genesis.vtx.push_back(txNew);
          genesis.hashPrevBlock = 0;
          genesis.hashMerkleRoot = genesis.BuildMerkleTree();
          genesis.nVersion = 1;
          genesis.nTime    = 1528305090;
          genesis.nBits    = bnProofOfWorkLimit.GetCompact();
          genesis.nNonce   = 161065;
  
          //MineGenesis(genesis);
  
          hashGenesisBlock = genesis.GetHash();
  
          assert(hashGenesisBlock == uint256("0xa476df1c24885975eb230daee528a92e2f391f16dfa9ff70b045ce5da1e0ea1b"));
          assert(genesis.hashMerkleRoot == uint256("0xf6fa9e38aa1497570395972da17a82998410db6beed782e1fbfa02e11bd2a85f"));
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, 63); // S
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1, 125); // s
          base58Prefixes[SECRET_KEY] =     std::vector<unsigned char>(1, 45); // K
          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> >();
  
          convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main));
  
          nLastPOWBlock = 1000;
      }
  
      virtual const CBlock& GenesisBlock() const { return genesis; }
      virtual Network NetworkID() const { return CChainParams::MAIN; }
  
      virtual const vector<CAddress>& FixedSeeds() const {
          return vFixedSeeds;
      }
  protected:
      CBlock genesis;
      vector<CAddress> vFixedSeeds;
  };
  static CMainParams mainParams;
  
  
  //
  // Testnet
  //
  
  class CTestNetParams : public CMainParams {
  public:
      CTestNetParams() {
          // 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 4-byte int at any alignment.
          pchMessageStart[0] = 0xb7;
          pchMessageStart[1] = 0x57;
          pchMessageStart[2] = 0x27;
          pchMessageStart[3] = 0xf9;
          bnProofOfWorkLimit = CBigNum(~uint256(0) >> 16);
          vAlertPubKey = ParseHex("04c629dd47950d15c4f63db4e67247335e09dec8b4ca4c157a23858e2503709e5fe3ba75d5b5263b046ae4b20af135a4dc79e66123ad9a15e65a98798bfee60724");
          nDefaultPort = 48300;
          nRPCPort = 48310;
          strDataDir = "testnet";
  
          // Modify the testnet genesis block so the timestamp is valid for a later start.
          genesis.nBits  = bnProofOfWorkLimit.GetCompact();
          genesis.nNonce = 58158;
  
  
  
          hashGenesisBlock = genesis.GetHash();
  
          //assert(hashGenesisBlock == uint256("0x0000c13a52f2b21b7559227d797c4d1e21c3f55fbd1b0dc565e30b87fad06f23"));
  
          vFixedSeeds.clear();
          vSeeds.clear();
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, 63); // S
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1, 125); // s
          base58Prefixes[SECRET_KEY]     = std::vector<unsigned char>(1, 58); // Q
          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> >();
  
          convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test));
  
          nLastPOWBlock = 0x7fffffff;
      }
      virtual Network NetworkID() const { return CChainParams::TESTNET; }
  };
  static CTestNetParams testNetParams;
  
  
  //
  // Regression test
  //
  class CRegTestParams : public CTestNetParams {
  public:
      CRegTestParams() {
          pchMessageStart[0] = 0x73;
          pchMessageStart[1] = 0xa7;
          pchMessageStart[2] = 0xf4;
          pchMessageStart[3] = 0xae;
          bnProofOfWorkLimit = CBigNum(~uint256(0) >> 1);
          genesis.nTime = 1520529257;
          genesis.nBits  = bnProofOfWorkLimit.GetCompact();
          genesis.nNonce = 0;
          hashGenesisBlock = genesis.GetHash();
          nDefaultPort = 18444;
          strDataDir = "regtest";
  
  
  
  
  
  
          //assert(hashGenesisBlock == uint256("0x3cb5bd88bf8eeb1c58fd9d40edf39e3f85043987af257622c4b6069349a77a08"));
  
          vSeeds.clear();  // Regtest mode doesn't have any DNS seeds.
      }
  
      virtual bool RequireRPCPassword() const { return false; }
      virtual Network NetworkID() const { return CChainParams::REGTEST; }
  };
  static CRegTestParams regTestParams;
  
  static CChainParams *pCurrentParams = &mainParams;
  
  const CChainParams &Params() {
      return *pCurrentParams;
  }
  
  void SelectParams(CChainParams::Network network) {
      switch (network) {
          case CChainParams::MAIN:
              pCurrentParams = &mainParams;
              break;
          case CChainParams::TESTNET:
              pCurrentParams = &testNetParams;
              break;
          case CChainParams::REGTEST:
              pCurrentParams = &regTestParams;
              break;
          default:
              assert(false && "Unimplemented network");
              return;
      }
  }
  
  bool SelectParamsFromCommandLine() {
      bool fRegTest = GetBoolArg("-regtest", false);
      bool fTestNet = GetBoolArg("-testnet", false);
  
      if (fTestNet && fRegTest) {
          return false;
      }
  
      if (fRegTest) {
          SelectParams(CChainParams::REGTEST);
      } else if (fTestNet) {
          SelectParams(CChainParams::TESTNET);
      } else {
          SelectParams(CChainParams::MAIN);
      }
      return true;
  }
  