mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
cmd/geth: update DeveloperGenesisBlock usage to return faucet address and key, enhance dev account display
This commit is contained in:
parent
e4c61f4c26
commit
e6ff50dbfb
4 changed files with 39 additions and 9 deletions
|
|
@ -304,7 +304,7 @@ func dumpGenesis(ctx *cli.Context) error {
|
|||
if utils.IsNetworkPreset(ctx) {
|
||||
genesis = utils.MakeGenesis(ctx)
|
||||
} else if ctx.IsSet(utils.DeveloperFlag.Name) && !ctx.IsSet(utils.DataDirFlag.Name) {
|
||||
genesis = core.DeveloperGenesisBlock(11_500_000, nil)
|
||||
genesis, _, _ = core.DeveloperGenesisBlock(11_500_000, nil)
|
||||
}
|
||||
|
||||
if genesis != nil {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
|
|
@ -29,6 +30,8 @@ import (
|
|||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/console/prompt"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/internal/debug"
|
||||
|
|
@ -342,7 +345,20 @@ func geth(ctx *cli.Context) error {
|
|||
defer stack.Close()
|
||||
|
||||
startNode(ctx, stack, false)
|
||||
|
||||
if ctx.IsSet(utils.DeveloperFlag.Name) && !ctx.IsSet(utils.DataDirFlag.Name) {
|
||||
_, faucetAddr, faucetKey := core.DeveloperGenesisBlock(0, nil)
|
||||
fmt.Println("Developer Faucet Account")
|
||||
fmt.Println("========================")
|
||||
fmt.Printf("Address: %s\n", faucetAddr.Hex())
|
||||
if faucetKey != nil {
|
||||
fmt.Printf("Private Key: 0x%s\n", hex.EncodeToString(crypto.FromECDSA(faucetKey)))
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
stack.Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1787,7 +1787,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
|||
log.Info("Using developer account", "address", developer.Address)
|
||||
|
||||
// Create a new developer genesis block or reuse existing one
|
||||
cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &developer.Address)
|
||||
cfg.Genesis, _, _ = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &developer.Address)
|
||||
if ctx.IsSet(DataDirFlag.Name) {
|
||||
chaindb := tryMakeReadOnlyDatabase(ctx, stack)
|
||||
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import (
|
|||
"math/big"
|
||||
"strings"
|
||||
|
||||
"crypto/ecdsa"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
|
|
@ -644,12 +646,27 @@ func DefaultHoodiGenesisBlock() *Genesis {
|
|||
}
|
||||
}
|
||||
|
||||
// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
|
||||
func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
|
||||
// DeveloperGenesisBlock returns the 'geth --dev' genesis block, faucet address, and key.
|
||||
func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) (*Genesis, common.Address, *ecdsa.PrivateKey) {
|
||||
config := *params.AllDevChainProtocolChanges
|
||||
|
||||
alloc := make(map[common.Address]types.Account)
|
||||
|
||||
var faucetAddr common.Address
|
||||
var faucetKey *ecdsa.PrivateKey
|
||||
if faucet == nil {
|
||||
// Generate a new dev account for the faucet
|
||||
key, err := crypto.GenerateKey()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to generate dev faucet key: %w", err))
|
||||
}
|
||||
faucetAddr = crypto.PubkeyToAddress(key.PublicKey)
|
||||
faucetKey = key
|
||||
} else {
|
||||
faucetAddr = *faucet
|
||||
}
|
||||
alloc[faucetAddr] = types.Account{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}
|
||||
|
||||
// Add precompiles and system contracts
|
||||
precompileAddrs := [][]byte{
|
||||
{0x01}, {0x02}, {0x03}, {0x04}, {0x05}, {0x06}, {0x07}, {0x08}, {0x09}, {0x0a}, {0x0b}, {0x0c}, {0x0d}, {0x0e}, {0x0f}, {0x10}, {0x11},
|
||||
|
|
@ -662,18 +679,15 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
|
|||
alloc[params.WithdrawalQueueAddress] = types.Account{Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0}
|
||||
alloc[params.ConsolidationQueueAddress] = types.Account{Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0}
|
||||
|
||||
if faucet != nil {
|
||||
alloc[*faucet] = types.Account{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}
|
||||
}
|
||||
|
||||
genesis := &Genesis{
|
||||
Config: &config,
|
||||
GasLimit: gasLimit,
|
||||
BaseFee: big.NewInt(params.InitialBaseFee),
|
||||
Difficulty: big.NewInt(0),
|
||||
Alloc: alloc,
|
||||
Coinbase: faucetAddr,
|
||||
}
|
||||
return genesis
|
||||
return genesis, faucetAddr, faucetKey
|
||||
}
|
||||
|
||||
func decodePrealloc(data string) types.GenesisAlloc {
|
||||
|
|
|
|||
Loading…
Reference in a new issue