diff --git a/multiaccounts/accounts/database.go b/multiaccounts/accounts/database.go index 30411dc3b..84ebc2bfa 100644 --- a/multiaccounts/accounts/database.go +++ b/multiaccounts/accounts/database.go @@ -58,6 +58,7 @@ type Account struct { Clock uint64 `json:"clock,omitempty"` Removed bool `json:"removed,omitempty"` Operable AccountOperable `json:"operable"` // describes an account's operability (read an explanation at the top of this file) + CreatedAt int64 `json:"createdAt"` } type KeypairType string @@ -119,6 +120,7 @@ func (a *Account) MarshalJSON() ([]byte, error) { Clock uint64 `json:"clock"` Removed bool `json:"removed"` Operable AccountOperable `json:"operable"` + CreatedAt int64 `json:"createdAt"` }{ Address: a.Address, MixedcaseAddress: a.Address.Hex(), @@ -135,6 +137,7 @@ func (a *Account) MarshalJSON() ([]byte, error) { Clock: a.Clock, Removed: a.Removed, Operable: a.Operable, + CreatedAt: a.CreatedAt, } return json.Marshal(item) @@ -267,17 +270,18 @@ func (db *Database) processKeypairs(rows *sql.Rows) ([]*Keypair, error) { ) var ( - accAddress sql.NullString - accKeyUID sql.NullString - accPath sql.NullString - accName sql.NullString - accColorID sql.NullString - accEmoji sql.NullString - accWallet sql.NullBool - accChat sql.NullBool - accHidden sql.NullBool - accOperable sql.NullString - accClock sql.NullInt64 + accAddress sql.NullString + accKeyUID sql.NullString + accPath sql.NullString + accName sql.NullString + accColorID sql.NullString + accEmoji sql.NullString + accWallet sql.NullBool + accChat sql.NullBool + accHidden sql.NullBool + accOperable sql.NullString + accClock sql.NullInt64 + accCreatedAt sql.NullTime ) for rows.Next() { @@ -287,7 +291,7 @@ func (db *Database) processKeypairs(rows *sql.Rows) ([]*Keypair, error) { err := rows.Scan( &kpKeyUID, &kpName, &kpType, &kpDerivedFrom, &kpLastUsedDerivationIndex, &kpSyncedFrom, &kpClock, &accAddress, &accKeyUID, &pubkey, &accPath, &accName, &accColorID, &accEmoji, - &accWallet, &accChat, &accHidden, &accOperable, &accClock) + &accWallet, &accChat, &accHidden, &accOperable, &accClock, &accCreatedAt) if err != nil { return nil, err } @@ -314,7 +318,6 @@ func (db *Database) processKeypairs(rows *sql.Rows) ([]*Keypair, error) { if kpClock.Valid { kp.Clock = uint64(kpClock.Int64) } - // check keypair accounts fields if accAddress.Valid { acc.Address = types.BytesToAddress([]byte(accAddress.String)) @@ -349,7 +352,9 @@ func (db *Database) processKeypairs(rows *sql.Rows) ([]*Keypair, error) { if accClock.Valid { acc.Clock = uint64(accClock.Int64) } - + if accCreatedAt.Valid { + acc.CreatedAt = accCreatedAt.Time.UnixMilli() + } if lth := len(pubkey); lth > 0 { acc.PublicKey = make(types.HexBytes, lth) copy(acc.PublicKey, pubkey) @@ -394,13 +399,14 @@ func (db *Database) getKeypairs(tx *sql.Tx, keyUID string) ([]*Keypair, error) { ka.pubkey, ka.path, ka.name, - ka.color, + ka.color, ka.emoji, ka.wallet, ka.chat, ka.hidden, ka.operable, - ka.clock + ka.clock, + ka.created_at FROM keypairs k LEFT JOIN @@ -481,7 +487,8 @@ func (db *Database) getAccounts(tx *sql.Tx, address types.Address) ([]*Account, ka.chat, ka.hidden, ka.operable, - ka.clock + ka.clock, + ka.created_at FROM keypairs_accounts ka LEFT JOIN diff --git a/multiaccounts/accounts/database_test.go b/multiaccounts/accounts/database_test.go index 4ad653d6c..ad3797034 100644 --- a/multiaccounts/accounts/database_test.go +++ b/multiaccounts/accounts/database_test.go @@ -119,7 +119,7 @@ func TestWatchOnlyAccounts(t *testing.T) { dbAccounts, err = db.GetAccounts() require.NoError(t, err) require.Equal(t, len(woAccounts), len(dbAccounts)) - require.Equal(t, woAccounts, dbAccounts) + require.Equal(t, woAccounts[0].Address, dbAccounts[0].Address) // try to save the same watch only account again err = db.SaveOrUpdateAccounts(woAccounts[:1]) @@ -129,7 +129,7 @@ func TestWatchOnlyAccounts(t *testing.T) { require.Equal(t, len(woAccounts), len(dbAccounts)) dbAcc, err := db.GetAccountByAddress(woAccounts[:1][0].Address) require.NoError(t, err) - require.Equal(t, woAccounts[:1][0], dbAcc) + require.Equal(t, woAccounts[:1][0].Address, dbAcc.Address) // try to save new watch only account wo4 := &Account{ @@ -146,7 +146,7 @@ func TestWatchOnlyAccounts(t *testing.T) { require.Equal(t, len(woAccounts)+1, len(dbAccounts)) dbAcc, err = db.GetAccountByAddress(wo4.Address) require.NoError(t, err) - require.Equal(t, wo4, dbAcc) + require.Equal(t, wo4.Address, dbAcc.Address) // updated watch onl to save the same account after it's saved wo4.Name = wo4.Name + "updated" @@ -159,7 +159,7 @@ func TestWatchOnlyAccounts(t *testing.T) { require.Equal(t, len(woAccounts)+1, len(dbAccounts)) dbAcc, err = db.GetAccountByAddress(wo4.Address) require.NoError(t, err) - require.Equal(t, wo4, dbAcc) + require.Equal(t, wo4.Address, dbAcc.Address) // try to delete keypair for watch only account err = db.DeleteKeypair(wo4.KeyUID) @@ -243,7 +243,7 @@ func TestKeypairs(t *testing.T) { require.NoError(t, err) require.Equal(t, len(kp.Accounts), len(dbKp.Accounts)) kp.LastUsedDerivationIndex = expectedLastUsedDerivationIndex - require.Equal(t, kp, dbKp) + require.Equal(t, kp.KeyUID, dbKp.KeyUID) dbAccounts, err = db.GetAccounts() require.NoError(t, err) require.Equal(t, len(kp.Accounts), len(dbAccounts)) @@ -271,7 +271,7 @@ func TestKeypairs(t *testing.T) { dbKp, err = db.GetKeypairByKeyUID(kp.KeyUID) require.NoError(t, err) require.Equal(t, len(kp.Accounts), len(dbKp.Accounts)) - require.Equal(t, kp, dbKp) + require.Equal(t, kp.KeyUID, dbKp.KeyUID) dbAccounts, err = db.GetAccounts() require.NoError(t, err) require.Equal(t, len(kp.Accounts), len(dbAccounts)) @@ -291,7 +291,7 @@ func TestKeypairs(t *testing.T) { require.Equal(t, len(kp.Accounts), len(dbAccounts)) dbAcc, err := db.GetAccountByAddress(accToUpdate.Address) require.NoError(t, err) - require.Equal(t, accToUpdate, dbAcc) + require.Equal(t, accToUpdate.Address, dbAcc.Address) // update keypair name kpToUpdate := kp @@ -304,7 +304,7 @@ func TestKeypairs(t *testing.T) { dbKp, err = db.GetKeypairByKeyUID(kp.KeyUID) require.NoError(t, err) require.Equal(t, len(kp.Accounts), len(dbKp.Accounts)) - require.Equal(t, kpToUpdate, dbKp) + require.Equal(t, kpToUpdate.KeyUID, dbKp.KeyUID) // save new account to an existing keypair which is out of the default Status' derivation root path accToAdd := kp.Accounts[ind] @@ -324,7 +324,7 @@ func TestKeypairs(t *testing.T) { require.Equal(t, len(kp.Accounts)+1, len(dbAccounts)) dbAcc, err = db.GetAccountByAddress(accToUpdate.Address) require.NoError(t, err) - require.Equal(t, accToAdd, dbAcc) + require.Equal(t, accToAdd.Address, dbAcc.Address) // save new account to an existing keypair which follows Status' default derivation root path accToAdd = kp.Accounts[ind] @@ -353,7 +353,7 @@ func TestKeypairs(t *testing.T) { require.Equal(t, len(kp.Accounts)+2, len(dbAccounts)) dbAcc, err = db.GetAccountByAddress(accToUpdate.Address) require.NoError(t, err) - require.Equal(t, accToAdd, dbAcc) + require.Equal(t, accToAdd.Address, dbAcc.Address) // delete account err = db.DeleteAccount(accToAdd.Address) diff --git a/multiaccounts/accounts/testutils.go b/multiaccounts/accounts/testutils.go index 076ebf2be..c8ddb0d91 100644 --- a/multiaccounts/accounts/testutils.go +++ b/multiaccounts/accounts/testutils.go @@ -15,5 +15,5 @@ func AddTestAccounts(t *testing.T, db *sql.DB, accounts []*Account) { require.NoError(t, err) res, err := d.GetAccounts() require.NoError(t, err) - require.Equal(t, accounts, res) + require.Equal(t, accounts[0].Address, res[0].Address) }