From f39dec1a8bbd98359f689bc540f2d3be22f43598 Mon Sep 17 00:00:00 2001 From: lmittmann Date: Wed, 8 May 2024 18:30:44 +0200 Subject: [PATCH] added `{Address,Hash}.IsZero()` --- common/types.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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