6 log "github.com/sirupsen/logrus"
8 "github.com/vapor/consensus"
9 "github.com/vapor/crypto"
10 "github.com/vapor/crypto/ed25519/chainkd"
11 "github.com/vapor/protocol/bc"
12 "github.com/vapor/protocol/bc/types"
13 "github.com/vapor/protocol/vm/vmutil"
16 func GenesisArguments(c *Config) []byte {
17 pubKeys := chainkd.XPubKeys(c.Federation.Xpubs)
18 fedpegScript, err := vmutil.P2SPMultiSigProgram(pubKeys, c.Federation.Quorum)
20 log.Panicf("fail on decode genesis arguments for federation")
23 scriptHash := crypto.Sha256(fedpegScript)
25 control, err := vmutil.P2WSHProgram(scriptHash)
27 log.Panicf("Fail converts scriptHash to program on GenesisArguments: %v", err)
33 func GenesisTx() *types.Tx {
34 contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4")
36 log.Panicf("fail on decode genesis tx output control program")
39 coinbaseInput := GenesisArguments(CommonConfig)
41 txData := types.TxData{
43 Inputs: []*types.TxInput{
44 types.NewCoinbaseInput(coinbaseInput[:]),
46 Outputs: []*types.TxOutput{
47 types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract),
50 return types.NewTx(txData)
53 func mainNetGenesisBlock() *types.Block {
55 txStatus := bc.NewTransactionStatus()
56 if err := txStatus.SetStatus(0, false); err != nil {
57 log.Panicf(err.Error())
59 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
61 log.Panicf("fail on calc genesis tx status merkle root")
64 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
66 log.Panicf("fail on calc genesis tx merkel root")
69 block := &types.Block{
70 BlockHeader: types.BlockHeader{
73 Timestamp: 1524549600000,
74 BlockCommitment: types.BlockCommitment{
75 TransactionsMerkleRoot: merkleRoot,
76 TransactionStatusHash: txStatusHash,
79 Transactions: []*types.Tx{tx},
84 func testNetGenesisBlock() *types.Block {
86 txStatus := bc.NewTransactionStatus()
87 if err := txStatus.SetStatus(0, false); err != nil {
88 log.Panicf(err.Error())
90 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
92 log.Panicf("fail on calc genesis tx status merkle root")
95 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
97 log.Panicf("fail on calc genesis tx merkel root")
100 block := &types.Block{
101 BlockHeader: types.BlockHeader{
104 Timestamp: 1528945000000,
105 BlockCommitment: types.BlockCommitment{
106 TransactionsMerkleRoot: merkleRoot,
107 TransactionStatusHash: txStatusHash,
110 Transactions: []*types.Tx{tx},
115 func soloNetGenesisBlock() *types.Block {
117 txStatus := bc.NewTransactionStatus()
118 if err := txStatus.SetStatus(0, false); err != nil {
119 log.Panicf(err.Error())
121 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
123 log.Panicf("fail on calc genesis tx status merkle root")
126 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
128 log.Panicf("fail on calc genesis tx merkel root")
131 block := &types.Block{
132 BlockHeader: types.BlockHeader{
135 Timestamp: 1528945000000,
136 BlockCommitment: types.BlockCommitment{
137 TransactionsMerkleRoot: merkleRoot,
138 TransactionStatusHash: txStatusHash,
141 Transactions: []*types.Tx{tx},
146 // GenesisBlock will return genesis block
147 func GenesisBlock() *types.Block {
148 return map[string]func() *types.Block{
149 "main": mainNetGenesisBlock,
150 "test": testNetGenesisBlock,
151 "solo": soloNetGenesisBlock,
152 "vapor": soloNetGenesisBlock,
153 }[consensus.ActiveNetParams.Name]()