From 7853dbc315a7a9d7d450d92e4342b59c155a514c Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 11 Dec 2024 15:20:59 +0300 Subject: [PATCH] [#1557] morph/event: Remove embedded structs from scriptHashWithValue Also, make them public, because otherwise `unused` linter complains. ``` pkg/morph/event/utils.go:25:2 unused field `typ` is unused ``` This complain is wrong, though: we _use_ `typ` field because the whole struct is used as a map key. Signed-off-by: Evgenii Stratonikov --- pkg/morph/event/listener.go | 12 ++++-------- pkg/morph/event/utils.go | 18 ++---------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/pkg/morph/event/listener.go b/pkg/morph/event/listener.go index 9852a3d62..7a16eb991 100644 --- a/pkg/morph/event/listener.go +++ b/pkg/morph/event/listener.go @@ -180,7 +180,7 @@ func (l *listener) subscribe(errCh chan error) { // fill the list with the contracts with set event parsers. l.mtx.RLock() for hashType := range l.notificationParsers { - scHash := hashType.ScriptHash() + scHash := hashType.Hash // prevent repetitions for _, hash := range hashes { @@ -189,7 +189,7 @@ func (l *listener) subscribe(errCh chan error) { } } - hashes = append(hashes, hashType.ScriptHash()) + hashes = append(hashes, hashType.Hash) } l.mtx.RUnlock() @@ -326,9 +326,7 @@ func (l *listener) parseAndHandleNotification(ctx context.Context, notifyEvent * ) // get the event parser - keyEvent := scriptHashWithType{} - keyEvent.SetScriptHash(notifyEvent.ScriptHash) - keyEvent.SetType(typEvent) + keyEvent := scriptHashWithType{Hash: notifyEvent.ScriptHash, Type: typEvent} l.mtx.RLock() parser, ok := l.notificationParsers[keyEvent] @@ -451,9 +449,7 @@ func (l *listener) RegisterNotificationHandler(hi NotificationHandlerInfo) { l.mtx.Lock() defer l.mtx.Unlock() - var k scriptHashWithType - k.hash = hi.Contract - k.typ = hi.Type + k := scriptHashWithType{Hash: hi.Contract, Type: hi.Type} l.notificationParsers[k] = hi.Parser l.notificationHandlers[k] = append( diff --git a/pkg/morph/event/utils.go b/pkg/morph/event/utils.go index 99ea9a7f0..058959c63 100644 --- a/pkg/morph/event/utils.go +++ b/pkg/morph/event/utils.go @@ -20,13 +20,9 @@ type scriptHashValue struct { hash util.Uint160 } -type typeValue struct { - typ Type -} - type scriptHashWithType struct { - scriptHashValue - typeValue + Hash util.Uint160 + Type Type } type notaryRequestTypes struct { @@ -73,16 +69,6 @@ func (s scriptHashValue) ScriptHash() util.Uint160 { return s.hash } -// SetType is an event type setter. -func (s *typeValue) SetType(v Type) { - s.typ = v -} - -// GetType is an event type getter. -func (s typeValue) GetType() Type { - return s.typ -} - // WorkerPoolHandler sets closure over worker pool w with passed handler h. func WorkerPoolHandler(w util2.WorkerPool, h Handler, log *logger.Logger) Handler { return func(ctx context.Context, e Event) {