github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/config/genesis.go (about) 1 package config 2 3 import ( 4 "encoding/hex" 5 6 log "github.com/sirupsen/logrus" 7 8 "github.com/bytom/bytom/consensus" 9 "github.com/bytom/bytom/protocol/bc" 10 "github.com/bytom/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 if err := txStatus.SetStatus(0, false); err != nil { 35 log.Panicf(err.Error()) 36 } 37 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus) 38 if err != nil { 39 log.Panicf("fail on calc genesis tx status merkle root") 40 } 41 42 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx}) 43 if err != nil { 44 log.Panicf("fail on calc genesis tx merkel root") 45 } 46 47 block := &types.Block{ 48 BlockHeader: types.BlockHeader{ 49 Version: 1, 50 Height: 0, 51 Nonce: 9253507043297, 52 Timestamp: 1524549600, 53 Bits: 2161727821137910632, 54 BlockCommitment: types.BlockCommitment{ 55 TransactionsMerkleRoot: merkleRoot, 56 TransactionStatusHash: txStatusHash, 57 }, 58 }, 59 Transactions: []*types.Tx{tx}, 60 } 61 return block 62 } 63 64 func testNetGenesisBlock() *types.Block { 65 tx := GenesisTx() 66 txStatus := bc.NewTransactionStatus() 67 if err := txStatus.SetStatus(0, false); err != nil { 68 log.Panicf(err.Error()) 69 } 70 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus) 71 if err != nil { 72 log.Panicf("fail on calc genesis tx status merkle root") 73 } 74 75 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx}) 76 if err != nil { 77 log.Panicf("fail on calc genesis tx merkel root") 78 } 79 80 block := &types.Block{ 81 BlockHeader: types.BlockHeader{ 82 Version: 1, 83 Height: 0, 84 Nonce: 9253507043297, 85 Timestamp: 1528945000, 86 Bits: 2305843009214532812, 87 BlockCommitment: types.BlockCommitment{ 88 TransactionsMerkleRoot: merkleRoot, 89 TransactionStatusHash: txStatusHash, 90 }, 91 }, 92 Transactions: []*types.Tx{tx}, 93 } 94 return block 95 } 96 97 func soloNetGenesisBlock() *types.Block { 98 tx := GenesisTx() 99 txStatus := bc.NewTransactionStatus() 100 if err := txStatus.SetStatus(0, false); err != nil { 101 log.Panicf(err.Error()) 102 } 103 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus) 104 if err != nil { 105 log.Panicf("fail on calc genesis tx status merkle root") 106 } 107 108 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx}) 109 if err != nil { 110 log.Panicf("fail on calc genesis tx merkel root") 111 } 112 113 block := &types.Block{ 114 BlockHeader: types.BlockHeader{ 115 Version: 1, 116 Height: 0, 117 Nonce: 9253507043297, 118 Timestamp: 1528945000, 119 Bits: 2305843009214532812, 120 BlockCommitment: types.BlockCommitment{ 121 TransactionsMerkleRoot: merkleRoot, 122 TransactionStatusHash: txStatusHash, 123 }, 124 }, 125 Transactions: []*types.Tx{tx}, 126 } 127 return block 128 } 129 130 // GenesisBlock will return genesis block 131 func GenesisBlock() *types.Block { 132 return map[string]func() *types.Block{ 133 "main": mainNetGenesisBlock, 134 "test": testNetGenesisBlock, 135 "solo": soloNetGenesisBlock, 136 }[consensus.ActiveNetParams.Name]() 137 }