From 4ccb953b75838d5d782df90a370c4b077addffaa Mon Sep 17 00:00:00 2001 From: Adam Hamrick Date: Thu, 20 Jun 2024 13:34:50 -0400 Subject: [PATCH] Adds a handy conversion (#1007) --- config/examples/testconfig.go | 2 +- utils/conversions/conversions.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/examples/testconfig.go b/config/examples/testconfig.go index 79361db21..f64cddb73 100644 --- a/config/examples/testconfig.go +++ b/config/examples/testconfig.go @@ -176,7 +176,7 @@ func GetConfig(configurationName string, product Product) (TestConfig, error) { func (c *TestConfig) readNetworkConfiguration() error { // currently we need to read that kind of secrets only for network configuration - if c == nil { + if c.Network == nil { c.Network = &ctf_config.NetworkConfig{} } err := c.Network.Default() diff --git a/utils/conversions/conversions.go b/utils/conversions/conversions.go index d86f29538..85b3f284d 100644 --- a/utils/conversions/conversions.go +++ b/utils/conversions/conversions.go @@ -21,6 +21,15 @@ func PrivateKeyToAddress(privateKey *ecdsa.PrivateKey) (common.Address, error) { return crypto.PubkeyToAddress(*publicKeyECDSA), nil } +// PrivateKeyHexToAddress is a handy converter for a string private key to a usable eth address +func PrivateKeyHexToAddress(privateKeyStr string) (common.Address, error) { + privateKey, err := crypto.HexToECDSA(privateKeyStr) + if err != nil { + return common.Address{}, fmt.Errorf("Error converting private key to ECDSA format: %s", err) + } + return PrivateKeyToAddress(privateKey) +} + // Credit to kimxilxyong: https://github.com/ethereum/go-ethereum/issues/21221#issuecomment-802092592 // EtherToWei converts an ETH float amount to wei