Skip to content

Commit

Permalink
Adds a handy conversion (#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra authored Jun 20, 2024
1 parent 45fef62 commit 4ccb953
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/examples/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions utils/conversions/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4ccb953

Please sign in to comment.