waddrmgr: fix botched merge

This commit is contained in:
Olaoluwa Osuntokun 2018-05-14 22:16:53 -07:00
parent 7770cac383
commit ccb49eaf2a

View file

@ -1060,7 +1060,8 @@ func (m *Manager) Unlock(ns walletdb.ReadBucket, passphrase []byte) error {
// Use the crypto private key to decrypt all of the account private // Use the crypto private key to decrypt all of the account private
// extended keys. // extended keys.
for account, acctInfo := range m.acctInfo { for _, manager := range m.scopedManagers {
for account, acctInfo := range manager.acctInfo {
decrypted, err := m.cryptoKeyPriv.Decrypt(acctInfo.acctKeyEncrypted) decrypted, err := m.cryptoKeyPriv.Decrypt(acctInfo.acctKeyEncrypted)
if err != nil { if err != nil {
m.lock() m.lock()
@ -1080,19 +1081,21 @@ func (m *Manager) Unlock(ns walletdb.ReadBucket, passphrase []byte) error {
acctInfo.acctKeyPriv = acctKeyPriv acctInfo.acctKeyPriv = acctKeyPriv
} }
// Derive any private keys that are pending due to them being created // We'll also derive any private keys that are pending due to
// while the address manager was locked. // them being created while the address manager was locked.
for _, info := range m.deriveOnUnlock { for _, info := range manager.deriveOnUnlock {
addressKey, err := m.deriveKeyFromPath(ns, info.managedAddr.account, addressKey, err := manager.deriveKeyFromPath(
info.branch, info.index, true) ns, info.managedAddr.Account(), info.branch,
info.index, true,
)
if err != nil { if err != nil {
m.lock() m.lock()
return err return err
} }
// It's ok to ignore the error here since it can only fail if // It's ok to ignore the error here since it can only
// the extended key is not private, however it was just derived // fail if the extended key is not private, however it
// as a private key. // was just derived as a private key.
privKey, _ := addressKey.ECPrivKey() privKey, _ := addressKey.ECPrivKey()
addressKey.Zero() addressKey.Zero()
@ -1106,7 +1109,6 @@ func (m *Manager) Unlock(ns walletdb.ReadBucket, passphrase []byte) error {
return managerError(ErrCrypto, str, err) return managerError(ErrCrypto, str, err)
} }
// TODO(roasbeef): don't need to do anythign further?
switch a := info.managedAddr.(type) { switch a := info.managedAddr.(type) {
case *managedAddress: case *managedAddress:
a.privKeyEncrypted = privKeyEncrypted a.privKeyEncrypted = privKeyEncrypted
@ -1115,8 +1117,9 @@ func (m *Manager) Unlock(ns walletdb.ReadBucket, passphrase []byte) error {
} }
// Avoid re-deriving this key on subsequent unlocks. // Avoid re-deriving this key on subsequent unlocks.
m.deriveOnUnlock[0] = nil manager.deriveOnUnlock[0] = nil
m.deriveOnUnlock = m.deriveOnUnlock[1:] manager.deriveOnUnlock = manager.deriveOnUnlock[1:]
}
} }
m.locked = false m.locked = false