From d65946e9c025067af6713db58cf29c6ae379e6cb Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 7 Dec 2020 15:03:18 +0100 Subject: [PATCH] Use IsOwnAccount instead of Wallet when watching for transactions There was an issue in using the `Wallet` flag when checking accounts to watch for transactions. `Wallet` indicates that it's the default wallet, not whether is a wallet account. That can only be checked by looking at the type (and the `Wallet` flag). If the type is `generated`, `key` or `seed` it should be watched for transactions. --- VERSION | 2 +- multiaccounts/accounts/account_test.go | 35 ++++++++++++++++++++++++++ multiaccounts/accounts/database.go | 14 +++++++++++ services/ext/service.go | 2 +- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 multiaccounts/accounts/account_test.go diff --git a/VERSION b/VERSION index 8446488ff..91d98abbb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.64.4 +0.64.5 diff --git a/multiaccounts/accounts/account_test.go b/multiaccounts/accounts/account_test.go new file mode 100644 index 000000000..553ae3e7f --- /dev/null +++ b/multiaccounts/accounts/account_test.go @@ -0,0 +1,35 @@ +package accounts + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIsOwnAccount(t *testing.T) { + account := Account{Wallet: true} + require.True(t, account.IsOwnAccount()) + + account = Account{ + Type: accountTypeGenerated, + } + require.True(t, account.IsOwnAccount()) + + account = Account{ + Type: accountTypeKey, + } + require.True(t, account.IsOwnAccount()) + + account = Account{ + Type: accountTypeSeed, + } + require.True(t, account.IsOwnAccount()) + + account = Account{ + Type: accountTypeWatch, + } + require.False(t, account.IsOwnAccount()) + + account = Account{} + require.False(t, account.IsOwnAccount()) +} diff --git a/multiaccounts/accounts/database.go b/multiaccounts/accounts/database.go index 87ad15ffb..6b1cecf16 100644 --- a/multiaccounts/accounts/database.go +++ b/multiaccounts/accounts/database.go @@ -36,6 +36,20 @@ type Account struct { Color string `json:"color"` } +const ( + accountTypeGenerated = "generated" + accountTypeKey = "key" + accountTypeSeed = "seed" + accountTypeWatch = "watch" +) + +// IsOwnAccount returns true if this is an account we have the private key for +// NOTE: Wallet flag can't be used as it actually indicates that it's the default +// Wallet +func (a *Account) IsOwnAccount() bool { + return a.Wallet || a.Type == accountTypeSeed || a.Type == accountTypeGenerated || a.Type == accountTypeKey +} + type Settings struct { // required Address types.Address `json:"address"` diff --git a/services/ext/service.go b/services/ext/service.go index a288d1051..701b0e3fa 100644 --- a/services/ext/service.go +++ b/services/ext/service.go @@ -313,7 +313,7 @@ func (s *Service) verifyTransactionLoop(tick time.Duration, cancel <-chan struct } var wallets []types.Address for _, account := range accounts { - if account.Wallet { + if account.IsOwnAccount() { wallets = append(wallets, types.BytesToAddress(account.Address.Bytes())) } }