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.
This commit is contained in:
Andrea Maria Piana 2020-12-07 15:03:18 +01:00
parent 0b2bd2863b
commit d65946e9c0
4 changed files with 51 additions and 2 deletions

View File

@ -1 +1 @@
0.64.4
0.64.5

View File

@ -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())
}

View File

@ -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"`

View File

@ -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()))
}
}