text: // Copyright (c) 2010 Satoshi Nakamoto
  // Copyright (c) 2009-2014 The Bitcoin developers
  // Copyright (c) 2014-2015 The Dash developers
  // Copyright (c) 2015-2017 The PIVX developers
  // Copyright (c) 2019 The LemonAd 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 "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("0x000001b69797ef267202e468c39efaedf96dd12c87e4a0f4a4f88f44f480c8d0"))//Genesis block
      (81493, uint256("0xfe723b59edc9ad0ca38c5d3241e14f7ffc9701c8d5fa22a8f40f512c7688cc4f")); 
  static const Checkpoints::CCheckpointData data = {
      &mapCheckpoints,
      1556866138, // * UNIX timestamp of last checkpoint block
      164612,    // * total number of transactions between genesis and last checkpoint
                  //   (the tx=... number in the SetBestChain debug.log lines)
      10        // * estimated number of transactions per day after checkpoint
  };
  
  static Checkpoints::MapCheckpoints mapCheckpointsTestnet =
      boost::assign::map_list_of(0, uint256("0x000004d08e006b044bf35226f5083a10ae65f145f3993fa5e02757a15d4c441a"));
  static const Checkpoints::CCheckpointData dataTestnet = {
      &mapCheckpointsTestnet,
      1551618428,
      0,
      5};
  
  static Checkpoints::MapCheckpoints mapCheckpointsRegtest =
      boost::assign::map_list_of(0, uint256("0x001"));
  static const Checkpoints::CCheckpointData dataRegtest = {
      &mapCheckpointsRegtest,
      1551618428,
      0,
      5};
  
  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] = 0x32; // L
          pchMessageStart[1] = 0x29; // A
          pchMessageStart[2] = 0x2c; // D
          pchMessageStart[3] = 0x88; // T-8
          vAlertPubKey = ParseHex("0480594b0433a2b1b08e872f43de05d5a4459de677b761132e41d202af9a93b5ea88090f5615885e89c5fe8b784039676aec0b0692c9aa9e0096e6a893777e0c81");
          nDefaultPort = 52271;
          bnProofOfWorkLimit = ~uint256(0) >> 20; // LemonAd starting difficulty is 1 / 2^12
          nSubsidyHalvingInterval = 525000;
          nMaxReorganizationDepth = 100;
          nEnforceBlockUpgradeMajority = 750;
          nRejectBlockOutdatedMajority = 950;
          nToCheckBlockUpgradeMajority = 1000;
          nMinerThreads = 0;
          nTargetTimespan = 1 * 60; // LemonAd: 1 day
          nTargetSpacing = 1 * 60;  // LemonAd: 1 minute
          nLastPOWBlock = 300;
          nMaturity = 15;
          nMasternodeCountDrift = 20;
          nModifierUpdateBlock = 615800;
          nMaxMoneyOut = 21000000 * COIN;
          nMinStakeReserve = 1;
          nStakeInputMinimal = 20 * COIN;
  
  
  	const char* pszTimestamp = "This is a message from the future: LemonAd will become a great Ad platform";
          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 = 0 * COIN;
          txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
          genesis.vtx.push_back(txNew);
          genesis.hashPrevBlock = 0;
          genesis.hashMerkleRoot = genesis.BuildMerkleTree();
          genesis.nVersion = 1;
          genesis.nBits = 0x1e0ffff0;
          
          genesis.nTime = 1551618441;
          genesis.nNonce = 1675604;
         
          hashGenesisBlock = genesis.GetHash();
          
          assert(hashGenesisBlock == uint256("0x000001b69797ef267202e468c39efaedf96dd12c87e4a0f4a4f88f44f480c8d0"));
          assert(genesis.hashMerkleRoot == uint256("0x27cebcba64aec2035345866d10cb34d90f06142bee017ea130474b25cda63eed"));
  
          //vSeeds.push_back(CDNSSeedData("68.183.65.69", "68.183.65.69"));           // Single node address
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, 48); //L
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1, 23); //A
          base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1, 30); //D
          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));
  
          fRequireRPCPassword = true;
          fMiningRequiresPeers = true;
          fAllowMinDifficultyBlocks = true;
          fDefaultConsistencyChecks = false;
          fRequireStandard = true;
          fMineBlocksOnDemand = false;
          fSkipProofOfWorkCheck = false;
          fTestnetToBeDeprecatedFieldRPC = false;
          fHeadersFirstSyncingActive = false;
  
          nPoolMaxTransactions = 3;
          strSporkKey = "0421f06143b152c47902601ca08187f719d68231f0bfb64b9aac8ef8e13d0dff1d08afe8f15ca9736becc8b396417a1e47629c079215f48ff1d7a749f93eb44a88";
          strObfuscationPoolDummyAddress = "LXdAq6yiAAHGZvLLHrazx1fV2zsxYAC4Gw";
          nStartMasternodePayments = 1550086291; //Genesis time
          
          strDevAddress = "LRi27eCZGAuSvjJzAv9938m9e6JCgbux6B";
      }
  
      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] = 0x51;
          pchMessageStart[1] = 0x5d;
          pchMessageStart[2] = 0x5a;
          pchMessageStart[3] = 0xba;
          vAlertPubKey = ParseHex("04332624f3311758c7803c2e1daa5541ea84505b25803910cf7dd974da0b5fee492f89429c403bfe79141745bc5ade083bbc43785a0f76c3d8c6e99ce1a8816cfd");
          nDefaultPort = 52272;
          nEnforceBlockUpgradeMajority = 51;
          nRejectBlockOutdatedMajority = 75;
          nToCheckBlockUpgradeMajority = 100;
          nMinerThreads = 0;
          nTargetTimespan = 1 * 60; // LemonAd: 1 day
          nTargetSpacing = 1 * 60;  // LemonAd: 1 minute
          nLastPOWBlock = 300;
          nMaturity = 15;
          nMasternodeCountDrift = 4;
          nModifierUpdateBlock = 51197; //approx Mon, 17 Apr 2017 04:00:00 GMT
          nMaxMoneyOut = 21000000 * COIN;
  
          //! Modify the testnet genesis block so the timestamp is valid for a later start.
          genesis.nTime = 1551618428;
          genesis.nNonce = 2964066;
  
          hashGenesisBlock = genesis.GetHash();
               
          assert(hashGenesisBlock == uint256("0x000004d08e006b044bf35226f5083a10ae65f145f3993fa5e02757a15d4c441a"));
  
          vFixedSeeds.clear();
          vSeeds.clear();
          
          //vSeeds.push_back(CDNSSeedData("68.183.65.69", "68.183.65.69"));
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1, 139); //L
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1, 23); //A
          base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1, 30); //D
          // Testnet lemonad BIP32 pubkeys start with 'DRKV'
          base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x3a)(0x80)(0x61)(0xa0).convert_to_container<std::vector<unsigned char> >();
          // Testnet lemonad BIP32 prvkeys start with 'DRKP'
          base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x3a)(0x80)(0x58)(0x37).convert_to_container<std::vector<unsigned char> >();
          // Testnet lemonad 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));
  
          fRequireRPCPassword = true;
          fMiningRequiresPeers = true;
          fAllowMinDifficultyBlocks = true;
          fDefaultConsistencyChecks = false;
          fRequireStandard = false;
          fMineBlocksOnDemand = false;
          fTestnetToBeDeprecatedFieldRPC = true;
  
          nPoolMaxTransactions = 2;
          strSporkKey = "0421f06143b152c47902601ca08187f719d68231f0bfb64b9aac8ef8e13d0dff1d08afe8f15ca9736becc8b396417a1e47629c079215f48ff1d7a749f93eb44a88";
          strObfuscationPoolDummyAddress = "y1XQ5Q9rNLKX2FsMuToKEQU2kgeM8c2Jrz";
          nStartMasternodePayments = 1550086371; //Fri, 09 Jan 2015 21:05:58 GMT
          
          strDevAddress = "y9v4qAD2sQCAoz1PezWkQ67jW1uvGzZZgq";
      }
      const Checkpoints::CCheckpointData& Checkpoints() const
      {
          return dataTestnet;
      }
  };
  static CTestNetParams testNetParams;
  
  /**
   * Regression test
   */
  class CRegTestParams : public CTestNetParams
  {
  public:
      CRegTestParams()
      {
          networkID = CBaseChainParams::REGTEST;
          strNetworkID = "regtest";
          strNetworkID = "regtest";
          pchMessageStart[0] = 0x51;
          pchMessageStart[1] = 0x5d;
          pchMessageStart[2] = 0x5a;
          pchMessageStart[3] = 0xba;
          nSubsidyHalvingInterval = 150;
          nEnforceBlockUpgradeMajority = 750;
          nRejectBlockOutdatedMajority = 950;
          nToCheckBlockUpgradeMajority = 1000;
          nMinerThreads = 1;
          nTargetTimespan = 24 * 60 * 60; // Lemonad: 1 day
          nTargetSpacing = 1 * 60;        // Lemonad: 1 minutes
          bnProofOfWorkLimit = ~uint256(0) >> 1;
          genesis.nTime = 1551618428;
          genesis.nBits = 0x207fffff;
          genesis.nNonce = 0;
  
          hashGenesisBlock = genesis.GetHash();
          nDefaultPort = 52275;
          
          //assert(hashGenesisBlock == uint256("0x"));
  
          vFixedSeeds.clear(); //! Testnet mode doesn't have any fixed seeds.
          vSeeds.clear();      //! Testnet mode doesn't have any DNS seeds.
  
          fRequireRPCPassword = false;
          fMiningRequiresPeers = true;
          fAllowMinDifficultyBlocks = true;
          fDefaultConsistencyChecks = true;
          fRequireStandard = false;
          fMineBlocksOnDemand = 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 = 52276;
          vFixedSeeds.clear(); //! Unit test mode doesn't have any fixed seeds.
          vSeeds.clear();      //! Unit test mode doesn't have any DNS seeds.
  
          fRequireRPCPassword = false;
          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;
  }
  