fix: review comments applied

`GetKeypairs(includeRemoved bool)` removed
`GetActiveKeypairs()` added
`GetAllKeypairs()` added

`GetAccounts(includeRemoved bool)` removed
`GetActiveAccounts()` added
`GetAllAccounts()` added
This commit is contained in:
Sale Djenic 2023-07-25 17:17:17 +02:00 committed by saledjenic
parent d5bba5d80f
commit 6a5cdbaa8b
19 changed files with 83 additions and 71 deletions

View File

@ -694,7 +694,7 @@ func (b *GethStatusBackend) MigrateKeyStoreDir(acc multiaccounts.Account, passwo
if err != nil { if err != nil {
return err return err
} }
accounts, err := accountDB.GetAccounts(false) accounts, err := accountDB.GetActiveAccounts()
if err != nil { if err != nil {
return err return err
} }
@ -1168,7 +1168,7 @@ func (b *GethStatusBackend) ConvertToRegularAccount(mnemonic string, currPasswor
return err return err
} }
knownAccounts, err := db.GetAccounts(false) knownAccounts, err := db.GetActiveAccounts()
if err != nil { if err != nil {
return err return err
} }

View File

@ -713,8 +713,14 @@ func (db *Database) markKeypairRemoved(tx *sql.Tx, keyUID string, clock uint64)
return err return err
} }
func (db *Database) GetKeypairs(includeRemoved bool) ([]*Keypair, error) { // Returns active keypairs (excluding removed and excluding removed accounts).
return db.getKeypairs(nil, "", includeRemoved) func (db *Database) GetActiveKeypairs() ([]*Keypair, error) {
return db.getKeypairs(nil, "", false)
}
// Returns all keypairs (including removed and removed accounts).
func (db *Database) GetAllKeypairs() ([]*Keypair, error) {
return db.getKeypairs(nil, "", true)
} }
// Returns keypair if it is not marked as removed and its accounts which are not marked as removed. // Returns keypair if it is not marked as removed and its accounts which are not marked as removed.
@ -722,8 +728,14 @@ func (db *Database) GetKeypairByKeyUID(keyUID string) (*Keypair, error) {
return db.getKeypairByKeyUID(nil, keyUID) return db.getKeypairByKeyUID(nil, keyUID)
} }
func (db *Database) GetAccounts(includeRemoved bool) ([]*Account, error) { // Returns active accounts (excluding removed).
return db.getAccounts(nil, types.Address{}, includeRemoved) func (db *Database) GetActiveAccounts() ([]*Account, error) {
return db.getAccounts(nil, types.Address{}, false)
}
// Returns all accounts (including removed).
func (db *Database) GetAllAccounts() ([]*Account, error) {
return db.getAccounts(nil, types.Address{}, true)
} }
// Returns account if it is not marked as removed. // Returns account if it is not marked as removed.

View File

