fix(wallet): accessing tokens block range nil on empty acc.
Fixed a crash in local notification service on a nil block number in HistoryReady event
This commit is contained in:
parent
fe604b2806
commit
6e666f7c27
|
@ -122,7 +122,6 @@ func TestTransactionNotification(t *testing.T) {
|
|||
|
||||
feed.Send(walletevent.Event{
|
||||
Type: transfer.EventRecentHistoryReady,
|
||||
BlockNumber: big.NewInt(0),
|
||||
Accounts: []common.Address{header.Address},
|
||||
})
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@ func (db *Database) GetWalletPreference() (rst NotificationPreference, err error
|
|||
pref := db.db.QueryRow("SELECT service, event, identifier, enabled FROM local_notifications_preferences WHERE service = 'wallet' AND event = 'transaction' AND identifier = 'all'")
|
||||
|
||||
err = pref.Scan(&rst.Service, &rst.Event, &rst.Identifier, &rst.Enabled)
|
||||
if err == sql.ErrNoRows {
|
||||
return rst, nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ func (s *Service) SubscribeWallet(publisher *event.Feed) error {
|
|||
|
||||
s.StartWalletWatcher()
|
||||
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// StartWalletWatcher - Forward wallet events to notifications
|
||||
|
@ -167,6 +167,7 @@ func (s *Service) StartWalletWatcher() {
|
|||
maxKnownBlocks := map[common.Address]*big.Int{}
|
||||
go func() {
|
||||
defer s.walletTransmitter.wg.Done()
|
||||
historyReady := false
|
||||
for {
|
||||
select {
|
||||
case <-s.walletTransmitter.quit:
|
||||
|
@ -180,7 +181,7 @@ func (s *Service) StartWalletWatcher() {
|
|||
}
|
||||
return
|
||||
case event := <-events:
|
||||
if event.Type == transfer.EventNewTransfers && len(maxKnownBlocks) > 0 && event.BlockNumber != nil {
|
||||
if event.Type == transfer.EventNewTransfers && historyReady && event.BlockNumber != nil {
|
||||
newBlocks := false
|
||||
for _, address := range event.Accounts {
|
||||
if _, ok := maxKnownBlocks[address]; !ok {
|
||||
|
@ -200,6 +201,8 @@ func (s *Service) StartWalletWatcher() {
|
|||
})
|
||||
}
|
||||
} else if event.Type == transfer.EventRecentHistoryReady {
|
||||
historyReady = true
|
||||
if event.BlockNumber != nil {
|
||||
for _, address := range event.Accounts {
|
||||
if _, ok := maxKnownBlocks[address]; !ok {
|
||||
maxKnownBlocks[address] = event.BlockNumber
|
||||
|
@ -208,6 +211,7 @@ func (s *Service) StartWalletWatcher() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
|
@ -817,7 +817,7 @@ func (c *loadBlocksAndTransfersCommand) fetchHistoryBlocks(ctx context.Context,
|
|||
// If we blockRange is nil, we need to load all blocks from `fromNum` to `toNum`
|
||||
// As current implementation checks ETH first then tokens, tokens ranges maybe behind ETH ranges in
|
||||
// cases when block searching was interrupted, so we use tokens ranges
|
||||
if blockRange != nil {
|
||||
if blockRange != nil && blockRange.tokens != nil {
|
||||
if blockRange.tokens.LastKnown != nil && toNum.Cmp(blockRange.tokens.LastKnown) > 0 {
|
||||
ranges = append(ranges, []*big.Int{blockRange.tokens.LastKnown, toNum})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue