chore: moved accounts event watcher to accountsevent package

This commit is contained in:
Dario Gabriel Lipicar 2023-10-09 16:31:00 -03:00 committed by dlipicar
parent e17a247d0f
commit c2ff377585
3 changed files with 20 additions and 10 deletions

View File

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

View File

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

View File

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