diff --git a/common/types.go b/common/types.go index b914787d13..6182884090 100644 --- a/common/types.go +++ b/common/types.go @@ -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