@ -66,7 +66,7 @@ func TestMoveWalletAccount(t *testing.T) {
{Address: types.Address{0x06}, Type: AccountTypeWatch, Position: 5}, {Address: types.Address{0x06}, Type: AccountTypeWatch, Position: 5},
} }
require.NoError(t, db.SaveOrUpdateAccounts(accounts, false)) require.NoError(t, db.SaveOrUpdateAccounts(accounts, false))
dbAccounts, err := db.GetAccounts(false) dbAccounts, err := db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Len(t, dbAccounts, len(accounts)) require.Len(t, dbAccounts, len(accounts))
for i := 0; i < len(accounts); i++ { for i := 0; i < len(accounts); i++ {
@ -95,7 +95,7 @@ func TestMoveWalletAccount(t *testing.T) {
{Address: types.Address{0x06}, Type: AccountTypeWatch, Position: 5}, {Address: types.Address{0x06}, Type: AccountTypeWatch, Position: 5},
} }
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(accounts); i++ { for i := 0; i < len(accounts); i++ {
require.True(t, SameAccounts(accounts[i], dbAccounts[i])) require.True(t, SameAccounts(accounts[i], dbAccounts[i]))
@ -121,7 +121,7 @@ func TestMoveWalletAccount(t *testing.T) {
{Address: types.Address{0x02}, Type: AccountTypeWatch, Position: 5}, {Address: types.Address{0x02}, Type: AccountTypeWatch, Position: 5},
} }
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
for i := 0; i < len(accounts); i++ { for i := 0; i < len(accounts); i++ {
require.True(t, SameAccounts(accounts[i], dbAccounts[i])) require.True(t, SameAccounts(accounts[i], dbAccounts[i]))
@ -184,7 +184,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
defer stop() defer stop()
// check the db // check the db
dbAccounts, err := db.GetAccounts(false) dbAccounts, err := db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 0, len(dbAccounts)) require.Equal(t, 0, len(dbAccounts))
@ -197,7 +197,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
require.Error(t, err) require.Error(t, err)
// check the db after that trying to save keypair with watch only accounts // check the db after that trying to save keypair with watch only accounts
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 0, len(dbAccounts)) require.Equal(t, 0, len(dbAccounts))
@ -207,7 +207,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
_, err = db.GetKeypairByKeyUID(woAccounts[0].KeyUID) _, err = db.GetKeypairByKeyUID(woAccounts[0].KeyUID)
require.Error(t, err) require.Error(t, err)
require.True(t, err == ErrDbKeypairNotFound) require.True(t, err == ErrDbKeypairNotFound)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(woAccounts), len(dbAccounts)) require.Equal(t, len(woAccounts), len(dbAccounts))
require.Equal(t, woAccounts[0].Address, dbAccounts[0].Address) require.Equal(t, woAccounts[0].Address, dbAccounts[0].Address)
@ -215,7 +215,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
// try to save the same watch only account again // try to save the same watch only account again
err = db.SaveOrUpdateAccounts(woAccounts[:1], false) err = db.SaveOrUpdateAccounts(woAccounts[:1], false)
require.NoError(t, err) require.NoError(t, err)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(woAccounts), len(dbAccounts)) require.Equal(t, len(woAccounts), len(dbAccounts))
dbAcc, err := db.GetAccountByAddress(woAccounts[:1][0].Address) dbAcc, err := db.GetAccountByAddress(woAccounts[:1][0].Address)
@ -232,7 +232,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
} }
err = db.SaveOrUpdateAccounts([]*Account{wo4}, false) err = db.SaveOrUpdateAccounts([]*Account{wo4}, false)
require.NoError(t, err) require.NoError(t, err)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(woAccounts)+1, len(dbAccounts)) require.Equal(t, len(woAccounts)+1, len(dbAccounts))
dbAcc, err = db.GetAccountByAddress(wo4.Address) dbAcc, err = db.GetAccountByAddress(wo4.Address)
@ -245,7 +245,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
wo4.Emoji = wo4.Emoji + "updated" wo4.Emoji = wo4.Emoji + "updated"
err = db.SaveOrUpdateAccounts([]*Account{wo4}, false) err = db.SaveOrUpdateAccounts([]*Account{wo4}, false)
require.NoError(t, err) require.NoError(t, err)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(woAccounts)+1, len(dbAccounts)) require.Equal(t, len(woAccounts)+1, len(dbAccounts))
dbAcc, err = db.GetAccountByAddress(wo4.Address) dbAcc, err = db.GetAccountByAddress(wo4.Address)
@ -260,7 +260,7 @@ func TestWatchOnlyAccounts(t *testing.T) {
// try to delete watch only account // try to delete watch only account
err = db.RemoveAccount(wo4.Address, 0) err = db.RemoveAccount(wo4.Address, 0)
require.NoError(t, err) require.NoError(t, err)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(woAccounts), len(dbAccounts)) require.Equal(t, len(woAccounts), len(dbAccounts))
_, err = db.GetAccountByAddress(wo4.Address) _, err = db.GetAccountByAddress(wo4.Address)
@ -275,14 +275,14 @@ func TestUpdateKeypairName(t *testing.T) {
kp := GetProfileKeypairForTest(true, false, false) kp := GetProfileKeypairForTest(true, false, false)
// check the db // check the db
dbAccounts, err := db.GetAccounts(false) dbAccounts, err := db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 0, len(dbAccounts)) require.Equal(t, 0, len(dbAccounts))
// save keypair // save keypair
err = db.SaveOrUpdateKeypair(kp) err = db.SaveOrUpdateKeypair(kp)
require.NoError(t, err) require.NoError(t, err)
dbKeypairs, err := db.GetKeypairs(false) dbKeypairs, err := db.GetActiveKeypairs()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(dbKeypairs)) require.Equal(t, 1, len(dbKeypairs))
require.True(t, SameKeypairs(kp, dbKeypairs[0])) require.True(t, SameKeypairs(kp, dbKeypairs[0]))
@ -313,10 +313,10 @@ func TestKeypairs(t *testing.T) {
defer stop() defer stop()
// check the db // check the db
dbKeypairs, err := db.GetKeypairs(false) dbKeypairs, err := db.GetActiveKeypairs()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 0, len(dbKeypairs)) require.Equal(t, 0, len(dbKeypairs))
dbAccounts, err := db.GetAccounts(false) dbAccounts, err := db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 0, len(dbAccounts)) require.Equal(t, 0, len(dbAccounts))
@ -328,7 +328,7 @@ func TestKeypairs(t *testing.T) {
// save keypair // save keypair
err = db.SaveOrUpdateKeypair(kp) err = db.SaveOrUpdateKeypair(kp)
require.NoError(t, err) require.NoError(t, err)
dbKeypairs, err = db.GetKeypairs(false) dbKeypairs, err = db.GetActiveKeypairs()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(dbKeypairs)) require.Equal(t, 1, len(dbKeypairs))
dbKp, err := db.GetKeypairByKeyUID(kp.KeyUID) dbKp, err := db.GetKeypairByKeyUID(kp.KeyUID)
@ -336,7 +336,7 @@ func TestKeypairs(t *testing.T) {
require.Equal(t, len(kp.Accounts), len(dbKp.Accounts)) require.Equal(t, len(kp.Accounts), len(dbKp.Accounts))
kp.LastUsedDerivationIndex = expectedLastUsedDerivationIndex kp.LastUsedDerivationIndex = expectedLastUsedDerivationIndex
require.Equal(t, kp.KeyUID, dbKp.KeyUID) require.Equal(t, kp.KeyUID, dbKp.KeyUID)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts), len(dbAccounts)) require.Equal(t, len(kp.Accounts), len(dbAccounts))
@ -350,7 +350,7 @@ func TestKeypairs(t *testing.T) {
// save keypair again to test the flow below // save keypair again to test the flow below
err = db.SaveOrUpdateKeypair(kp) err = db.SaveOrUpdateKeypair(kp)
require.NoError(t, err) require.NoError(t, err)
dbKeypairs, err = db.GetKeypairs(false) dbKeypairs, err = db.GetActiveKeypairs()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(dbKeypairs)) require.Equal(t, 1, len(dbKeypairs))
@ -364,7 +364,7 @@ func TestKeypairs(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts), len(dbKp.Accounts)) require.Equal(t, len(kp.Accounts), len(dbKp.Accounts))
require.Equal(t, kp.KeyUID, dbKp.KeyUID) require.Equal(t, kp.KeyUID, dbKp.KeyUID)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts), len(dbAccounts)) require.Equal(t, len(kp.Accounts), len(dbAccounts))
@ -378,7 +378,7 @@ func TestKeypairs(t *testing.T) {
dbKp, err = db.GetKeypairByKeyUID(kp.KeyUID) dbKp, err = db.GetKeypairByKeyUID(kp.KeyUID)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts), len(dbKp.Accounts)) require.Equal(t, len(kp.Accounts), len(dbKp.Accounts))
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts), len(dbAccounts)) require.Equal(t, len(kp.Accounts), len(dbAccounts))
dbAcc, err := db.GetAccountByAddress(accToUpdate.Address) dbAcc, err := db.GetAccountByAddress(accToUpdate.Address)
@ -390,7 +390,7 @@ func TestKeypairs(t *testing.T) {
kpToUpdate.Name = kpToUpdate.Name + "updated" kpToUpdate.Name = kpToUpdate.Name + "updated"
err = db.SaveOrUpdateKeypair(kp) err = db.SaveOrUpdateKeypair(kp)
require.NoError(t, err) require.NoError(t, err)
dbKeypairs, err = db.GetKeypairs(false) dbKeypairs, err = db.GetActiveKeypairs()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(dbKeypairs)) require.Equal(t, 1, len(dbKeypairs))
dbKp, err = db.GetKeypairByKeyUID(kp.KeyUID) dbKp, err = db.GetKeypairByKeyUID(kp.KeyUID)
@ -411,7 +411,7 @@ func TestKeypairs(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts)+1, len(dbKp.Accounts)) require.Equal(t, len(kp.Accounts)+1, len(dbKp.Accounts))
require.Equal(t, kp.LastUsedDerivationIndex, dbKp.LastUsedDerivationIndex) require.Equal(t, kp.LastUsedDerivationIndex, dbKp.LastUsedDerivationIndex)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts)+1, len(dbAccounts)) require.Equal(t, len(kp.Accounts)+1, len(dbAccounts))
dbAcc, err = db.GetAccountByAddress(accToUpdate.Address) dbAcc, err = db.GetAccountByAddress(accToUpdate.Address)
@ -440,7 +440,7 @@ func TestKeypairs(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts)+2, len(dbKp.Accounts)) require.Equal(t, len(kp.Accounts)+2, len(dbKp.Accounts))
require.Equal(t, expectedLastUsedDerivationIndex, dbKp.LastUsedDerivationIndex) require.Equal(t, expectedLastUsedDerivationIndex, dbKp.LastUsedDerivationIndex)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts)+2, len(dbAccounts)) require.Equal(t, len(kp.Accounts)+2, len(dbAccounts))
dbAcc, err = db.GetAccountByAddress(accToUpdate.Address) dbAcc, err = db.GetAccountByAddress(accToUpdate.Address)
@ -450,7 +450,7 @@ func TestKeypairs(t *testing.T) {
// delete account // delete account
err = db.RemoveAccount(accToAdd.Address, 0) err = db.RemoveAccount(accToAdd.Address, 0)
require.NoError(t, err) require.NoError(t, err)
dbAccounts, err = db.GetAccounts(false) dbAccounts, err = db.GetActiveAccounts()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, len(kp.Accounts)+1, len(dbAccounts)) require.Equal(t, len(kp.Accounts)+1, len(dbAccounts))
_, err = db.GetAccountByAddress(accToAdd.Address) _, err = db.GetAccountByAddress(accToAdd.Address)

