Add wallet API to set better earliest block height.

This commit is contained in:
Josh Rickmar 2013-12-09 17:03:51 -05:00
parent 35a991e503
commit 7a91209a4c
2 changed files with 22 additions and 0 deletions

View file

@ -597,6 +597,11 @@ func NotifyNewBlockChainHeight(reply chan []byte, height int32) {
// NtfnBlockConnected handles btcd notifications resulting from newly
// connected blocks to the main blockchain.
//
// TODO(jrick): Send block time with notification. This will be used
// to mark wallet files with a possibly-better earliest block height,
// and will greatly reduce rescan times for wallets created with an
// out of sync btcd.
func NtfnBlockConnected(n btcws.Notification) {
bcn, ok := n.(*btcws.BlockConnectedNtfn)
if !ok {

View file

@ -1090,6 +1090,16 @@ func (w *Wallet) EarliestBlockHeight() int32 {
return height
}
// SetBetterEarliestBlockHeight sets a better earliest block height.
// At wallet creation time, a earliest block is guessed, but this
// could be incorrect if btcd is out of sync. This function can be
// used to correct a previous guess with a better value.
func (w *Wallet) SetBetterEarliestBlockHeight(height int32) {
if height > w.keyGenerator.firstBlock {
w.keyGenerator.firstBlock = height
}
}
// ImportPrivateKey creates a new encrypted btcAddress with a
// user-provided private key and adds it to the wallet. If the
// import is successful, the payment address string is returned.
@ -1136,6 +1146,13 @@ func (w *Wallet) ImportPrivateKey(privkey []byte, compressed bool,
return addrstr, nil
}
// CreateDate returns the Unix time of the wallet creation time. This
// is used to compare the wallet creation time against block headers and
// set a better minimum block height of where to being rescans.
func (w *Wallet) CreateDate() int64 {
return w.createDate
}
// AddressInfo holds information regarding an address needed to manage
// a complete wallet.
type AddressInfo struct {