OSDN Git Service

edit version for prod
[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 // GenesisBlock will return genesis block
32 func GenesisBlock() *types.Block {
33         tx := genesisTx()
34         txStatus := bc.NewTransactionStatus()
35         txStatus.SetStatus(0, false)
36         txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
37         if err != nil {
38                 log.Panicf("fail on calc genesis tx status merkle root")
39         }
40
41         merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{tx.Tx})
42         if err != nil {
43                 log.Panicf("fail on calc genesis tx merkel root")
44         }
45
46         block := &types.Block{
47                 BlockHeader: types.BlockHeader{
48                         Version:   1,
49                         Height:    0,
50                         Nonce:     9253507043297,
51                         Timestamp: 1524549600,
52                         Bits:      2161727821137910632,
53                         BlockCommitment: types.BlockCommitment{
54                                 TransactionsMerkleRoot: merkleRoot,
55                                 TransactionStatusHash:  txStatusHash,
56                         },
57                 },
58                 Transactions: []*types.Tx{tx},
59         }
60         return block
61 }