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