2021-01-06 20:56:40 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
2021-05-14 06:52:18 +00:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2021-09-03 18:06:36 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2021-01-06 20:56:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// IsEmptyHash returns true if the hash corresponds to an empty ethereum hex hash.
|
|
|
|
func IsEmptyHash(hash string) bool {
|
2021-09-03 18:06:36 +00:00
|
|
|
return bytes.Equal(common.HexToHash(hash).Bytes(), common.Hash{}.Bytes())
|
2021-01-06 20:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsZeroAddress returns true if the address corresponds to an empty ethereum hex address.
|
|
|
|
func IsZeroAddress(address string) bool {
|
2021-09-03 18:06:36 +00:00
|
|
|
return bytes.Equal(common.HexToAddress(address).Bytes(), common.Address{}.Bytes())
|
2021-01-06 20:56:40 +00:00
|
|
|
}
|
2021-05-14 06:52:18 +00:00
|
|
|
|
|
|
|
// ValidateAddress returns an error if the provided string is either not a hex formatted string address
|
|
|
|
func ValidateAddress(address string) error {
|
2021-09-03 18:06:36 +00:00
|
|
|
if !common.IsHexAddress(address) {
|
2021-05-14 06:52:18 +00:00
|
|
|
return sdkerrors.Wrapf(
|
|
|
|
sdkerrors.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address",
|
|
|
|
address,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|