[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-25 15:10:11 +03:00 committed by Alex Vanin
parent ca41810859
commit 1664cf9869

View file

@ -104,10 +104,6 @@ func (s *subscriber) Close() {
} }
func (s *subscriber) BlockNotifications() (<-chan *block.Block, error) { 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 { if _, err := s.client.SubscribeForNewBlocks(nil); err != nil {
return nil, errors.Wrap(err, "could not subscribe for new block events") 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 return nil, err
} }
if err := wsClient.Init(); err != nil {
return nil, errors.Wrap(err, "could not init ws client")
}
sub := &subscriber{ sub := &subscriber{
RWMutex: new(sync.RWMutex), RWMutex: new(sync.RWMutex),
log: p.Log, log: p.Log,