diff --git a/multiaccounts/accounts/database.go b/multiaccounts/accounts/database.go index 15d94a4d3..a41d547e1 100644 --- a/multiaccounts/accounts/database.go +++ b/multiaccounts/accounts/database.go @@ -743,8 +743,23 @@ func (db *Database) GetAccountByAddress(address types.Address) (*Account, error) return db.getAccountByAddress(nil, address) } -func (db *Database) GetWatchOnlyAccounts(includeRemoved bool) (res []*Account, err error) { - accounts, err := db.getAccounts(nil, types.Address{}, includeRemoved) +// Returns active watch only accounts (excluding removed). +func (db *Database) GetActiveWatchOnlyAccounts() (res []*Account, err error) { + accounts, err := db.getAccounts(nil, types.Address{}, false) + if err != nil { + return nil, err + } + for _, acc := range accounts { + if acc.Type == AccountTypeWatch { + res = append(res, acc) + } + } + return +} + +// Returns all watch only accounts (including removed). +func (db *Database) GetAllWatchOnlyAccounts() (res []*Account, err error) { + accounts, err := db.getAccounts(nil, types.Address{}, true) if err != nil { return nil, err } diff --git a/protocol/messenger.go b/protocol/messenger.go index a877cbb1c..6374dfdf2 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -2581,7 +2581,7 @@ func (m *Messenger) SyncDevices(ctx context.Context, ensName, photoPath string, } // we have to sync deleted watch only accounts as well - woAccounts, err := m.settings.GetWatchOnlyAccounts(true) + woAccounts, err := m.settings.GetAllWatchOnlyAccounts() if err != nil { return err } diff --git a/protocol/messenger_backup.go b/protocol/messenger_backup.go index 66b6335b0..918975dbc 100644 --- a/protocol/messenger_backup.go +++ b/protocol/messenger_backup.go @@ -446,7 +446,7 @@ func (m *Messenger) backupKeypairs() ([]*protobuf.Backup, error) { } func (m *Messenger) backupWatchOnlyAccounts() ([]*protobuf.Backup, error) { - accounts, err := m.settings.GetWatchOnlyAccounts(true) + accounts, err := m.settings.GetAllWatchOnlyAccounts() if err != nil { return nil, err } diff --git a/protocol/messenger_backup_test.go b/protocol/messenger_backup_test.go index c94ce2d68..e6baf985b 100644 --- a/protocol/messenger_backup_test.go +++ b/protocol/messenger_backup_test.go @@ -822,7 +822,7 @@ func (s *MessengerBackupSuite) TestBackupWatchOnlyAccounts() { woAccounts := accounts.GetWatchOnlyAccountsForTest() err := bob1.settings.SaveOrUpdateAccounts(woAccounts, false) s.Require().NoError(err) - dbWoAccounts1, err := bob1.settings.GetWatchOnlyAccounts(false) + dbWoAccounts1, err := bob1.settings.GetActiveWatchOnlyAccounts() s.Require().NoError(err) s.Require().Equal(len(woAccounts), len(dbWoAccounts1)) s.Require().True(haveSameElements(woAccounts, dbWoAccounts1, accounts.SameAccounts)) @@ -848,7 +848,7 @@ func (s *MessengerBackupSuite) TestBackupWatchOnlyAccounts() { ) s.Require().NoError(err) - dbWoAccounts2, err := bob2.settings.GetWatchOnlyAccounts(false) + dbWoAccounts2, err := bob2.settings.GetActiveWatchOnlyAccounts() s.Require().NoError(err) s.Require().Equal(len(woAccounts), len(dbWoAccounts2)) s.Require().True(haveSameElements(woAccounts, dbWoAccounts2, accounts.SameAccounts)) diff --git a/protocol/messenger_sync_wallets_test.go b/protocol/messenger_sync_wallets_test.go index 202cbcf24..c8749fc5a 100644 --- a/protocol/messenger_sync_wallets_test.go +++ b/protocol/messenger_sync_wallets_test.go @@ -146,7 +146,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() { woAccounts := accounts.GetWatchOnlyAccountsForTest() err = s.m.settings.SaveOrUpdateAccounts(woAccounts, false) s.Require().NoError(err) - dbWoAccounts1, err := s.m.settings.GetWatchOnlyAccounts(false) + dbWoAccounts1, err := s.m.settings.GetActiveWatchOnlyAccounts() s.Require().NoError(err) s.Require().Equal(len(woAccounts), len(dbWoAccounts1)) s.Require().True(haveSameElements(woAccounts, dbWoAccounts1, accounts.SameAccounts)) @@ -206,7 +206,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() { s.Require().NoError(err) s.Require().True(accounts.SameKeypairsWithDifferentSyncedFrom(privKeyKp, dbPrivKeyKp2, true, "", accounts.AccountNonOperable)) - dbWoAccounts2, err := alicesOtherDevice.settings.GetWatchOnlyAccounts(false) + dbWoAccounts2, err := alicesOtherDevice.settings.GetActiveWatchOnlyAccounts() s.Require().NoError(err) s.Require().Equal(len(woAccounts), len(dbWoAccounts2)) s.Require().True(haveSameElements(woAccounts, dbWoAccounts2, accounts.SameAccounts)) diff --git a/services/accounts/accounts.go b/services/accounts/accounts.go index 33dc75952..c7751b790 100644 --- a/services/accounts/accounts.go +++ b/services/accounts/accounts.go @@ -85,7 +85,7 @@ func (api *API) GetAccounts(ctx context.Context) ([]*accounts.Account, error) { } func (api *API) GetWatchOnlyAccounts(ctx context.Context) ([]*accounts.Account, error) { - return api.db.GetWatchOnlyAccounts(false) + return api.db.GetActiveWatchOnlyAccounts() } func (api *API) GetKeypairs(ctx context.Context) ([]*accounts.Keypair, error) {