Merge pull request #569 from wpaulino/import-priv-key-birthday

wallet/wallet: only set new birthday if before current within ImportPrivateKey
This commit is contained in:
Olaoluwa Osuntokun 2018-11-06 14:29:38 +11:00 committed by GitHub
commit 69684e9091
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,8 +23,6 @@ import (
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/hdkeychain"
"github.com/btcsuite/btcwallet/chain"
@ -33,6 +31,7 @@ import (
"github.com/btcsuite/btcwallet/wallet/txrules"
"github.com/btcsuite/btcwallet/walletdb"
"github.com/btcsuite/btcwallet/wtxmgr"
"github.com/davecgh/go-spew/spew"
)
const (
@ -2644,6 +2643,14 @@ func (w *Wallet) ImportPrivateKey(scope waddrmgr.KeyScope, wif *btcutil.WIF,
if err != nil {
return err
}
// We'll only update our birthday with the new one if it is
// before our current one. Otherwise, we won't rescan for
// potentially relevant chain events that occurred between them.
if newBirthday.After(w.Manager.Birthday()) {
return nil
}
return w.Manager.SetBirthday(addrmgrNs, newBirthday)
})
if err != nil {