text: // Copyright (c) 2010 Satoshi Nakamoto
  // Copyright (c) 2009-2014 The Bitcoin developers
  // Copyright (c) 2014-2015 The Dash developers
  // Copyright (c) 2015-2019 The PIVX developers
  // Distributed under the MIT software license, see the accompanying
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  
  #include "libzerocoin/Params.h"
  #include "chainparams.h"
  #include "random.h"
  #include "util.h"
  #include "utilstrencodings.h"
  
  #include <assert.h>
  
  #include <boost/assign/list_of.hpp>
  
  using namespace std;
  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);
      }
  }
  
  //   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
  static Checkpoints::MapCheckpoints mapCheckpoints =
      boost::assign::map_list_of
      (0, uint256("0000049b84c6e87ca522c05b4c5aa88b1b87bd683639e4394ef6dfd00edc4a7b"));
  static const Checkpoints::CCheckpointData data = {
      &mapCheckpoints,
      1576256114, // * UNIX timestamp of last checkpoint block
      0,    // * total number of transactions between genesis and last checkpoint
                  //   (the tx=... number in the SetBestChain debug.log lines)
      0        // * estimated number of transactions per day after checkpoint
  };
  
  static Checkpoints::MapCheckpoints mapCheckpointsTestnet =
      boost::assign::map_list_of
      (0, uint256("0x001"));
  static const Checkpoints::CCheckpointData dataTestnet = {
      &mapCheckpointsTestnet,
      1576256114,
      0,
      0};
  
  static Checkpoints::MapCheckpoints mapCheckpointsRegtest =
      boost::assign::map_list_of(0, uint256("0x001"));
  static const Checkpoints::CCheckpointData dataRegtest = {
      &mapCheckpointsRegtest,
      1576256114,
      0,
      0};
  
  libzerocoin::ZerocoinParams* CChainParams::Zerocoin_Params(bool useModulusV1) const
  {
      assert(this);
      static CBigNum bnHexModulus = 0;
      if (!bnHexModulus)
          bnHexModulus.SetHex(zerocoinModulus);
      static libzerocoin::ZerocoinParams ZCParamsHex = libzerocoin::ZerocoinParams(bnHexModulus);
      static CBigNum bnDecModulus = 0;
      if (!bnDecModulus)
          bnDecModulus.SetDec(zerocoinModulus);
      static libzerocoin::ZerocoinParams ZCParamsDec = libzerocoin::ZerocoinParams(bnDecModulus);
  
      if (useModulusV1)
          return &ZCParamsHex;
  
      return &ZCParamsDec;
  }
  
  class CMainParams : public CChainParams
  {
  public:
      CMainParams()
      {
          networkID = CBaseChainParams::MAIN;
          strNetworkID = "main";
          /**
           * 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] = 0xbd;
          pchMessageStart[1] = 0xe9;
          pchMessageStart[2] = 0x81;
          pchMessageStart[3] = 0xbb;
          vAlertPubKey = ParseHex("04c1b9574272a51a63f4745bfda48b7acea9ce85b2a91e498c03a562ee449a954ca9ad0982b79a54ec4ed25c597dae2b9db39f5c15ad40e6829c63f1bb89032b12");
          nDefaultPort = 14780;
          bnProofOfWorkLimit = ~uint256(0) >> 20; // Novacash starting difficulty is 1 / 2^12
          nSubsidyHalvingInterval = 210000;
          nMaxReorganizationDepth = 100;
          nEnforceBlockUpgradeMajority = 8100; // 75%
          nRejectBlockOutdatedMajority = 10260; // 95%
          nToCheckBlockUpgradeMajority = 10800; // Approximate expected amount of blocks in 7 days (1440*7.5)
          nMinerThreads = 0;
          nTargetTimespan = 10 * 60;
          nTargetSpacing = 1 * 60;
          nMaturity = 20;
          nMasternodeCountDrift = 20;
          nMaxMoneyOut = 9999999999 * COIN;
  
          /** Height or Time Based Activations **/
          nLastPOWBlock = 1000;
          nModifierUpdateBlock = 0;
          nZerocoinStartHeight = 0;
          nZerocoinStartTime = 1576256114;
          nBlockEnforceSerialRange = 1; //Enforce serial range starting this block
          nBlockRecalculateAccumulators = 999999999; //Trigger a recalculation of accumulators
          nBlockFirstFraudulent = 999999999; //First block that bad serials emerged
          nBlockLastGoodCheckpoint = 999999999; //Last valid accumulator checkpoint
          nBlockEnforceInvalidUTXO = 999999999; //Start enforcing the invalid UTXO's
          nInvalidAmountFiltered = 0; //Amount of invalid coins filtered through exchanges, that should be considered valid
          nBlockZerocoinV2 = 999999999;
          nBlockDoubleAccumulated = 999999999;
          nEnforceNewSporkKey = 1576256114;
          nRejectOldSporkKey = 1527811200; 
  
          // Public coin spend enforcement
          nPublicZCSpends = 1;
  
          // Fake Serial Attack
          nFakeSerialBlockheightEnd = 0;
          nSupplyBeforeFakeSerial = 0;   // zerocoin supply at block nFakeSerialBlockheightEnd
  
          /**
           * Build the genesis block. Note that the output of the genesis coinbase cannot
           * be spent as it did not originally exist in the database.
           *
           * CBlock(hash=00000ffd590b14, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=e0028e, nTime=1390095618, nBits=1e0ffff0, nNonce=28917698, vtx=1)
           *   CTransaction(hash=e0028e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
           *     CTxIn(COutPoint(000000, -1), coinbase 04fff0000049b84c6e87ca522c05b4c5aa88b1b87bd683639e4394ef6dfd00edc4a7bd01044c5957697265642030392f4a616e2f3230313420546865204772616e64204578706572696d656e7420476f6573204c6976653a204f76657273746f636b2e636f6d204973204e6f7720416363657074696e6720426974636f696e73)
           *     CTxOut(nValue=50.00000000, scriptPubKey=0xA9037BAC7050C479B121CF)
           *   vMerkleTree: e0028e
           */
          const char* pszTimestamp = "Die Tochter des Jaegers";
          CMutableTransaction txNew;
          txNew.vin.resize(1);
          txNew.vout.resize(1);
          txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
          txNew.vout[0].nValue = 50 * COIN;
          txNew.vout[0].scriptPubKey = CScript() << ParseHex("04b3df135d6719e3354e1472c1d411fcf62c0e66ca39d84f9d752a5d06a4f9d823573ac5f993b38e8fad93ca1cbcfa8c84d2d6ce118b0f109f77005a59f7f62f81") << OP_CHECKSIG;
          genesis.vtx.push_back(txNew);
          genesis.hashPrevBlock = 0;
          genesis.hashMerkleRoot = genesis.BuildMerkleTree();
          genesis.nVersion = 1;
          genesis.nTime = 1576256114;
          genesis.nBits = 0x1e0ffff0;
          genesis.nNonce = 23260184;
  
          hashGenesisBlock = genesis.GetHash();
          assert(hashGenesisBlock == uint256("0x0000049b84c6e87ca522c05b4c5aa88b1b87bd683639e4394ef6dfd00edc4a7b"));
          assert(genesis.hashMerkleRoot == uint256("0x9f80784978e0cd6e756f612931b8cdb5c3f36cb8d7ff2e40ce46ba5ba85103fd"));
  
          vSeeds.push_back(CDNSSeedData("novabit.cash", "node01.novabit.cash"));
          vSeeds.push_back(CDNSSeedData("n2.novabit.cash", "node02.novabit.cash"));
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, 53);
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1, 54);
          base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1, 181);
          base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x02)(0x2D)(0x25)(0x33).convert_to_container<std::vector<unsigned char> >();
          base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x02)(0x21)(0x31)(0x2B).convert_to_container<std::vector<unsigned char> >();
          // 	BIP44 coin type is from https://github.com/satoshilabs/slips/blob/master/slip-0044.md
          base58Prefixes[EXT_COIN_TYPE] = boost::assign::list_of(0x80)(0x00)(0x00)(0x77).convert_to_container<std::vector<unsigned char> >();
  
          convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main));
  
          fMiningRequiresPeers = true;
          fAllowMinDifficultyBlocks = false;
          fDefaultConsistencyChecks = false;
          fRequireStandard = true;
          fMineBlocksOnDemand = false;
          fSkipProofOfWorkCheck = false;
          fTestnetToBeDeprecatedFieldRPC = false;
          fHeadersFirstSyncingActive = false;
  
          nPoolMaxTransactions = 3;
          nBudgetCycleBlocks = 43200;
          strSporkKey = "04d9173bd822e59adf07405dfffdd040c8c54c57cf7cf3a627f6db0f8ba988df3111350d10e17042f3640bb29392c092ca38dfb8b508f77dd40656fe280a043877";
          strSporkKeyOld = "04B433E6598390C992F4F022F20D3B4CBBE691652EE7C48243B81701CBDB7CC7D7BF0EE09E154E6FCBF2043D65AF4E9E97B89B5DBAF830D83B9B7F469A6C45A717";
          strObfuscationPoolDummyAddress = "NX8ZaNgAqvCG21GD1fFjCwDQGXsCB5bjrt";
          nStartMasternodePayments = 1576256114;
  
          /** Zerocoin */
          zerocoinModulus = "25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784"
              "4069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911"
              "6507761337985909570009733045974880842840179742910064245869181719511874612151517265463228221686998754918242243363"
              "7259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133"
              "8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548"
              "31438167899885040445364023527381951378636564391212010397122822120720357";
          nMaxZerocoinSpendsPerTransaction = 7; // Assume about 20kb each
          nMaxZerocoinPublicSpendsPerTransaction = 637; // Assume about 220 bytes each input
          nMinZerocoinMintFee = 1 * CENT; //high fee required for zerocoin mints
          nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19
          nRequiredAccumulation = 1;
          nDefaultSecurityLevel = 100; //full security level for accumulators
          nZerocoinHeaderVersion = 4; //Block headers must be this version once zerocoin is active
          nZerocoinRequiredStakeDepth = 200; //The required confirmations for a znova to be stakable
  
          nBudget_Fee_Confirmations = 6; // Number of confirmations for the finalization fee
          nProposalEstablishmentTime = 60 * 60 * 24; // Proposals must be at least a day old to make it into a budget
      }
  
      const Checkpoints::CCheckpointData& Checkpoints() const
      {
          return data;
      }
  };
  static CMainParams mainParams;
  
  /**
   * Testnet (v3)
   */
  class CTestNetParams : public CMainParams
  {
  public:
      CTestNetParams()
      {
          networkID = CBaseChainParams::TESTNET;
          strNetworkID = "test";
          pchMessageStart[0] = 0x7e;
          pchMessageStart[1] = 0x13;
          pchMessageStart[2] = 0x83;
          pchMessageStart[3] = 0x16;
          vAlertPubKey = ParseHex("04d377c438c713ece769b7aa9487a968c24ec0d20934723113199bc40096c065f4fbacee75d984755ea7683a216a5a421fbda383f5a981b46b946254397da867c6");
          nDefaultPort = 24780;
          nEnforceBlockUpgradeMajority = 4860; // 75%
          nRejectBlockOutdatedMajority = 6156; // 95%
          nToCheckBlockUpgradeMajority = 6480; // 4 days
          nMinerThreads = 0;
          nTargetTimespan = 10 * 60;
          nTargetSpacing = 1 * 60;
          nLastPOWBlock = 200;
          nMaturity = 15;
          nMasternodeCountDrift = 4;
          nModifierUpdateBlock = 0;
          nMaxMoneyOut = 43199500 * COIN;
          nZerocoinStartHeight = 0;
          nZerocoinStartTime = 1576256114;
          nBlockEnforceSerialRange = 1; //Enforce serial range starting this block
          nBlockRecalculateAccumulators = 999999999; //Trigger a recalculation of accumulators
          nBlockFirstFraudulent = 999999999; //First block that bad serials emerged
          nBlockLastGoodCheckpoint = 999999999; //Last valid accumulator checkpoint
          nBlockEnforceInvalidUTXO = 999999999; //Start enforcing the invalid UTXO's
          nInvalidAmountFiltered = 0; //Amount of invalid coins filtered through exchanges, that should be considered valid
          nBlockZerocoinV2 = 999999999; //!> The block that zerocoin v2 becomes active
          nEnforceNewSporkKey = 1576256114;
          nRejectOldSporkKey = 1522454400; 
  
          // Public coin spend enforcement
          nPublicZCSpends = 1;
  
          // Fake Serial Attack
          nFakeSerialBlockheightEnd = -1;
          nSupplyBeforeFakeSerial = 0;
  
          //! Modify the testnet genesis block so the timestamp is valid for a later start.
          genesis.nTime = 1576256114;
          genesis.nNonce = 23260184;
  
          hashGenesisBlock = genesis.GetHash();
          assert(hashGenesisBlock == uint256("0x0000049b84c6e87ca522c05b4c5aa88b1b87bd683639e4394ef6dfd00edc4a7b"));
  
          vFixedSeeds.clear();
          vSeeds.clear();
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, 65); 
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1, 66);  
          base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1, 193);     
          
          base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x3a)(0x80)(0x61)(0xa0).convert_to_container<std::vector<unsigned char> >();
          
          base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x3a)(0x80)(0x58)(0x37).convert_to_container<std::vector<unsigned char> >();
          // Testnet novacash BIP44 coin type is '1' (All coin's testnet default)
          base58Prefixes[EXT_COIN_TYPE] = boost::assign::list_of(0x80)(0x00)(0x00)(0x01).convert_to_container<std::vector<unsigned char> >();
  
          convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test));
  
          fMiningRequiresPeers = true;
          fAllowMinDifficultyBlocks = true;
          fDefaultConsistencyChecks = false;
          fRequireStandard = true;
          fMineBlocksOnDemand = false;
          fTestnetToBeDeprecatedFieldRPC = true;
  
          nPoolMaxTransactions = 2;
          nBudgetCycleBlocks = 144; //!< Ten cycles per day on testnet
          strSporkKey = "041985e10ebc4190162c9a3ff30694b30bef09cb58eaf2a2644037245c5dba34fd43a0b558f734f17171f407b27e5b950794ba08bedcecdd335d5197fee9c46593";
          strSporkKeyOld = "04348C2F50F90267E64FACC65BFDC9D0EB147D090872FB97ABAE92E9A36E6CA60983E28E741F8E7277B11A7479B626AC115BA31463AC48178A5075C5A9319D4A38";
          strObfuscationPoolDummyAddress = "TXLH4u3ZanUfcuoPCRwTv9L9TzQJ8KYkE3";
          nStartMasternodePayments = 1576256114;
          nBudget_Fee_Confirmations = 3; // Number of confirmations for the finalization fee. We have to make this very short
                                         // here because we only have a 8 block finalization window on testnet
  
          nProposalEstablishmentTime = 60 * 5; // Proposals must be at least 5 mns old to make it into a test budget
      }
      const Checkpoints::CCheckpointData& Checkpoints() const
      {
          return dataTestnet;
      }
  };
  static CTestNetParams testNetParams;
  
  /**
   * Regression test
   */
  class CRegTestParams : public CTestNetParams
  {
  public:
      CRegTestParams()
      {
          networkID = CBaseChainParams::REGTEST;
          strNetworkID = "regtest";
          pchMessageStart[0] = 0x40;
          pchMessageStart[1] = 0xc3;
          pchMessageStart[2] = 0xef;
          pchMessageStart[3] = 0x2f;
          nDefaultPort = 51476;
          nSubsidyHalvingInterval = 150;
          nEnforceBlockUpgradeMajority = 750;
          nRejectBlockOutdatedMajority = 950;
          nToCheckBlockUpgradeMajority = 1000;
          nMinerThreads = 1;
          nTargetTimespan = 24 * 60 * 60; // Novacash: 1 day
          nTargetSpacing = 1 * 60;        // Novacash: 1 minutes
          bnProofOfWorkLimit = ~uint256(0) >> 1;
          nLastPOWBlock = 250;
          nMaturity = 20;
          nMasternodeCountDrift = 4;
          nModifierUpdateBlock = 0; //approx Mon, 17 Apr 2017 04:00:00 GMT
          nMaxMoneyOut = 43199500 * COIN;
          nZerocoinStartHeight = 300;
          nBlockZerocoinV2 = 300;
          nZerocoinStartTime = 1576256114;
          nBlockEnforceSerialRange = 1; //Enforce serial range starting this block
          nBlockRecalculateAccumulators = 999999999; //Trigger a recalculation of accumulators
          nBlockFirstFraudulent = 999999999; //First block that bad serials emerged
          nBlockLastGoodCheckpoint = 999999999; //Last valid accumulator checkpoint
  
          // Public coin spend enforcement
          nPublicZCSpends = 350;
  
          // Fake Serial Attack
          nFakeSerialBlockheightEnd = -1;
  
          //! Modify the regtest genesis block so the timestamp is valid for a later start.
          genesis.nTime = 1576256114;
          genesis.nNonce = 23260184;
  
          hashGenesisBlock = genesis.GetHash();
          assert(hashGenesisBlock == uint256("0x0000049b84c6e87ca522c05b4c5aa88b1b87bd683639e4394ef6dfd00edc4a7b"));
          //assert(hashGenesisBlock == uint256("0x0cca4b36309492c45260e3677107ff4431796762dd02ee4e270ffb22a2d018a1"));
  
          vFixedSeeds.clear(); //! Testnet mode doesn't have any fixed seeds.
          vSeeds.clear();      //! Testnet mode doesn't have any DNS seeds.
  
          fMiningRequiresPeers = false;
          fAllowMinDifficultyBlocks = true;
          fDefaultConsistencyChecks = true;
          fRequireStandard = false;
          fMineBlocksOnDemand = true;
          fSkipProofOfWorkCheck = true;
          fTestnetToBeDeprecatedFieldRPC = false;
      }
      const Checkpoints::CCheckpointData& Checkpoints() const
      {
          return dataRegtest;
      }
  };
  static CRegTestParams regTestParams;
  
  /**
   * Unit test
   */
  class CUnitTestParams : public CMainParams, public CModifiableParams
  {
  public:
      CUnitTestParams()
      {
          networkID = CBaseChainParams::UNITTEST;
          strNetworkID = "unittest";
          nDefaultPort = 51478;
          vFixedSeeds.clear(); //! Unit test mode doesn't have any fixed seeds.
          vSeeds.clear();      //! Unit test mode doesn't have any DNS seeds.
  
          fMiningRequiresPeers = false;
          fDefaultConsistencyChecks = true;
          fAllowMinDifficultyBlocks = false;
          fMineBlocksOnDemand = true;
      }
  
      const Checkpoints::CCheckpointData& Checkpoints() const
      {
          // UnitTest share the same checkpoints as MAIN
          return data;
      }
  
      //! Published setters to allow changing values in unit test cases
      virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) { nSubsidyHalvingInterval = anSubsidyHalvingInterval; }
      virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority) { nEnforceBlockUpgradeMajority = anEnforceBlockUpgradeMajority; }
      virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority) { nRejectBlockOutdatedMajority = anRejectBlockOutdatedMajority; }
      virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority) { nToCheckBlockUpgradeMajority = anToCheckBlockUpgradeMajority; }
      virtual void setDefaultConsistencyChecks(bool afDefaultConsistencyChecks) { fDefaultConsistencyChecks = afDefaultConsistencyChecks; }
      virtual void setAllowMinDifficultyBlocks(bool afAllowMinDifficultyBlocks) { fAllowMinDifficultyBlocks = afAllowMinDifficultyBlocks; }
      virtual void setSkipProofOfWorkCheck(bool afSkipProofOfWorkCheck) { fSkipProofOfWorkCheck = afSkipProofOfWorkCheck; }
  };
  static CUnitTestParams unitTestParams;
  
  
  static CChainParams* pCurrentParams = 0;
  
  CModifiableParams* ModifiableParams()
  {
      assert(pCurrentParams);
      assert(pCurrentParams == &unitTestParams);
      return (CModifiableParams*)&unitTestParams;
  }
  
  const CChainParams& Params()
  {
      assert(pCurrentParams);
      return *pCurrentParams;
  }
  
  CChainParams& Params(CBaseChainParams::Network network)
  {
      switch (network) {
      case CBaseChainParams::MAIN:
          return mainParams;
      case CBaseChainParams::TESTNET:
          return testNetParams;
      case CBaseChainParams::REGTEST:
          return regTestParams;
      case CBaseChainParams::UNITTEST:
          return unitTestParams;
      default:
          assert(false && "Unimplemented network");
          return mainParams;
      }
  }
  
  void SelectParams(CBaseChainParams::Network network)
  {
      SelectBaseParams(network);
      pCurrentParams = &Params(network);
  }
  
  bool SelectParamsFromCommandLine()
  {
      CBaseChainParams::Network network = NetworkIdFromCommandLine();
      if (network == CBaseChainParams::MAX_NETWORK_TYPES)
          return false;
  
      SelectParams(network);
      return true;
  }
  