View File

@ -28,7 +28,7 @@ func TestKeycards(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
err = db.SaveOrUpdateKeypair(kp2) err = db.SaveOrUpdateKeypair(kp2)
require.NoError(t, err) require.NoError(t, err)
dbKeypairs, err := db.GetKeypairs(false) dbKeypairs, err := db.GetActiveKeypairs()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 2, len(dbKeypairs)) require.Equal(t, 2, len(dbKeypairs))
@ -168,7 +168,7 @@ func TestKeycardsRemovalWhenDeletingKeypair(t *testing.T) {
// Pre-condition // Pre-condition
err := db.SaveOrUpdateKeypair(kp2) err := db.SaveOrUpdateKeypair(kp2)
require.NoError(t, err) require.NoError(t, err)
dbKeypairs, err := db.GetKeypairs(false) dbKeypairs, err := db.GetActiveKeypairs()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(dbKeypairs)) require.Equal(t, 1, len(dbKeypairs))
@ -197,7 +197,7 @@ func TestKeycardsRemovalWhenDeletingKeypair(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// Check db state after deletion // Check db state after deletion
dbKeypairs, err = db.GetKeypairs(false) dbKeypairs, err = db.GetActiveKeypairs()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 0, len(dbKeypairs)) require.Equal(t, 0, len(dbKeypairs))

