OSDN Git Service

Add bytomd command line param about setting log level (#1115)
[bytom/bytom.git] / config / genesis.go
1 package config
2
3 import (
4         "encoding/hex"
5
6         log "github.com/sirupsen/logrus"
7
8         "github.com/bytom/consensus"
9         "github.com/bytom/protocol/bc"
10         "github.com/bytom/protocol/bc/types"
11 )
12
13 func genesisTx() *types.Tx {
14         contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4")
15         if err != nil {
16                 log.Panicf("fail on decode genesis tx output control program")
17         }
18
19         txData := types.TxData{
20                 Version: 1,
21                 Inputs: []*types.TxInput{
22                         types.NewCoinbaseInput([]byte("Information is power. -- Jan/11/2013. Computing is power. -- Apr/24/2018.")),
23                 },
24                 Outputs: []*types.TxOutput{
25                         types.NewTxOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract),
26                 },
27         }
28         return types.NewTx(txData)
29 }
30
31 func mainNetGenesisBlock() *types.Block {
32         tx := genesisTx()
33         txStatus := bc.NewTransactionStatus()
34         txStatus.SetStatus(0, false)
35         txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
36         if err != nil {
37                 log.Panicf("fail on calc genesis tx status merkle root")
38         }
39
40         merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{tx.Tx})
41         if err != nil {
42                 log.Panicf("fail on calc genesis tx merkel root")
43         }
44
45         block := &types.Block{
46                 BlockHeader: types.BlockHeader{
47                         Version:   1,
48                         Height:    0,
49                         Nonce:     9253507043297,
50                         Timestamp: 1524549600,
51                         Bits:      2161727821137910632,
52                         BlockCommitment: types.BlockCommitment{
53                                 TransactionsMerkleRoot: merkleRoot,
54                                 TransactionStatusHash:  txStatusHash,
55                         },
56                 },
57                 Transactions: []*types.Tx{tx},
58         }
59         return block
60 }
61
62 func testNetGenesisBlock() *types.Block {
63         tx := genesisTx()
64         txStatus := bc.NewTransactionStatus()
65         txStatus.SetStatus(0, false)
66         txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
67         if err != nil {
68                 log.Panicf("fail on calc genesis tx status merkle root")
69         }
70
71         merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{tx.Tx})
72         if err != nil {
73                 log.Panicf("fail on calc genesis tx merkel root")
74         }
75
76         block := &types.Block{
77                 BlockHeader: types.BlockHeader{
78                         Version:   1,
79                         Height:    0,
80                         Nonce:     9253507043297,
81                         Timestamp: 1528945000,
82                         Bits:      2305843009214532812,
83                         BlockCommitment: types.BlockCommitment{
84                                 TransactionsMerkleRoot: merkleRoot,
85                                 TransactionStatusHash:  txStatusHash,
86                         },
87                 },
88                 Transactions: []*types.Tx{tx},
89         }
90         return block
91 }
92
93 func soloNetGenesisBlock() *types.Block {
94         tx := genesisTx()
95         txStatus := bc.NewTransactionStatus()
96         txStatus.SetStatus(0, false)
97         txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
98         if err != nil {
99                 log.Panicf("fail on calc genesis tx status merkle root")
100         }
101
102         merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{tx.Tx})
103         if err != nil {
104                 log.Panicf("fail on calc genesis tx merkel root")
105         }
106
107         block := &types.Block{
108                 BlockHeader: types.BlockHeader{
109                         Version:   1,
110                         Height:    0,
111                         Nonce:     9253507043297,
112                         Timestamp: 1528945000,
113                         Bits:      2305843009214532812,
114                         BlockCommitment: types.BlockCommitment{
115                                 TransactionsMerkleRoot: merkleRoot,
116                                 TransactionStatusHash:  txStatusHash,
117                         },
118                 },
119                 Transactions: []*types.Tx{tx},
120         }
121         return block
122 }
123
124 // GenesisBlock will return genesis block
125 func GenesisBlock() *types.Block {
126         return map[string]func() *types.Block{
127                 "main": mainNetGenesisBlock,
128                 "test": testNetGenesisBlock,
129                 "solo": soloNetGenesisBlock,
130         }[consensus.ActiveNetParams.Name]()
131 }