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 var FedAddressPath = [][]byte{
17 []byte{0x2C, 0x00, 0x00, 0x00},
18 []byte{0x99, 0x00, 0x00, 0x00},
19 []byte{0x01, 0x00, 0x00, 0x00},
20 []byte{0x00, 0x00, 0x00, 0x00},
21 []byte{0x01, 0x00, 0x00, 0x00},
24 func FederationPMultiSigScript(c *Config) []byte {
25 xpubs := c.Federation.Xpubs
26 derivedXPubs := chainkd.DeriveXPubs(xpubs, FedAddressPath)
27 program, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(derivedXPubs), c.Federation.Quorum)
29 log.Panicf("fail to generate federation scirpt for federation: %v", err)
35 func FederationWScript(c *Config) []byte {
36 script := FederationPMultiSigScript(c)
37 scriptHash := crypto.Sha256(script)
38 wscript, err := vmutil.P2WSHProgram(scriptHash)
40 log.Panicf("Fail converts scriptHash to witness: %v", err)
46 func GenesisTx() *types.Tx {
47 contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4")
49 log.Panicf("fail on decode genesis tx output control program")
52 coinbaseInput := FederationWScript(CommonConfig)
54 txData := types.TxData{
56 Inputs: []*types.TxInput{
57 types.NewCoinbaseInput(coinbaseInput[:]),
59 Outputs: []*types.TxOutput{
60 types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.BlockSubsidy(0), contract),
63 return types.NewTx(txData)
66 func mainNetGenesisBlock() *types.Block {
68 txStatus := bc.NewTransactionStatus()
69 if err := txStatus.SetStatus(0, false); err != nil {
70 log.Panicf(err.Error())
72 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
74 log.Panicf("fail on calc genesis tx status merkle root")
77 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
79 log.Panicf("fail on calc genesis tx merkel root")
82 block := &types.Block{
83 BlockHeader: types.BlockHeader{
86 Timestamp: 1562840600003,
87 BlockCommitment: types.BlockCommitment{
88 TransactionsMerkleRoot: merkleRoot,
89 TransactionStatusHash: txStatusHash,
92 Transactions: []*types.Tx{tx},
97 func testNetGenesisBlock() *types.Block {
99 txStatus := bc.NewTransactionStatus()
100 if err := txStatus.SetStatus(0, false); err != nil {
101 log.Panicf(err.Error())
103 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
105 log.Panicf("fail on calc genesis tx status merkle root")
108 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
110 log.Panicf("fail on calc genesis tx merkel root")
113 block := &types.Block{
114 BlockHeader: types.BlockHeader{
117 Timestamp: 1562840600001,
118 BlockCommitment: types.BlockCommitment{
119 TransactionsMerkleRoot: merkleRoot,
120 TransactionStatusHash: txStatusHash,
123 Transactions: []*types.Tx{tx},
128 func soloNetGenesisBlock() *types.Block {
130 txStatus := bc.NewTransactionStatus()
131 if err := txStatus.SetStatus(0, false); err != nil {
132 log.Panicf(err.Error())
134 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
136 log.Panicf("fail on calc genesis tx status merkle root")
139 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
141 log.Panicf("fail on calc genesis tx merkel root")
144 block := &types.Block{
145 BlockHeader: types.BlockHeader{
148 Timestamp: 1562840600000,
149 BlockCommitment: types.BlockCommitment{
150 TransactionsMerkleRoot: merkleRoot,
151 TransactionStatusHash: txStatusHash,
154 Transactions: []*types.Tx{tx},
159 // GenesisBlock will return genesis block
160 func GenesisBlock() *types.Block {
161 return map[string]func() *types.Block{
162 "main": mainNetGenesisBlock,
163 "test": testNetGenesisBlock,
164 "solo": soloNetGenesisBlock,
165 }[consensus.ActiveNetParams.Name]()