OSDN Git Service

spv merkle tree proof (#1262)
[bytom/bytom.git] / config / genesis.go
index 46b02a2..4ca222b 100644 (file)
@@ -28,17 +28,16 @@ func genesisTx() *types.Tx {
        return types.NewTx(txData)
 }
 
-// GenesisBlock will return genesis block
-func GenesisBlock() *types.Block {
+func mainNetGenesisBlock() *types.Block {
        tx := genesisTx()
        txStatus := bc.NewTransactionStatus()
        txStatus.SetStatus(0, false)
-       txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
+       txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
        if err != nil {
                log.Panicf("fail on calc genesis tx status merkle root")
        }
 
-       merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{tx.Tx})
+       merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
        if err != nil {
                log.Panicf("fail on calc genesis tx merkel root")
        }
@@ -59,3 +58,74 @@ func GenesisBlock() *types.Block {
        }
        return block
 }
+
+func testNetGenesisBlock() *types.Block {
+       tx := genesisTx()
+       txStatus := bc.NewTransactionStatus()
+       txStatus.SetStatus(0, false)
+       txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
+       if err != nil {
+               log.Panicf("fail on calc genesis tx status merkle root")
+       }
+
+       merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
+       if err != nil {
+               log.Panicf("fail on calc genesis tx merkel root")
+       }
+
+       block := &types.Block{
+               BlockHeader: types.BlockHeader{
+                       Version:   1,
+                       Height:    0,
+                       Nonce:     9253507043297,
+                       Timestamp: 1528945000,
+                       Bits:      2305843009214532812,
+                       BlockCommitment: types.BlockCommitment{
+                               TransactionsMerkleRoot: merkleRoot,
+                               TransactionStatusHash:  txStatusHash,
+                       },
+               },
+               Transactions: []*types.Tx{tx},
+       }
+       return block
+}
+
+func soloNetGenesisBlock() *types.Block {
+       tx := genesisTx()
+       txStatus := bc.NewTransactionStatus()
+       txStatus.SetStatus(0, false)
+       txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
+       if err != nil {
+               log.Panicf("fail on calc genesis tx status merkle root")
+       }
+
+       merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
+       if err != nil {
+               log.Panicf("fail on calc genesis tx merkel root")
+       }
+
+       block := &types.Block{
+               BlockHeader: types.BlockHeader{
+                       Version:   1,
+                       Height:    0,
+                       Nonce:     9253507043297,
+                       Timestamp: 1528945000,
+                       Bits:      2305843009214532812,
+                       BlockCommitment: types.BlockCommitment{
+                               TransactionsMerkleRoot: merkleRoot,
+                               TransactionStatusHash:  txStatusHash,
+                       },
+               },
+               Transactions: []*types.Tx{tx},
+       }
+       return block
+}
+
+// GenesisBlock will return genesis block
+func GenesisBlock() *types.Block {
+       return map[string]func() *types.Block{
+               "main": mainNetGenesisBlock,
+               "test": testNetGenesisBlock,
+               "solo": soloNetGenesisBlock,
+       }[consensus.ActiveNetParams.Name]()
+}