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 // FedAddressPath is used to derive federation root xpubs for signing cross-chain txs
17 var FedAddressPath = [][]byte{
18 []byte{0x2C, 0x00, 0x00, 0x00},
19 []byte{0x99, 0x00, 0x00, 0x00},
20 []byte{0x01, 0x00, 0x00, 0x00},
21 []byte{0x00, 0x00, 0x00, 0x00},
22 []byte{0x01, 0x00, 0x00, 0x00},
25 func FederationPMultiSigScript(c *Config) []byte {
26 xpubs := c.Federation.Xpubs
27 derivedXPubs := chainkd.DeriveXPubs(xpubs, FedAddressPath)
28 program, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(derivedXPubs), c.Federation.Quorum)
30 log.Panicf("fail to generate federation scirpt for federation: %v", err)
36 func FederationWScript(c *Config) []byte {
37 script := FederationPMultiSigScript(c)
38 scriptHash := crypto.Sha256(script)
39 wscript, err := vmutil.P2WSHProgram(scriptHash)
41 log.Panicf("Fail converts scriptHash to witness: %v", err)
47 func GenesisTx() *types.Tx {
48 contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4")
50 log.Panicf("fail on decode genesis tx output control program")
53 coinbaseInput := FederationWScript(CommonConfig)
55 txData := types.TxData{
57 Inputs: []*types.TxInput{
58 types.NewCoinbaseInput(coinbaseInput[:]),
60 Outputs: []*types.TxOutput{
61 types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.BlockSubsidy(0), contract),
64 return types.NewTx(txData)
67 func mainNetGenesisBlock() *types.Block {
69 txStatus := bc.NewTransactionStatus()
70 if err := txStatus.SetStatus(0, false); err != nil {
71 log.Panicf(err.Error())
73 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
75 log.Panicf("fail on calc genesis tx status merkle root")
78 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
80 log.Panicf("fail on calc genesis tx merkel root")
83 block := &types.Block{
84 BlockHeader: types.BlockHeader{
87 Timestamp: 1563344560002,
88 BlockCommitment: types.BlockCommitment{
89 TransactionsMerkleRoot: merkleRoot,
90 TransactionStatusHash: txStatusHash,
93 Transactions: []*types.Tx{tx},
98 func testNetGenesisBlock() *types.Block {
100 txStatus := bc.NewTransactionStatus()
101 if err := txStatus.SetStatus(0, false); err != nil {
102 log.Panicf(err.Error())
104 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
106 log.Panicf("fail on calc genesis tx status merkle root")
109 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
111 log.Panicf("fail on calc genesis tx merkel root")
114 block := &types.Block{
115 BlockHeader: types.BlockHeader{
118 Timestamp: 1563344560001,
119 BlockCommitment: types.BlockCommitment{
120 TransactionsMerkleRoot: merkleRoot,
121 TransactionStatusHash: txStatusHash,
124 Transactions: []*types.Tx{tx},
129 func soloNetGenesisBlock() *types.Block {
131 txStatus := bc.NewTransactionStatus()
132 if err := txStatus.SetStatus(0, false); err != nil {
133 log.Panicf(err.Error())
135 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
137 log.Panicf("fail on calc genesis tx status merkle root")
140 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
142 log.Panicf("fail on calc genesis tx merkel root")
145 block := &types.Block{
146 BlockHeader: types.BlockHeader{
149 Timestamp: 1563344560000,
150 BlockCommitment: types.BlockCommitment{
151 TransactionsMerkleRoot: merkleRoot,
152 TransactionStatusHash: txStatusHash,
155 Transactions: []*types.Tx{tx},
160 // GenesisBlock will return genesis block
161 func GenesisBlock() *types.Block {
162 return map[string]func() *types.Block{
163 "main": mainNetGenesisBlock,
164 "test": testNetGenesisBlock,
165 "solo": soloNetGenesisBlock,
166 }[consensus.ActiveNetParams.Name]()