From 1664cf9869eb35d63699a2880556e73d3c5320ef Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 25 Jan 2021 15:10:11 +0300 Subject: [PATCH] [#324] morph/subscriber: Init ws client in Subscriber's constructor Replace WSClient.Init call from the body of BlockNotifications method to constructor New since Init should be called before working with client according to neo-go docs. Signed-off-by: Leonard Lyubich --- pkg/morph/subscriber/subscriber.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/morph/subscriber/subscriber.go b/pkg/morph/subscriber/subscriber.go index 73ad5a7fc..39c65107e 100644 --- a/pkg/morph/subscriber/subscriber.go +++ b/pkg/morph/subscriber/subscriber.go @@ -104,10 +104,6 @@ func (s *subscriber) Close() { } func (s *subscriber) BlockNotifications() (<-chan *block.Block, error) { - if err := s.client.Init(); err != nil { - return nil, errors.Wrap(err, "could not init ws client") - } - if _, err := s.client.SubscribeForNewBlocks(nil); err != nil { return nil, errors.Wrap(err, "could not subscribe for new block events") } @@ -171,6 +167,10 @@ func New(ctx context.Context, p *Params) (Subscriber, error) { return nil, err } + if err := wsClient.Init(); err != nil { + return nil, errors.Wrap(err, "could not init ws client") + } + sub := &subscriber{ RWMutex: new(sync.RWMutex), log: p.Log,