github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/store/orgchain/genesis/genesis.go (about)

     1  package genesis
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"github.com/sixexorg/magnetic-ring/common"
     7  	maintypes "github.com/sixexorg/magnetic-ring/core/mainchain/types"
     8  	"github.com/sixexorg/magnetic-ring/core/orgchain/types"
     9  	"github.com/sixexorg/magnetic-ring/store/orgchain/states"
    10  	"github.com/sixexorg/magnetic-ring/store/storelaw"
    11  )
    12  
    13  func NewGensisState(tx *maintypes.Transaction) *states.AccountState {
    14  	if tx.TxType != maintypes.CreateLeague {
    15  		return nil
    16  	}
    17  	balance := big.NewInt(0)
    18  	account := &states.AccountState{
    19  		Address: tx.TxData.From,
    20  		Height:  1,
    21  		Data: &states.Account{
    22  			Nonce:       1,
    23  			Balance:     balance.Mul(tx.TxData.MetaBox, big.NewInt(int64(tx.TxData.Rate))),
    24  			EnergyBalance: big.NewInt(20000000000),
    25  		},
    26  	}
    27  	return account
    28  }
    29  func GensisBlock(tx *maintypes.Transaction, createTime uint64) (*types.Block, storelaw.AccountStaters) {
    30  	leagueId := maintypes.ToLeagueAddress(tx)
    31  	leagueId = leagueId
    32  	state := NewGensisState(tx)
    33  	sts := storelaw.AccountStaters{state}
    34  
    35  	block := &types.Block{
    36  		Header: &types.Header{
    37  			LeagueId:      leagueId,
    38  			PrevBlockHash: common.Hash{},
    39  			Version:       0x01,
    40  			BlockRoot:     common.Hash{},
    41  			TxRoot:        common.Hash{},
    42  			Difficulty:    big.NewInt(10),
    43  			Height:        1,
    44  			Timestamp:     createTime,
    45  			ReceiptsRoot:  common.Hash{},
    46  			StateRoot:     sts.GetHashRoot(),
    47  		},
    48  	}
    49  	return block, sts
    50  }