cmd/utils: add --dev.alloc flag

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-09-11 17:49:07 +08:00
parent 4e1e37323d
commit 86cfddab5b

View file

@ -21,6 +21,7 @@ import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex" "encoding/hex"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"math" "math"
@ -173,6 +174,12 @@ var (
Value: 11500000, Value: 11500000,
Category: flags.DevCategory, Category: flags.DevCategory,
} }
DeveloperAllocFlag = &cli.PathFlag{
Name: "dev.alloc",
Usage: "Genesis account allocation file to use in developer mode",
TakesFile: true,
Category: flags.DevCategory,
}
IdentityFlag = &cli.StringFlag{ IdentityFlag = &cli.StringFlag{
Name: "identity", Name: "identity",
@ -1876,8 +1883,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
} }
log.Info("Using developer account", "address", developer.Address) log.Info("Using developer account", "address", developer.Address)
var alloc core.GenesisAlloc
if allocPath := ctx.Path(DeveloperAllocFlag.Name); allocPath != "" {
data, err := os.ReadFile(allocPath)
if err != nil {
Fatalf("Failed to read developer genesis alloc file: %v", err)
}
if err := json.Unmarshal(data, &alloc); err != nil {
Fatalf("Failed to parse developer genesis alloc file: %v", err)
}
}
// Create a new developer genesis block or reuse existing one // 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, &alloc)
if ctx.IsSet(DataDirFlag.Name) { if ctx.IsSet(DataDirFlag.Name) {
chaindb := tryMakeReadOnlyDatabase(ctx, stack) chaindb := tryMakeReadOnlyDatabase(ctx, stack)
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) { if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {