7 log "github.com/sirupsen/logrus"
9 "github.com/vapor/consensus"
10 "github.com/vapor/crypto"
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 var signBlockPubkeys []ed25519.PublicKey
21 for _, xpub := range consensus.ActiveNetParams.FedpegXPubs {
22 fedpegPubkeys = append(fedpegPubkeys, xpub.PublicKey())
24 fedpegScript, _ := vmutil.P2SPMultiSigProgram(fedpegPubkeys, len(fedpegPubkeys))
26 for _, xpub := range consensus.ActiveNetParams.SignBlockXPubs {
27 signBlockPubkeys = append(signBlockPubkeys, xpub.PublicKey())
29 signBlockScript, _ := vmutil.P2SPMultiSigProgram(signBlockPubkeys, len(signBlockPubkeys))
31 hasher := sha256.New()
32 hasher.Write(fedpegScript)
33 hasher.Write(signBlockScript)
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),
59 return types.NewTx(txData)
62 func mainNetGenesisBlock() *types.Block {
64 txStatus := bc.NewTransactionStatus()
65 if err := txStatus.SetStatus(0, false); err != nil {
66 log.Panicf(err.Error())
68 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
70 log.Panicf("fail on calc genesis tx status merkle root")
73 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
75 log.Panicf("fail on calc genesis tx merkel root")
78 block := &types.Block{
79 BlockHeader: types.BlockHeader{
82 Timestamp: 1524549600,
83 BlockCommitment: types.BlockCommitment{
84 TransactionsMerkleRoot: merkleRoot,
85 TransactionStatusHash: txStatusHash,
88 Transactions: []*types.Tx{tx},
92 if consensus.ActiveNetParams.Signer == "" {
95 copy(xPrv[:], []byte(consensus.ActiveNetParams.Signer))
96 msg, _ := block.MarshalText()
97 sign := xPrv.Sign(msg)
98 pubHash := crypto.Ripemd160(xPrv.XPub().PublicKey())
99 control, err := vmutil.P2WPKHProgram([]byte(pubHash))
101 log.Panicf(err.Error())
103 block.Proof.Sign = sign
104 block.Proof.ControlProgram = control
108 func testNetGenesisBlock() *types.Block {
110 txStatus := bc.NewTransactionStatus()
111 if err := txStatus.SetStatus(0, false); err != nil {
112 log.Panicf(err.Error())
114 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
116 log.Panicf("fail on calc genesis tx status merkle root")
119 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
121 log.Panicf("fail on calc genesis tx merkel root")
124 block := &types.Block{
125 BlockHeader: types.BlockHeader{
128 Timestamp: 1528945000,
129 BlockCommitment: types.BlockCommitment{
130 TransactionsMerkleRoot: merkleRoot,
131 TransactionStatusHash: txStatusHash,
134 Transactions: []*types.Tx{tx},
139 func soloNetGenesisBlock() *types.Block {
141 txStatus := bc.NewTransactionStatus()
142 if err := txStatus.SetStatus(0, false); err != nil {
143 log.Panicf(err.Error())
145 txStatusHash, err := types.TxStatusMerkleRoot(txStatus.VerifyStatus)
147 log.Panicf("fail on calc genesis tx status merkle root")
150 merkleRoot, err := types.TxMerkleRoot([]*bc.Tx{tx.Tx})
152 log.Panicf("fail on calc genesis tx merkel root")
155 block := &types.Block{
156 BlockHeader: types.BlockHeader{
159 Timestamp: 1528945000,
160 BlockCommitment: types.BlockCommitment{
161 TransactionsMerkleRoot: merkleRoot,
162 TransactionStatusHash: txStatusHash,
165 Transactions: []*types.Tx{tx},
170 // GenesisBlock will return genesis block
171 func GenesisBlock() *types.Block {
172 return map[string]func() *types.Block{
173 "main": mainNetGenesisBlock,
174 "test": testNetGenesisBlock,
175 "solo": soloNetGenesisBlock,
176 }[consensus.ActiveNetParams.Name]()