[#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:
parent
ca41810859
commit
1664cf9869
1 changed files with 4 additions and 4 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue