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:
parent
0b2bd2863b
commit
d65946e9c0
|
@ -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())
|
||||||
|
}
|
|
@ -36,6 +36,20 @@ type Account struct {
|
||||||
Color string `json:"color"`
|
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 {
|
type Settings struct {
|
||||||
// required
|
// required
|
||||||
Address types.Address `json:"address"`
|
Address types.Address `json:"address"`
|
||||||
|
|
|
@ -313,7 +313,7 @@ func (s *Service) verifyTransactionLoop(tick time.Duration, cancel <-chan struct
|
||||||
}
|
}
|
||||||
var wallets []types.Address
|
var wallets []types.Address
|
||||||
for _, account := range accounts {
|
for _, account := range accounts {
|
||||||
if account.Wallet {
|
if account.IsOwnAccount() {
|
||||||
wallets = append(wallets, types.BytesToAddress(account.Address.Bytes()))
|
wallets = append(wallets, types.BytesToAddress(account.Address.Bytes()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue