chore(accounts)_: added two convenient functions to accounts
- `IsWalletNonWatchOnlyAccount` - `IsWalletAccountReadyForTransaction`
This commit is contained in:
parent
e9f11f70dd
commit
5555f98dd5
|
@ -11,30 +11,30 @@ import (
|
||||||
|
|
||||||
func TestIsOwnAccount(t *testing.T) {
|
func TestIsOwnAccount(t *testing.T) {
|
||||||
account := Account{Wallet: true}
|
account := Account{Wallet: true}
|
||||||
require.True(t, account.IsOwnAccount())
|
require.True(t, account.IsWalletNonWatchOnlyAccount())
|
||||||
|
|
||||||
account = Account{
|
account = Account{
|
||||||
Type: AccountTypeGenerated,
|
Type: AccountTypeGenerated,
|
||||||
}
|
}
|
||||||
require.True(t, account.IsOwnAccount())
|
require.True(t, account.IsWalletNonWatchOnlyAccount())
|
||||||
|
|
||||||
account = Account{
|
account = Account{
|
||||||
Type: AccountTypeKey,
|
Type: AccountTypeKey,
|
||||||
}
|
}
|
||||||
require.True(t, account.IsOwnAccount())
|
require.True(t, account.IsWalletNonWatchOnlyAccount())
|
||||||
|
|
||||||
account = Account{
|
account = Account{
|
||||||
Type: AccountTypeSeed,
|
Type: AccountTypeSeed,
|
||||||
}
|
}
|
||||||
require.True(t, account.IsOwnAccount())
|
require.True(t, account.IsWalletNonWatchOnlyAccount())
|
||||||
|
|
||||||
account = Account{
|
account = Account{
|
||||||
Type: AccountTypeWatch,
|
Type: AccountTypeWatch,
|
||||||
}
|
}
|
||||||
require.False(t, account.IsOwnAccount())
|
require.False(t, account.IsWalletNonWatchOnlyAccount())
|
||||||
|
|
||||||
account = Account{}
|
account = Account{}
|
||||||
require.False(t, account.IsOwnAccount())
|
require.False(t, account.IsWalletNonWatchOnlyAccount())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshal(t *testing.T) {
|
func TestUnmarshal(t *testing.T) {
|
||||||
|
|
|
@ -114,11 +114,14 @@ const (
|
||||||
TestSepoliaPreferredChainIDsDefault = "11155111:420:421614"
|
TestSepoliaPreferredChainIDsDefault = "11155111:420:421614"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsOwnAccount returns true if this is an account we have the private key for
|
// Returns true if an account is a wallet account that logged in user has a control over, otherwise returns false.
|
||||||
// NOTE: Wallet flag can't be used as it actually indicates that it's the default
|
func (a *Account) IsWalletNonWatchOnlyAccount() bool {
|
||||||
// Wallet
|
return !a.Chat && a.Type != AccountTypeWatch
|
||||||
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 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) {
|
func (a *Account) MarshalJSON() ([]byte, error) {
|
||||||
|
|
|
@ -336,7 +336,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.IsOwnAccount() {
|
if account.IsWalletNonWatchOnlyAccount() {
|
||||||
wallets = append(wallets, types.BytesToAddress(account.Address.Bytes()))
|
wallets = append(wallets, types.BytesToAddress(account.Address.Bytes()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue