From c2ff37758591d555118f4657f200172575f2dcf2 Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Mon, 9 Oct 2023 16:31:00 -0300 Subject: [PATCH] chore: moved accounts event watcher to accountsevent package --- .../accounts => accounts/accountsevent}/watcher.go | 9 ++++----- services/wallet/collectibles/controller.go | 13 +++++++++---- services/wallet/collectibles/service.go | 8 +++++++- 3 files changed, 20 insertions(+), 10 deletions(-) rename services/{wallet/accounts => accounts/accountsevent}/watcher.go (87%) diff --git a/services/wallet/accounts/watcher.go b/services/accounts/accountsevent/watcher.go similarity index 87% rename from services/wallet/accounts/watcher.go rename to services/accounts/accountsevent/watcher.go index 4fdd5f438..b10e4e475 100644 --- a/services/wallet/accounts/watcher.go +++ b/services/accounts/accountsevent/watcher.go @@ -1,4 +1,4 @@ -package walletaccounts +package accountsevent import ( "context" @@ -7,11 +7,10 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" "github.com/status-im/status-go/multiaccounts/accounts" - "github.com/status-im/status-go/services/accounts/accountsevent" "github.com/status-im/status-go/services/wallet/async" ) -type AccountsChangeCb func(changedAddresses []common.Address, eventType accountsevent.EventType, currentAddresses []common.Address) +type AccountsChangeCb func(changedAddresses []common.Address, eventType EventType, currentAddresses []common.Address) // Watcher executes a given callback whenever an account gets added/removed type Watcher struct { @@ -48,7 +47,7 @@ func (w *Watcher) Stop() { } } -func onAccountsChange(accountsDB *accounts.Database, callback AccountsChangeCb, changedAddresses []common.Address, eventType accountsevent.EventType) { +func onAccountsChange(accountsDB *accounts.Database, callback AccountsChangeCb, changedAddresses []common.Address, eventType EventType) { currentEthAddresses, err := accountsDB.GetWalletAddresses() if err != nil { @@ -67,7 +66,7 @@ func onAccountsChange(accountsDB *accounts.Database, callback AccountsChangeCb, } func watch(ctx context.Context, accountsDB *accounts.Database, accountFeed *event.Feed, callback AccountsChangeCb) error { - ch := make(chan accountsevent.Event, 1) + ch := make(chan Event, 1) sub := accountFeed.Subscribe(ch) defer sub.Unsubscribe() diff --git a/services/wallet/collectibles/controller.go b/services/wallet/collectibles/controller.go index d293ff55a..7cb7fc1b2 100644 --- a/services/wallet/collectibles/controller.go +++ b/services/wallet/collectibles/controller.go @@ -13,7 +13,6 @@ import ( "github.com/status-im/status-go/multiaccounts/accounts" "github.com/status-im/status-go/rpc/network" "github.com/status-im/status-go/services/accounts/accountsevent" - walletAccounts "github.com/status-im/status-go/services/wallet/accounts" "github.com/status-im/status-go/services/wallet/async" walletCommon "github.com/status-im/status-go/services/wallet/common" "github.com/status-im/status-go/services/wallet/transfer" @@ -43,13 +42,19 @@ type Controller struct { commands commandPerAddressAndChainID timers timerPerAddressAndChainID group *async.Group - accountsWatcher *walletAccounts.Watcher + accountsWatcher *accountsevent.Watcher walletEventsWatcher *walletevent.Watcher commandsLock sync.RWMutex } -func NewController(db *sql.DB, walletFeed *event.Feed, accountsDB *accounts.Database, accountsFeed *event.Feed, networkManager *network.Manager, manager *Manager) *Controller { +func NewController( + db *sql.DB, + walletFeed *event.Feed, + accountsDB *accounts.Database, + accountsFeed *event.Feed, + networkManager *network.Manager, + manager *Manager) *Controller { return &Controller{ manager: manager, ownershipDB: NewOwnershipDB(db), @@ -285,7 +290,7 @@ func (c *Controller) startAccountsWatcher() { } } - c.accountsWatcher = walletAccounts.NewWatcher(c.accountsDB, c.accountsFeed, accountChangeCb) + c.accountsWatcher = accountsevent.NewWatcher(c.accountsDB, c.accountsFeed, accountChangeCb) c.accountsWatcher.Start() } diff --git a/services/wallet/collectibles/service.go b/services/wallet/collectibles/service.go index 7581f41ed..742e96666 100644 --- a/services/wallet/collectibles/service.go +++ b/services/wallet/collectibles/service.go @@ -50,7 +50,13 @@ type Service struct { scheduler *async.MultiClientScheduler } -func NewService(db *sql.DB, walletFeed *event.Feed, accountsDB *accounts.Database, accountsFeed *event.Feed, networkManager *network.Manager, manager *Manager) *Service { +func NewService( + db *sql.DB, + walletFeed *event.Feed, + accountsDB *accounts.Database, + accountsFeed *event.Feed, + networkManager *network.Manager, + manager *Manager) *Service { return &Service{ manager: manager, controller: NewController(db, walletFeed, accountsDB, accountsFeed, networkManager, manager),