mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
cmd/geth: remove PrintDevAccounts function and related dev account generation logic
This commit is contained in:
parent
538a9416a8
commit
e4c61f4c26
2 changed files with 1 additions and 69 deletions
|
|
@ -42,11 +42,6 @@ import (
|
|||
_ "github.com/ethereum/go-ethereum/eth/tracers/live"
|
||||
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
|
||||
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
|
@ -333,22 +328,6 @@ func prepare(ctx *cli.Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PrintDevAccounts(devAccounts []core.DevAccount) {
|
||||
fmt.Println("Available Accounts")
|
||||
fmt.Println("==================")
|
||||
for i, acct := range devAccounts {
|
||||
ethBal := new(big.Float).Quo(new(big.Float).SetInt(acct.Balance), big.NewFloat(1e18))
|
||||
fmt.Printf("(%d) %s (%s ETH)\n", i, acct.Address.Hex(), ethBal.Text('f', 18))
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println("Private Keys")
|
||||
fmt.Println("==================")
|
||||
for i, acct := range devAccounts {
|
||||
fmt.Printf("(%d) 0x%s\n", i, hex.EncodeToString(crypto.FromECDSA(acct.PrivateKey)))
|
||||
}
|
||||
}
|
||||
|
||||
// geth is the main entry point into the system if no special subcommand is run.
|
||||
// It creates a default node based on the command line arguments and runs it in
|
||||
// blocking mode, waiting for it to be shut down.
|
||||
|
|
@ -359,13 +338,6 @@ func geth(ctx *cli.Context) error {
|
|||
|
||||
prepare(ctx)
|
||||
|
||||
if ctx.IsSet(utils.DeveloperFlag.Name) {
|
||||
devAccounts, err := core.GenerateDevAccounts()
|
||||
if err == nil {
|
||||
PrintDevAccounts(devAccounts)
|
||||
}
|
||||
}
|
||||
|
||||
stack := makeFullNode(ctx)
|
||||
defer stack.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ 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"
|
||||
|
|
@ -646,50 +644,12 @@ func DefaultHoodiGenesisBlock() *Genesis {
|
|||
}
|
||||
}
|
||||
|
||||
const (
|
||||
devAccountCount = 10
|
||||
devAccountSeedPrefix = "dev-account-seed-"
|
||||
devAccountBalance = 10000
|
||||
)
|
||||
|
||||
type DevAccount struct {
|
||||
Address common.Address
|
||||
PrivateKey *ecdsa.PrivateKey
|
||||
Balance *big.Int
|
||||
}
|
||||
|
||||
func GenerateDevAccounts() ([]DevAccount, error) {
|
||||
var devAccounts []DevAccount
|
||||
for i := 0; i < devAccountCount; i++ {
|
||||
seed := append([]byte(devAccountSeedPrefix), byte(i))
|
||||
key, err := crypto.ToECDSA(crypto.Keccak256(seed))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addr := crypto.PubkeyToAddress(key.PublicKey)
|
||||
devAccounts = append(devAccounts, DevAccount{
|
||||
Address: addr,
|
||||
PrivateKey: key,
|
||||
Balance: new(big.Int).Mul(big.NewInt(devAccountBalance), big.NewInt(1e18)),
|
||||
})
|
||||
}
|
||||
return devAccounts, nil
|
||||
}
|
||||
|
||||
// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
|
||||
func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
|
||||
config := *params.AllDevChainProtocolChanges
|
||||
|
||||
devAccounts, err := GenerateDevAccounts()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to generate dev accounts: %w", err))
|
||||
}
|
||||
|
||||
alloc := make(map[common.Address]types.Account)
|
||||
// Prefund dev accounts
|
||||
for _, acct := range devAccounts {
|
||||
alloc[acct.Address] = types.Account{Balance: acct.Balance}
|
||||
}
|
||||
|
||||
// Add precompiles and system contracts
|
||||
precompileAddrs := [][]byte{
|
||||
{0x01}, {0x02}, {0x03}, {0x04}, {0x05}, {0x06}, {0x07}, {0x08}, {0x09}, {0x0a}, {0x0b}, {0x0c}, {0x0d}, {0x0e}, {0x0f}, {0x10}, {0x11},
|
||||
|
|
|
|||
Loading…
Reference in a new issue