View File

@ -13,7 +13,7 @@ func MockTestAccounts(tb testing.TB, db *sql.DB, accounts []*Account) {
err = d.SaveOrUpdateAccounts(accounts, false) err = d.SaveOrUpdateAccounts(accounts, false)
require.NoError(tb, err) require.NoError(tb, err)
res, err := d.GetAccounts(false) res, err := d.GetActiveAccounts()
require.NoError(tb, err) require.NoError(tb, err)
require.Equal(tb, accounts[0].Address, res[0].Address) require.Equal(tb, accounts[0].Address, res[0].Address)
} }

View File

@ -151,7 +151,7 @@ func (s *MessengerCommunitiesTokenPermissionsSuite) newMessenger(password string
s.Require().NoError(err) s.Require().NoError(err)
} }
walletAccounts, err := messenger.settings.GetAccounts(false) walletAccounts, err := messenger.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Len(walletAccounts, len(walletAddresses)) s.Require().Len(walletAccounts, len(walletAddresses))
for i := range walletAddresses { for i := range walletAddresses {

View File

@ -2565,7 +2565,7 @@ func (m *Messenger) SyncDevices(ctx context.Context, ensName, photoPath string,
} }
// we have to sync deleted keypairs as well // we have to sync deleted keypairs as well
keypairs, err := m.settings.GetKeypairs(true) keypairs, err := m.settings.GetAllKeypairs()
if err != nil { if err != nil {
return err return err
} }

View File

@ -421,7 +421,7 @@ func (m *Messenger) backupProfile(ctx context.Context, clock uint64) ([]*protobu
} }
func (m *Messenger) backupKeypairs() ([]*protobuf.Backup, error) { func (m *Messenger) backupKeypairs() ([]*protobuf.Backup, error) {
keypairs, err := m.settings.GetKeypairs(false) keypairs, err := m.settings.GetActiveKeypairs()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -772,7 +772,7 @@ func (s *MessengerBackupSuite) TestBackupKeycards() {
s.Require().NoError(err) s.Require().NoError(err)
err = bob1.settings.SaveOrUpdateKeypair(kp3) err = bob1.settings.SaveOrUpdateKeypair(kp3)
s.Require().NoError(err) s.Require().NoError(err)
dbKeypairs, err := bob1.settings.GetKeypairs(false) dbKeypairs, err := bob1.settings.GetActiveKeypairs()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(3, len(dbKeypairs)) s.Require().Equal(3, len(dbKeypairs))

View File

@ -752,7 +752,7 @@ func (m *Messenger) SetMutePropertyOnChatsByCategory(request *requests.MuteCateg
// getAccountsToShare is used to get the wallet accounts to share either when requesting to join a community or when editing // getAccountsToShare is used to get the wallet accounts to share either when requesting to join a community or when editing
// requestToJoinID can be empty when editing // requestToJoinID can be empty when editing
func (m *Messenger) getAccountsToShare(addressesToReveal []string, airdropAddress string, communityID types.HexBytes, password string, requestToJoinID []byte) (map[gethcommon.Address]*protobuf.RevealedAccount, []gethcommon.Address, error) { func (m *Messenger) getAccountsToShare(addressesToReveal []string, airdropAddress string, communityID types.HexBytes, password string, requestToJoinID []byte) (map[gethcommon.Address]*protobuf.RevealedAccount, []gethcommon.Address, error) {
walletAccounts, err := m.settings.GetAccounts(false) walletAccounts, err := m.settings.GetActiveAccounts()
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -819,7 +819,7 @@ func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommun
} }
if request.Password != "" { if request.Password != "" {
walletAccounts, err := m.settings.GetAccounts(false) walletAccounts, err := m.settings.GetActiveAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -975,7 +975,7 @@ func (m *Messenger) EditSharedAddressesForCommunity(request *requests.EditShared
return nil, err return nil, err
} }
walletAccounts, err := m.settings.GetAccounts(false) walletAccounts, err := m.settings.GetActiveAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -4122,7 +4122,7 @@ func (m *Messenger) CheckPermissionsToJoinCommunity(request *requests.CheckPermi
return nil, err return nil, err
} }
accounts, err := m.settings.GetAccounts(false) accounts, err := m.settings.GetActiveAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -4141,7 +4141,7 @@ func (m *Messenger) CheckCommunityChannelPermissions(request *requests.CheckComm
return nil, err return nil, err
} }
accounts, err := m.settings.GetAccounts(false) accounts, err := m.settings.GetActiveAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -4160,7 +4160,7 @@ func (m *Messenger) CheckAllCommunityChannelsPermissions(request *requests.Check
return nil, err return nil, err
} }
accounts, err := m.settings.GetAccounts(false) accounts, err := m.settings.GetActiveAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -89,7 +89,7 @@ func (s *MessengerSyncKeycardChangeSuite) SetupTest() {
s.Require().NoError(err) s.Require().NoError(err)
// err = s.main.settings.SaveOrUpdateKeypair(kp3) // err = s.main.settings.SaveOrUpdateKeypair(kp3)
// s.Require().NoError(err) // s.Require().NoError(err)
dbKeypairs, err := s.main.settings.GetKeypairs(false) dbKeypairs, err := s.main.settings.GetActiveKeypairs()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(2, len(dbKeypairs)) s.Require().Equal(2, len(dbKeypairs))
@ -103,7 +103,7 @@ func (s *MessengerSyncKeycardChangeSuite) SetupTest() {
s.Require().NoError(err) s.Require().NoError(err)
// err = s.other.settings.SaveOrUpdateKeypair(kp3) // err = s.other.settings.SaveOrUpdateKeypair(kp3)
// s.Require().NoError(err) // s.Require().NoError(err)
dbKeypairs, err = s.other.settings.GetKeypairs(false) dbKeypairs, err = s.other.settings.GetActiveKeypairs()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(2, len(dbKeypairs)) s.Require().Equal(2, len(dbKeypairs))
} }

View File

@ -89,7 +89,7 @@ func (s *MessengerSyncKeycardsStateSuite) SetupTest() {
s.Require().NoError(err) s.Require().NoError(err)
err = s.main.settings.SaveOrUpdateKeypair(kp3) err = s.main.settings.SaveOrUpdateKeypair(kp3)
s.Require().NoError(err) s.Require().NoError(err)
dbKeypairs, err := s.main.settings.GetKeypairs(false) dbKeypairs, err := s.main.settings.GetActiveKeypairs()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(3, len(dbKeypairs)) s.Require().Equal(3, len(dbKeypairs))
@ -103,7 +103,7 @@ func (s *MessengerSyncKeycardsStateSuite) SetupTest() {
s.Require().NoError(err) s.Require().NoError(err)
err = s.other.settings.SaveOrUpdateKeypair(kp3) err = s.other.settings.SaveOrUpdateKeypair(kp3)
s.Require().NoError(err) s.Require().NoError(err)
dbKeypairs, err = s.other.settings.GetKeypairs(false) dbKeypairs, err = s.other.settings.GetActiveKeypairs()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(3, len(dbKeypairs)) s.Require().Equal(3, len(dbKeypairs))
} }

View File

@ -151,7 +151,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
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))
dbAccounts1, err := s.m.settings.GetAccounts(false) dbAccounts1, err := s.m.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(profileKp.Accounts)+len(seedPhraseKp.Accounts)+len(privKeyKp.Accounts)+len(woAccounts), len(dbAccounts1)) s.Require().Equal(len(profileKp.Accounts)+len(seedPhraseKp.Accounts)+len(privKeyKp.Accounts)+len(woAccounts), len(dbAccounts1))
@ -211,7 +211,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
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))
dbAccounts2, err := alicesOtherDevice.settings.GetAccounts(false) dbAccounts2, err := alicesOtherDevice.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(profileKp.Accounts)+len(seedPhraseKp.Accounts)+len(privKeyKp.Accounts)+len(woAccounts), len(dbAccounts2)) s.Require().Equal(len(profileKp.Accounts)+len(seedPhraseKp.Accounts)+len(privKeyKp.Accounts)+len(woAccounts), len(dbAccounts2))
@ -297,7 +297,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
err = s.m.settings.SaveOrUpdateAccounts(woAccounts, false) err = s.m.settings.SaveOrUpdateAccounts(woAccounts, false)
s.Require().NoError(err, "wo accounts alice.settings.SaveOrUpdateKeypair") s.Require().NoError(err, "wo accounts alice.settings.SaveOrUpdateKeypair")
dbAccounts, err := s.m.settings.GetAccounts(false) dbAccounts, err := s.m.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbAccounts)-1) s.Require().Equal(len(woAccounts), len(dbAccounts)-1)
@ -310,7 +310,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
err = alicesOtherDevice.settings.SaveOrUpdateAccounts(woAccounts, false) err = alicesOtherDevice.settings.SaveOrUpdateAccounts(woAccounts, false)
s.Require().NoError(err, "wo accounts alice.settings.SaveOrUpdateKeypair") s.Require().NoError(err, "wo accounts alice.settings.SaveOrUpdateKeypair")
dbAccounts, err = alicesOtherDevice.settings.GetAccounts(false) dbAccounts, err = alicesOtherDevice.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbAccounts)-1) s.Require().Equal(len(woAccounts), len(dbAccounts)-1)
@ -358,7 +358,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
{Address: types.Address{0x16}, Type: accounts.AccountTypeWatch, Position: 5}, {Address: types.Address{0x16}, Type: accounts.AccountTypeWatch, Position: 5},
} }
dbAccounts, err = s.m.settings.GetAccounts(false) dbAccounts, err = s.m.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbAccounts)-1) s.Require().Equal(len(woAccounts), len(dbAccounts)-1)
for i := 0; i < len(woAccounts); i++ { for i := 0; i < len(woAccounts); i++ {
@ -380,7 +380,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
s.Require().NoError(err) s.Require().NoError(err)
// check on alice's other device // check on alice's other device
dbAccounts, err = alicesOtherDevice.settings.GetAccounts(false) dbAccounts, err = alicesOtherDevice.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbAccounts)-1) s.Require().Equal(len(woAccounts), len(dbAccounts)-1)
for i := 0; i < len(woAccounts); i++ { for i := 0; i < len(woAccounts); i++ {
@ -408,7 +408,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
{Address: types.Address{0x12}, Type: accounts.AccountTypeWatch, Position: 5}, {Address: types.Address{0x12}, Type: accounts.AccountTypeWatch, Position: 5},
} }
dbAccounts, err = s.m.settings.GetAccounts(false) dbAccounts, err = s.m.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbAccounts)-1) s.Require().Equal(len(woAccounts), len(dbAccounts)-1)
for i := 0; i < len(woAccounts); i++ { for i := 0; i < len(woAccounts); i++ {
@ -430,7 +430,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountsReorder() {
s.Require().NoError(err) s.Require().NoError(err)
// check on alice's other device // check on alice's other device
dbAccounts, err = alicesOtherDevice.settings.GetAccounts(false) dbAccounts, err = alicesOtherDevice.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(len(woAccounts), len(dbAccounts)-1) s.Require().Equal(len(woAccounts), len(dbAccounts)-1)
for i := 0; i < len(woAccounts); i++ { for i := 0; i < len(woAccounts); i++ {
@ -491,7 +491,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountOrderAfterDeletion() {
err = s.m.settings.SaveOrUpdateAccounts(woAccounts, false) err = s.m.settings.SaveOrUpdateAccounts(woAccounts, false)
s.Require().NoError(err) s.Require().NoError(err)
// Check accounts // Check accounts
dbAccounts1, err := s.m.settings.GetAccounts(false) dbAccounts1, err := s.m.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
totalNumOfAccounts := len(profileKp.Accounts) + len(seedPhraseKp.Accounts) + len(privKeyKp.Accounts) + len(woAccounts) totalNumOfAccounts := len(profileKp.Accounts) + len(seedPhraseKp.Accounts) + len(privKeyKp.Accounts) + len(woAccounts)
s.Require().Equal(totalNumOfAccounts, len(dbAccounts1)) s.Require().Equal(totalNumOfAccounts, len(dbAccounts1))
@ -553,7 +553,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountOrderAfterDeletion() {
}) })
s.Require().NoError(err) s.Require().NoError(err)
dbAccounts2, err := alicesOtherDevice.settings.GetAccounts(false) dbAccounts2, err := alicesOtherDevice.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(totalNumOfAccounts, len(dbAccounts2)) s.Require().Equal(totalNumOfAccounts, len(dbAccounts2))
@ -579,11 +579,11 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountOrderAfterDeletion() {
}) })
s.Require().NoError(err) s.Require().NoError(err)
dbAccounts1, err = s.m.settings.GetAccounts(false) dbAccounts1, err = s.m.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(totalNumOfAccounts, len(dbAccounts1)) s.Require().Equal(totalNumOfAccounts, len(dbAccounts1))
dbAccounts2, err = alicesOtherDevice.settings.GetAccounts(false) dbAccounts2, err = alicesOtherDevice.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(totalNumOfAccounts, len(dbAccounts2)) s.Require().Equal(totalNumOfAccounts, len(dbAccounts2))
@ -609,11 +609,11 @@ func (s *MessengerSyncWalletSuite) TestSyncWalletAccountOrderAfterDeletion() {
}) })
s.Require().NoError(err) s.Require().NoError(err)
dbAccounts1, err = s.m.settings.GetAccounts(false) dbAccounts1, err = s.m.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(totalNumOfAccounts, len(dbAccounts1)) s.Require().Equal(totalNumOfAccounts, len(dbAccounts1))
dbAccounts2, err = alicesOtherDevice.settings.GetAccounts(false) dbAccounts2, err = alicesOtherDevice.settings.GetActiveAccounts()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(totalNumOfAccounts, len(dbAccounts2)) s.Require().Equal(totalNumOfAccounts, len(dbAccounts2))

