[#971] morph/subscriber: Adapt extended notification structure

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-10-21 18:09:26 +03:00 committed by Alex Vanin
parent c9f2804885
commit 3666ae7ad2
2 changed files with 7 additions and 9 deletions

View file

@ -7,7 +7,6 @@ import (
"sync" "sync"
"github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
@ -185,7 +184,7 @@ func (l *listener) listen(ctx context.Context, intError chan<- error) error {
return nil return nil
} }
func (l listener) listenLoop(ctx context.Context, chEvent <-chan *state.NotificationEvent, intErr chan<- error) { func (l listener) listenLoop(ctx context.Context, chEvent <-chan *subscriptions.NotificationEvent, intErr chan<- error) {
var ( var (
blockChan <-chan *block.Block blockChan <-chan *block.Block
@ -281,7 +280,7 @@ loop:
} }
} }
func (l listener) parseAndHandleNotification(notifyEvent *state.NotificationEvent) { func (l listener) parseAndHandleNotification(notifyEvent *subscriptions.NotificationEvent) {
log := l.log.With( log := l.log.With(
zap.String("script hash LE", notifyEvent.ScriptHash.StringLE()), zap.String("script hash LE", notifyEvent.ScriptHash.StringLE()),
) )

View file

@ -8,7 +8,6 @@ import (
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/rpc/client"
"github.com/nspcc-dev/neo-go/pkg/rpc/response" "github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
@ -19,7 +18,7 @@ import (
type ( type (
// Subscriber is an interface of the NotificationEvent listener. // Subscriber is an interface of the NotificationEvent listener.
Subscriber interface { Subscriber interface {
SubscribeForNotification(...util.Uint160) (<-chan *state.NotificationEvent, error) SubscribeForNotification(...util.Uint160) (<-chan *subscriptions.NotificationEvent, error)
UnsubscribeForNotification() UnsubscribeForNotification()
BlockNotifications() (<-chan *block.Block, error) BlockNotifications() (<-chan *block.Block, error)
SubscribeForNotaryRequests(mainTXSigner util.Uint160) (<-chan *subscriptions.NotaryRequestEvent, error) SubscribeForNotaryRequests(mainTXSigner util.Uint160) (<-chan *subscriptions.NotaryRequestEvent, error)
@ -31,7 +30,7 @@ type (
log *zap.Logger log *zap.Logger
client *client.WSClient client *client.WSClient
notifyChan chan *state.NotificationEvent notifyChan chan *subscriptions.NotificationEvent
notifyIDs map[util.Uint160]string notifyIDs map[util.Uint160]string
blockChan chan *block.Block blockChan chan *block.Block
@ -54,7 +53,7 @@ var (
errNilLogger = errors.New("chain/subscriber: logger was not provided to the constructor") errNilLogger = errors.New("chain/subscriber: logger was not provided to the constructor")
) )
func (s *subscriber) SubscribeForNotification(contracts ...util.Uint160) (<-chan *state.NotificationEvent, error) { func (s *subscriber) SubscribeForNotification(contracts ...util.Uint160) (<-chan *subscriptions.NotificationEvent, error) {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
@ -150,7 +149,7 @@ func (s *subscriber) routeNotifications(ctx context.Context) {
continue continue
} }
s.notifyChan <- &notifyEvent.NotificationEvent s.notifyChan <- notifyEvent
case response.BlockEventID: case response.BlockEventID:
b, ok := notification.Value.(*block.Block) b, ok := notification.Value.(*block.Block)
if !ok { if !ok {
@ -213,7 +212,7 @@ func New(ctx context.Context, p *Params) (Subscriber, error) {
RWMutex: new(sync.RWMutex), RWMutex: new(sync.RWMutex),
log: p.Log, log: p.Log,
client: wsClient, client: wsClient,
notifyChan: make(chan *state.NotificationEvent), notifyChan: make(chan *subscriptions.NotificationEvent),
notifyIDs: make(map[util.Uint160]string), notifyIDs: make(map[util.Uint160]string),
blockChan: make(chan *block.Block), blockChan: make(chan *block.Block),
notaryChan: make(chan *subscriptions.NotaryRequestEvent), notaryChan: make(chan *subscriptions.NotaryRequestEvent),