mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 21:42:48 +01:00
Rescan Improvements (#2379)
* Rescan Improvements * Make test use fetchFilters instead
This commit is contained in:
parent
307ba23d0d
commit
901fb2af17
2 changed files with 18 additions and 10 deletions
|
@ -159,13 +159,13 @@ class WalletUnitTest extends BitcoinSWalletTest {
|
|||
|
||||
it should "match block filters" in { wallet: Wallet =>
|
||||
for {
|
||||
matched <- wallet.getMatchingBlocks(
|
||||
height <- wallet.chainQueryApi.getFilterCount()
|
||||
matched <- wallet.fetchFiltersInRange(
|
||||
scripts = Vector(
|
||||
// this is a random address which is included into the test block
|
||||
BitcoinAddress("n1RH2x3b3ah4TGQtgrmNAHfmad9wr8U2QY").scriptPubKey),
|
||||
startOpt = None,
|
||||
endOpt = None
|
||||
)(system.dispatcher)
|
||||
parallelismLevel = 1
|
||||
)(heightRange = 0.to(height).toVector)
|
||||
} yield {
|
||||
assert(
|
||||
Vector(BlockMatchingResponse(blockHash = testBlockHash,
|
||||
|
|
|
@ -111,6 +111,8 @@ private[wallet] trait RescanHandling extends WalletLogger {
|
|||
elements = range.toVector,
|
||||
f = fetchFiltersInRange(scripts, parallelismLevel),
|
||||
batchSize = batchSize)
|
||||
|
||||
_ <- downloadAndProcessBlocks(matched.map(_.blockHash.flip))
|
||||
} yield {
|
||||
logger.info(s"Matched ${matched.length} blocks on rescan")
|
||||
matched
|
||||
|
@ -128,10 +130,9 @@ private[wallet] trait RescanHandling extends WalletLogger {
|
|||
addressBatchSize: Int): Future[Unit] = {
|
||||
for {
|
||||
scriptPubKeys <- generateScriptPubKeys(account, addressBatchSize)
|
||||
blocks <- matchBlocks(scriptPubKeys = scriptPubKeys,
|
||||
endOpt = endOpt,
|
||||
startOpt = startOpt)
|
||||
_ <- downloadAndProcessBlocks(blocks)
|
||||
_ <- matchBlocks(scriptPubKeys = scriptPubKeys,
|
||||
endOpt = endOpt,
|
||||
startOpt = startOpt)
|
||||
externalGap <- calcAddressGap(HDChainType.External, account)
|
||||
changeGap <- calcAddressGap(HDChainType.Change, account)
|
||||
res <-
|
||||
|
@ -249,10 +250,17 @@ private[wallet] trait RescanHandling extends WalletLogger {
|
|||
address <- getNewChangeAddress(account)
|
||||
} yield prev :+ address
|
||||
}
|
||||
} yield addresses.map(_.scriptPubKey) ++ changeAddresses.map(_.scriptPubKey)
|
||||
spksDb <- scriptPubKeyDAO.findAll()
|
||||
} yield {
|
||||
val addrSpks =
|
||||
addresses.map(_.scriptPubKey) ++ changeAddresses.map(_.scriptPubKey)
|
||||
val otherSpks = spksDb.map(_.scriptPubKey)
|
||||
|
||||
(addrSpks ++ otherSpks).distinct
|
||||
}
|
||||
}
|
||||
|
||||
private def fetchFiltersInRange(
|
||||
private[wallet] def fetchFiltersInRange(
|
||||
scripts: Vector[ScriptPubKey],
|
||||
parallelismLevel: Int)(
|
||||
heightRange: Vector[Int]): Future[Vector[BlockMatchingResponse]] = {
|
||||
|
|
Loading…
Add table
Reference in a new issue