PPCoin: Tool generating genesis block
authorSunny King <p2pcoin@gmail.com>
Wed, 9 Nov 2011 23:02:41 +0000 (23:02 +0000)
committerSunny King <p2pcoin@gmail.com>
Wed, 9 Nov 2011 23:02:41 +0000 (23:02 +0000)
src/init.cpp
src/main.cpp
src/makefile.unix
src/ppcoin/genesis.cpp [new file with mode: 0644]
src/ppcoin/obj/.gitignore [new file with mode: 0644]

index 635799c..ceacf64 100644 (file)
@@ -1,4 +1,5 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2011 The PPCoin developers
 // Distributed under the MIT/X11 software license, see the accompanying
 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
 #include "headers.h"
@@ -80,6 +81,7 @@ void HandleSIGTERM(int)
 // Start
 //
 #ifndef GUI
+#if !defined(PPCOIN_GENESIS)
 int main(int argc, char* argv[])
 {
     bool fRet = false;
@@ -91,6 +93,7 @@ int main(int argc, char* argv[])
     return 1;
 }
 #endif
+#endif
 
 bool AppInit(int argc, char* argv[])
 {
index 594f1d3..d122852 100644 (file)
@@ -1,4 +1,5 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2011 The PPCoin developers
 // Distributed under the MIT/X11 software license, see the accompanying
 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
 #include "headers.h"
@@ -30,7 +31,7 @@ unsigned int nTransactionsUpdated = 0;
 map<COutPoint, CInPoint> mapNextTx;
 
 map<uint256, CBlockIndex*> mapBlockIndex;
-uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
+uint256 hashGenesisBlock("0x0000000088ddd1db81553a3908a2980587924d434938371aaa57d0e1e03e54dc");
 CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
 const int nTotalBlocksEstimate = 134444; // Conservative estimate of total nr of blocks on main chain
 const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download"
@@ -1288,14 +1289,8 @@ bool CBlock::AcceptBlock()
 
     // Check that the block chain matches the known block chain up to a checkpoint
     if (!fTestNet)
-        if ((nHeight ==  11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ||
-            (nHeight ==  33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) ||
-            (nHeight ==  68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) ||
-            (nHeight ==  70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ||
-            (nHeight ==  74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")) ||
-            (nHeight == 105000 && hash != uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")) ||
-            (nHeight == 118000 && hash != uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553")) ||
-            (nHeight == 134444 && hash != uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")))
+        // ppcoin: no checkpoint yet; to be created after beta
+        if ((nHeight == -1 && hash != uint256("0x83f760b87b13d7002eaccc4a5a154aaea0f861e52b6eb481d30a344f55605c01")))
             return error("AcceptBlock() : rejected by checkpoint lockin at %d", nHeight);
 
     // Write block to history file
@@ -1515,7 +1510,7 @@ bool LoadBlockIndex(bool fAllowNew)
         //   vMerkleTree: 4a5e1e
 
         // Genesis block
-        const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
+        const char* pszTimestamp = "MarketWatch 07/Nov/2011 Gold tops $1,790 to end at over six-week high";
         CTransaction txNew;
         txNew.vin.resize(1);
         txNew.vout.resize(1);
@@ -1527,9 +1522,9 @@ bool LoadBlockIndex(bool fAllowNew)
         block.hashPrevBlock = 0;
         block.hashMerkleRoot = block.BuildMerkleTree();
         block.nVersion = 1;
-        block.nTime    = 1231006505;
+        block.nTime    = 1320807728;
         block.nBits    = 0x1d00ffff;
-        block.nNonce   = 2083236893;
+        block.nNonce   = 319190438;
 
         if (fTestNet)
         {
@@ -1542,7 +1537,7 @@ bool LoadBlockIndex(bool fAllowNew)
         printf("%s\n", block.GetHash().ToString().c_str());
         printf("%s\n", hashGenesisBlock.ToString().c_str());
         printf("%s\n", block.hashMerkleRoot.ToString().c_str());
-        assert(block.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
+        assert(block.hashMerkleRoot == uint256("0x4b9b3b5ebff8f552ba5c29e7eaa571ff16b63f50f6425865b280b3a7f670a2c4"));
         block.print();
         assert(block.GetHash() == hashGenesisBlock);
 
index bb26bf5..fc7a3b5 100644 (file)
@@ -1,4 +1,5 @@
 # Copyright (c) 2009-2010 Satoshi Nakamoto
+# Copyright (c) 2011 The PPCoin developers
 # Distributed under the MIT/X11 software license, see the accompanying
 # file license.txt or http://www.opensource.org/licenses/mit-license.php.
 
@@ -28,6 +29,10 @@ ifdef USE_UPNP
        DEFS += -DUSE_UPNP=$(USE_UPNP)
 endif
 
+ifneq (${PPCOIN_GENESIS}, 0)
+       DEFS += -DPPCOIN_GENESIS
+endif
+
 LIBS+= \
  -Wl,-Bdynamic \
    -l gthread-2.0 \
@@ -82,9 +87,16 @@ test_bitcoin: obj/test/test_bitcoin.o
        $(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework
 
 clean:
-       -rm -f bitcoin bitcoind test_bitcoin
+       -rm -f bitcoin bitcoind test_bitcoin genesis
        -rm -f obj/*.o
        -rm -f obj/nogui/*.o
        -rm -f obj/test/*.o
        -rm -f cryptopp/obj/*.o
        -rm -f headers.h.gch
+       -rm -f ppcoin/obj/*.o
+
+ppcoin/obj/%.o: ppcoin/%.cpp
+       $(CXX) -c $(CXXFLAGS) -o $@ $<
+
+genesis: ppcoin/obj/genesis.o $(OBJS:obj/%=obj/nogui/%)
+       $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
diff --git a/src/ppcoin/genesis.cpp b/src/ppcoin/genesis.cpp
new file mode 100644 (file)
index 0000000..3fe6d1a
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (c) 2011 The PPCoin developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file license.txt or http://www.opensource.org/licenses/mit-license.php.
+#include "../headers.h"
+#include "../db.h"
+#include "../net.h"
+#include "../init.h"
+#include "../main.h"
+#include "../util.h"
+
+using namespace std;
+using namespace boost;
+
+int main(int argc, char *argv[])
+{
+    fPrintToConsole = true;
+    printf("PPCoin Begin Genesis Block\n");
+
+    // Genesis block
+    const char* pszTimestamp = "MarketWatch 07/Nov/2011 Gold tops $1,790 to end at over six-week high";
+    CTransaction txNew;
+    txNew.vin.resize(1);
+    txNew.vout.resize(1);
+    txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(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("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
+    CBlock block;
+    block.vtx.push_back(txNew);
+    block.hashPrevBlock = 0;
+    block.hashMerkleRoot = block.BuildMerkleTree();
+    block.nVersion = 1;
+    block.nBits    = 0x1d00ffff;
+    block.nTime    = GetAdjustedTime();
+    block.nNonce   = 0;
+
+    CBigNum bnTarget;
+    bnTarget.SetCompact(block.nBits);
+
+    while (block.GetHash() > bnTarget.getuint256())
+    {
+        if (block.nNonce % 1048576 == 0)
+            printf("n=%dM hash=%s\n", block.nNonce / 1048576,
+                   block.GetHash().ToString().c_str());
+        block.nTime = GetAdjustedTime();
+        block.nNonce++;
+    }
+
+    printf("PPCoin Found Genesis Block:\n");
+    printf("genesis hash=%s\n", block.GetHash().ToString().c_str());
+    printf("merkle  root=%s\n", block.hashMerkleRoot.ToString().c_str());
+    block.print();
+
+    printf("PPCoin End Genesis Block\n");
+} 
diff --git a/src/ppcoin/obj/.gitignore b/src/ppcoin/obj/.gitignore
new file mode 100644 (file)
index 0000000..d6b7ef3
--- /dev/null
@@ -0,0 +1,2 @@
+*
+!.gitignore