diff --git a/app/server-test/src/test/scala/org/bitcoins/server/RoutesSpec.scala b/app/server-test/src/test/scala/org/bitcoins/server/RoutesSpec.scala index 1a718b8410..aa48343819 100644 --- a/app/server-test/src/test/scala/org/bitcoins/server/RoutesSpec.scala +++ b/app/server-test/src/test/scala/org/bitcoins/server/RoutesSpec.scala @@ -25,7 +25,6 @@ import org.bitcoins.core.protocol.script.EmptyScriptWitness import org.bitcoins.core.protocol.transaction._ import org.bitcoins.core.protocol.{BitcoinAddress, BlockStamp, P2PKHAddress} import org.bitcoins.core.psbt.PSBT -import org.bitcoins.core.util.FutureUtil import org.bitcoins.core.wallet.fee.{FeeUnit, SatoshisPerVirtualByte} import org.bitcoins.core.wallet.utxo._ import org.bitcoins.crypto.{ @@ -757,7 +756,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { (mockNode .broadcastTransaction(_: Transaction)) .expects(tx) - .returning(FutureUtil.unit) + .returning(Future.unit) .anyNumberOfTimes() val route = @@ -805,7 +804,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { (mockWalletApi.broadcastTransaction _) .expects(EmptyTransaction) - .returning(FutureUtil.unit) + .returning(Future.unit) .anyNumberOfTimes() val route = walletRoutes.handleCommand( @@ -877,7 +876,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { (mockWalletApi.broadcastTransaction _) .expects(EmptyTransaction) - .returning(FutureUtil.unit) + .returning(Future.unit) .anyNumberOfTimes() val route = walletRoutes.handleCommand( @@ -958,7 +957,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { (mockWalletApi.broadcastTransaction _) .expects(EmptyTransaction) - .returning(FutureUtil.unit) + .returning(Future.unit) .anyNumberOfTimes() val route = walletRoutes.handleCommand( @@ -1059,7 +1058,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { (mockWalletApi.broadcastTransaction _) .expects(EmptyTransaction) - .returning(FutureUtil.unit) + .returning(Future.unit) .anyNumberOfTimes() val route = walletRoutes.handleCommand( @@ -1080,7 +1079,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { (mockWalletApi.broadcastTransaction _) .expects(EmptyTransaction) - .returning(FutureUtil.unit) + .returning(Future.unit) .anyNumberOfTimes() val route = walletRoutes.handleCommand( @@ -1102,7 +1101,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { (mockWalletApi.broadcastTransaction _) .expects(EmptyTransaction) - .returning(FutureUtil.unit) + .returning(Future.unit) .anyNumberOfTimes() val route = walletRoutes.handleCommand( @@ -1161,7 +1160,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { _: Int, _: Boolean)(_: ExecutionContext)) .expects(None, None, 100, false, executor) - .returning(FutureUtil.unit) + .returning(Future.unit) val route1 = walletRoutes.handleCommand( @@ -1188,7 +1187,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { 100, false, executor) - .returning(FutureUtil.unit) + .returning(Future.unit) val route2 = walletRoutes.handleCommand( @@ -1215,7 +1214,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { 100, false, executor) - .returning(FutureUtil.unit) + .returning(Future.unit) val route3 = walletRoutes.handleCommand( @@ -1242,7 +1241,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { 100, false, executor) - .returning(FutureUtil.unit) + .returning(Future.unit) val route4 = walletRoutes.handleCommand( @@ -1298,7 +1297,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory { _: Int, _: Boolean)(_: ExecutionContext)) .expects(None, None, 55, false, executor) - .returning(FutureUtil.unit) + .returning(Future.unit) val route8 = walletRoutes.handleCommand( diff --git a/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala b/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala index af395e1ffd..76f336df7a 100644 --- a/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala +++ b/app/server/src/main/scala/org/bitcoins/server/BitcoinSServerMain.scala @@ -10,7 +10,7 @@ import org.bitcoins.core.Core import org.bitcoins.core.api.chain.ChainApi import org.bitcoins.core.api.feeprovider.FeeRateApi import org.bitcoins.core.api.node.NodeApi -import org.bitcoins.core.util.{FutureUtil, NetworkUtil} +import org.bitcoins.core.util.NetworkUtil import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte import org.bitcoins.feeprovider.FeeProviderName._ import org.bitcoins.feeprovider.MempoolSpaceTarget.HourFeeTarget @@ -209,7 +209,7 @@ class BitcoinSServerMain(override val args: Array[String]) } lazy val onHeaders: OnBlockHeadersReceived = { headers => if (headers.isEmpty) { - FutureUtil.unit + Future.unit } else { wallet.updateUtxoPendingStates().map(_ => ()) } diff --git a/app/server/src/main/scala/org/bitcoins/server/BitcoindRpcAppConfig.scala b/app/server/src/main/scala/org/bitcoins/server/BitcoindRpcAppConfig.scala index 0e859ec1e3..815e369ea9 100644 --- a/app/server/src/main/scala/org/bitcoins/server/BitcoindRpcAppConfig.scala +++ b/app/server/src/main/scala/org/bitcoins/server/BitcoindRpcAppConfig.scala @@ -6,7 +6,6 @@ import java.nio.file._ import akka.actor.ActorSystem import com.typesafe.config.Config -import org.bitcoins.core.util.FutureUtil import org.bitcoins.db._ import org.bitcoins.node.NodeType import org.bitcoins.node.config.NodeAppConfig @@ -42,11 +41,11 @@ case class BitcoindRpcAppConfig( case NodeType.BitcoindBackend => client.start().map(_ => ()) case NodeType.SpvNode | NodeType.NeutrinoNode | NodeType.FullNode => - FutureUtil.unit + Future.unit } } - override def stop(): Future[Unit] = FutureUtil.unit + override def stop(): Future[Unit] = Future.unit lazy val DEFAULT_BINARY_PATH: File = BitcoindInstance.DEFAULT_BITCOIND_LOCATION diff --git a/app/server/src/main/scala/org/bitcoins/server/BitcoindRpcBackendUtil.scala b/app/server/src/main/scala/org/bitcoins/server/BitcoindRpcBackendUtil.scala index a5cb1065e9..f1cf04a196 100644 --- a/app/server/src/main/scala/org/bitcoins/server/BitcoindRpcBackendUtil.scala +++ b/app/server/src/main/scala/org/bitcoins/server/BitcoindRpcBackendUtil.scala @@ -61,7 +61,7 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger { utxos <- wallet.listUtxos() lastConfirmedOpt = utxos.filter(_.blockHash.isDefined).lastOption _ <- lastConfirmedOpt match { - case None => FutureUtil.unit + case None => Future.unit case Some(utxo) => for { heightOpt <- bitcoind.getBlockHeight(utxo.blockHash.get) @@ -70,7 +70,7 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger { logger.info( s"Last utxo occurred at block $height, syncing from there") doSync(height, bitcoindHeight) - case None => FutureUtil.unit + case None => Future.unit } } yield () } @@ -240,7 +240,7 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger { } else if (prevCount > count) { Future.failed(new RuntimeException( s"Bitcoind is at a block height ($count) before the wallet's ($prevCount)")) - } else FutureUtil.unit + } else Future.unit } () } diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/BitcoindRpcClient.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/BitcoindRpcClient.scala index 4d361501ce..9bb3da03a2 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/BitcoindRpcClient.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/BitcoindRpcClient.scala @@ -14,7 +14,6 @@ import org.bitcoins.core.p2p.CompactFilterMessage import org.bitcoins.core.protocol.BlockStamp import org.bitcoins.core.protocol.blockchain.BlockHeader import org.bitcoins.core.protocol.transaction.Transaction -import org.bitcoins.core.util.FutureUtil import org.bitcoins.core.wallet.fee.FeeUnit import org.bitcoins.crypto.{ DoubleSha256Digest, @@ -123,7 +122,7 @@ class BitcoindRpcClient(val instance: BitcoindInstance)(implicit sendRawTransaction(transaction).map(_ => ()) override def downloadBlocks( - blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = FutureUtil.unit + blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = Future.unit override def processHeaders(headers: Vector[BlockHeader]): Future[ChainApi] = Future.successful(this) diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala index be1b47aa5b..07e6b67297 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala @@ -20,7 +20,7 @@ import org.bitcoins.core.config.{ TestNet3 } import org.bitcoins.core.crypto.ECPrivateKeyUtil -import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, StartStopAsync} +import org.bitcoins.core.util.{BitcoinSLogger, StartStopAsync} import org.bitcoins.crypto.ECPrivateKey import org.bitcoins.rpc.BitcoindException import org.bitcoins.rpc.config.BitcoindAuthCredentials.{ @@ -227,7 +227,7 @@ trait Client extends BitcoinSLogger with StartStopAsync[BitcoindRpcClient] { _ <- { if (system.name == BitcoindRpcClient.ActorSystemName) { system.terminate() - } else FutureUtil.unit + } else Future.unit } } yield this.asInstanceOf[BitcoindRpcClient] } diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/util/AsyncUtil.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/util/AsyncUtil.scala index daffe08dc8..a48e372373 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/util/AsyncUtil.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/util/AsyncUtil.scala @@ -1,7 +1,7 @@ package org.bitcoins.rpc.util import akka.actor.ActorSystem -import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil} +import org.bitcoins.core.util.BitcoinSLogger import scala.concurrent._ import scala.concurrent.duration.{DurationInt, FiniteDuration} @@ -87,7 +87,7 @@ abstract class AsyncUtil extends BitcoinSLogger { conditionF().flatMap { condition => if (condition) { - FutureUtil.unit + Future.unit } else if (counter == maxTries) { Future.failed(RpcRetryException( s"Condition timed out after $maxTries attempts with interval=$interval waiting periods", @@ -99,7 +99,7 @@ abstract class AsyncUtil extends BitcoinSLogger { system.scheduler.scheduleOnce(delay = interval, runnable = runnable) p.future.flatMap { - case true => FutureUtil.unit + case true => Future.unit case false => retryUntilSatisfiedWithCounter(conditionF = conditionF, interval = interval, diff --git a/chain/src/main/scala-2.12/org/bitcoins/chain/blockchain/Blockchain.scala b/chain/src/main/scala-2.12/org/bitcoins/chain/blockchain/Blockchain.scala index 4fc8a6a43b..1576a03698 100644 --- a/chain/src/main/scala-2.12/org/bitcoins/chain/blockchain/Blockchain.scala +++ b/chain/src/main/scala-2.12/org/bitcoins/chain/blockchain/Blockchain.scala @@ -7,7 +7,7 @@ import scala.collection.mutable /** @inheritdoc */ case class Blockchain(headers: Vector[BlockHeaderDb]) extends BaseBlockChain { - protected[blockchain] def compObjectfromHeaders( + protected[blockchain] def compObjectFromHeaders( headers: scala.collection.immutable.Seq[BlockHeaderDb]): Blockchain = Blockchain.fromHeaders(headers) diff --git a/chain/src/main/scala-2.13/org/bitcoins/chain/blockchain/Blockchain.scala b/chain/src/main/scala-2.13/org/bitcoins/chain/blockchain/Blockchain.scala index 94458a8c39..8588f8e91c 100644 --- a/chain/src/main/scala-2.13/org/bitcoins/chain/blockchain/Blockchain.scala +++ b/chain/src/main/scala-2.13/org/bitcoins/chain/blockchain/Blockchain.scala @@ -5,7 +5,7 @@ import org.bitcoins.core.api.chain.db.BlockHeaderDb /** @inheritdoc */ case class Blockchain(headers: Vector[BlockHeaderDb]) extends BaseBlockChain { - protected[blockchain] def compObjectfromHeaders( + protected[blockchain] def compObjectFromHeaders( headers: scala.collection.immutable.Seq[BlockHeaderDb]) = Blockchain.fromHeaders(headers) diff --git a/chain/src/main/scala/org/bitcoins/chain/blockchain/BaseBlockChain.scala b/chain/src/main/scala/org/bitcoins/chain/blockchain/BaseBlockChain.scala index 320c082fe0..9a9e9d13a6 100644 --- a/chain/src/main/scala/org/bitcoins/chain/blockchain/BaseBlockChain.scala +++ b/chain/src/main/scala/org/bitcoins/chain/blockchain/BaseBlockChain.scala @@ -33,7 +33,7 @@ import scala.annotation.tailrec */ private[blockchain] trait BaseBlockChain extends SeqWrapper[BlockHeaderDb] { - protected[blockchain] def compObjectfromHeaders( + protected[blockchain] def compObjectFromHeaders( headers: scala.collection.immutable.Seq[BlockHeaderDb]): Blockchain lazy val tip: BlockHeaderDb = headers.head @@ -58,7 +58,7 @@ private[blockchain] trait BaseBlockChain extends SeqWrapper[BlockHeaderDb] { def fromHeader(header: BlockHeaderDb): Option[Blockchain] = { val headerIdxOpt = findHeaderIdx(header.hashBE) headerIdxOpt.map { idx => - val newChain = this.compObjectfromHeaders(headers.splitAt(idx)._2) + val newChain = this.compObjectFromHeaders(headers.splitAt(idx)._2) require(newChain.tip == header) newChain } diff --git a/chain/src/main/scala/org/bitcoins/chain/blockchain/ChainHandler.scala b/chain/src/main/scala/org/bitcoins/chain/blockchain/ChainHandler.scala index 6de9242029..8bb922f2b3 100644 --- a/chain/src/main/scala/org/bitcoins/chain/blockchain/ChainHandler.scala +++ b/chain/src/main/scala/org/bitcoins/chain/blockchain/ChainHandler.scala @@ -79,7 +79,7 @@ class ChainHandler( //since we have same chainwork, just take the oldest tip //as that's "more likely" to have been propagated first //and had more miners building on top of it - chainsByWork.sortBy(_.tip.time).head.tip + chainsByWork.minBy(_.tip.time).tip } } bestHeader @@ -153,7 +153,7 @@ class ChainHandler( createdF.map { headers => if (chainConfig.chainCallbacks.onBlockHeaderConnected.nonEmpty) { - headersToBeCreated.reverseIterator.foldLeft(FutureUtil.unit) { + headersToBeCreated.reverseIterator.foldLeft(Future.unit) { (acc, header) => for { _ <- acc @@ -198,38 +198,26 @@ class ChainHandler( protected def nextBlockHeaderBatchRangeWithChains( prevStopHash: DoubleSha256DigestBE, batchSize: Int, - blockchains: Vector[Blockchain]): Future[Option[FilterSyncMarker]] = { - for { - prevBlockHeaderOpt <- getHeader(prevStopHash) - headerOpt <- prevBlockHeaderOpt match { - case Some(_) => - findNextHeader(prevBlockHeaderOpt, batchSize, blockchains) - case None => - if (prevStopHash == DoubleSha256DigestBE.empty) { - for { - next <- findNextHeader(None, batchSize, blockchains) - } yield next - } else { - Future.successful(None) - } - } - } yield { - headerOpt - } - } + blockchains: Vector[Blockchain]): Future[Option[FilterSyncMarker]] = for { + prevBlockHeaderOpt <- getHeader(prevStopHash) + headerOpt <- + if (prevBlockHeaderOpt.isDefined) + findNextHeader(prevBlockHeaderOpt, batchSize, blockchains) + else if (prevStopHash == DoubleSha256DigestBE.empty) + findNextHeader(None, batchSize, blockchains) + else Future.successful(None) + } yield headerOpt /** @inheritdoc */ override def nextBlockHeaderBatchRange( prevStopHash: DoubleSha256DigestBE, - batchSize: Int): Future[Option[FilterSyncMarker]] = { - val blockchainsF = blockHeaderDAO.getBlockchains() + batchSize: Int): Future[Option[FilterSyncMarker]] = for { - blockchains <- blockchainsF + blockchains <- blockHeaderDAO.getBlockchains() syncMarkerOpt <- nextBlockHeaderBatchRangeWithChains(prevStopHash, batchSize, blockchains) } yield syncMarkerOpt - } /** Finds the next header in the chain. Uses chain work to break ties * returning only the header in the chain with the most work @@ -384,7 +372,7 @@ class ChainHandler( s"Previous filter header does not exist: $firstFilter" ) } - } else FutureUtil.unit + } else Future.unit _ <- filterHeaderDAO.createAll(filterHeadersToCreate) } yield { val minHeightOpt = filterHeadersToCreate.minByOption(_.height) diff --git a/chain/src/main/scala/org/bitcoins/chain/config/ChainAppConfig.scala b/chain/src/main/scala/org/bitcoins/chain/config/ChainAppConfig.scala index 161bc87d9d..58c923ebc5 100644 --- a/chain/src/main/scala/org/bitcoins/chain/config/ChainAppConfig.scala +++ b/chain/src/main/scala/org/bitcoins/chain/config/ChainAppConfig.scala @@ -6,7 +6,7 @@ import org.bitcoins.chain.db.ChainDbManagement import org.bitcoins.chain.models.BlockHeaderDAO import org.bitcoins.chain.pow.Pow import org.bitcoins.core.api.chain.db.BlockHeaderDbHelper -import org.bitcoins.core.util.{FutureUtil, Mutable} +import org.bitcoins.core.util.Mutable import org.bitcoins.db._ import java.nio.file.Path @@ -73,7 +73,7 @@ case class ChainAppConfig( isInit <- isStarted() _ <- { if (isInit) { - FutureUtil.unit + Future.unit } else { val genesisHeader = BlockHeaderDbHelper.fromBlockHeader( @@ -85,7 +85,7 @@ case class ChainAppConfig( val bhCreatedF = blockHeaderDAO.create(genesisHeader) bhCreatedF.flatMap { _ => logger.info(s"Inserted genesis block header into DB") - FutureUtil.unit + Future.unit } } } @@ -104,7 +104,7 @@ case class ChainAppConfig( override def stop(): Future[Unit] = { val _ = stopHikariLogger() - FutureUtil.unit + Future.unit } lazy val filterHeaderBatchSize: Int = { diff --git a/chain/src/main/scala/org/bitcoins/chain/models/BlockHeaderDAO.scala b/chain/src/main/scala/org/bitcoins/chain/models/BlockHeaderDAO.scala index 327758df34..cdba36111c 100644 --- a/chain/src/main/scala/org/bitcoins/chain/models/BlockHeaderDAO.scala +++ b/chain/src/main/scala/org/bitcoins/chain/models/BlockHeaderDAO.scala @@ -59,7 +59,7 @@ case class BlockHeaderDAO()(implicit table.filter(_.hash.inSet(hashes)) } - /** Retrives the ancestor for the given block header at the given height + /** Retrieves the ancestor for the given block header at the given height * @param child * @param height * @return @@ -71,37 +71,29 @@ case class BlockHeaderDAO()(implicit * To avoid making many database reads, we make one database read for all * possibly useful block headers. */ - val headersF = getBetweenHeights(from = height, to = child.height - 1) + lazy val headersF = getBetweenHeights(from = height, to = child.height - 1) /* * We then bucket sort these headers by height so that any ancestor can be found * in linear time assuming a bounded number of contentious tips. */ val headersByHeight: Array[Vector[BlockHeaderDb]] = - new Array[Vector[BlockHeaderDb]](_length = (child.height - height).toInt) - - /* - * I believe Array's of Objects are instantiated with null, which is evil, - * and so we start by giving each element of the array a Vector.empty. - */ - headersByHeight.indices.foreach(index => - headersByHeight(index) = Vector.empty) + Array.fill(child.height - height)(Vector.empty[BlockHeaderDb]) // Bucket sort headersF.map { headers => headers.foreach { header => - val index = (header.height - height).toInt + val index = header.height - height headersByHeight(index) = headersByHeight(index).:+(header) } - // Now that the bucket sort is done, we get rid of mutability - val groupedByHeightHeaders: List[Vector[BlockHeaderDb]] = - headersByHeight.toList + val groupedByHeightHeaders: Array[Vector[BlockHeaderDb]] = + headersByHeight.reverse @tailrec def loop( currentHeader: BlockHeaderDb, - headersByDescHeight: List[Vector[BlockHeaderDb]]): Option[ + headersByDescHeight: Array[Vector[BlockHeaderDb]]): Option[ BlockHeaderDb] = { if (currentHeader.height == height) { Some(currentHeader) @@ -116,7 +108,7 @@ case class BlockHeaderDAO()(implicit } } - loop(child, groupedByHeightHeaders.reverse) + loop(child, groupedByHeightHeaders) } } diff --git a/chain/src/main/scala/org/bitcoins/chain/pow/Pow.scala b/chain/src/main/scala/org/bitcoins/chain/pow/Pow.scala index 6fa94a565c..1918439fed 100644 --- a/chain/src/main/scala/org/bitcoins/chain/pow/Pow.scala +++ b/chain/src/main/scala/org/bitcoins/chain/pow/Pow.scala @@ -13,7 +13,7 @@ import org.bitcoins.core.util.NumberUtil sealed abstract class Pow { /** Gets the next proof of work requirement for a block - * @see [[https://github.com/bitcoin/bitcoin/blob/35477e9e4e3f0f207ac6fa5764886b15bf9af8d0/src/pow.cpp#L13 Mimics bitcoin core implmentation]] + * @see [[https://github.com/bitcoin/bitcoin/blob/35477e9e4e3f0f207ac6fa5764886b15bf9af8d0/src/pow.cpp#L13 Mimics bitcoin core implementation]] */ def getNetworkWorkRequired( newPotentialTip: BlockHeader, @@ -76,7 +76,7 @@ sealed abstract class Pow { chainParams) case None => throw new RuntimeException( - s"Could not find block at height=${firstHeight} out of ${blockchain.length} headers to calculate pow difficutly change") + s"Could not find block at height=$firstHeight out of ${blockchain.length} headers to calculate pow difficulty change") } } @@ -120,7 +120,7 @@ sealed abstract class Pow { bnNew = powLimit } - val newTarget = NumberUtil.targetCompression(bnNew, false) + val newTarget = NumberUtil.targetCompression(bnNew, isNegative = false) newTarget } diff --git a/core/src/main/scala/org/bitcoins/core/api/Callback.scala b/core/src/main/scala/org/bitcoins/core/api/Callback.scala index 73d35c77ad..1c20808aab 100644 --- a/core/src/main/scala/org/bitcoins/core/api/Callback.scala +++ b/core/src/main/scala/org/bitcoins/core/api/Callback.scala @@ -1,7 +1,7 @@ package org.bitcoins.core.api import grizzled.slf4j.Logger -import org.bitcoins.core.util.{FutureUtil, SeqWrapper} +import org.bitcoins.core.util.SeqWrapper import scala.concurrent.{ExecutionContext, Future} import scala.util.control.NonFatal @@ -29,7 +29,7 @@ trait Callback3[T1, T2, T3] extends Callback[(T1, T2, T3)] { object Callback { /** Does nothing */ - def noop[T]: T => Future[Unit] = _ => FutureUtil.unit + def noop[T]: T => Future[Unit] = _ => Future.unit } /** Manages a set of callbacks, should be used to manage execution and logging if needed */ diff --git a/core/src/main/scala/org/bitcoins/core/util/FutureUtil.scala b/core/src/main/scala/org/bitcoins/core/util/FutureUtil.scala index 91c3dedc98..434d74acbb 100644 --- a/core/src/main/scala/org/bitcoins/core/util/FutureUtil.scala +++ b/core/src/main/scala/org/bitcoins/core/util/FutureUtil.scala @@ -30,8 +30,6 @@ object FutureUtil { FutureUtil.sequentially(items)(x => x) } - val unit: Future[Unit] = Future.successful(()) - def none[T]: Future[Option[T]] = Future.successful(Option.empty[T]) def emptyVec[T]: Future[Vector[T]] = Future.successful(Vector.empty[T]) diff --git a/db-commons/src/main/scala/org/bitcoins/db/AppConfig.scala b/db-commons/src/main/scala/org/bitcoins/db/AppConfig.scala index 7b8513ec78..d0eb282853 100644 --- a/db-commons/src/main/scala/org/bitcoins/db/AppConfig.scala +++ b/db-commons/src/main/scala/org/bitcoins/db/AppConfig.scala @@ -3,7 +3,7 @@ package org.bitcoins.db import com.typesafe.config._ import org.bitcoins.core.config._ import org.bitcoins.core.protocol.blockchain.BitcoinChainParams -import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, StartStopAsync} +import org.bitcoins.core.util.{BitcoinSLogger, StartStopAsync} import java.nio.file.{Files, Path, Paths} import scala.concurrent.Future @@ -27,7 +27,7 @@ abstract class AppConfig extends StartStopAsync[Unit] with BitcoinSLogger { * something else entirely. */ override def start(): Future[Unit] = { - FutureUtil.unit + Future.unit } /** Sub members of AppConfig should override this type with diff --git a/db-commons/src/main/scala/org/bitcoins/db/DbManagement.scala b/db-commons/src/main/scala/org/bitcoins/db/DbManagement.scala index 8265f813ca..66767b7640 100644 --- a/db-commons/src/main/scala/org/bitcoins/db/DbManagement.scala +++ b/db-commons/src/main/scala/org/bitcoins/db/DbManagement.scala @@ -122,7 +122,7 @@ trait DbManagement extends BitcoinSLogger { ec: ExecutionContext): Future[Unit] = appConfig.schemaName match { case None => - FutureUtil.unit + Future.unit case Some(schema) => val sql = if (createIfNotExists) diff --git a/dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/config/DLCOracleAppConfig.scala b/dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/config/DLCOracleAppConfig.scala index c7ce6f3c3b..da7b663260 100644 --- a/dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/config/DLCOracleAppConfig.scala +++ b/dlc-oracle/src/main/scala/org/bitcoins/dlc/oracle/config/DLCOracleAppConfig.scala @@ -5,7 +5,6 @@ import org.bitcoins.core.config.NetworkParameters import org.bitcoins.core.crypto.ExtKeyVersion.SegWitMainNetPriv import org.bitcoins.core.hd.HDPurpose import org.bitcoins.core.protocol.tlv.EnumEventDescriptorV0TLV -import org.bitcoins.core.util.FutureUtil import org.bitcoins.core.wallet.keymanagement.KeyManagerParams import org.bitcoins.crypto.AesPassword import org.bitcoins.db.DatabaseDriver._ @@ -86,7 +85,7 @@ case class DLCOracleAppConfig( _ <- eventDAO.upsertAll(updated) } yield () - } else FutureUtil.unit + } else Future.unit migrationWorkAroundF.map { _ => if (isHikariLoggingEnabled) { diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala index 57a70cbce7..9c35828257 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala +++ b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala @@ -23,7 +23,7 @@ import org.bitcoins.core.protocol.ln.routing.{ChannelRoute, NodeRoute, Route} import org.bitcoins.core.protocol.ln.{LnInvoice, LnParams, PaymentPreimage} import org.bitcoins.core.protocol.script.ScriptPubKey import org.bitcoins.core.protocol.{Address, BitcoinAddress} -import org.bitcoins.core.util.{BytesUtil, FutureUtil, StartStopAsync} +import org.bitcoins.core.util.{BytesUtil, StartStopAsync} import org.bitcoins.core.wallet.fee.SatoshisPerByte import org.bitcoins.crypto.{DoubleSha256DigestBE, Sha256Digest} import org.bitcoins.eclair.rpc.api._ @@ -815,7 +815,7 @@ class EclairRpcClient( val actorSystemF = if (system.name == EclairRpcClient.ActorSystemName) { system.terminate() } else { - FutureUtil.unit + Future.unit } actorSystemF.map(_ => this) } diff --git a/key-manager/src/main/scala/org/bitcoins/keymanager/config/KeyManagerAppConfig.scala b/key-manager/src/main/scala/org/bitcoins/keymanager/config/KeyManagerAppConfig.scala index 09eb9dcf31..4f8d9d49cc 100644 --- a/key-manager/src/main/scala/org/bitcoins/keymanager/config/KeyManagerAppConfig.scala +++ b/key-manager/src/main/scala/org/bitcoins/keymanager/config/KeyManagerAppConfig.scala @@ -2,7 +2,6 @@ package org.bitcoins.keymanager.config import com.typesafe.config.Config import org.bitcoins.core.config.NetworkParameters -import org.bitcoins.core.util.FutureUtil import org.bitcoins.crypto.AesPassword import org.bitcoins.db._ import org.bitcoins.keymanager.WalletStorage @@ -61,10 +60,10 @@ case class KeyManagerAppConfig( Files.createDirectories(newDefaultFile.getParent) Files.copy(oldDefaultFile, newDefaultFile) } - FutureUtil.unit + Future.unit } - override def stop(): Future[Unit] = FutureUtil.unit + override def stop(): Future[Unit] = Future.unit lazy val aesPasswordOpt: Option[AesPassword] = { val passOpt = config.getStringOrNone(s"bitcoin-s.$moduleName.aesPassword") diff --git a/node-test/src/test/scala/org/bitcoins/node/networking/peer/MerkleBuffersTest.scala b/node-test/src/test/scala/org/bitcoins/node/networking/peer/MerkleBuffersTest.scala index 5c155908e1..e3831fa427 100644 --- a/node-test/src/test/scala/org/bitcoins/node/networking/peer/MerkleBuffersTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/networking/peer/MerkleBuffersTest.scala @@ -3,7 +3,6 @@ package org.bitcoins.node.networking.peer import _root_.org.scalatest.compatible.Assertion import org.bitcoins.core.protocol.blockchain.{Block, MerkleBlock} import org.bitcoins.core.protocol.transaction.Transaction -import org.bitcoins.core.util.FutureUtil import org.bitcoins.node.{NodeCallbacks, OnMerkleBlockReceived} import org.bitcoins.testkit.core.gen.{ BlockchainElementsGenerator, @@ -36,7 +35,7 @@ class MerkleBuffersTest extends BitcoinSAsyncTest with CachedBitcoinSAppConfig { Try(assert(txs == merkleTxs, "Received TXs in callback was not the ones we put in"))) callbackCount = callbackCount + 1 - FutureUtil.unit + Future.unit } val callbacks = NodeCallbacks(onMerkleBlockReceived = Vector(callback)) diff --git a/node/src/main/scala/org/bitcoins/node/Node.scala b/node/src/main/scala/org/bitcoins/node/Node.scala index 0a75f70c7a..f3027790cd 100644 --- a/node/src/main/scala/org/bitcoins/node/Node.scala +++ b/node/src/main/scala/org/bitcoins/node/Node.scala @@ -13,7 +13,6 @@ import org.bitcoins.core.api.chain._ import org.bitcoins.core.api.node.NodeApi import org.bitcoins.core.p2p.{NetworkPayload, TypeIdentifier} import org.bitcoins.core.protocol.transaction.Transaction -import org.bitcoins.core.util.FutureUtil import org.bitcoins.crypto.{DoubleSha256Digest, DoubleSha256DigestBE} import org.bitcoins.node.config.NodeAppConfig import org.bitcoins.node.models.{ @@ -257,7 +256,7 @@ trait Node extends NodeApi with ChainQueryApi with P2PLogger { override def downloadBlocks( blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = { if (blockHashes.isEmpty) { - FutureUtil.unit + Future.unit } else { for { peerMsgSender <- peerMsgSenderF diff --git a/node/src/main/scala/org/bitcoins/node/config/NodeAppConfig.scala b/node/src/main/scala/org/bitcoins/node/config/NodeAppConfig.scala index 6137ad82b4..bfbee37775 100644 --- a/node/src/main/scala/org/bitcoins/node/config/NodeAppConfig.scala +++ b/node/src/main/scala/org/bitcoins/node/config/NodeAppConfig.scala @@ -4,7 +4,7 @@ import akka.Done import akka.actor.ActorSystem import com.typesafe.config.Config import org.bitcoins.chain.config.ChainAppConfig -import org.bitcoins.core.util.{FutureUtil, Mutable} +import org.bitcoins.core.util.Mutable import org.bitcoins.db.{AppConfigFactory, DbAppConfig, JdbcProfileComponent} import org.bitcoins.node._ import org.bitcoins.node.db.NodeDbManagement @@ -65,7 +65,7 @@ case class NodeAppConfig( override def stop(): Future[Unit] = { val _ = stopHikariLogger() - FutureUtil.unit + Future.unit } lazy val nodeType: NodeType = diff --git a/node/src/main/scala/org/bitcoins/node/networking/peer/DataMessageHandler.scala b/node/src/main/scala/org/bitcoins/node/networking/peer/DataMessageHandler.scala index 0005f119b2..62353c8692 100644 --- a/node/src/main/scala/org/bitcoins/node/networking/peer/DataMessageHandler.scala +++ b/node/src/main/scala/org/bitcoins/node/networking/peer/DataMessageHandler.scala @@ -5,7 +5,6 @@ import org.bitcoins.chain.config.ChainAppConfig import org.bitcoins.core.api.chain.ChainApi import org.bitcoins.core.gcs.BlockFilter import org.bitcoins.core.p2p._ -import org.bitcoins.core.util.FutureUtil import org.bitcoins.crypto.DoubleSha256DigestBE import org.bitcoins.node.config.NodeAppConfig import org.bitcoins.node.models.BroadcastAbleTransactionDAO @@ -138,7 +137,7 @@ case class DataMessageHandler( logger.info( s"Received maximum amount of filters in one batch. This means we are not synced, requesting more") sendNextGetCompactFilterCommand(peerMsgSender, newFilterHeight) - } else FutureUtil.unit + } else Future.unit } yield { this.copy( chainApi = newChainApi, diff --git a/node/src/main/scala/org/bitcoins/node/networking/peer/PeerMessageSender.scala b/node/src/main/scala/org/bitcoins/node/networking/peer/PeerMessageSender.scala index 9f7992a788..5680f33ad3 100644 --- a/node/src/main/scala/org/bitcoins/node/networking/peer/PeerMessageSender.scala +++ b/node/src/main/scala/org/bitcoins/node/networking/peer/PeerMessageSender.scala @@ -10,7 +10,6 @@ import org.bitcoins.core.bloom.BloomFilter import org.bitcoins.core.number.Int32 import org.bitcoins.core.p2p._ import org.bitcoins.core.protocol.transaction.Transaction -import org.bitcoins.core.util.FutureUtil import org.bitcoins.crypto.{ DoubleSha256Digest, DoubleSha256DigestBE, @@ -52,12 +51,12 @@ case class PeerMessageSender(client: P2PClient)(implicit conf: NodeAppConfig) case true => logger.info(s"Disconnecting peer at socket=${socket}") (client.actor ! Tcp.Close) - FutureUtil.unit + Future.unit case false => val err = s"Cannot disconnect client that is not connected to socket=${socket}!" logger.warn(err) - FutureUtil.unit + Future.unit } } @@ -237,7 +236,7 @@ case class PeerMessageSender(client: P2PClient)(implicit conf: NodeAppConfig) logger.debug(s"Sending msg=${msg.commandName} to peer=${socket}") val newtworkMsg = NetworkMessage(conf.network, msg) client.actor ! newtworkMsg - FutureUtil.unit + Future.unit } } diff --git a/testkit/src/main/scala/org/bitcoins/testkit/chain/fixture/ChainFixtureHelper.scala b/testkit/src/main/scala/org/bitcoins/testkit/chain/fixture/ChainFixtureHelper.scala index cdcd55bab4..b568fdaf75 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/chain/fixture/ChainFixtureHelper.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/chain/fixture/ChainFixtureHelper.scala @@ -1,6 +1,5 @@ package org.bitcoins.testkit.chain.fixture -import org.bitcoins.core.util.FutureUtil import org.bitcoins.testkit.chain.ChainUnitTest import org.bitcoins.testkit.chain.fixture.ChainFixture.{ BitcoindZmqChainHandlerWithBlock, @@ -46,7 +45,7 @@ trait ChainFixtureHelper { this: ChainUnitTest => def destroyFixture(fixture: ChainFixture): Future[Any] = { fixture match { - case Empty => FutureUtil.unit + case Empty => Future.unit case GenisisBlockHeaderDAO(_) => ChainUnitTest.destroyAllTables() case PopulatedBlockHeaderDAO(_) => ChainUnitTest.destroyAllTables() case GenisisChainHandler(_) => ChainUnitTest.destroyAllTables() diff --git a/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala index 2e68145bdd..a4218455b7 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/rpc/BitcoindRpcTestUtil.scala @@ -22,7 +22,7 @@ import org.bitcoins.core.protocol.transaction.{ TransactionInput, TransactionOutPoint } -import org.bitcoins.core.util.{BitcoinSLogger, EnvUtil, FutureUtil} +import org.bitcoins.core.util.{BitcoinSLogger, EnvUtil} import org.bitcoins.crypto.{ DoubleSha256Digest, DoubleSha256DigestBE, @@ -993,7 +993,7 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger { seenBlock <- hasSeenBlock(receiver, blockHash) _ <- if (seenBlock) { - FutureUtil.unit + Future.unit } else { sender .getBlockRaw(blockHash) diff --git a/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala b/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala index ff8a268b02..f55c1e310b 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/wallet/BitcoinSWalletTest.scala @@ -330,7 +330,7 @@ trait BitcoinSWalletTest extends BitcoinSFixture with EmbeddedPg { val destroy: WalletAppConfig => Future[Unit] = walletAppConfig => { FileUtil.deleteTmpDir(walletAppConfig.datadir) walletAppConfig.stop() - FutureUtil.unit + Future.unit } makeDependentFixture(builder, destroy = destroy)(test) } @@ -356,10 +356,10 @@ object BitcoinSWalletTest extends WalletLogger { object MockNodeApi extends NodeApi { override def broadcastTransaction(transaction: Transaction): Future[Unit] = - FutureUtil.unit + Future.unit override def downloadBlocks( - blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = FutureUtil.unit + blockHashes: Vector[DoubleSha256Digest]): Future[Unit] = Future.unit } diff --git a/wallet/src/main/scala/org/bitcoins/wallet/Wallet.scala b/wallet/src/main/scala/org/bitcoins/wallet/Wallet.scala index 4daa8e9117..06444f839c 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/Wallet.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/Wallet.scala @@ -114,7 +114,7 @@ abstract class Wallet logger.info( s"Missing relevant ${utxos.size} wallet transactions, fetching their blocks..") nodeApi.downloadBlocks(blockHashes.distinct) - } else FutureUtil.unit + } else Future.unit } yield () private def checkRootAccount: Future[Unit] = { @@ -133,7 +133,7 @@ abstract class Wallet s"It is possible we have a different key manager being used than expected, key manager=$keyManager" Future.failed(new RuntimeException(errorMsg)) } else { - FutureUtil.unit + Future.unit } case None => val errorMsg = s"Missing root xpub for account $account in database" @@ -187,7 +187,7 @@ abstract class Wallet val matcher = SimpleFilterMatcher(blockFilter) if (matcher.matchesAny(scriptPubKeys.toVector.map(_.asmBytes))) { nodeApi.downloadBlocks(Vector(blockHash)) - } else FutureUtil.unit + } else Future.unit } hash = blockFilters.last._1.flip height <- chainQueryApi.getBlockHeight(hash) diff --git a/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala b/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala index 319028e2b8..c9180ce202 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala @@ -5,7 +5,7 @@ import org.bitcoins.core.api.chain.ChainQueryApi import org.bitcoins.core.api.feeprovider.FeeRateApi import org.bitcoins.core.api.node.NodeApi import org.bitcoins.core.hd._ -import org.bitcoins.core.util.{FutureUtil, Mutable} +import org.bitcoins.core.util.Mutable import org.bitcoins.core.wallet.keymanagement.{ KeyManagerInitializeError, KeyManagerParams @@ -166,7 +166,7 @@ case class WalletAppConfig( if (isHikariLoggingEnabled) { val _ = stopHikariLogger() } - FutureUtil.unit + Future.unit } /** The path to our encrypted mnemonic seed */ diff --git a/wallet/src/main/scala/org/bitcoins/wallet/internal/FundTransactionHandling.scala b/wallet/src/main/scala/org/bitcoins/wallet/internal/FundTransactionHandling.scala index 46da285faf..ffdeed62dd 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/internal/FundTransactionHandling.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/internal/FundTransactionHandling.scala @@ -110,7 +110,7 @@ trait FundTransactionHandling extends WalletLogger { self: Wallet => } _ <- if (markAsReserved) markUTXOsAsReserved(selectedUtxos.map(_._1)) - else FutureUtil.unit + else Future.unit } yield { logger.info { val utxosStr = utxoSpendingInfos diff --git a/wallet/src/main/scala/org/bitcoins/wallet/internal/RescanHandling.scala b/wallet/src/main/scala/org/bitcoins/wallet/internal/RescanHandling.scala index 759559068c..56060724f8 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/internal/RescanHandling.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/internal/RescanHandling.scala @@ -150,14 +150,14 @@ private[wallet] trait RescanHandling extends WalletLogger { private def pruneUnusedAddresses(): Future[Unit] = { for { addressDbs <- addressDAO.findAll() - _ <- addressDbs.foldLeft(FutureUtil.unit) { (prevF, addressDb) => + _ <- addressDbs.foldLeft(Future.unit) { (prevF, addressDb) => for { _ <- prevF spendingInfoDbs <- spendingInfoDAO.findByScriptPubKeyId(addressDb.scriptPubKeyId) _ <- if (spendingInfoDbs.isEmpty) addressDAO.delete(addressDb) - else FutureUtil.unit + else Future.unit } yield () } } yield () @@ -193,7 +193,7 @@ private[wallet] trait RescanHandling extends WalletLogger { private def downloadAndProcessBlocks( blocks: Vector[DoubleSha256Digest]): Future[Unit] = { logger.info(s"Requesting ${blocks.size} block(s)") - blocks.foldLeft(FutureUtil.unit) { (prevF, blockHash) => + blocks.foldLeft(Future.unit) { (prevF, blockHash) => val completedF = subscribeForBlockProcessingCompletionSignal(blockHash) for { _ <- prevF