Skip to content

Commit b3c9624

Browse files
committed
accounts/keystore: small code simplification (ethereum#18394)
1 parent de2dc3f commit b3c9624

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

accounts/keystore/wallet.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ func (w *keystoreWallet) SelfDerive(base accounts.DerivationPath, chain ethereum
8484
// able to sign via our shared keystore backend).
8585
func (w *keystoreWallet) SignHash(account accounts.Account, hash []byte) ([]byte, error) {
8686
// Make sure the requested account is contained within
87-
if account.Address != w.account.Address {
88-
return nil, accounts.ErrUnknownAccount
89-
}
90-
if account.URL != (accounts.URL{}) && account.URL != w.account.URL {
87+
if !w.Contains(account) {
9188
return nil, accounts.ErrUnknownAccount
9289
}
9390
// Account seems valid, request the keystore to sign
@@ -100,10 +97,7 @@ func (w *keystoreWallet) SignHash(account accounts.Account, hash []byte) ([]byte
10097
// be able to sign via our shared keystore backend).
10198
func (w *keystoreWallet) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
10299
// Make sure the requested account is contained within
103-
if account.Address != w.account.Address {
104-
return nil, accounts.ErrUnknownAccount
105-
}
106-
if account.URL != (accounts.URL{}) && account.URL != w.account.URL {
100+
if !w.Contains(account) {
107101
return nil, accounts.ErrUnknownAccount
108102
}
109103
// Account seems valid, request the keystore to sign
@@ -114,10 +108,7 @@ func (w *keystoreWallet) SignTx(account accounts.Account, tx *types.Transaction,
114108
// given hash with the given account using passphrase as extra authentication.
115109
func (w *keystoreWallet) SignHashWithPassphrase(account accounts.Account, passphrase string, hash []byte) ([]byte, error) {
116110
// Make sure the requested account is contained within
117-
if account.Address != w.account.Address {
118-
return nil, accounts.ErrUnknownAccount
119-
}
120-
if account.URL != (accounts.URL{}) && account.URL != w.account.URL {
111+
if !w.Contains(account) {
121112
return nil, accounts.ErrUnknownAccount
122113
}
123114
// Account seems valid, request the keystore to sign
@@ -128,10 +119,7 @@ func (w *keystoreWallet) SignHashWithPassphrase(account accounts.Account, passph
128119
// transaction with the given account using passphrase as extra authentication.
129120
func (w *keystoreWallet) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
130121
// Make sure the requested account is contained within
131-
if account.Address != w.account.Address {
132-
return nil, accounts.ErrUnknownAccount
133-
}
134-
if account.URL != (accounts.URL{}) && account.URL != w.account.URL {
122+
if !w.Contains(account) {
135123
return nil, accounts.ErrUnknownAccount
136124
}
137125
// Account seems valid, request the keystore to sign

0 commit comments

Comments
 (0)