OSDN Git Service

init version of edit block header (#389)
[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/legacy"
9 )
10
11 // GenerateGenesisTx will return genesis transaction
12 func GenerateGenesisTx() *legacy.Tx {
13         txData := legacy.TxData{
14                 Version:        1,
15                 SerializedSize: 63,
16                 Inputs: []*legacy.TxInput{
17                         legacy.NewCoinbaseInput([]byte("May 4th Be With You"), nil),
18                 },
19                 Outputs: []*legacy.TxOutput{
20                         &legacy.TxOutput{
21                                 AssetVersion: 1,
22                                 OutputCommitment: legacy.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 legacy.NewTx(txData)
35 }
36
37 // GenerateGenesisBlock will return genesis block
38 func GenerateGenesisBlock() *legacy.Block {
39         genesisCoinbaseTx := GenerateGenesisTx()
40         merkleRoot, err := bc.MerkleRoot([]*bc.Tx{genesisCoinbaseTx.Tx})
41         if err != nil {
42                 log.Panicf("Fatal create merkelRoot")
43         }
44         txStatus := bc.NewTransactionStatus()
45
46         block := &legacy.Block{
47                 BlockHeader: legacy.BlockHeader{
48                         Version:   1,
49                         Height:    0,
50                         Nonce:     4216077,
51                         Timestamp: 1516788453,
52                         BlockCommitment: legacy.BlockCommitment{
53                                 TransactionsMerkleRoot: merkleRoot,
54                                 TransactionStatusHash:  bc.EntryID(txStatus),
55                         },
56                         Bits: 2305843009222082559,
57                 },
58                 Transactions: []*legacy.Tx{genesisCoinbaseTx},
59         }
60         return block
61 }