mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 06:31:55 +01:00
Use FutureUtil.makeAsync where we are attmepting to create async Futures (#4583)
This commit is contained in:
parent
7b754138b8
commit
b04a34ad02
8 changed files with 20 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
package org.bitcoins.commons.util
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
|
||||
import java.io.File
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
@ -27,7 +28,7 @@ trait NativeProcessFactory extends Logging {
|
|||
}
|
||||
|
||||
/** Starts the binary by spinning up a new process */
|
||||
def startBinary(): Future[Unit] = Future {
|
||||
def startBinary(): Future[Unit] = FutureUtil.makeAsync { () =>
|
||||
processOpt match {
|
||||
case Some(p) =>
|
||||
//don't do anything as it is already started
|
||||
|
@ -49,7 +50,7 @@ trait NativeProcessFactory extends Logging {
|
|||
* If the client is a remote client (not started on the host operating system)
|
||||
* this method is a no-op
|
||||
*/
|
||||
def stopBinary(): Future[Unit] = Future {
|
||||
def stopBinary(): Future[Unit] = FutureUtil.makeAsync { () =>
|
||||
processOpt match {
|
||||
case Some(process) =>
|
||||
if (process.isAlive()) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import akka.stream.scaladsl.{Keep, Sink, Source}
|
|||
import org.bitcoins.core.protocol.blockchain.Block
|
||||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.protocol.transaction.{Transaction, WitnessTransaction}
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.rpc.config.BitcoindRpcAppConfig
|
||||
|
@ -66,7 +67,7 @@ class ScanBitcoind()(implicit
|
|||
.mapAsync(numParallelism) { case (block, height) =>
|
||||
logger.info(
|
||||
s"Searching block at height=$height hashBE=${block.blockHeader.hashBE.hex}")
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
f(block)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -388,7 +388,7 @@ class ChainHandler(
|
|||
_ = require(
|
||||
filterHeaders.size == messages.size,
|
||||
s"Filter batch size does not match filter header batch size ${messages.size} != ${filterHeaders.size}")
|
||||
compactFilterDbs <- Future {
|
||||
compactFilterDbs <- FutureUtil.makeAsync { () =>
|
||||
filterHeaders.map { filterHeader =>
|
||||
findFilterDbFromMessage(filterHeader, messagesByBlockHash)
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ class ChainHandler(
|
|||
} else {
|
||||
filtersByHash.get(filterHeader.previousFilterHeaderBE) match {
|
||||
case Some(prevHeader) =>
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
checkHeight(filterHeader, prevHeader)
|
||||
}
|
||||
case None =>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.api
|
||||
|
||||
import org.bitcoins.core.util.SeqWrapper
|
||||
import org.bitcoins.core.util.{FutureUtil, SeqWrapper}
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.util.control.NonFatal
|
||||
|
@ -49,7 +49,7 @@ case class CallbackHandler[C, T <: Callback[C]](
|
|||
val executeFs = wrapped.map { callback =>
|
||||
// Need to wrap in another future so they are all started at once
|
||||
// and do not block each other
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
callback(param).recover { case NonFatal(err) =>
|
||||
recoverFunc(err)
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class DLCFeeTestVectorTest extends BitcoinSJvmTest {
|
|||
assert(vecResult.isSuccess)
|
||||
|
||||
def assertBatch(vec: Vector[DLCFeeTestVector]): Future[Vector[Assertion]] =
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
vec.map { case testVec =>
|
||||
assert(DLCFeeTestVector.apply(testVec.inputs) == testVec)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.bitcoins.testkitcore.util
|
|||
import org.bitcoins.asyncutil.AsyncUtil
|
||||
import org.bitcoins.core.config.{NetworkParameters, RegTest}
|
||||
import org.bitcoins.core.protocol.blockchain.ChainParams
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.scalacheck.{Gen, Shrink}
|
||||
import org.scalactic.anyvals.PosInt
|
||||
import org.scalatest._
|
||||
|
@ -182,7 +183,7 @@ trait BaseAsyncTest
|
|||
def forAllParallel[A](gen: Gen[A])(
|
||||
func: A => Assertion): Future[Assertion] = {
|
||||
forAllAsync(gen) { a: A =>
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
func(a)
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +195,7 @@ trait BaseAsyncTest
|
|||
def forAllParallel[A, B, C](genA: Gen[A], genB: Gen[B])(
|
||||
func: (A, B) => Assertion): Future[Assertion] = {
|
||||
forAllAsync(genA, genB) { case (inputA, inputB) =>
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
func(inputA, inputB)
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +207,7 @@ trait BaseAsyncTest
|
|||
def forAllParallel[A, B, C](genA: Gen[A], genB: Gen[B], genC: Gen[C])(
|
||||
func: (A, B, C) => Assertion): Future[Assertion] = {
|
||||
forAllAsync(genA, genB, genC) { case (inputA, inputB, inputC) =>
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
func(inputA, inputB, inputC)
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +223,7 @@ trait BaseAsyncTest
|
|||
genD: Gen[D])(func: (A, B, C, D) => Assertion): Future[Assertion] = {
|
||||
forAllAsync(genA, genB, genC, genD) {
|
||||
case (inputA, inputB, inputC, inputD) =>
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
func(inputA, inputB, inputC, inputD)
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +240,7 @@ trait BaseAsyncTest
|
|||
genE: Gen[E])(func: (A, B, C, D, E) => Assertion): Future[Assertion] = {
|
||||
forAllAsync(genA, genB, genC, genD, genE) {
|
||||
case (inputA, inputB, inputC, inputD, inputE) =>
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
func(inputA, inputB, inputC, inputD, inputE)
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +259,7 @@ trait BaseAsyncTest
|
|||
func: (A, B, C, D, E, F) => Assertion): Future[Assertion] = {
|
||||
forAllAsync(genA, genB, genC, genD, genE, genF) {
|
||||
case (inputA, inputB, inputC, inputD, inputE, inputF) =>
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
func(inputA, inputB, inputC, inputD, inputE, inputF)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.bitcoins.core.hd.{HDAccount, HDChainType}
|
|||
import org.bitcoins.core.protocol.BlockStamp.BlockHeight
|
||||
import org.bitcoins.core.protocol.script.ScriptPubKey
|
||||
import org.bitcoins.core.protocol.{BitcoinAddress, BlockStamp}
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.core.wallet.rescan.RescanState
|
||||
import org.bitcoins.crypto.DoubleSha256Digest
|
||||
import org.bitcoins.wallet.{Wallet, WalletLogger}
|
||||
|
@ -530,7 +531,7 @@ private[wallet] trait RescanHandling extends WalletLogger {
|
|||
.sequence(filterGroups.map { filterGroup =>
|
||||
// We need to wrap in a future here to make sure we can
|
||||
// potentially run these matches in parallel
|
||||
Future {
|
||||
FutureUtil.makeAsync { () =>
|
||||
// Find any matches in the group and add the corresponding block hashes into the result
|
||||
filterGroup
|
||||
.foldLeft(Vector.empty[BlockMatchingResponse]) {
|
||||
|
|
|
@ -678,7 +678,7 @@ case class SpendingInfoDAO()(implicit
|
|||
}
|
||||
}
|
||||
|
||||
def hasDuplicates(): Future[Boolean] = Future {
|
||||
def hasDuplicates(): Future[Boolean] = FutureUtil.makeAsync { () =>
|
||||
withStatement(
|
||||
s"SELECT EXISTS (SELECT tx_outpoint, COUNT(*) FROM $fullTableName GROUP BY tx_outpoint HAVING COUNT(*) > 1)") {
|
||||
st =>
|
||||
|
|
Loading…
Add table
Reference in a new issue