From 42ec06d06cf7ea01aa712fd6209758015143ca08 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 8 Mar 2021 17:28:04 -0700 Subject: [PATCH] Handle disconnect for new subscription and unsubscribe accordingly --- docs/api.md | 2 +- server/websocket.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index e98a4fb6..ff080d25 100644 --- a/docs/api.md +++ b/docs/api.md @@ -765,7 +765,7 @@ The websocket interface provides the following requests: The client can subscribe to the following events: - `subscribeNewBlock` - new block added to blockchain -- `subscribeNewTransaction` - new transaction added to blockchain (mempool for all addresses) +- `subscribeNewTransaction` - new transaction added to blockchain (all addresses) - `subscribeAddresses` - new transaction for given address (list of addresses) - `subscribeFiatRates` - new currency rate ticker diff --git a/server/websocket.go b/server/websocket.go index 0cb68afc..7548875d 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -246,6 +246,7 @@ func (s *WebsocketServer) onConnect(c *websocketChannel) { func (s *WebsocketServer) onDisconnect(c *websocketChannel) { s.unsubscribeNewBlock(c) + s.unsubscribeNewTransaction(c) s.unsubscribeAddresses(c) s.unsubscribeFiatRates(c) glog.Info("Client disconnected ", c.id, ", ", c.ip) @@ -684,7 +685,6 @@ func (s *WebsocketServer) unsubscribeNewBlock(c *websocketChannel) (res interfac func (s *WebsocketServer) subscribeNewTransaction(c *websocketChannel, req *websocketReq) (res interface{}, err error) { s.newTransactionSubscriptionsLock.Lock() defer s.newTransactionSubscriptionsLock.Unlock() - glog.Infof("subscribeNewTransaction: %+v\n%v\n", c, req.ID) s.newTransactionSubscriptions[c] = req.ID return &subscriptionResponse{true}, nil } @@ -692,7 +692,6 @@ func (s *WebsocketServer) subscribeNewTransaction(c *websocketChannel, req *webs func (s *WebsocketServer) unsubscribeNewTransaction(c *websocketChannel) (res interface{}, err error) { s.newTransactionSubscriptionsLock.Lock() defer s.newTransactionSubscriptionsLock.Unlock() - glog.Infof("unsubscribeNewTransaction: %+v\n", c) delete(s.newTransactionSubscriptions, c) return &subscriptionResponse{false}, nil }