mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 18:02:54 +01:00
Rescan when UTXOs don't have associated transactions (#1562)
* Rescan for missing utxos * Move to Wallet.start * Start and stop wallet threads with wallet * Fix warning
This commit is contained in:
parent
fc6b5712bc
commit
9016f0bbca
@ -97,6 +97,7 @@ object Main extends App with BitcoinSLogger {
|
||||
chainApi,
|
||||
BitcoinerLiveFeeRateProvider(60),
|
||||
bip39PasswordOpt)
|
||||
_ <- wallet.start()
|
||||
} yield wallet
|
||||
|
||||
//add callbacks to our unitialized node
|
||||
|
@ -13,7 +13,7 @@ import org.bitcoins.core.protocol.script.ScriptPubKey
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.script.constant.ScriptConstant
|
||||
import org.bitcoins.core.script.control.OP_RETURN
|
||||
import org.bitcoins.core.util.{BitcoinScriptUtil, Mutable}
|
||||
import org.bitcoins.core.util.{BitcoinScriptUtil, FutureUtil, Mutable}
|
||||
import org.bitcoins.core.wallet.builder.{
|
||||
RawTxBuilderWithFinalizer,
|
||||
RawTxSigner,
|
||||
@ -75,9 +75,43 @@ abstract class Wallet
|
||||
this
|
||||
}
|
||||
|
||||
private def utxosWithMissingTx: Future[Vector[SpendingInfoDb]] = {
|
||||
for {
|
||||
utxos <- spendingInfoDAO.findAllUnspent()
|
||||
hasTxs <- FutureUtil.foldLeftAsync(Vector.empty[SpendingInfoDb], utxos) {
|
||||
(accum, utxo) =>
|
||||
// If we don't have tx in our transactionDAO, add it to the list
|
||||
transactionDAO
|
||||
.read(utxo.txid)
|
||||
.map(txOpt => if (txOpt.isEmpty) accum :+ utxo else accum)
|
||||
}
|
||||
} yield hasTxs
|
||||
}
|
||||
|
||||
protected def downloadMissingUtxos: Future[Unit] =
|
||||
for {
|
||||
utxos <- utxosWithMissingTx
|
||||
blockHashes = utxos.flatMap(_.blockHash.map(_.flip))
|
||||
// Download the block the tx is from so we process the block and subsequent txs
|
||||
_ <- nodeApi.downloadBlocks(blockHashes.distinct)
|
||||
} yield ()
|
||||
|
||||
override def start(): Future[Unit] = {
|
||||
for {
|
||||
_ <- walletConfig.start()
|
||||
_ <- downloadMissingUtxos
|
||||
} yield {
|
||||
startWalletThread()
|
||||
}
|
||||
}
|
||||
|
||||
override def stop(): Unit = {
|
||||
walletConfig.stop()
|
||||
stopWalletThread()
|
||||
for {
|
||||
_ <- walletConfig.stop()
|
||||
} yield {
|
||||
stopWalletThread()
|
||||
}
|
||||
()
|
||||
}
|
||||
|
||||
override def broadcastTransaction(transaction: Transaction): Future[Unit] =
|
||||
|
@ -58,6 +58,8 @@ trait WalletApi extends WalletLogger {
|
||||
def broadcastTransaction(transaction: Transaction): Future[Unit] =
|
||||
nodeApi.broadcastTransaction(transaction)
|
||||
|
||||
def start(): Future[Unit]
|
||||
|
||||
def stop(): Unit
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user