chore(accounts)_: added two convenient functions to accounts

- `IsWalletNonWatchOnlyAccount`
- `IsWalletAccountReadyForTransaction`
This commit is contained in:
Sale Djenic 2023-11-17 12:55:10 +01:00 committed by saledjenic
parent e9f11f70dd
commit 5555f98dd5
4 changed files with 16 additions and 13 deletions

View File

@ -1 +1 @@
0.171.14
0.171.15

View File

@ -11,30 +11,30 @@ import (
func TestIsOwnAccount(t *testing.T) {
account := Account{Wallet: true}
require.True(t, account.IsOwnAccount())
require.True(t, account.IsWalletNonWatchOnlyAccount())
account = Account{
Type: AccountTypeGenerated,
}
require.True(t, account.IsOwnAccount())
require.True(t, account.IsWalletNonWatchOnlyAccount())
account = Account{
Type: AccountTypeKey,
}
require.True(t, account.IsOwnAccount())
require.True(t, account.IsWalletNonWatchOnlyAccount())
account = Account{
Type: AccountTypeSeed,
}
require.True(t, account.IsOwnAccount())
require.True(t, account.IsWalletNonWatchOnlyAccount())
account = Account{
Type: AccountTypeWatch,
}
require.False(t, account.IsOwnAccount())
require.False(t, account.IsWalletNonWatchOnlyAccount())
account = Account{}
require.False(t, account.IsOwnAccount())
require.False(t, account.IsWalletNonWatchOnlyAccount())
}
func TestUnmarshal(t *testing.T) {

View File

@ -114,11 +114,14 @@ const (
TestSepoliaPreferredChainIDsDefault = "11155111:420:421614"
)
// 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
// Returns true if an account is a wallet account that logged in user has a control over, otherwise returns false.
func (a *Account) IsWalletNonWatchOnlyAccount() bool {
return !a.Chat && a.Type != AccountTypeWatch
}
// Returns true if an account is a wallet account that is ready for sending transactions, otherwise returns false.
func (a *Account) IsWalletAccountReadyForTransaction() bool {
return a.IsWalletNonWatchOnlyAccount() && a.Operable != AccountNonOperable
}
func (a *Account) MarshalJSON() ([]byte, error) {

View File

@ -336,7 +336,7 @@ func (s *Service) verifyTransactionLoop(tick time.Duration, cancel <-chan struct
}
var wallets []types.Address
for _, account := range accounts {
if account.IsOwnAccount() {
if account.IsWalletNonWatchOnlyAccount() {
wallets = append(wallets, types.BytesToAddress(account.Address.Bytes()))
}
}