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 FederationPMultiSigScript(c *Config) []byte {
17 xpubs := c.Federation.Xpubs
18 program, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(xpubs), c.Federation.Quorum)
20 log.Panicf("fail to generate federation scirpt for federation: %v", err)
26 func FederationWScript(c *Config) []byte {
27 script := FederationPMultiSigScript(c)
28 scriptHash := crypto.Sha256(script)
29 wscript, err := vmutil.P2WSHProgram(scriptHash)
31 log.Panicf("Fail converts scriptHash to witness: %v", err)
37 func GenesisTx() *types.Tx {
38 contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4")
40 log.Panicf("fail on decode genesis tx output control program")
43 coinbaseInput := FederationWScript(CommonConfig)
45 txData := types.TxData{
47 Inputs: []*types.TxInput{
48 types.NewCoinbaseInput(coinbaseInput[:]),
50 Outputs: []*types.TxOutput{
51 types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.BlockSubsidy(0), contract),
54 return types.NewTx(txData)
57 func mainNetGenesisBlock() *types.Block {
59 txStatus := bc.NewTransactionStatus()
60 if err := txStatus.SetStatus(0, false); err != nil {
61 log.Panicf(err.Error())
63 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
65 log.Panicf("fail on calc genesis tx status merkle root")
68 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
70 log.Panicf("fail on calc genesis tx merkel root")
73 block := &types.Block{
74 BlockHeader: types.BlockHeader{
77 Timestamp: 1562840600003,
78 BlockCommitment: types.BlockCommitment{
79 TransactionsMerkleRoot: merkleRoot,
80 TransactionStatusHash: txStatusHash,
83 Transactions: []*types.Tx{tx},
88 func testNetGenesisBlock() *types.Block {
90 txStatus := bc.NewTransactionStatus()
91 if err := txStatus.SetStatus(0, false); err != nil {
92 log.Panicf(err.Error())
94 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
96 log.Panicf("fail on calc genesis tx status merkle root")
99 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
101 log.Panicf("fail on calc genesis tx merkel root")
104 block := &types.Block{
105 BlockHeader: types.BlockHeader{
108 Timestamp: 1562840600001,
109 BlockCommitment: types.BlockCommitment{
110 TransactionsMerkleRoot: merkleRoot,
111 TransactionStatusHash: txStatusHash,
114 Transactions: []*types.Tx{tx},
119 func soloNetGenesisBlock() *types.Block {
121 txStatus := bc.NewTransactionStatus()
122 if err := txStatus.SetStatus(0, false); err != nil {
123 log.Panicf(err.Error())
125 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
127 log.Panicf("fail on calc genesis tx status merkle root")
130 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
132 log.Panicf("fail on calc genesis tx merkel root")
135 block := &types.Block{
136 BlockHeader: types.BlockHeader{
139 Timestamp: 1562840600000,
140 BlockCommitment: types.BlockCommitment{
141 TransactionsMerkleRoot: merkleRoot,
142 TransactionStatusHash: txStatusHash,
145 Transactions: []*types.Tx{tx},
150 // GenesisBlock will return genesis block
151 func GenesisBlock() *types.Block {
152 return map[string]func() *types.Block{
153 "main": mainNetGenesisBlock,
154 "test": testNetGenesisBlock,
155 "solo": soloNetGenesisBlock,
156 }[consensus.ActiveNetParams.Name]()