1
0
Fork 0
mirror of https://github.com/bitcoin-s/bitcoin-s.git synced 2025-03-26 21:42:48 +01:00

Rescan when UTXOs don't have associated transactions ()

* Rescan for missing utxos

* Move to Wallet.start

* Start and stop wallet threads with wallet

* Fix warning
This commit is contained in:
Ben Carman 2020-06-25 07:58:10 -05:00 committed by GitHub
parent fdb4026356
commit 021e21d61b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 3 deletions
app/server/src/main/scala/org/bitcoins/server
wallet/src/main/scala/org/bitcoins/wallet

View file

@ -97,6 +97,7 @@ object Main extends App with BitcoinSLogger {
chainApi,
BitcoinerLiveFeeRateProvider(60),
bip39PasswordOpt)
_ <- wallet.start()
} yield wallet
//add callbacks to our unitialized node

View file

@ -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] =

View file

@ -58,6 +58,8 @@ trait WalletApi extends WalletLogger {
def broadcastTransaction(transaction: Transaction): Future[Unit] =
nodeApi.broadcastTransaction(transaction)
def start(): Future[Unit]
def stop(): Unit
/**