added {Address,Hash}.IsZero()

This commit is contained in:
lmittmann 2024-05-08 18:30:44 +02:00
parent 35b2d07f4b
commit f39dec1a8b

View file

@ -50,6 +50,9 @@ var (
// MaxHash represents the maximum possible hash value.
MaxHash = HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
addr0 Address // zero Address
hash0 Hash // zero Hash
)
// Hash represents the 32 byte Keccak256 hash of arbitrary data.
@ -194,6 +197,11 @@ func (h *Hash) UnmarshalGraphQL(input interface{}) error {
return err
}
// IsZero returns true for the zero hash.
func (h Hash) IsZero() bool {
return h == hash0
}
// UnprefixedHash allows marshaling a Hash without 0x prefix.
type UnprefixedHash Hash
@ -371,6 +379,11 @@ func (a *Address) UnmarshalGraphQL(input interface{}) error {
return err
}
// IsZero returns true for the zero address.
func (a Address) IsZero() bool {
return a == addr0
}
// UnprefixedAddress allows marshaling an Address without 0x prefix.
type UnprefixedAddress Address