Bitcoin Forum
July 22, 2024, 09:30:03 PM *
News: Help 1Dq create 15th anniversary forum artwork.
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Alternate cryptocurrencies / Altcoin Discussion / How do I get the genesis code to work well? Please, Someone Help me~!^ on: April 26, 2018, 11:28:39 AM
I am a regular person who became interested in crypto programming this time.

But I have a problem programming, so I write this. Please, I would appreciate your help. really thank you.


============================================================
The problem is that in making individual coins folk, there is no answer to how to form the Genesis block.

I chose just "nihilo coin source" for the exercise!

I can modify several coin features and do it right way.

But I don't know, how to make new genesis block hash value.

I did some searching. and find this "Genesis Block Generator, https://bitcointalk.org/index.php?topic=181981.0"

and I used that code for generating genesis block and hash and nnonce value.

and I put that value in my source at  chainparams.cpp and checkpoints.cpp .

and Run "make -f makefile.unix USE_UPNP=- "
But It doesn't work with this error AGAIN AGAIN AGAIN... Embarrassed Embarrassed Embarrassed Embarrassed
============================================================
 
Code:
ubuntu@ubuntu-VirtualBox:~/Desktop/test/src$ ./testd
testd: chainparams.cpp:94: CMainParams::CMainParams(): Assertion `hashGenesisBlock == uint256("0x803a095a9705f06c6e52f1308374ef5be3ba7a842559b218eb324e38c5444e16")' failed.
Aborted (core dumped)
============================================================
And this is chainparams.cpp

Code:
// 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 pnSeeds array into usable address objects.
static void convertSeeds(std::vector<CAddress> &vSeedsOut, const unsigned int *data, unsigned int count, int port)
{
    // 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 k = 0; k < count; ++k)
   {
       struct in_addr ip;
       unsigned int i = data[k], t;
       
       // -- convert to big endian
       t =   (i & 0x000000ff) << 24u
           | (i & 0x0000ff00) << 8u
           | (i & 0x00ff0000) >> 8u
           | (i & 0xff000000) >> 24u;
       
       memcpy(&ip, &t, sizeof(ip));
       
       CAddress addr(CService(ip, 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] = 0xb1;
       pchMessageStart[1] = 0xc2;
       pchMessageStart[2] = 0x3c;
       pchMessageStart[3] = 0xd1;
       vAlertPubKey = ParseHex("0498041d17a04788c7490899e35c8314a3a9fd369332900eec05e2b0589cd2147478985144d91956b6c732c9427fb3e8b153a7ae7681aa05729c91bb4b7536f9c3");
       nDefaultPort = 18858;
       nRPCPort = 13858;
       bnProofOfWorkLimit = CBigNum(~uint256(0) >> 16);

       // 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=000001faef25dec4fbcf906e6242621df2c183bf232f263d0ba5b101911e4563, ver=1, hashPrevBlock=0000000000000000000000000000000000000000000000000000000000000000, hashMerkleRoot=12630d16a97f24b287c8c2594dda5fb98c9e6c70fc61d44191931ea2aa08dc90, nTime=1393221600, nBits=1e0fffff, nNonce=164482, vtx=1, vchBlockSig=)
       //  Coinbase(hash=12630d16a9, nTime=1393221600, ver=1, vin.size=1, vout.size=1, nLockTime=0)
       //    CTxIn(COutPoint(0000000000, 4294967295), coinbase 00012a24323020466562203230313420426974636f696e2041544d7320636f6d6520746f20555341)
       //    CTxOut(empty)
       //  vMerkleTree: 12630d16a9
       const char* pszTimestamp = "This is test";
       std::vector<CTxIn> vin;
       vin.resize(1);
       vin[0].scriptSig = CScript() << 0 << CBigNum(42) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
       std::vector<CTxOut> vout;
       vout.resize(1);
       vout[0].SetEmpty();
       CTransaction txNew(1, 1524734223, vin, vout, 0);
       genesis.vtx.push_back(txNew);
       genesis.hashPrevBlock = 0;
       genesis.hashMerkleRoot = genesis.BuildMerkleTree();
       genesis.nVersion = 1;
       genesis.nTime    = 1524734223;
       genesis.nBits    = 0x1f00ffff;
       genesis.nNonce   = 289220;
       
       hashGenesisBlock = genesis.GetHash();
       assert(hashGenesisBlock == uint256("0x803a095a9705f06c6e52f1308374ef5be3ba7a842559b218eb324e38c5444e16"));
       assert(genesis.hashMerkleRoot == uint256("0x055a67b1b326ce2701e15876d87f9035dd930e7dea8627e92e1ba7bbe8f1c850"));

       base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,53);
       base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,112);
       base58Prefixes[SECRET_KEY] =     std::vector<unsigned char>(1,181);
       base58Prefixes[STEALTH_ADDRESS] = std::vector<unsigned char>(1,40);
       base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >();
       base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();
       vSeeds.push_back(CDNSSeedData("1",  "127.0.0.1"));
      // vSeeds.push_back(CDNSSeedData("2",  "ns2.test.space"));//
      // vSeeds.push_back(CDNSSeedData("3",  "ns3.test.space"));//
       //vSeeds.push_back(CDNSSeedData("4",  "ns4.test.space"));//
       //vSeeds.push_back(CDNSSeedData("5",  "ns5.test.space"));//
      // vSeeds.push_back(CDNSSeedData("6",  "ns6.test.space"));//
      // vSeeds.push_back(CDNSSeedData("7",  "ns7.test.space"));//
      // vSeeds.push_back(CDNSSeedData("8",  "ns8.test.space"));//
      // vSeeds.push_back(CDNSSeedData("9",  "ns9.test.space"));//
      // vSeeds.push_back(CDNSSeedData("10", "ns10.test.space"));//
      // convertSeeds(vFixedSeeds, pnSeed, ARRAYLEN(pnSeed), nDefaultPort);

       nPoolMaxTransactions = 3;
       //strSporkKey = "046f78dcf911fbd61910136f7f0f8d90578f68d0b3ac973b5040fb7afb501b5939f39b108b0569dca71488f5bbf498d92e4d1194f6f941307ffd95f75e76869f0e";
       //strMasternodePaymentsPubKey = "046f78dcf911fbd61910136f7f0f8d90578f68d0b3ac973b5040fb7afb501b5939f39b108b0569dca71488f5bbf498d92e4d1194f6f941307ffd95f75e76869f0e";
       strDarksendPoolDummyAddress = "NVVUpZWDQYSfb2mF6yqtK1P6j6Kd3gbrK8";
       nLastPOWBlock = 100;
       nPOSStartBlock = 1;
   }

   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] = 0xd2;
       pchMessageStart[1] = 0xc2;
       pchMessageStart[2] = 0xb1;
       pchMessageStart[3] = 0xd4;
       bnProofOfWorkLimit = CBigNum(~uint256(0) >> 16);
       vAlertPubKey = ParseHex("04263773dcadb756271c7a3e915d493284472c02e9bf639dca63bff3d937b8cd82064b279fd8a02da94112c0902e90a1de65ba686cfe8affc9b79b88f8944c8d5b");
       nDefaultPort = 18857;
       nRPCPort = 13857;
       strDataDir = "testnet";

       // Modify the testnet genesis block so the timestamp is valid for a later start.
       genesis.nBits  = 1524734223;
       genesis.nNonce = 289220;
 
       assert(hashGenesisBlock == uint256("0x803a095a9705f06c6e52f1308374ef5be3ba7a842559b218eb324e38c5444e16"));

       vFixedSeeds.clear();
       vSeeds.clear();

       base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,9);
       base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
       base58Prefixes[SECRET_KEY]     = std::vector<unsigned char>(1,239);
       base58Prefixes[STEALTH_ADDRESS] = std::vector<unsigned char>(1,40);
       base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
       base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();

       convertSeeds(vFixedSeeds, pnTestnetSeed, ARRAYLEN(pnTestnetSeed), nDefaultPort);

       nLastPOWBlock = 0x7fffffff;
   }
   virtual Network NetworkID() const { return CChainParams::TESTNET; }
};
static CTestNetParams testNetParams;


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;
       default:
           assert(false && "Unimplemented network");
           return;
   }
}

bool SelectParamsFromCommandLine() {
   
   bool fTestNet = GetBoolArg("-testnet", false);
   
   if (fTestNet) {
       SelectParams(CChainParams::TESTNET);
   } else {
       SelectParams(CChainParams::MAIN);
   }
   return true;
}
============================================================
how to get new genesisblockhash and nnonce value??
Please tell me where I can get code for generating.
I haven't been able to solve the problem for days.
plz.....

============================================================
And it doesnt working ...... this is code for searching genesis block .. it works good at litecoin0.8 source. but not working at nihilo coin source. How to fix it... plz someone help me. It's driving me crazy.

Code:
if (true && block.GetHash() != hashGenesisBlock)
        {
            printf("Searching for genesis block...\n");
            // This will figure out a valid hash and Nonce if you're
            // creating a different genesis block:
            uint256 hashTarget = CBigNum().SetCompact(block.nBits).getuint256();
            uint256 thash;
            char scratchpad[SCRYPT_SCRATCHPAD_SIZE];
 
            loop
            {
#if defined(USE_SSE2)
                // Detection would work, but in cases where we KNOW it always has SSE2,
                // it is faster to use directly than to use a function pointer or conditional.
#if defined(_M_X64) || defined(__x86_64__) || defined(_M_AMD64) || (defined(MAC_OSX) && defined(__i386__))
                // Always SSE2: x86_64 or Intel MacOS X
                scrypt_1024_1_1_256_sp_sse2(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#else
                // Detect SSE2: 32bit x86 Linux or Windows
                scrypt_1024_1_1_256_sp(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#endif
#else
                // Generic scrypt
                scrypt_1024_1_1_256_sp_generic(BEGIN(block.nVersion), BEGIN(thash), scratchpad);
#endif
                if (thash <= hashTarget)
                    break;
                if ((block.nNonce & 0xFFF) == 0)
                {
                    printf("nonce %08X: hash = %s (target = %s)\n", block.nNonce, thash.ToString().c_str(), hashTarget.ToString().c_str());
                }
                ++block.nNonce;
                if (block.nNonce == 0)
                {
                    printf("NONCE WRAPPED, incrementing time\n");
                    ++block.nTime;
                }
            }
            printf("block.nTime = %u \n", block.nTime);
            printf("block.nNonce = %u \n", block.nNonce);
            printf("block.GetHash = %s\n", block.GetHash().ToString().c_str());
        }
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!