cmd/utils: use IsHexAddress method (#32997)

Using the `IsHexAddress` method will result in no gaps in the
verification logic, making it simpler.
This commit is contained in:
maskpp 2025-10-23 17:56:47 +08:00 committed by Alvarez
parent b01111fbbe
commit b7d47f71d6

View file

@ -20,7 +20,6 @@ package utils
import ( import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -1341,15 +1340,10 @@ func setEtherbase(ctx *cli.Context, cfg *ethconfig.Config) {
return return
} }
addr := ctx.String(MinerPendingFeeRecipientFlag.Name) addr := ctx.String(MinerPendingFeeRecipientFlag.Name)
if strings.HasPrefix(addr, "0x") || strings.HasPrefix(addr, "0X") { if !common.IsHexAddress(addr) {
addr = addr[2:]
}
b, err := hex.DecodeString(addr)
if err != nil || len(b) != common.AddressLength {
Fatalf("-%s: invalid pending block producer address %q", MinerPendingFeeRecipientFlag.Name, addr) Fatalf("-%s: invalid pending block producer address %q", MinerPendingFeeRecipientFlag.Name, addr)
return
} }
cfg.Miner.PendingFeeRecipient = common.BytesToAddress(b) cfg.Miner.PendingFeeRecipient = common.HexToAddress(addr)
} }
func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) { func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {