Add rescan field to walletinfo response (#3933)

This commit is contained in:
rorp 2021-12-23 14:30:26 -08:00 committed by GitHub
parent 0c134c7e9b
commit 41b96c4c7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 1 deletions

View file

@ -828,6 +828,7 @@ case class WalletRoutes(wallet: AnyDLCHDWalletApi)(implicit
for {
accountDb <- wallet.getDefaultAccount()
walletState <- wallet.getSyncState()
rescan <- wallet.isRescanning()
} yield {
Obj(
WalletAppConfig.moduleName ->
@ -839,7 +840,8 @@ case class WalletRoutes(wallet: AnyDLCHDWalletApi)(implicit
"xpub" -> Str(accountDb.xpub.toString),
"hdPath" -> Str(accountDb.hdAccount.toString),
"height" -> Num(walletState.height),
"blockHash" -> Str(walletState.blockHash.hex)
"blockHash" -> Str(walletState.blockHash.hex),
"rescan" -> rescan
)
)
}

View file

@ -402,6 +402,8 @@ trait WalletApi extends StartStopAsync[WalletApi] {
def isChange(output: TransactionOutput): Future[Boolean]
def getSyncState(): Future[BlockSyncState]
def isRescanning(): Future[Boolean]
}
/** An HDWallet that uses Neutrino to sync */

View file

@ -161,10 +161,12 @@ class NeutrinoNodeWithWalletTest extends NodeTestWithCachedBitcoindNewest {
def condition(): Future[Boolean] = {
for {
rescan <- wallet.isRescanning()
balance <- wallet.getBalance()
addresses <- wallet.listAddresses()
utxos <- wallet.listUtxos()
} yield {
!rescan &&
balance == BitcoinSWalletTest.expectedDefaultAmt + TestAmount &&
utxos.size == 4 &&
addresses.map(_.scriptPubKey.hex).sorted == utxos
@ -201,6 +203,8 @@ class NeutrinoNodeWithWalletTest extends NodeTestWithCachedBitcoindNewest {
_ = assert(addresses.isEmpty)
_ = assert(utxos.isEmpty)
rescan <- wallet.isRescanning()
_ = assert(!rescan)
_ <- wallet.fullRescanNeutrinoWallet(addressBatchSize = 7)
_ <- AsyncUtil.awaitConditionF(condition)

View file

@ -14,14 +14,20 @@ import org.bitcoins.core.util.FutureUtil
import org.bitcoins.crypto.DoubleSha256Digest
import org.bitcoins.wallet.{Wallet, WalletLogger}
import java.util.concurrent.atomic.AtomicBoolean
import scala.concurrent.{ExecutionContext, Future}
private[wallet] trait RescanHandling extends WalletLogger {
self: Wallet =>
private val rescanning = new AtomicBoolean(false)
/////////////////////
// Public facing API
override def isRescanning(): Future[Boolean] =
Future.successful(rescanning.get())
/** @inheritdoc */
override def rescanNeutrinoWallet(
startOpt: Option[BlockStamp],
@ -46,6 +52,8 @@ private[wallet] trait RescanHandling extends WalletLogger {
addressBatchSize: Int,
useCreationTime: Boolean = true): Future[Unit] = {
rescanning.set(true)
logger.info(s"Starting rescanning the wallet from ${startOpt} to ${endOpt}")
val start = System.currentTimeMillis()
@ -66,6 +74,7 @@ private[wallet] trait RescanHandling extends WalletLogger {
} yield ()
res.onComplete { _ =>
rescanning.set(false)
logger.info(
s"Finished rescanning the wallet. It took ${System.currentTimeMillis() - start}ms")
}