View File

@ -27,7 +27,7 @@ func (m *Messenger) retrieveWalletBalances() error {
if m.walletAPI == nil { if m.walletAPI == nil {
m.logger.Warn("wallet api not enabled") m.logger.Warn("wallet api not enabled")
} }
accounts, err := m.settings.GetAccounts(false) accounts, err := m.settings.GetActiveAccounts()
if err != nil { if err != nil {
return err return err
} }
@ -375,7 +375,7 @@ func (m *Messenger) syncAccountsPositions(rawMessageHandler RawMessageHandler) e
_, chat := m.getLastClockWithRelatedChat() _, chat := m.getLastClockWithRelatedChat()
allDbAccounts, err := m.settings.GetAccounts(false) allDbAccounts, err := m.settings.GetActiveAccounts()
if err != nil { if err != nil {
return err return err
} }
@ -480,7 +480,7 @@ func (m *Messenger) resolveAndSyncKeypairOrJustWalletAccount(keyUID string, addr
if keyUID == "" { if keyUID == "" {
var dbAccount *accounts.Account var dbAccount *accounts.Account
allDbAccounts, err := m.settings.GetAccounts(true) // removed accounts included allDbAccounts, err := m.settings.GetAllAccounts() // removed accounts included
if err != nil { if err != nil {
return err return err
} }
@ -502,7 +502,7 @@ func (m *Messenger) resolveAndSyncKeypairOrJustWalletAccount(keyUID string, addr
} }
} else { } else {
var dbKeypair *accounts.Keypair var dbKeypair *accounts.Keypair
allDbKeypairs, err := m.settings.GetKeypairs(true) // removed keypairs included allDbKeypairs, err := m.settings.GetAllKeypairs() // removed keypairs included
if err != nil { if err != nil {
return err return err
} }

View File

@ -81,7 +81,7 @@ func (api *API) MoveWalletAccount(ctx context.Context, fromPosition int64, toPos
} }
func (api *API) GetAccounts(ctx context.Context) ([]*accounts.Account, error) { func (api *API) GetAccounts(ctx context.Context) ([]*accounts.Account, error) {
return api.db.GetAccounts(false) return api.db.GetActiveAccounts()
} }
func (api *API) GetWatchOnlyAccounts(ctx context.Context) ([]*accounts.Account, error) { func (api *API) GetWatchOnlyAccounts(ctx context.Context) ([]*accounts.Account, error) {
@ -89,7 +89,7 @@ func (api *API) GetWatchOnlyAccounts(ctx context.Context) ([]*accounts.Account,
} }
func (api *API) GetKeypairs(ctx context.Context) ([]*accounts.Keypair, error) { func (api *API) GetKeypairs(ctx context.Context) ([]*accounts.Keypair, error) {
return api.db.GetKeypairs(false) return api.db.GetActiveKeypairs()
} }
func (api *API) GetAccountByAddress(ctx context.Context, address types.Address) (*accounts.Account, error) { func (api *API) GetAccountByAddress(ctx context.Context, address types.Address) (*accounts.Account, error) {

View File

@ -322,7 +322,7 @@ func (s *Service) verifyTransactionLoop(tick time.Duration, cancel <-chan struct
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
accounts, err := s.accountsDB.GetAccounts(false) accounts, err := s.accountsDB.GetActiveAccounts()
if err != nil { if err != nil {
log.Error("failed to retrieve accounts", "err", err) log.Error("failed to retrieve accounts", "err", err)
} }

View File

@ -105,7 +105,7 @@ func NewAPI(ctx context.Context, acc *accounts.Database, rpcClient *rpc.Client,
func (api *API) Market(chainID uint64) ([]StickerPack, error) { func (api *API) Market(chainID uint64) ([]StickerPack, error) {
// TODO: eventually this should be changed to include pagination // TODO: eventually this should be changed to include pagination
accs, err := api.accountsDB.GetAccounts(false) accs, err := api.accountsDB.GetActiveAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -80,7 +80,7 @@ func (api *API) ProcessPending(chainID uint64) (pendingChanged StickerPackCollec
return nil, err return nil, err
} }
accs, err := api.accountsDB.GetAccounts(false) accs, err := api.accountsDB.GetActiveAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -433,7 +433,7 @@ func (api *API) GetDerivedAddressesForMnemonic(ctx context.Context, mnemonic str
// Generates addresses for the provided paths, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function) // Generates addresses for the provided paths, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function)
func (api *API) getDerivedAddresses(id string, paths []string) ([]*DerivedAddress, error) { func (api *API) getDerivedAddresses(id string, paths []string) ([]*DerivedAddress, error) {
addedAccounts, err := api.s.accountsDB.GetAccounts(false) addedAccounts, err := api.s.accountsDB.GetActiveAccounts()
if err != nil { if err != nil {
return nil, err return nil, err
} }