Handle disconnect for new subscription and unsubscribe accordingly

pull/574/head
kevin 2021-03-08 17:28:04 -07:00
parent ac1465d091
commit 42ec06d06c
2 changed files with 2 additions and 3 deletions

View File

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

View File

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