[#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>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2021-01-25 15:10:11 +03:00 committed by Alex Vanin
parent ca41810859
commit 1664cf9869
1 changed files with 4 additions and 4 deletions

View File

@ -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,