Added AccountType to enforce strict typing on Accounts

Also a tpyo was fixed, probably introduced by me.
This commit is contained in:
Samuel Hawksby-Robinson 2022-08-25 16:09:08 +01:00
parent 9b04633bb7
commit 26b33aa09d
8 changed files with 20 additions and 14 deletions

View File

@ -686,7 +686,7 @@ func TestConvertAccount(t *testing.T) {
keycardSettings := settings.Settings{
KeycardInstanceUID: "0xdeadbeef",
KeycardPAiredOn: 1,
KeycardPairedOn: 1,
KeycardPairing: "pairing",
}

View File

@ -561,7 +561,7 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(keyStoreDir string, account
return err
}
err = accountDB.SaveSettingField(settings.KeycardPairedOn, s.KeycardPAiredOn)
err = accountDB.SaveSettingField(settings.KeycardPairedOn, s.KeycardPairedOn)
if err != nil {
return err
}

View File

@ -22,7 +22,7 @@ type Account struct {
Address types.Address `json:"address"`
Wallet bool `json:"wallet"`
Chat bool `json:"chat"`
Type string `json:"type,omitempty"`
Type AccountType `json:"type,omitempty"`
Storage string `json:"storage,omitempty"`
Path string `json:"path,omitempty"`
PublicKey types.HexBytes `json:"public-key,omitempty"`
@ -35,11 +35,17 @@ type Account struct {
Removed bool `json:"removed,omitempty"`
}
type AccountType string
func (a AccountType) String() string {
return string(a)
}
const (
AccountTypeGenerated = "generated"
AccountTypeKey = "key"
AccountTypeSeed = "seed"
AccountTypeWatch = "watch"
AccountTypeGenerated AccountType = "generated"
AccountTypeKey AccountType = "key"
AccountTypeSeed AccountType = "seed"
AccountTypeWatch AccountType = "watch"
)
// IsOwnAccount returns true if this is an account we have the private key for
@ -55,7 +61,7 @@ func (a *Account) MarshalJSON() ([]byte, error) {
MixedcaseAddress string `json:"mixedcase-address"`
Wallet bool `json:"wallet"`
Chat bool `json:"chat"`
Type string `json:"type,omitempty"`
Type AccountType `json:"type,omitempty"`
Storage string `json:"storage,omitempty"`
Path string `json:"path,omitempty"`
PublicKey types.HexBytes `json:"public-key,omitempty"`

View File

@ -123,7 +123,7 @@ INSERT INTO settings (
s.InstallationID,
s.KeyUID,
s.KeycardInstanceUID,
s.KeycardPAiredOn,
s.KeycardPairedOn,
s.KeycardPairing,
s.LatestDerivedPath,
s.Mnemonic,
@ -286,7 +286,7 @@ func (db *Database) GetSettings() (Settings, error) {
&s.InstallationID,
&s.KeyUID,
&s.KeycardInstanceUID,
&s.KeycardPAiredOn,
&s.KeycardPairedOn,
&s.KeycardPairing,
&s.LastUpdated,
&s.LatestDerivedPath,

View File

@ -126,7 +126,7 @@ type Settings struct {
InstallationID string `json:"installation-id"`
KeyUID string `json:"key-uid"`
KeycardInstanceUID string `json:"keycard-instance-uid,omitempty"`
KeycardPAiredOn int64 `json:"keycard-paired-on,omitempty"`
KeycardPairedOn int64 `json:"keycard-paired-on,omitempty"`
KeycardPairing string `json:"keycard-pairing,omitempty"`
LastUpdated *int64 `json:"last-updated,omitempty"`
LatestDerivedPath uint `json:"latest-derived-path"`

View File

@ -3019,7 +3019,7 @@ func (m *Messenger) syncWallets(accs []*accounts.Account) error {
Address: acc.Address.Bytes(),
Wallet: acc.Wallet,
Chat: acc.Chat,
Type: acc.Type,
Type: acc.Type.String(),
Storage: acc.Storage,
Path: acc.Path,
PublicKey: acc.PublicKey,

View File

@ -2037,7 +2037,7 @@ func (m *Messenger) HandleSyncWalletAccount(state *ReceivedMessageState, message
Address: types.BytesToAddress(message.Address),
Wallet: message.Wallet,
Chat: message.Chat,
Type: message.Type,
Type: accounts.AccountType(message.Type),
Storage: message.Storage,
PublicKey: types.HexBytes(message.PublicKey),
Path: message.Path,

View File

@ -90,7 +90,7 @@ func (api *API) DeleteAccount(ctx context.Context, address types.Address) error
func (api *API) AddAccountWatch(ctx context.Context, address string, name string, color string, emoji string) error {
account := &accounts.Account{
Address: types.Address(common.HexToAddress(address)),
Type: "watch",
Type: accounts.AccountTypeWatch,
Name: name,
Emoji: emoji,
Color: color,