From 96febdb6a56fad523356af82ac9164460b769df1 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 25 Jan 2021 14:53:12 +0300 Subject: [PATCH] [#324] morph/subscriber: Make block channel in constructor Replace block channel's initialization from BlockNotifications method body to Subscriber's constructor in order to prevent potential writing to nil channel. Signed-off-by: Leonard Lyubich --- pkg/morph/subscriber/subscriber.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/morph/subscriber/subscriber.go b/pkg/morph/subscriber/subscriber.go index 6772e0fa..73ad5a7f 100644 --- a/pkg/morph/subscriber/subscriber.go +++ b/pkg/morph/subscriber/subscriber.go @@ -112,8 +112,6 @@ func (s *subscriber) BlockNotifications() (<-chan *block.Block, error) { return nil, errors.Wrap(err, "could not subscribe for new block events") } - s.blockChan = make(chan *block.Block) - return s.blockChan, nil } @@ -179,6 +177,7 @@ func New(ctx context.Context, p *Params) (Subscriber, error) { client: wsClient, notify: make(chan *state.NotificationEvent), notifyIDs: make(map[util.Uint160]string), + blockChan: make(chan *block.Block), } // Worker listens all events from neo-go websocket and puts them