This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
/
genesis.go
67 lines (60 loc) · 1.58 KB
/
genesis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package config
import (
log "github.com/sirupsen/logrus"
"github.com/bytom/consensus"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/types"
)
// GenerateGenesisTx will return genesis transaction
func GenerateGenesisTx() *types.Tx {
txData := types.TxData{
Version: 1,
SerializedSize: 63,
Inputs: []*types.TxInput{
types.NewCoinbaseInput([]byte("May 4th Be With You")),
},
Outputs: []*types.TxOutput{
&types.TxOutput{
AssetVersion: 1,
OutputCommitment: types.OutputCommitment{
AssetAmount: bc.AssetAmount{
AssetId: consensus.BTMAssetID,
Amount: consensus.InitialBlockSubsidy,
},
VMVersion: 1,
ControlProgram: []byte{81},
},
},
},
}
return types.NewTx(txData)
}
// GenerateGenesisBlock will return genesis block
func GenerateGenesisBlock() *types.Block {
genesisCoinbaseTx := GenerateGenesisTx()
merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{genesisCoinbaseTx.Tx})
if err != nil {
log.Panicf("Fatal create tx merkelRoot")
}
txStatus := bc.NewTransactionStatus()
txStatus.SetStatus(0, false)
txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
if err != nil {
log.Panicf("Fatal create tx status gmerkelRoot")
}
block := &types.Block{
BlockHeader: types.BlockHeader{
Version: 1,
Height: 0,
Nonce: 4216085,
Timestamp: 1516788453,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: merkleRoot,
TransactionStatusHash: txStatusHash,
},
Bits: 2305843009222082559,
},
Transactions: []*types.Tx{genesisCoinbaseTx},
}
return block
}