From ccbb203c5a72b1fca34a7bfaf2b887ea2edf118a Mon Sep 17 00:00:00 2001 From: Nevio Vesic <0x19@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:44:39 +0200 Subject: [PATCH] NamedAddr AppendTags() and IsZeroAddress() (#208) --- storage/variable.go | 4 ++-- utils/addr.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/storage/variable.go b/storage/variable.go index 1df0c472..1415cf77 100644 --- a/storage/variable.go +++ b/storage/variable.go @@ -25,7 +25,7 @@ func (v *Variable) IsAddressType() bool { } // IsDynamicArray checks if the variable is a dynamic array. -// Currently returns false and needs implementation for dynamic array checking. +// Currently, returns false and needs implementation for dynamic array checking. func (v *Variable) IsDynamicArray() bool { variableType := v.StateVariable.GetType() return strings.Contains(variableType, "[]") @@ -52,7 +52,7 @@ func (v *Variable) IsStructType() bool { return strings.HasPrefix(variableType, "struct") } -// IsStructType checks if the variable is of a contract type. +// IsContractType checks if the variable is of a contract type. // Returns true if the variable type starts with "contract". func (v *Variable) IsContractType() bool { variableType := v.StateVariable.GetType() diff --git a/utils/addr.go b/utils/addr.go index 31698dba..feb3c2a9 100644 --- a/utils/addr.go +++ b/utils/addr.go @@ -23,3 +23,18 @@ type NamedAddr struct { Addr common.Address `json:"addr"` Type AddressType `json:"type"` } + +// AppendTags appends unique tags to the named address +func (n NamedAddr) AppendTags(tags ...string) NamedAddr { + for _, tag := range tags { + if !StringInSlice(tag, n.Tags) { + n.Tags = append(n.Tags, tag) + } + } + return n +} + +// IsZeroAddress checks whenever named address is zero address +func (n NamedAddr) IsZeroAddress() bool { + return n.Addr == ZeroAddress +}