fix: function name change

`GetWatchOnlyAccounts(includeRemoved bool)` removed
`GetActiveWatchOnlyAccounts()` added
`GetAllWatchOnlyAccounts()` added
This commit is contained in:
Sale Djenic 2023-07-26 07:52:45 +02:00 committed by saledjenic
parent 6a5cdbaa8b
commit 20bc27619b
6 changed files with 24 additions and 9 deletions

View File

@ -743,8 +743,23 @@ func (db *Database) GetAccountByAddress(address types.Address) (*Account, error)
return db.getAccountByAddress(nil, address) return db.getAccountByAddress(nil, address)
} }
func (db *Database) GetWatchOnlyAccounts(includeRemoved bool) (res []*Account, err error) { // Returns active watch only accounts (excluding removed).
accounts, err := db.getAccounts(nil, types.Address{}, includeRemoved) 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -2581,7 +2581,7 @@ func (m *Messenger) SyncDevices(ctx context.Context, ensName, photoPath string,
} }
// we have to sync deleted watch only accounts as well // we have to sync deleted watch only accounts as well
woAccounts, err := m.settings.GetWatchOnlyAccounts(true) woAccounts, err := m.settings.GetAllWatchOnlyAccounts()
if err != nil { if err != nil {
return err return err
} }

View File

@ -446,7 +446,7 @@ func (m *Messenger) backupKeypairs() ([]*protobuf.Backup, error) {
} }
func (m *Messenger) backupWatchOnlyAccounts() ([]*protobuf.Backup, error) { func (m *Messenger) backupWatchOnlyAccounts() ([]*protobuf.Backup, error) {
accounts, err := m.settings.GetWatchOnlyAccounts(true) accounts, err := m.settings.GetAllWatchOnlyAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -822,7 +822,7 @@ func (s *MessengerBackupSuite) TestBackupWatchOnlyAccounts() {
woAccounts := accounts.GetWatchOnlyAccountsForTest() woAccounts := accounts.GetWatchOnlyAccountsForTest()
err := bob1.settings.SaveOrUpdateAccounts(woAccounts, false) err := bob1.settings.SaveOrUpdateAccounts(woAccounts, false)
s.Require().NoError(err) s.Require().NoError(err)
dbWoAccounts1, err := bob1.settings.GetWatchOnlyAccounts(false) dbWoAccounts1, err := bob1.settings.GetActiveWatchOnlyAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbWoAccounts1)) s.Require().Equal(len(woAccounts), len(dbWoAccounts1))
s.Require().True(haveSameElements(woAccounts, dbWoAccounts1, accounts.SameAccounts)) s.Require().True(haveSameElements(woAccounts, dbWoAccounts1, accounts.SameAccounts))
@ -848,7 +848,7 @@ func (s *MessengerBackupSuite) TestBackupWatchOnlyAccounts() {
) )
s.Require().NoError(err) s.Require().NoError(err)
dbWoAccounts2, err := bob2.settings.GetWatchOnlyAccounts(false) dbWoAccounts2, err := bob2.settings.GetActiveWatchOnlyAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbWoAccounts2)) s.Require().Equal(len(woAccounts), len(dbWoAccounts2))
s.Require().True(haveSameElements(woAccounts, dbWoAccounts2, accounts.SameAccounts)) s.Require().True(haveSameElements(woAccounts, dbWoAccounts2, accounts.SameAccounts))

View File

@ -146,7 +146,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
woAccounts := accounts.GetWatchOnlyAccountsForTest() woAccounts := accounts.GetWatchOnlyAccountsForTest()
err = s.m.settings.SaveOrUpdateAccounts(woAccounts, false) err = s.m.settings.SaveOrUpdateAccounts(woAccounts, false)
s.Require().NoError(err) s.Require().NoError(err)
dbWoAccounts1, err := s.m.settings.GetWatchOnlyAccounts(false) dbWoAccounts1, err := s.m.settings.GetActiveWatchOnlyAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbWoAccounts1)) s.Require().Equal(len(woAccounts), len(dbWoAccounts1))
s.Require().True(haveSameElements(woAccounts, dbWoAccounts1, accounts.SameAccounts)) s.Require().True(haveSameElements(woAccounts, dbWoAccounts1, accounts.SameAccounts))
@ -206,7 +206,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
s.Require().NoError(err) s.Require().NoError(err)
s.Require().True(accounts.SameKeypairsWithDifferentSyncedFrom(privKeyKp, dbPrivKeyKp2, true, "", accounts.AccountNonOperable)) 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().NoError(err)
s.Require().Equal(len(woAccounts), len(dbWoAccounts2)) s.Require().Equal(len(woAccounts), len(dbWoAccounts2))
s.Require().True(haveSameElements(woAccounts, dbWoAccounts2, accounts.SameAccounts)) s.Require().True(haveSameElements(woAccounts, dbWoAccounts2, accounts.SameAccounts))

View File

@ -85,7 +85,7 @@ func (api *API) GetAccounts(ctx context.Context) ([]*accounts.Account, error) {
} }
func (api *API) GetWatchOnlyAccounts(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) { func (api *API) GetKeypairs(ctx context.Context) ([]*accounts.Keypair, error) {