diff --git a/pkg/walletmanager/filesystem.go b/pkg/walletmanager/filesystem.go index f497c99f7..eedc8b290 100644 --- a/pkg/walletmanager/filesystem.go +++ b/pkg/walletmanager/filesystem.go @@ -79,7 +79,7 @@ func (w *Wallet) Load(filePath string) (*account.Account, error) { return nil, fmt.Errorf("reading wallet from '%s': %w", filePath, err) } - acc := account.NewEmpty() + acc := account.Account{} err = acc.Unmarshal(data) if err != nil { return nil, fmt.Errorf("%w: %w", ErrUnmarshalAccount, err) @@ -95,8 +95,8 @@ func (w *Wallet) Load(filePath string) (*account.Account, error) { } // Address in the file is optional, if it's not set, we use the public key - if acc.Address.Object.Data == nil { - acc.Address = *types.NewAddressFromPublicKey(&acc.PublicKey) + if acc.Address == nil || acc.Address.Object == nil || acc.Address.Object.Data == nil { + acc.Address = types.NewAddressFromPublicKey(acc.PublicKey) } return &acc, nil diff --git a/pkg/walletmanager/validation.go b/pkg/walletmanager/validation.go index 75ef47323..8cac289ea 100644 --- a/pkg/walletmanager/validation.go +++ b/pkg/walletmanager/validation.go @@ -24,7 +24,7 @@ func (w *Wallet) NicknameIsUnique(nickname string) error { return nil } -func (w *Wallet) AddressIsUnique(address types.Address) error { +func (w *Wallet) AddressIsUnique(address *types.Address) error { for _, account := range w.accounts { if bytes.Equal(account.Address.Data, address.Data) { return ErrAddressNotUnique diff --git a/pkg/walletmanager/wallet_test.go b/pkg/walletmanager/wallet_test.go index dd6b1a7c2..00ed2d8f4 100644 --- a/pkg/walletmanager/wallet_test.go +++ b/pkg/walletmanager/wallet_test.go @@ -26,7 +26,7 @@ func TestWallet(t *testing.T) { sampleNonce := [12]byte{113, 122, 168, 123, 48, 187, 178, 12, 209, 91, 243, 63} sampleNickname := "bonjour2" sampleAccount, err := account.New( - &[]uint8{account.AccountLastVersion}[0], + uint8(account.AccountLastVersion), sampleNickname, &types.Address{ Object: &object.Object{ @@ -81,7 +81,7 @@ func TestWallet(t *testing.T) { t.Run("Add Account: address not unique", func(t *testing.T) { sampleAccount, err := account.New( - &[]uint8{account.AccountLastVersion}[0], + uint8(account.AccountLastVersion), "bonjour3", &types.Address{ Object: &object.Object{ @@ -122,7 +122,7 @@ func TestWallet(t *testing.T) { acc, err := w.GetAccount(sampleNickname) assert.NoError(t, err) assert.NotNil(t, acc) - assert.Equal(t, uint8(1), *acc.Version) + assert.Equal(t, uint8(1), acc.Version) assert.Equal(t, sampleNickname, acc.Nickname) assert.Equal(t, sampleSalt, acc.Salt) assert.Equal(t, sampleNonce, acc.Nonce) @@ -154,7 +154,7 @@ func TestWallet(t *testing.T) { copy(t, "../../tests/wallet_unit-test.yaml", accountPath) acc := assertAccountIsPresent(t, w, nickname) - assert.Equal(t, uint8(1), *acc.Version) + assert.Equal(t, uint8(1), acc.Version) assert.Equal(t, 2, w.GetAccountCount()) })