OSDN Git Service

Merge pull request #664 from Bytom/dev_modify_datadir
[bytom/bytom.git] / config / genesis.go
1 package config
2
3 import (
4         log "github.com/sirupsen/logrus"
5
6         "github.com/bytom/consensus"
7         "github.com/bytom/protocol/bc"
8         "github.com/bytom/protocol/bc/types"
9 )
10
11 // GenerateGenesisTx will return genesis transaction
12 func GenerateGenesisTx() *types.Tx {
13         txData := types.TxData{
14                 Version:        1,
15                 SerializedSize: 63,
16                 Inputs: []*types.TxInput{
17                         types.NewCoinbaseInput([]byte("May 4th Be With You")),
18                 },
19                 Outputs: []*types.TxOutput{
20                         &types.TxOutput{
21                                 AssetVersion: 1,
22                                 OutputCommitment: types.OutputCommitment{
23                                         AssetAmount: bc.AssetAmount{
24                                                 AssetId: consensus.BTMAssetID,
25                                                 Amount:  consensus.InitialBlockSubsidy,
26                                         },
27                                         VMVersion:      1,
28                                         ControlProgram: []byte{81},
29                                 },
30                         },
31                 },
32         }
33
34         return types.NewTx(txData)
35 }
36
37 // GenerateGenesisBlock will return genesis block
38 func GenerateGenesisBlock() *types.Block {
39         genesisCoinbaseTx := GenerateGenesisTx()
40         merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{genesisCoinbaseTx.Tx})
41         if err != nil {
42                 log.Panicf("Fatal create tx merkelRoot")
43         }
44
45         txStatus := bc.NewTransactionStatus()
46         txStatus.SetStatus(0, false)
47         txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
48         if err != nil {
49                 log.Panicf("Fatal create tx status gmerkelRoot")
50         }
51
52         block := &types.Block{
53                 BlockHeader: types.BlockHeader{
54                         Version:   1,
55                         Height:    0,
56                         Nonce:     4216236,
57                         Timestamp: 1523352600,
58                         BlockCommitment: types.BlockCommitment{
59                                 TransactionsMerkleRoot: merkleRoot,
60                                 TransactionStatusHash:  txStatusHash,
61                         },
62                         Bits: 2305843009214532812,
63                 },
64                 Transactions: []*types.Tx{genesisCoinbaseTx},
65         }
66         return block
67 }