-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: missing functions from chain types & bump go mod deps (for evm)
- Loading branch information
Showing
4 changed files
with
273 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
errortypes "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// IsEmptyHash returns true if the hash corresponds to an empty ethereum hex hash. | ||
func IsEmptyHash(hash string) bool { | ||
return bytes.Equal(common.HexToHash(hash).Bytes(), common.Hash{}.Bytes()) | ||
} | ||
|
||
// IsZeroAddress returns true if the address corresponds to an empty ethereum hex address. | ||
func IsZeroAddress(address string) bool { | ||
return bytes.Equal(common.HexToAddress(address).Bytes(), common.Address{}.Bytes()) | ||
} | ||
|
||
// ValidateAddress returns an error if the provided string is either not a hex formatted string address | ||
func ValidateAddress(address string) error { | ||
if !common.IsHexAddress(address) { | ||
return errorsmod.Wrapf( | ||
errortypes.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address", | ||
address, | ||
) | ||
} | ||
return nil | ||
} | ||
|
||
// ValidateNonZeroAddress returns an error if the provided string is not a hex | ||
// formatted string address or is equal to zero | ||
func ValidateNonZeroAddress(address string) error { | ||
if IsZeroAddress(address) { | ||
return errorsmod.Wrapf( | ||
errortypes.ErrInvalidAddress, "address '%s' must not be zero", | ||
address, | ||
) | ||
} | ||
return ValidateAddress(address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.