text: // Copyright (c) 2010 Satoshi Nakamoto
  // Copyright (c) 2009-2017 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 <memory>
  
  #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(MakeTransactionRef(std::move(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 = "NY times 27/03/2019,Indonesian Empathy for An-Noor Mosque";
      const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
      return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
  }
  
  void CChainParams::UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
  {
      consensus.vDeployments[d].nStartTime = nStartTime;
      consensus.vDeployments[d].nTimeout = nTimeout;
  }
  
  /**
   * 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 = 525600;
          consensus.BIP16Height = 0 ; // 87afb798a3ad9378fcd56123c81fb31cfd9a8df4719b9774d71730c16315a092 - October 1, 2012 | 218579
          consensus.BIP34Height = 0 ; // 710000
          consensus.BIP34Hash = uint256S("8726aec79f762e7db527eda310026afd0921dc2f585f0f125181b7f4fc30b1bc");
          consensus.BIP65Height = 0 ; // bab3041e8977e0dc3eeff63fe707b92bde1dd449d8efafb248c27c8264cc311a | 918684
          consensus.BIP66Height = 0 ; // 7aceee012833fa8952f8835d8b1b3ae233cd6ab08fdb27a771d2bd7bdc491894 | 811879
          consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); 
          consensus.nPowTargetTimespan = 1 * 24 * 60 * 60; // daily
          consensus.nPowTargetSpacing = 1 * 60;
          consensus.fPowAllowMinDifficultyBlocks = false;
          consensus.fPowNoRetargeting = false;
          consensus.nRuleChangeActivationThreshold = std::ceil(consensus.nMinerConfirmationWindow * 0.95); //6048; // 75% of 8064
          consensus.nMinerConfirmationWindow = consensus.nPowTargetTimespan / consensus.nPowTargetSpacing; //8064; // nPowTargetTimespan / nPowTargetSpacing * 4
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 11553913419; // Maret 30, 2019
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1585535915; // Maret 30, 2020
  
          // Deployment of BIP68, BIP112, and BIP113.
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 11553913419; // Maret 30, 2019
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1585535915; // Maret 30, 2020
  
          // Deployment of SegWit (BIP141, BIP143, and BIP147)
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 11553913419; // Maret 30, 2019
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1585535915; // Maret 30, 2020
  
          // The best chain should have at least this much work.
          consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000");
  
  
          // By default assume that the signatures in ancestors of this block are valid.
          consensus.defaultAssumeValid = uint256S("0x02a9adcc44226b86936199011a0e71a0b09966040da2905a4f2cc8fd2f05d071"); //1441280
  
          /**
           * 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] = 0xa9;
          pchMessageStart[1] = 0xd4;
          pchMessageStart[2] = 0xaf;
          pchMessageStart[3] = 0x18;
          nDefaultPort = 4333;
          nPruneAfterHeight = 100000;
  
  
          genesis = CreateGenesisBlock(1553841937, 589744, 0x1e0ffff0, 1, 50 * COIN);
          consensus.hashGenesisBlock = genesis.GetHash();
          assert(consensus.hashGenesisBlock == uint256S("0x10a6a0f9ba1c3b31c03e0e4ee552f41dfb48e9b1bd327cc16629119ac96acae7"));
          assert(genesis.hashMerkleRoot == uint256S("0xbb3fb267c2145cd4191f836e8f0d9708d39873d4e76fc2203b401cb82d72d3cf"));
  
  
          // Note that of those with the service bits flag, most only support a subset of possible options
          // vSeeds.emplace_back("seed-a.bintancoin.loshan.co.uk");
          // vSeeds.emplace_back("dnsseed.thrasher.io");
          // vSeeds.emplace_back("dnsseed.bintancointools.com");
          // vSeeds.emplace_back("dnsseed.bintancoinpool.org");
          // vSeeds.emplace_back("dnsseed.koin-project.com");
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,25);
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
          base58Prefixes[SCRIPT_ADDRESS2] = std::vector<unsigned char>(1,26);
          base58Prefixes[SECRET_KEY] =     std::vector<unsigned char>(1,176);
          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> >();
  
          bech32_hrp = "bin";
  
          vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
  
          fDefaultConsistencyChecks = false;
          fRequireStandard = true;
          fMineBlocksOnDemand = false;
  
          checkpointData = {
              {
                  {    50, uint256S("0x1a6562590ef19d1045d06c4055742d38288e9e6dcd71ccde5cee80f1d5a774eb")},
                  {   500, uint256S("0x0604cd3138feed202ef293e062da2f4720f77a05d25ee036a7a01c9cfcdd1f0a")},
                  {  5000, uint256S("0x0f8eb4b72b6e0c9e88b388eb967b49e067ef1004bf07bffc22c3acb13b43580a")},
                  { 15000, uint256S("0xd4c999ae43633bd2036188d2bca68e1be8202b2cc1f3a1c42a728eaff7d2483d")},
                  { 23656, uint256S("0xea2b9494893ab14f3498083ea908749613c11305938e2c04814a0a645cdf110f")},
                  { 45951, uint256S("0x14d44f66226b8663b3e543fcc5fc8ee7d63f28c6f6c039b1360c15730c6dbad9")},
                  { 72569, uint256S("0xb23a11d61db0efeaaed4a1c20f85525314f8adbc63a2335a7d4d6e3e8a8d467c")},
                  {139426, uint256S("0x97f1008bc1c198670bebc378161252b480c042e5f56f3a15d14a057e9ca81197")},
                  {172158, uint256S("0xaf9f966664c8d6f0f7275a418ca8c5e81a5e2d1644725f828e27d50a10a98174")},
                  {182149, uint256S("0x627fa920ca8f788f262db2727780f6d64477201c51cd6b14d1be25a35023ed4f")},
                  {261542, uint256S("0x72d5099b1f43429e43c35fbc221c66901730b5020fe89785f00f39eea7c748a7")},
                  {390000, uint256S("0x52691d8ea843168a64956b3625b1a24df1983af74465a75bc0aba0cd97527c50")},
                  {415300, uint256S("0x936b6980446ae248cb8e224c80da583a3be399a62e42a0c40137c9ac29f5226f")},
                  {470503, uint256S("0x3addd8c6695adb072f6186f68f523dfe3f10b0f5bb6d41763051ec167788ea1d")},
                  {832670, uint256S("0x7555d1d6caa0a9f0a02073030f40bf69bf53bc04569c90e5174be367e0e7cd5b")},
                  {902583, uint256S("0x5997cf357e0310fa5008f8dd1abaf2175f757002c039a7320b0722610c37be4a")},
              }
          };
  
          chainTxData = ChainTxData{
              // Data as of block 59c9b9d3fec105bdc716d84caa7579503d5b05b73618d0bf2d5fa639f780a011 (height 1353397).
              1553841937, // * UNIX timestamp of last known number of transactions
              589744,  // * total number of transactions between genesis and that timestamp
                      //   (the tx=... number in the SetBestChain debug.log lines)
              0.04     // * estimated number of transactions per second after that timestamp
          };
      }
  };
  
  /**
   * Testnet (v3)
   */
  class CTestNetParams : public CChainParams {
  public:
      CTestNetParams() {
          strNetworkID = "test";
          consensus.nSubsidyHalvingInterval = 525600;
          consensus.BIP16Height = 0; // always enforce P2SH BIP16 on regtest
          consensus.BIP34Height = 0; //76
          consensus.BIP34Hash = uint256S("b0f1db017eba4c71f2708828fd6e73625f8483cad686cf813269f956f5f93e10");
          consensus.BIP65Height = 0 ; // 8075c771ed8b495ffd943980a95f702ab34fce3c8c54e379548bda33cc8c0573 | 76
          consensus.BIP66Height = 0 ; // 8075c771ed8b495ffd943980a95f702ab34fce3c8c54e379548bda33cc8c0573 | 76
          consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
          consensus.nPowTargetTimespan = 1 * 24 * 60 * 60; // daily
          consensus.nPowTargetSpacing = 1 * 60;
          consensus.fPowAllowMinDifficultyBlocks = true;
          consensus.fPowNoRetargeting = false;
          consensus.nRuleChangeActivationThreshold = std::ceil(consensus.nMinerConfirmationWindow * 0.75); //1512; // 75% for testchains
          consensus.nMinerConfirmationWindow = consensus.nPowTargetTimespan / consensus.nPowTargetSpacing; //2016; // nPowTargetTimespan / nPowTargetSpacing
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 11553913419; // Maret 30, 2019
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1585535915; // Maret 30, 2020
  
          // Deployment of BIP68, BIP112, and BIP113.
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 11553913419; // Maret 30, 2019
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1585535915; // Maret 30, 2020
  
          // Deployment of SegWit (BIP141, BIP143, and BIP147)
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 11553913419; // Maret 30, 2019
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1585535915; // Maret 30, 2020
  
          // The best chain should have at least this much work.
          consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000000000000000");
  
          // By default assume that the signatures in ancestors of this block are valid.
          consensus.defaultAssumeValid = uint256S("0x3bc6fee9097f73926ac61cb3dfe58d114bf89900f825f71e33f36082871931ed"); //612653
  
          pchMessageStart[0] = 0xda;
          pchMessageStart[1] = 0xa9;
          pchMessageStart[2] = 0xd0;
          pchMessageStart[3] = 0xd6;
          nDefaultPort = 40331;
          nPruneAfterHeight = 1000;
  
          genesis = CreateGenesisBlock(1553842014, 1696700, 0x1e0ffff0, 1, 50 * COIN);
          consensus.hashGenesisBlock = genesis.GetHash();
          assert(consensus.hashGenesisBlock == uint256S("0x52a20615664934e65859d9ab6c07d3dd1228ba744395869d83912adbf9f8a814"));
          assert(genesis.hashMerkleRoot == uint256S("0xbb3fb267c2145cd4191f836e8f0d9708d39873d4e76fc2203b401cb82d72d3cf"));
  
          vFixedSeeds.clear();
          vSeeds.clear();
          // nodes with support for servicebits filtering should be at the top
          // vSeeds.emplace_back("testnet-seed.bintancointools.com");
          // vSeeds.emplace_back("seed-b.bintancoin.loshan.co.uk");
          // vSeeds.emplace_back("dnsseed-testnet.thrasher.io");
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,85);
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
          base58Prefixes[SCRIPT_ADDRESS2] = std::vector<unsigned char>(1,58);
          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> >();
  
          bech32_hrp = "tbin";
  
          vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
  
          fDefaultConsistencyChecks = false;
          fRequireStandard = false;
          fMineBlocksOnDemand = false;
  
          checkpointData = (CCheckpointData) {
              {
                  {3190, uint256S("5119e090c80757fec3c9f1dca46e3481688fed2fea905db0af7994857abb92a6")},
              }
          };
  
          chainTxData = ChainTxData{
              // Data as of block a0afbded94d4be233e191525dc2d467af5c7eab3143c852c3cd549831022aad6 (height 343833)
              1553842014,
              1696700,
              0.1
  
          };
  
      }
  };
  
  /**
   * Regression test
   */
  class CRegTestParams : public CChainParams {
  public:
      CRegTestParams() {
          strNetworkID = "regtest";
          consensus.nSubsidyHalvingInterval = 150;
          consensus.BIP16Height = 0; // always enforce P2SH BIP16 on regtest
          consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
          consensus.BIP34Hash = uint256();
          consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
          consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
          consensus.powLimit = uint256S("6fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
          consensus.nPowTargetTimespan = 1 * 24 * 60 * 60; // daily
          consensus.nPowTargetSpacing = 1 * 60;
          consensus.fPowAllowMinDifficultyBlocks = true;
          consensus.fPowNoRetargeting = true;
          consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
          consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
          consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 0;
          consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
          consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
  
          // The best chain should have at least this much work.
          consensus.nMinimumChainWork = uint256S("0x00");
  
          // By default assume that the signatures in ancestors of this block are valid.
          consensus.defaultAssumeValid = uint256S("0x00");
  
          pchMessageStart[0] = 0xfa;
          pchMessageStart[1] = 0xbf;
          pchMessageStart[2] = 0xb5;
          pchMessageStart[3] = 0xda;
          nDefaultPort = 40333;
          nPruneAfterHeight = 1000;
  
          genesis = CreateGenesisBlock(1553842969, 0, 0x207fffff, 1, 50 * COIN);
          consensus.hashGenesisBlock = genesis.GetHash();
          assert(consensus.hashGenesisBlock == uint256S("0x65799041fd6814404b3eb63b848500e3cc73f88bd3c72b617aac9ba1d5665efa"));
          assert(genesis.hashMerkleRoot == uint256S("0xbb3fb267c2145cd4191f836e8f0d9708d39873d4e76fc2203b401cb82d72d3cf"));
  
  
          vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
          vSeeds.clear();      //!< Regtest mode doesn't have any DNS seeds.
  
          fDefaultConsistencyChecks = true;
          fRequireStandard = false;
          fMineBlocksOnDemand = true; 
  
          checkpointData = {
              {
                  {0, uint256S("5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9")},
              }
          };
  
          chainTxData = ChainTxData{
              0,
              0,
              0
          };
  
          base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,85);
          base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
          base58Prefixes[SCRIPT_ADDRESS2] = std::vector<unsigned char>(1,58);
          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> >();
  
          bech32_hrp = "rbin";
      }
  };
  
  static std::unique_ptr<CChainParams> globalChainParams;
  
  const CChainParams &Params() {
      assert(globalChainParams);
      return *globalChainParams;
  }
  
  std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
  {
      if (chain == CBaseChainParams::MAIN)
          return std::unique_ptr<CChainParams>(new CMainParams());
      else if (chain == CBaseChainParams::TESTNET)
          return std::unique_ptr<CChainParams>(new CTestNetParams());
      else if (chain == CBaseChainParams::REGTEST)
          return std::unique_ptr<CChainParams>(new CRegTestParams());
      throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
  }
  
  void SelectParams(const std::string& network)
  {
      SelectBaseParams(network);
      globalChainParams = CreateChainParams(network);
  }
  
  void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
  {
      globalChainParams->UpdateVersionBitsParameters(d, nStartTime, nTimeout);
  }
  