From c51cbb33325c951cdbdb90e7ff0ca66c3e400675 Mon Sep 17 00:00:00 2001 From: Jimmy Song Date: Thu, 20 Mar 2014 11:35:44 -0500 Subject: [PATCH] Refactor len(w.secret) != 32 Now using w.IsLocked() for all instances of above. Also changed one other place where the logic had to be reversed in nextChainedAddress (len(w.secret) == 32 was the condition). --- wallet/wallet.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index 6e865ca..45567da 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -860,7 +860,7 @@ func (w *Wallet) Lock() (err error) { } // Remove clear text passphrase from wallet. - if len(w.secret) != 32 { + if w.IsLocked() { err = ErrWalletLocked } else { zero(w.passphrase) @@ -900,7 +900,7 @@ func (w *Wallet) ChangePassphrase(new []byte) error { return ErrWalletIsWatchingOnly } - if len(w.secret) != 32 { + if w.IsLocked() { return ErrWalletLocked } @@ -974,13 +974,13 @@ func (w *Wallet) nextChainedAddress(bs *BlockStamp, keypoolSize uint) (*btcAddre nextAPKH, ok := w.chainIdxMap[w.highestUsed+1] if !ok { // Extending the keypool requires an unlocked wallet. - if len(w.secret) == 32 { - // Key is available, extend keypool. - if err := w.extendKeypool(keypoolSize, bs); err != nil { + if w.IsLocked() { + if err := w.extendLockedWallet(bs); err != nil { return nil, err } } else { - if err := w.extendLockedWallet(bs); err != nil { + // Key is available, extend keypool. + if err := w.extendKeypool(keypoolSize, bs); err != nil { return nil, err } } @@ -1025,7 +1025,7 @@ func (w *Wallet) extendKeypool(n uint, bs *BlockStamp) error { return errors.New("expected last chained address not found") } - if len(w.secret) != 32 { + if w.IsLocked() { return ErrWalletLocked } @@ -1126,7 +1126,7 @@ func (w *Wallet) createMissingPrivateKeys() error { return errors.New("missing previous chained address") } prevWAddr := w.addrMap[getAddressKey(apkh)] - if len(w.secret) != 32 { + if w.IsLocked() { return ErrWalletLocked } @@ -1214,7 +1214,7 @@ func (w *Wallet) AddressKey(a btcutil.Address) (key *ecdsa.PrivateKey, err error } // Wallet must be unlocked to decrypt the private key. - if len(w.secret) != 32 { + if w.IsLocked() { return nil, ErrWalletLocked } @@ -1395,7 +1395,7 @@ func (w *Wallet) ImportPrivateKey(privkey []byte, compressed bool, bs *BlockStam } // The wallet must be unlocked to encrypt the imported private key. - if len(w.secret) != 32 { + if w.IsLocked() { return nil, ErrWalletLocked }