8 log "github.com/sirupsen/logrus"
10 "github.com/vapor/consensus"
11 "github.com/vapor/crypto/ed25519"
12 "github.com/vapor/crypto/ed25519/chainkd"
13 "github.com/vapor/protocol/bc"
14 "github.com/vapor/protocol/bc/types"
15 "github.com/vapor/protocol/vm/vmutil"
18 func commitToArguments() (res *[32]byte) {
19 var fedpegPubkeys []ed25519.PublicKey
20 for _, xpub := range consensus.ActiveNetParams.FedpegXPubs {
21 fedpegPubkeys = append(fedpegPubkeys, xpub.PublicKey())
23 fedpegScript, _ := vmutil.P2SPMultiSigProgram(fedpegPubkeys, len(fedpegPubkeys))
25 var buffer bytes.Buffer
26 for _, address := range CommonConfig.Consensus.Dpos.Signers {
27 redeemContract := address.ScriptAddress()
28 buffer.Write(redeemContract)
31 hasher := sha256.New()
32 hasher.Write(fedpegScript)
33 hasher.Write(buffer.Bytes())
34 resSlice := hasher.Sum(nil)
36 copy(res[:], resSlice)
40 func genesisTx() *types.Tx {
42 contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4")
44 log.Panicf("fail on decode genesis tx output control program")
47 coinbaseInput := commitToArguments()
48 txData := types.TxData{
50 Inputs: []*types.TxInput{
51 // Any consensus-related values that are command-line set can be added here for anti-footgun
52 types.NewCoinbaseInput(coinbaseInput[:]),
53 //types.NewCoinbaseInput([]byte("Information is power. -- Jan/11/2013. Computing is power. -- Apr/24/2018.")),
55 Outputs: []*types.TxOutput{
56 types.NewTxOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract),
60 return types.NewTx(txData)
63 func mainNetGenesisBlock() *types.Block {
65 txStatus := bc.NewTransactionStatus()
66 if err := txStatus.SetStatus(0, false); err != nil {
67 log.Panicf(err.Error())
69 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
71 log.Panicf("fail on calc genesis tx status merkle root")
74 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
76 log.Panicf("fail on calc genesis tx merkel root")
80 if CommonConfig.Consensus.Dpos.XPrv == "" {
81 log.Panicf("Signer is empty")
83 xPrv.UnmarshalText([]byte(CommonConfig.Consensus.Dpos.XPrv))
84 b, _ := xPrv.XPub().MarshalText()
86 block := &types.Block{
87 BlockHeader: types.BlockHeader{
90 Timestamp: 1524549600,
91 BlockCommitment: types.BlockCommitment{
92 TransactionsMerkleRoot: merkleRoot,
93 TransactionStatusHash: txStatusHash,
97 Transactions: []*types.Tx{tx},
102 func testNetGenesisBlock() *types.Block {
104 txStatus := bc.NewTransactionStatus()
105 if err := txStatus.SetStatus(0, false); err != nil {
106 log.Panicf(err.Error())
108 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
110 log.Panicf("fail on calc genesis tx status merkle root")
113 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
115 log.Panicf("fail on calc genesis tx merkel root")
118 var xPrv chainkd.XPrv
119 if CommonConfig.Consensus.Dpos.XPrv == "" {
120 log.Panicf("Signer is empty")
122 xPrv.UnmarshalText([]byte(CommonConfig.Consensus.Dpos.XPrv))
123 b, _ := xPrv.XPub().MarshalText()
125 block := &types.Block{
126 BlockHeader: types.BlockHeader{
129 Timestamp: 1528945000,
130 BlockCommitment: types.BlockCommitment{
131 TransactionsMerkleRoot: merkleRoot,
132 TransactionStatusHash: txStatusHash,
136 Transactions: []*types.Tx{tx},
141 func soloNetGenesisBlock() *types.Block {
143 txStatus := bc.NewTransactionStatus()
144 if err := txStatus.SetStatus(0, false); err != nil {
145 log.Panicf(err.Error())
147 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
149 log.Panicf("fail on calc genesis tx status merkle root")
152 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
154 log.Panicf("fail on calc genesis tx merkel root")
157 var xPrv chainkd.XPrv
158 if CommonConfig.Consensus.Dpos.XPrv == "" {
159 log.Panicf("Signer is empty")
161 xPrv.UnmarshalText([]byte(CommonConfig.Consensus.Dpos.XPrv))
162 b, _ := xPrv.XPub().MarshalText()
164 block := &types.Block{
165 BlockHeader: types.BlockHeader{
168 Timestamp: 1528945000,
169 BlockCommitment: types.BlockCommitment{
170 TransactionsMerkleRoot: merkleRoot,
171 TransactionStatusHash: txStatusHash,
175 Transactions: []*types.Tx{tx},
180 // GenesisBlock will return genesis block
181 func GenesisBlock() *types.Block {
182 return map[string]func() *types.Block{
183 "main": mainNetGenesisBlock,
184 "test": testNetGenesisBlock,
185 "solo": soloNetGenesisBlock,
186 }[consensus.ActiveNetParams.Name]()