Bootstrap rescan requests with utxo set.
This commit is contained in:
parent
6024e0ecb6
commit
c9ff0531f9
2 changed files with 25 additions and 14 deletions
33
account.go
33
account.go
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwallet/tx"
|
"github.com/conformal/btcwallet/tx"
|
||||||
"github.com/conformal/btcwallet/wallet"
|
"github.com/conformal/btcwallet/wallet"
|
||||||
|
"github.com/conformal/btcwire"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
@ -391,11 +392,8 @@ func (a *Account) ImportPrivateKey(pk []byte, compressed bool,
|
||||||
log.Infof("Beginning rescan (height %d) for address %s",
|
log.Infof("Beginning rescan (height %d) for address %s",
|
||||||
bs.Height, addrStr)
|
bs.Height, addrStr)
|
||||||
|
|
||||||
rescanAddrs := map[string]struct{}{
|
|
||||||
addrStr: struct{}{},
|
|
||||||
}
|
|
||||||
jsonErr := Rescan(CurrentServerConn(), bs.Height,
|
jsonErr := Rescan(CurrentServerConn(), bs.Height,
|
||||||
rescanAddrs)
|
[]string{addrStr}, nil)
|
||||||
if jsonErr != nil {
|
if jsonErr != nil {
|
||||||
log.Errorf("Rescan for imported address %s failed: %v",
|
log.Errorf("Rescan for imported address %s failed: %v",
|
||||||
addrStr, jsonErr.Message)
|
addrStr, jsonErr.Message)
|
||||||
|
@ -522,7 +520,17 @@ func (a *Account) RescanActiveAddresses() {
|
||||||
height, a.name)
|
height, a.name)
|
||||||
|
|
||||||
// Rescan active addresses starting at the determined block height.
|
// Rescan active addresses starting at the determined block height.
|
||||||
Rescan(CurrentServerConn(), height, a.ActivePaymentAddresses())
|
addrs := a.SortedActiveAddresses()
|
||||||
|
addrStrs := make([]string, 0, len(addrs))
|
||||||
|
for i := range addrs {
|
||||||
|
addrStrs = append(addrStrs, addrs[i].Address().EncodeAddress())
|
||||||
|
}
|
||||||
|
unspentRecvTxOuts := a.TxStore.UnspentOutputs()
|
||||||
|
unspentOutPoints := make([]*btcwire.OutPoint, 0, len(unspentRecvTxOuts))
|
||||||
|
for _, record := range unspentRecvTxOuts {
|
||||||
|
unspentOutPoints = append(unspentOutPoints, record.OutPoint())
|
||||||
|
}
|
||||||
|
Rescan(CurrentServerConn(), height, addrStrs, unspentOutPoints)
|
||||||
a.MarkAllSynced()
|
a.MarkAllSynced()
|
||||||
AcctMgr.ds.FlushAccount(a)
|
AcctMgr.ds.FlushAccount(a)
|
||||||
|
|
||||||
|
@ -644,19 +652,20 @@ func (a *Account) RecoverAddresses(n int) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
addrStrs := make([]string, 0, len(addrs))
|
||||||
|
for i := range addrs {
|
||||||
|
addrStrs = append(addrStrs, addrs[i].EncodeAddress())
|
||||||
|
}
|
||||||
|
|
||||||
// Run a goroutine to rescan blockchain for recovered addresses.
|
// Run a goroutine to rescan blockchain for recovered addresses.
|
||||||
m := make(map[string]struct{})
|
go func(addrs []string) {
|
||||||
for i := range addrs {
|
jsonErr := Rescan(CurrentServerConn(), lastInfo.FirstBlock(),
|
||||||
m[addrs[i].EncodeAddress()] = struct{}{}
|
addrs, nil)
|
||||||
}
|
|
||||||
go func(addrs map[string]struct{}) {
|
|
||||||
jsonErr := Rescan(CurrentServerConn(), lastInfo.FirstBlock(), addrs)
|
|
||||||
if jsonErr != nil {
|
if jsonErr != nil {
|
||||||
log.Errorf("Rescanning for recovered addresses failed: %v",
|
log.Errorf("Rescanning for recovered addresses failed: %v",
|
||||||
jsonErr.Message)
|
jsonErr.Message)
|
||||||
}
|
}
|
||||||
}(m)
|
}(addrStrs)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,9 +366,11 @@ func NotifySpent(rpc ServerConn, op *btcwire.OutPoint) *btcjson.Error {
|
||||||
|
|
||||||
// Rescan requests a blockchain rescan for transactions to any number of
|
// Rescan requests a blockchain rescan for transactions to any number of
|
||||||
// addresses and notifications to inform wallet about such transactions.
|
// addresses and notifications to inform wallet about such transactions.
|
||||||
func Rescan(rpc ServerConn, beginBlock int32, addrs map[string]struct{}) *btcjson.Error {
|
func Rescan(rpc ServerConn, beginBlock int32, addrs []string,
|
||||||
|
outpoints []*btcwire.OutPoint) *btcjson.Error {
|
||||||
|
|
||||||
// NewRescanCmd cannot fail with no optargs, so omit the check.
|
// NewRescanCmd cannot fail with no optargs, so omit the check.
|
||||||
cmd, _ := btcws.NewRescanCmd(<-NewJSONID, beginBlock, addrs)
|
cmd, _ := btcws.NewRescanCmd(<-NewJSONID, beginBlock, addrs, outpoints)
|
||||||
request := NewServerRequest(cmd, nil)
|
request := NewServerRequest(cmd, nil)
|
||||||
response := <-rpc.SendRequest(request)
|
response := <-rpc.SendRequest(request)
|
||||||
return response.Error()
|
return response.Error()
|
||||||
|
|
Loading…
Reference in a new issue