code: func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
  	if db == nil {
  		db = rawdb.NewMemoryDatabase()
  	}
  	statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
  	for addr, account := range g.Alloc {
  		statedb.AddBalance(addr, account.Balance)
  		statedb.SetCode(addr, account.Code)
  		statedb.SetNonce(addr, account.Nonce)
  		for key, value := range account.Storage {
  			statedb.SetState(addr, key, value)
  		}
  	}
  	root := statedb.IntermediateRoot(false)
  	head := &types.Header{
  		Number:     new(big.Int).SetUint64(g.Number),
  		Nonce:      types.EncodeNonce(g.Nonce),
  		Time:       g.Timestamp,
  		ParentHash: g.ParentHash,
  		Extra:      g.ExtraData,
  		GasLimit:   g.GasLimit,
  		GasUsed:    g.GasUsed,
  		Difficulty: g.Difficulty,
  		MixDigest:  g.Mixhash,
  		Coinbase:   g.Coinbase,
  		Root:       root,
  	}
  	if g.GasLimit == 0 {
  		head.GasLimit = params.GenesisGasLimit
  	}
  	if g.Difficulty == nil {
  		head.Difficulty = params.GenesisDifficulty
  	}
  	statedb.Commit(false)
  	statedb.Database().TrieDB().Commit(root, true)
  
  	return types.NewBlock(head, nil, nil, nil)
  }
docs: // ToBlock creates the genesis block and writes state of a genesis specification
  // to the given database (or discards it if nil).