package config
import (
+ "encoding/hex"
+
log "github.com/sirupsen/logrus"
"github.com/bytom/consensus"
"github.com/bytom/protocol/bc/types"
)
-// GenerateGenesisTx will return genesis transaction
-func GenerateGenesisTx() *types.Tx {
+func genesisTx() *types.Tx {
+ contract, err := hex.DecodeString("00149514bf92cac8791dcc4cd7fd3ef4167ffc477f62")
+ if err != nil {
+ log.Panicf("fail on decode genesis tx output control program")
+ }
+
txData := types.TxData{
- Version: 1,
- SerializedSize: 63,
+ Version: 1,
Inputs: []*types.TxInput{
types.NewCoinbaseInput([]byte("May 4th Be With You")),
},
Outputs: []*types.TxOutput{
- &types.TxOutput{
- AssetVersion: 1,
- OutputCommitment: types.OutputCommitment{
- AssetAmount: bc.AssetAmount{
- AssetId: consensus.BTMAssetID,
- Amount: consensus.InitialBlockSubsidy,
- },
- VMVersion: 1,
- ControlProgram: []byte{81},
- },
- },
+ types.NewTxOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract),
},
}
-
return types.NewTx(txData)
}
-// GenerateGenesisBlock will return genesis block
-func GenerateGenesisBlock() *types.Block {
- genesisCoinbaseTx := GenerateGenesisTx()
- merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{genesisCoinbaseTx.Tx})
- if err != nil {
- log.Panicf("Fatal create tx merkelRoot")
- }
-
+// GenesisBlock will return genesis block
+func GenesisBlock() *types.Block {
+ tx := genesisTx()
txStatus := bc.NewTransactionStatus()
txStatus.SetStatus(0, false)
txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
if err != nil {
- log.Panicf("Fatal create tx status gmerkelRoot")
+ log.Panicf("fail on calc genesis tx status merkle root")
+ }
+
+ merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{tx.Tx})
+ if err != nil {
+ log.Panicf("fail on calc genesis tx merkel root")
}
block := &types.Block{
BlockHeader: types.BlockHeader{
Version: 1,
Height: 0,
- Nonce: 4216236,
+ Nonce: 2083236893,
Timestamp: 1524202000,
+ Bits: 2089670227111054243,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: merkleRoot,
TransactionStatusHash: txStatusHash,
},
- Bits: 2089670227111054243,
},
- Transactions: []*types.Tx{genesisCoinbaseTx},
+ Transactions: []*types.Tx{tx},
}
return block
}
package config
-import (
- "testing"
-)
-
-// test genesis
-func TestGenerateGenesisTx(t *testing.T) {
- if tx := GenerateGenesisTx(); tx == nil {
- t.Errorf("Generate genesis tx failed")
- }
-}
-
/*func TestGenerateGenesisBlock(t *testing.T) {
block := GenerateGenesisBlock()
nonce := block.Nonce
// for next block, when a lower difficulty Int actually reflects a more difficult
// mining progress.
func CalcNextRequiredDifficulty(lastBH, compareBH *types.BlockHeader) uint64 {
- if lastBH == nil {
- return consensus.PowMinBits
- } else if (lastBH.Height)%consensus.BlocksPerRetarget != 0 || lastBH.Height == 0 {
+ if (lastBH.Height)%consensus.BlocksPerRetarget != 0 || lastBH.Height == 0 {
return lastBH.Bits
}
CoinbasePendingBlockNumber = uint64(100)
subsidyReductionInterval = uint64(840000)
baseSubsidy = uint64(41250000000)
- InitialBlockSubsidy = uint64(1470000041250000000)
+ InitialBlockSubsidy = uint64(147000041250000000)
// config for pow mining
- PowMinBits = uint64(2305843009213861724)
BlocksPerRetarget = uint64(2016)
TargetSecondsPerBlock = uint64(150)
SeedPerRetarget = uint64(256)
Bech32HRPSegwit string
}
+// ActiveNetParams is ...
var ActiveNetParams = MainNetParams
// NetParams is the correspondence between chain_id and Params
testDB := dbm.NewDB("testdb", "leveldb", "temp")
store := NewStore(testDB)
- block := config.GenerateGenesisBlock()
+ block := config.GenesisBlock()
txStatus := bc.NewTransactionStatus()
if err := store.SaveBlock(block, txStatus); err != nil {
ctx := context.Background()
initActiveNetParams(config)
// Get store
- txDB := dbm.NewDB("txdb", config.DBBackend, config.DBDir())
- store := leveldb.NewStore(txDB)
+ coreDB := dbm.NewDB("core", config.DBBackend, config.DBDir())
+ store := leveldb.NewStore(coreDB)
tokenDB := dbm.NewDB("accesstoken", config.DBBackend, config.DBDir())
accessTokens := accesstoken.NewStore(tokenDB)
// Make event switch
eventSwitch := types.NewEventSwitch()
- _, err := eventSwitch.Start()
- if err != nil {
+ if _, err := eventSwitch.Start(); err != nil {
cmn.Exit(cmn.Fmt("Failed to start switch: %v", err))
}
func TestCalcReorganizeNodes(t *testing.T) {
c := &Chain{index: state.NewBlockIndex()}
- header := config.GenerateGenesisBlock().BlockHeader
+ header := config.GenesisBlock().BlockHeader
initNode, err := state.NewBlockNode(&header, nil)
if err != nil {
t.Fatal(err)
}
func (c *Chain) initChainStatus() error {
- genesisBlock := config.GenerateGenesisBlock()
+ genesisBlock := config.GenesisBlock()
txStatus := bc.NewTransactionStatus()
for i := range genesisBlock.Transactions {
txStatus.SetStatus(i, false)
func (w *Wallet) getRescanNotification() {
select {
case <-w.rescanCh:
- w.status.WorkHeight = 0
- block, _ := w.chain.GetBlockByHeight(w.status.WorkHeight)
- w.status.WorkHash = block.Hash()
+ block, _ := w.chain.GetBlockByHeight(0)
+ w.status.WorkHash = bc.Hash{}
+ w.AttachBlock(block)
default:
return
}