diff --git a/.scalafmt.conf b/.scalafmt.conf index ae2a0fc824..c87dafd95c 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,18 +1,46 @@ -version = "1.5.1" +version = "2.0.1" # See Documentation at https://scalameta.org/scalafmt/#Configuration -maxColumn=80 -docstrings=ScalaDoc -continuationIndent.callSite=2 -continuationIndent.defnSite=4 -align=some -align.openParenDefnSite=false -newlines.alwaysBeforeTopLevelStatements=true -newlines.sometimesBeforeColonInMethodReturnType=false -newlines.alwaysBeforeCurlyBraceLambdaParams=false -#newlines.alwaysBeforeMultilineDef=false +trailingCommas = never +maxColumn = 80 +docstrings = ScalaDoc +continuationIndent { + callSite = 2 + defnSite = 4 +} + +align = some +align { + openParenDefnSite = false + openParenCallSite = true +} + +danglingParentheses { + callSite = false + defnSite = false +} + +newlines { + alwaysBeforeTopLevelStatements = true + sometimesBeforeColonInMethodReturnType = false + alwaysBeforeCurlyBraceLambdaParams = false +} + +assumeStandardLibraryStripMargin = true rewrite.rules = [ - SortModifiers + SortModifiers, + RedundantParens, + SortImports ] +binPack.literalArgumentLists = true + +project { + excludeFilters = [ + .bloop, + .metals, + target + ] +} + # Consider Rewrite Rules diff --git a/.travis.yml b/.travis.yml index 453e125d86..a280022137 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,8 +53,10 @@ matrix: # compile website, to check for documentation regressions - stage: test - name: Compile website - script: sbt docs/mdoc + name: Compile website and check formatting + script: + - sbt docs/mdoc + - ./binaries/scalafmt --test --non-interactive # Release snapshots/versions of all libraries # run ci-release only if previous stages passed diff --git a/app/cli/src/main/scala/org/bitcoins/cli/Cli.scala b/app/cli/src/main/scala/org/bitcoins/cli/Cli.scala index 5045b94501..82f5fb478b 100644 --- a/app/cli/src/main/scala/org/bitcoins/cli/Cli.scala +++ b/app/cli/src/main/scala/org/bitcoins/cli/Cli.scala @@ -199,7 +199,9 @@ object Cli extends App { } val js = ujson.read(rawBody) - val jsObj = try { js.obj } catch { + val jsObj = try { + js.obj + } catch { case _: Throwable => error(s"Response was not a JSON object! Got: $rawBody") } diff --git a/app/cli/src/main/scala/org/bitcoins/cli/CliReaders.scala b/app/cli/src/main/scala/org/bitcoins/cli/CliReaders.scala index ecf48ee90a..9568cffee3 100644 --- a/app/cli/src/main/scala/org/bitcoins/cli/CliReaders.scala +++ b/app/cli/src/main/scala/org/bitcoins/cli/CliReaders.scala @@ -24,7 +24,7 @@ object CliReaders { val msg = s"$str is not a valid network! Valid networks: $networks" sys.error(msg) - } + } } implicit val bitcoinAddressReads: Read[BitcoinAddress] = diff --git a/app/server/src/main/scala/de/heikoseeberger/akkahttpupickle/UpickleSupport.scala b/app/server/src/main/scala/de/heikoseeberger/akkahttpupickle/UpickleSupport.scala index 44e3ddd580..5d89a5378a 100644 --- a/app/server/src/main/scala/de/heikoseeberger/akkahttpupickle/UpickleSupport.scala +++ b/app/server/src/main/scala/de/heikoseeberger/akkahttpupickle/UpickleSupport.scala @@ -22,7 +22,7 @@ import akka.http.scaladsl.model.MediaType import akka.http.scaladsl.model.MediaTypes.`application/json` import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller} import akka.util.ByteString -import upickle.default.{Reader, Writer, read, write} +import upickle.default.{read, write, Reader, Writer} import scala.collection.immutable.Seq /** diff --git a/binaries/scalafmt b/binaries/scalafmt new file mode 100755 index 0000000000..8220503ab2 Binary files /dev/null and b/binaries/scalafmt differ diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/BitcoindInstanceTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/BitcoindInstanceTest.scala index ceb001795c..5dbe6d5c6d 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/BitcoindInstanceTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/BitcoindInstanceTest.scala @@ -58,10 +58,10 @@ class BitcoindInstanceTest extends BitcoindRpcTest { it should "start a bitcoind with cookie based authentication" in { val confStr = s""" - |regtest=1 - |daemon=1 - |port=${RpcUtil.randomPort} - |rpcport=${RpcUtil.randomPort} + |regtest=1 + |daemon=1 + |port=${RpcUtil.randomPort} + |rpcport=${RpcUtil.randomPort} """.stripMargin val conf = BitcoindConfig(confStr, BitcoindRpcTestUtil.tmpDir()) @@ -76,12 +76,12 @@ class BitcoindInstanceTest extends BitcoindRpcTest { it should "start a bitcoind with user and password based authentication" in { val confStr = s""" - |daemon=1 - |regtest=1 - |rpcuser=foobar - |rpcpassword=barfoo - |port=${RpcUtil.randomPort} - |rpcport=${RpcUtil.randomPort} + |daemon=1 + |regtest=1 + |rpcuser=foobar + |rpcpassword=barfoo + |port=${RpcUtil.randomPort} + |rpcport=${RpcUtil.randomPort} """.stripMargin val conf = BitcoindConfig(confStr, BitcoindRpcTestUtil.tmpDir()) @@ -104,11 +104,11 @@ class BitcoindInstanceTest extends BitcoindRpcTest { val port = RpcUtil.randomPort val rpcPort = RpcUtil.randomPort val confStr = s""" - |daemon=1 - |rpcauth=bitcoin-s:6d7580be1deb4ae52bc4249871845b09$$82b282e7c6493f6982a5a7af9fbb1b671bab702e2f31bbb1c016bb0ea1cc27ca - |regtest=1 - |port=${RpcUtil.randomPort} - |rpcport=${RpcUtil.randomPort} + |daemon=1 + |rpcauth=bitcoin-s:6d7580be1deb4ae52bc4249871845b09$$82b282e7c6493f6982a5a7af9fbb1b671bab702e2f31bbb1c016bb0ea1cc27ca + |regtest=1 + |port=${RpcUtil.randomPort} + |rpcport=${RpcUtil.randomPort} """.stripMargin val conf = BitcoindConfig(confStr, BitcoindRpcTestUtil.tmpDir()) diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/WalletRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/WalletRpcTest.scala index f7deb9347a..e5239a8844 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/WalletRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/common/WalletRpcTest.scala @@ -3,7 +3,11 @@ package org.bitcoins.rpc.common import java.io.File import java.util.Scanner -import org.bitcoins.core.crypto.{DoubleSha256DigestBE, ECPrivateKey, ECPublicKey} +import org.bitcoins.core.crypto.{ + DoubleSha256DigestBE, + ECPrivateKey, + ECPublicKey +} import org.bitcoins.core.currency.{Bitcoins, CurrencyUnit, Satoshis} import org.bitcoins.core.number.{Int64, UInt32} import org.bitcoins.core.protocol.script.ScriptSignature @@ -249,7 +253,10 @@ class WalletRpcTest extends BitcoindRpcTest { val amount = Bitcoins(1.25) - def getChangeAddressAndAmount(client: BitcoindRpcClient, address: BitcoinAddress, txid: DoubleSha256DigestBE): Future[(BitcoinAddress, CurrencyUnit)] = { + def getChangeAddressAndAmount( + client: BitcoindRpcClient, + address: BitcoinAddress, + txid: DoubleSha256DigestBE): Future[(BitcoinAddress, CurrencyUnit)] = { for { rawTx <- client.getRawTransactionRaw(txid) } yield { @@ -271,9 +278,14 @@ class WalletRpcTest extends BitcoindRpcTest { address <- client.getNewAddress - txid <- BitcoindRpcTestUtil.fundBlockChainTransaction(client, otherClient, address, amount) + txid <- BitcoindRpcTestUtil.fundBlockChainTransaction(client, + otherClient, + address, + amount) - (changeAddress, changeAmount) <- getChangeAddressAndAmount(client, address, txid) + (changeAddress, changeAmount) <- getChangeAddressAndAmount(client, + address, + txid) groupingsAfter <- client.listAddressGroupings } yield { @@ -281,20 +293,24 @@ class WalletRpcTest extends BitcoindRpcTest { // the address should appear in a new address grouping assert(!groupingsBefore.exists(vec => vec.exists(_.address == address))) - val rpcAddress = groupingsAfter.find(vec => vec.exists(_.address == address)).get.head + val rpcAddress = + groupingsAfter.find(vec => vec.exists(_.address == address)).get.head assert(rpcAddress.address == address) assert(rpcAddress.balance == amount) // the change address should be added to an exiting address grouping - assert(!groupingsBefore.exists(vec => vec.exists(_.address == changeAddress))) + assert( + !groupingsBefore.exists(vec => vec.exists(_.address == changeAddress))) - val changeGroupingOpt = groupingsAfter.find(vec => vec.exists(_.address == changeAddress)) + val changeGroupingOpt = + groupingsAfter.find(vec => vec.exists(_.address == changeAddress)) assert(changeGroupingOpt.nonEmpty) val changeGrouping = changeGroupingOpt.get assert(changeGrouping.size > 1) - val rpcChangeAddress = changeGrouping.find(addr => addr.address == changeAddress).get + val rpcChangeAddress = + changeGrouping.find(addr => addr.address == changeAddress).get assert(rpcChangeAddress.address == changeAddress) assert(rpcChangeAddress.balance == changeAmount) } diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/config/BitcoindAuthCredentialsTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/config/BitcoindAuthCredentialsTest.scala index 992e49ee13..3db89fe83c 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/config/BitcoindAuthCredentialsTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/config/BitcoindAuthCredentialsTest.scala @@ -9,7 +9,7 @@ import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil class BitcoindAuthCredentialsTest extends BitcoinSUnitTest { it must "handle cookie based auth" in { val confStr = """ - |regtest=1 + |regtest=1 """.stripMargin val conf = BitcoindConfig(confStr, BitcoindRpcTestUtil.tmpDir()) val auth = BitcoindAuthCredentials.fromConfig(conf) @@ -25,9 +25,9 @@ class BitcoindAuthCredentialsTest extends BitcoinSUnitTest { it must "default to password based auth" in { val confStr = """ - |regtest=1 - |rpcuser=foo - |rpcpassword=bar + |regtest=1 + |rpcuser=foo + |rpcpassword=bar """.stripMargin val conf = BitcoindConfig(confStr, BitcoindRpcTestUtil.tmpDir()) val auth = BitcoindAuthCredentials.fromConfig(conf) @@ -44,9 +44,9 @@ class BitcoindAuthCredentialsTest extends BitcoinSUnitTest { it must "handle password based auth" in { val confStr = """ - |regtest=1 - |rpcuser=foo - |rpcpassword=bar + |regtest=1 + |rpcuser=foo + |rpcpassword=bar """.stripMargin val conf = BitcoindConfig(confStr, BitcoindRpcTestUtil.tmpDir()) diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/config/BitcoindConfigTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/config/BitcoindConfigTest.scala index 0cb64f218f..f8dc617c93 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/config/BitcoindConfigTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/config/BitcoindConfigTest.scala @@ -20,7 +20,7 @@ class BitcoindConfigTest extends BitcoinSUnitTest { it must "parse networks" in { val conf = BitcoindConfig(""" - |regtest=1 + |regtest=1 """.stripMargin, tmpDir) assert(conf.network == RegTest) @@ -28,13 +28,13 @@ class BitcoindConfigTest extends BitcoinSUnitTest { it must "prioritize a prefixed option" in { val confStr = """ - |regtest=1 - | - |rpcport=2000 - |regtest.rpcport=3000 - | - |[regtest] - |rpcport=4000 + |regtest=1 + | + |rpcport=2000 + |regtest.rpcport=3000 + | + |[regtest] + |rpcport=4000 """.stripMargin.split("\n") val conf = BitcoindConfig(confStr, tmpDir) @@ -44,14 +44,14 @@ class BitcoindConfigTest extends BitcoinSUnitTest { it must "avoid to get prefixed options in section headers" in { val confStr = """ - |regtest=1 - | - |rpcport=2000 - | - |[regtest] - |rpcport=4000 - | - |regtest.rpcport=3000 + |regtest=1 + | + |rpcport=2000 + | + |[regtest] + |rpcport=4000 + | + |regtest.rpcport=3000 """.stripMargin.split("\n") val conf = BitcoindConfig(confStr, tmpDir) @@ -61,12 +61,12 @@ class BitcoindConfigTest extends BitcoinSUnitTest { it must "avoid getting options for the wrong network" in { val confStr = """ - |testnet=1 - | - |[regtest] - |rpcport=4000 - | - |regtest.rpcport=3000 + |testnet=1 + | + |[regtest] + |rpcport=4000 + | + |regtest.rpcport=3000 """.stripMargin.split("\n") val conf = BitcoindConfig(confStr, tmpDir) @@ -76,17 +76,17 @@ class BitcoindConfigTest extends BitcoinSUnitTest { it must "get options with multiple header sections" in { val confStr = """ - |testnet=1 - | - |[test] - |rpcuser=username - |rpcport=3000 - | - |[regtest] - |rpcport=4000 - | - |[main] - |rpcport=1000 + |testnet=1 + | + |[test] + |rpcuser=username + |rpcport=3000 + | + |[regtest] + |rpcport=4000 + | + |[main] + |rpcport=1000 """.stripMargin.split("\n") val conf = BitcoindConfig(confStr, tmpDir) @@ -105,17 +105,17 @@ class BitcoindConfigTest extends BitcoinSUnitTest { it must "get options with multiple header sections when our section is the last" in { val confStr = """ - |regtest=1 - | - |[test] - |rpcport=3000 - | - |[main] - |rpcport=1000 + |regtest=1 + | + |[test] + |rpcport=3000 + | + |[main] + |rpcport=1000 - |[regtest] - |rpcport=4000 - |rpcuser=username + |[regtest] + |rpcport=4000 + |rpcuser=username """.stripMargin.split("\n") val conf = BitcoindConfig(confStr, tmpDir) diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/BitcoindV17RpcClientTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/BitcoindV17RpcClientTest.scala index 671a399f7f..b81a4b46d6 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/BitcoindV17RpcClientTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/BitcoindV17RpcClientTest.scala @@ -113,9 +113,8 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest { (client, _) <- clientsF addr <- client.getNewAddress info <- client.getAddressInfo(addr) - } yield - assert( - info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear)) + } yield assert( + info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear)) } it should "be able to get the address info for a given P2SHSegwit address" in { @@ -123,9 +122,8 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest { (client, _) <- clientsF addr <- client.getNewAddress(addressType = AddressType.P2SHSegwit) info <- client.getAddressInfo(addr) - } yield - assert( - info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear)) + } yield assert( + info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear)) } it should "be able to get the address info for a given Legacy address" in { @@ -133,9 +131,8 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest { (client, _) <- clientsF addr <- client.getNewAddress(addressType = AddressType.Legacy) info <- client.getAddressInfo(addr) - } yield - assert( - info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear)) + } yield assert( + info.timestamp.exists(_.getDayOfYear == LocalDateTime.now.getDayOfYear)) } // needs #360 to be merged @@ -180,7 +177,7 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest { case exc => logger.error(s"throwing $exc") throw exc - } + } def importTx(n: Int): Future[Unit] = for { diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/PsbtRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/PsbtRpcTest.scala index db349c9b1e..97c3462bde 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/PsbtRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v17/PsbtRpcTest.scala @@ -73,11 +73,10 @@ class PsbtRpcTest extends BitcoindRpcTest { Map(newAddr -> Bitcoins(0.5))) processed <- client.walletProcessPsbt(psbt) finalized <- client.finalizePsbt(processed.psbt) - } yield - finalized match { - case _: FinalizedPsbt => succeed - case _: NonFinalizedPsbt => fail - } + } yield finalized match { + case _: FinalizedPsbt => succeed + case _: NonFinalizedPsbt => fail + } } // copies this test from Core: https://github.com/bitcoin/bitcoin/blob/master/test/functional/rpc_psbt.py#L158 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 d03c42d39f..b4cdff048b 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 @@ -86,8 +86,6 @@ sealed trait BitcoindVersion object BitcoindVersion { - - /** The newest version of `bitcoind` we support */ val newest = V18 diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/config/BitcoindInstance.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/config/BitcoindInstance.scala index 0755ce77cf..e053bd969e 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/config/BitcoindInstance.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/config/BitcoindInstance.scala @@ -18,7 +18,6 @@ import java.nio.file.Files import scala.util.Properties - /** * Created by chris on 4/29/17. */ diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonReaders.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonReaders.scala index 97ea54d740..175c9813ab 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonReaders.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/serializers/JsonReaders.scala @@ -442,10 +442,9 @@ object JsonReaders { pubkey <- (json \ "pubkey").validate[ECPublicKey] masterFingerprint <- (json \ "master_fingerprint").validate[String] path <- (json \ "path").validate[String] - } yield - PsbtBIP32Deriv(pubkey = pubkey, - masterFingerprint = masterFingerprint, - path = path) + } yield PsbtBIP32Deriv(pubkey = pubkey, + masterFingerprint = masterFingerprint, + path = path) } implicit object RpcPsbtScriptReads extends Reads[RpcPsbtScript] { @@ -455,11 +454,10 @@ object JsonReaders { hex <- (json \ "hex").validate[ScriptPubKey] scriptType <- (json \ "type").validateOpt[ScriptType] address <- (json \ "address").validateOpt[BitcoinAddress] - } yield - RpcPsbtScript(asm = asm, - hex = hex, - scriptType = scriptType, - address = address) + } yield RpcPsbtScript(asm = asm, + hex = hex, + scriptType = scriptType, + address = address) } implicit object MapPubKeySignatureReads diff --git a/build.sbt b/build.sbt index c068ae4755..0fa34823d8 100644 --- a/build.sbt +++ b/build.sbt @@ -74,7 +74,7 @@ lazy val `bitcoin-s` = project import scala.collection.JavaConverters._ val logger = streams.value.log - def cleanPath(path: Path, isRoot: Boolean = true): Unit = { + def cleanPath(path: Path, isRoot: Boolean = true): Unit = if (Files.isDirectory(path)) { path.toFile.list().map { file => val toClean = path.resolve(file) @@ -89,7 +89,6 @@ lazy val `bitcoin-s` = project } else { Files.deleteIfExists(path) } - } val websiteScaladocDir = Paths.get("website", "static", "api").toAbsolutePath @@ -111,14 +110,17 @@ lazy val `bitcoin-s` = project .drop(1) // skip the root directory .foreach { child => val pathDiff = generatedDir.toPath.relativize(child) - Files.copy(child, - websiteScaladocDir.resolve(pathDiff), - StandardCopyOption.REPLACE_EXISTING) + Files.copy( + child, + websiteScaladocDir.resolve(pathDiff), + StandardCopyOption.REPLACE_EXISTING + ) } } catch { case e: Throwable => logger.err( - "Error when copying Scaladocs to website folder: ${e.toString}") + "Error when copying Scaladocs to website folder: ${e.toString}" + ) throw e } Seq(generatedDir) @@ -294,8 +296,10 @@ lazy val bench = project lazy val eclairRpcTest = project .in(file("eclair-rpc-test")) .settings(CommonSettings.testSettings: _*) - .settings(libraryDependencies ++= Deps.eclairRpcTest, - name := "bitcoin-s-eclair-rpc-test") + .settings( + libraryDependencies ++= Deps.eclairRpcTest, + name := "bitcoin-s-eclair-rpc-test" + ) .dependsOn(core % testAndCompile, testkit) lazy val nodeDbSettings = dbFlywaySettings("nodedb") diff --git a/chain/src/main/scala-2.11/org/bitcoins/chain/blockchain/Blockchain.scala b/chain/src/main/scala-2.11/org/bitcoins/chain/blockchain/Blockchain.scala index 955e5f7bbb..1d8abc4c1f 100644 --- a/chain/src/main/scala-2.11/org/bitcoins/chain/blockchain/Blockchain.scala +++ b/chain/src/main/scala-2.11/org/bitcoins/chain/blockchain/Blockchain.scala @@ -2,7 +2,7 @@ package org.bitcoins.chain.blockchain import org.bitcoins.chain.models.BlockHeaderDb -import scala.collection.{IndexedSeqLike, mutable} +import scala.collection.{mutable, IndexedSeqLike} /** @inheritdoc */ case class Blockchain(headers: Vector[BlockHeaderDb]) 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 dcc78da95e..f228647ddf 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 @@ -2,7 +2,7 @@ package org.bitcoins.chain.blockchain import org.bitcoins.chain.models.BlockHeaderDb -import scala.collection.{IndexedSeqLike, mutable} +import scala.collection.{mutable, IndexedSeqLike} /** @inheritdoc */ case class Blockchain(headers: Vector[BlockHeaderDb]) diff --git a/chain/src/main/scala/org/bitcoins/chain/api/ChainApi.scala b/chain/src/main/scala/org/bitcoins/chain/api/ChainApi.scala index 03b322b32c..3e76783f87 100644 --- a/chain/src/main/scala/org/bitcoins/chain/api/ChainApi.scala +++ b/chain/src/main/scala/org/bitcoins/chain/api/ChainApi.scala @@ -50,12 +50,11 @@ trait ChainApi { for { hash <- getBestBlockHash headerOpt <- getHeader(hash) - } yield - headerOpt match { - case None => - throw new RuntimeException( - s"We found best hash=${hash.hex} but could not retrieve the full header!!!") - case Some(header) => header - } + } yield headerOpt match { + case None => + throw new RuntimeException( + s"We found best hash=${hash.hex} but could not retrieve the full header!!!") + case Some(header) => header + } } } diff --git a/core-test/src/test/scala/org/bitcoins/core/crypto/BIP39SeedTest.scala b/core-test/src/test/scala/org/bitcoins/core/crypto/BIP39SeedTest.scala index c11cd2610f..483e02078a 100644 --- a/core-test/src/test/scala/org/bitcoins/core/crypto/BIP39SeedTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/crypto/BIP39SeedTest.scala @@ -8,7 +8,7 @@ import scala.util.{Failure, Try} class BIP39SeedTest extends BitcoinSUnitTest { behavior of "BIP39Seed" - override implicit val generatorDrivenConfig: PropertyCheckConfiguration = + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode it must "have serialization symmetry - with password" in { diff --git a/core-test/src/test/scala/org/bitcoins/core/crypto/ECDigitalSignatureTest.scala b/core-test/src/test/scala/org/bitcoins/core/crypto/ECDigitalSignatureTest.scala index c7da1c6938..17ab5c1d59 100644 --- a/core-test/src/test/scala/org/bitcoins/core/crypto/ECDigitalSignatureTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/crypto/ECDigitalSignatureTest.scala @@ -9,7 +9,7 @@ import scodec.bits.ByteVector */ class ECDigitalSignatureTest extends BitcoinSUnitTest { - override implicit val generatorDrivenConfig = generatorDrivenConfigNewCode + implicit override val generatorDrivenConfig = generatorDrivenConfigNewCode "ECDigitalSignature" must "say that empty signature is a valid DER encoded signature" in { val emptySiganture = ECDigitalSignature(ByteVector.empty) diff --git a/core-test/src/test/scala/org/bitcoins/core/crypto/ExtKeyTest.scala b/core-test/src/test/scala/org/bitcoins/core/crypto/ExtKeyTest.scala index 096c0e12d3..436a5449e3 100644 --- a/core-test/src/test/scala/org/bitcoins/core/crypto/ExtKeyTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/crypto/ExtKeyTest.scala @@ -15,7 +15,7 @@ import scala.util.{Failure, Success, Try} class ExtKeyTest extends BitcoinSUnitTest { - override implicit val generatorDrivenConfig: PropertyCheckConfiguration = + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode behavior of "ExtKey" diff --git a/core-test/src/test/scala/org/bitcoins/core/crypto/MnemonicCodeTest.scala b/core-test/src/test/scala/org/bitcoins/core/crypto/MnemonicCodeTest.scala index ecb744c694..46ca16c994 100644 --- a/core-test/src/test/scala/org/bitcoins/core/crypto/MnemonicCodeTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/crypto/MnemonicCodeTest.scala @@ -13,7 +13,7 @@ import scala.util.{Failure, Try} class MnemonicCodeTest extends BitcoinSUnitTest { - override implicit val generatorDrivenConfig: PropertyCheckConfiguration = + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode behavior of "MnemonicCode" diff --git a/core-test/src/test/scala/org/bitcoins/core/crypto/bip32/BIP32PathTest.scala b/core-test/src/test/scala/org/bitcoins/core/crypto/bip32/BIP32PathTest.scala index f2977e31c6..ab8b1a058b 100644 --- a/core-test/src/test/scala/org/bitcoins/core/crypto/bip32/BIP32PathTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/crypto/bip32/BIP32PathTest.scala @@ -16,7 +16,7 @@ import org.bitcoins.core.crypto.ExtPrivateKey class BIP32PathTest extends BitcoinSUnitTest { - override implicit val generatorDrivenConfig: PropertyCheckConfiguration = + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode behavior of "BIP32Child" diff --git a/core-test/src/test/scala/org/bitcoins/core/gcs/BlockFilterTest.scala b/core-test/src/test/scala/org/bitcoins/core/gcs/BlockFilterTest.scala index da59790701..6e86064858 100644 --- a/core-test/src/test/scala/org/bitcoins/core/gcs/BlockFilterTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/gcs/BlockFilterTest.scala @@ -63,15 +63,14 @@ class BlockFilterTest extends BitcoinSUnitTest { header <- array(6).validate[String].map(DoubleSha256DigestBE.fromHex) notes <- array(7).validate[String] - } yield - Bip158TestCase(height, - blockHash, - block, - scripts, - prevHeader, - filter, - header, - notes) + } yield Bip158TestCase(height, + blockHash, + block, + scripts, + prevHeader, + filter, + header, + notes) parseResult.get } diff --git a/core-test/src/test/scala/org/bitcoins/core/gcs/GCSTest.scala b/core-test/src/test/scala/org/bitcoins/core/gcs/GCSTest.scala index 3372bc43d1..a1073e3be1 100644 --- a/core-test/src/test/scala/org/bitcoins/core/gcs/GCSTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/gcs/GCSTest.scala @@ -240,7 +240,10 @@ class GCSTest extends BitcoinSUnitTest { } def genKey: Gen[SipHashKey] = - Gen.listOfN(16, NumberGenerator.byte).map(ByteVector(_)).map(SipHashKey(_)) + Gen + .listOfN(16, NumberGenerator.byte) + .map(ByteVector(_)) + .map(SipHashKey(_)) forAll(genPM, genItems, genKey) { case ((p, m), items, k) => diff --git a/core-test/src/test/scala/org/bitcoins/core/gcs/GolombFilterTest.scala b/core-test/src/test/scala/org/bitcoins/core/gcs/GolombFilterTest.scala index 70ef59256e..b45c4890fc 100644 --- a/core-test/src/test/scala/org/bitcoins/core/gcs/GolombFilterTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/gcs/GolombFilterTest.scala @@ -12,7 +12,10 @@ class GolombFilterTest extends BitcoinSUnitTest { it must "match encoded data for arbitrary GCS parameters" in { def genKey: Gen[SipHashKey] = - Gen.listOfN(16, NumberGenerator.byte).map(ByteVector(_)).map(SipHashKey(_)) + Gen + .listOfN(16, NumberGenerator.byte) + .map(ByteVector(_)) + .map(SipHashKey(_)) def genPMRand: Gen[(UInt8, UInt64, UInt64)] = NumberGenerator.genP.flatMap { p => @@ -49,7 +52,10 @@ class GolombFilterTest extends BitcoinSUnitTest { it must "match arbitrary encoded data for bip 158 GCS parameters" in { val genKey: Gen[SipHashKey] = - Gen.listOfN(16, NumberGenerator.byte).map(ByteVector(_)).map(SipHashKey(_)) + Gen + .listOfN(16, NumberGenerator.byte) + .map(ByteVector(_)) + .map(SipHashKey(_)) val genData: Gen[Vector[ByteVector]] = Gen.chooseNum(1, 10000).flatMap { size => diff --git a/core-test/src/test/scala/org/bitcoins/core/number/UInt32Spec.scala b/core-test/src/test/scala/org/bitcoins/core/number/UInt32Spec.scala index a31bd172e1..b3786f384d 100644 --- a/core-test/src/test/scala/org/bitcoins/core/number/UInt32Spec.scala +++ b/core-test/src/test/scala/org/bitcoins/core/number/UInt32Spec.scala @@ -112,7 +112,7 @@ class UInt32Spec extends Properties("UInt32") { Prop.forAllNoShrink(NumberGenerator.uInt32s, Gen.choose(0, 32)) { case (u32, shift) => val r = Try(u32 << shift) - val expected = (u32.toLong << shift) & 0xffffffffL + val expected = (u32.toLong << shift) & 0xFFFFFFFFL if (r.isSuccess && expected <= UInt32.max.toLong) { r.get == UInt32(expected) } else { diff --git a/core-test/src/test/scala/org/bitcoins/core/number/UInt8Spec.scala b/core-test/src/test/scala/org/bitcoins/core/number/UInt8Spec.scala index 98872f991c..2cd58ce502 100644 --- a/core-test/src/test/scala/org/bitcoins/core/number/UInt8Spec.scala +++ b/core-test/src/test/scala/org/bitcoins/core/number/UInt8Spec.scala @@ -25,7 +25,7 @@ class UInt8Spec extends Properties("UInt8Spec") { Prop.forAllNoShrink(NumberGenerator.uInt8, Gen.choose(0, 8)) { case (u8: UInt8, shift: Int) => val r = Try(u8 << shift) - val expected = (u8.toLong << shift) & 0xffL + val expected = (u8.toLong << shift) & 0xFFL if (expected <= UInt8.max.toLong) { r.get == UInt8(expected.toShort) } else { diff --git a/core-test/src/test/scala/org/bitcoins/core/protocol/Bech32Test.scala b/core-test/src/test/scala/org/bitcoins/core/protocol/Bech32Test.scala index 6e982faa96..a653a98558 100644 --- a/core-test/src/test/scala/org/bitcoins/core/protocol/Bech32Test.scala +++ b/core-test/src/test/scala/org/bitcoins/core/protocol/Bech32Test.scala @@ -13,7 +13,7 @@ import org.bitcoins.testkit.util.BitcoinSUnitTest import scala.util.{Failure, Success} class Bech32Test extends BitcoinSUnitTest { - override implicit val generatorDrivenConfig: PropertyCheckConfiguration = + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode behavior of "Bech32" diff --git a/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnInvoiceSignatureTest.scala b/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnInvoiceSignatureTest.scala index 3e2857061f..5fb68179c4 100644 --- a/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnInvoiceSignatureTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnInvoiceSignatureTest.scala @@ -7,7 +7,7 @@ import org.bitcoins.testkit.util.BitcoinSUnitTest class LnInvoiceSignatureTest extends BitcoinSUnitTest { - override implicit val generatorDrivenConfig: PropertyCheckConfiguration = + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode behavior of "LnInvoiceSignature" diff --git a/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnInvoiceUnitTest.scala b/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnInvoiceUnitTest.scala index 52fe53fe27..a4a20c9959 100644 --- a/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnInvoiceUnitTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnInvoiceUnitTest.scala @@ -25,7 +25,7 @@ import scodec.bits.ByteVector class LnInvoiceUnitTest extends BitcoinSUnitTest { behavior of "LnInvoice" - override implicit val generatorDrivenConfig: PropertyCheckConfiguration = + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode val hrpEmpty = LnHumanReadablePart(LnBitcoinMainNet) diff --git a/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnUtilTest.scala b/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnUtilTest.scala index 5f316e974d..ba003d7356 100644 --- a/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnUtilTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/protocol/ln/LnUtilTest.scala @@ -6,7 +6,7 @@ import org.bitcoins.core.protocol.ln.util.LnUtil import org.bitcoins.testkit.util.BitcoinSUnitTest class LnUtilTest extends BitcoinSUnitTest { - override implicit val generatorDrivenConfig: PropertyCheckConfiguration = + implicit override val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode behavior of "LnUtil" diff --git a/core-test/src/test/scala/org/bitcoins/core/protocol/ln/ShortChannelIdTest.scala b/core-test/src/test/scala/org/bitcoins/core/protocol/ln/ShortChannelIdTest.scala index 9c6519b1da..5c417ac882 100644 --- a/core-test/src/test/scala/org/bitcoins/core/protocol/ln/ShortChannelIdTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/protocol/ln/ShortChannelIdTest.scala @@ -6,27 +6,40 @@ class ShortChannelIdTest extends FlatSpec with MustMatchers { it must "convert short channel id to and from human readable form" in { // BOLT example - ShortChannelId.fromHumanReadableString("539268x845x1") must be (ShortChannelId.fromHex("83a8400034d0001")) - ShortChannelId.fromHex("83a8400034d0001").toHumanReadableString must be ("539268x845x1") + ShortChannelId.fromHumanReadableString("539268x845x1") must be( + ShortChannelId.fromHex("83a8400034d0001")) + ShortChannelId.fromHex("83a8400034d0001").toHumanReadableString must be( + "539268x845x1") // min value - ShortChannelId.fromHumanReadableString("0x0x0") must be (ShortChannelId.fromHex("0")) - ShortChannelId.fromHex("0").toHumanReadableString must be ("0x0x0") + ShortChannelId.fromHumanReadableString("0x0x0") must be( + ShortChannelId.fromHex("0")) + ShortChannelId.fromHex("0").toHumanReadableString must be("0x0x0") // max value - ShortChannelId.fromHumanReadableString("16777215x16777215x65535") must be (ShortChannelId.fromHex("ffffffffffffffff")) - ShortChannelId.fromHex("ffffffffffffffff").toHumanReadableString must be ("16777215x16777215x65535") + ShortChannelId.fromHumanReadableString("16777215x16777215x65535") must be( + ShortChannelId.fromHex("ffffffffffffffff")) + ShortChannelId.fromHex("ffffffffffffffff").toHumanReadableString must be( + "16777215x16777215x65535") } it must "validate short channel id components" in { - an [IllegalArgumentException] must be thrownBy ShortChannelId.fromHumanReadableString("16777216x0x0") - an [IllegalArgumentException] must be thrownBy ShortChannelId.fromHumanReadableString("-1x0x0") - an [IllegalArgumentException] must be thrownBy ShortChannelId.fromHumanReadableString("0x16777216x0") - an [IllegalArgumentException] must be thrownBy ShortChannelId.fromHumanReadableString("0x-1x0") - an [IllegalArgumentException] must be thrownBy ShortChannelId.fromHumanReadableString("0x0x65536") - an [IllegalArgumentException] must be thrownBy ShortChannelId.fromHumanReadableString("0x0x-1") - an [NoSuchElementException] must be thrownBy ShortChannelId.fromHumanReadableString("1x1x1x1") - ShortChannelId.fromHumanReadableString("cafebabe") must be (ShortChannelId.fromHex("cafebabe")) + an[IllegalArgumentException] must be thrownBy ShortChannelId + .fromHumanReadableString("16777216x0x0") + an[IllegalArgumentException] must be thrownBy ShortChannelId + .fromHumanReadableString("-1x0x0") + an[IllegalArgumentException] must be thrownBy ShortChannelId + .fromHumanReadableString("0x16777216x0") + an[IllegalArgumentException] must be thrownBy ShortChannelId + .fromHumanReadableString("0x-1x0") + an[IllegalArgumentException] must be thrownBy ShortChannelId + .fromHumanReadableString("0x0x65536") + an[IllegalArgumentException] must be thrownBy ShortChannelId + .fromHumanReadableString("0x0x-1") + an[NoSuchElementException] must be thrownBy ShortChannelId + .fromHumanReadableString("1x1x1x1") + ShortChannelId.fromHumanReadableString("cafebabe") must be( + ShortChannelId.fromHex("cafebabe")) } } diff --git a/core-test/src/test/scala/org/bitcoins/core/protocol/transaction/TransactionTest.scala b/core-test/src/test/scala/org/bitcoins/core/protocol/transaction/TransactionTest.scala index d00cac3374..9546ffa71b 100644 --- a/core-test/src/test/scala/org/bitcoins/core/protocol/transaction/TransactionTest.scala +++ b/core-test/src/test/scala/org/bitcoins/core/protocol/transaction/TransactionTest.scala @@ -173,10 +173,10 @@ class TransactionTest extends BitcoinSUnitTest { assert( outPoint.txId == input.previousOutput.txId, s""" - |OutPoint txId not the same as input prevout txid - |outPoint.txId: ${outPoint.txId} - |input prevout txid: ${input.previousOutput.txId} - |""".stripMargin + |OutPoint txId not the same as input prevout txid + |outPoint.txId: ${outPoint.txId} + |input prevout txid: ${input.previousOutput.txId} + |""".stripMargin ) val txSigComponent = amountOpt match { case Some(amount) => diff --git a/core/src/main/scala/org/bitcoins/core/crypto/TransactionSignatureSerializer.scala b/core/src/main/scala/org/bitcoins/core/crypto/TransactionSignatureSerializer.scala index c3838569d7..64a93485e2 100644 --- a/core/src/main/scala/org/bitcoins/core/crypto/TransactionSignatureSerializer.scala +++ b/core/src/main/scala/org/bitcoins/core/crypto/TransactionSignatureSerializer.scala @@ -62,10 +62,10 @@ sealed abstract class TransactionSignatureSerializer { val inputSigsRemoved = for { input <- spendingTransaction.inputs s = input.scriptSignature - } yield - TransactionInput(input.previousOutput, - NonStandardScriptSignature(s.compactSizeUInt.hex), - input.sequence) + } yield TransactionInput( + input.previousOutput, + NonStandardScriptSignature(s.compactSizeUInt.hex), + input.sequence) //make sure all scriptSigs have empty asm inputSigsRemoved.map( diff --git a/core/src/main/scala/org/bitcoins/core/gcs/GCS.scala b/core/src/main/scala/org/bitcoins/core/gcs/GCS.scala index 422fb100d2..dd1f948aea 100644 --- a/core/src/main/scala/org/bitcoins/core/gcs/GCS.scala +++ b/core/src/main/scala/org/bitcoins/core/gcs/GCS.scala @@ -4,7 +4,7 @@ import org.bitcoins.core.number.{UInt64, UInt8} import org.bitcoins.core.protocol.CompactSizeUInt import org.bouncycastle.crypto.macs.SipHash import org.bouncycastle.crypto.params.KeyParameter -import scodec.bits.{BitVector, BinStringSyntax, ByteVector} +import scodec.bits.{BinStringSyntax, BitVector, ByteVector} import scala.annotation.tailrec diff --git a/core/src/main/scala/org/bitcoins/core/number/NumberType.scala b/core/src/main/scala/org/bitcoins/core/number/NumberType.scala index ea726616ba..78b9ece775 100644 --- a/core/src/main/scala/org/bitcoins/core/number/NumberType.scala +++ b/core/src/main/scala/org/bitcoins/core/number/NumberType.scala @@ -133,7 +133,7 @@ sealed abstract class UInt32 extends UnsignedNumber[UInt32] { override def apply: A => UInt32 = UInt32(_) override def hex: String = BitcoinSUtil.encodeHex(toLong).slice(8, 16) - override def andMask = 0xffffffffL + override def andMask = 0xFFFFFFFFL } /** @@ -142,7 +142,7 @@ sealed abstract class UInt32 extends UnsignedNumber[UInt32] { sealed abstract class UInt64 extends UnsignedNumber[UInt64] { override def hex: String = encodeHex(underlying) override def apply: A => UInt64 = UInt64(_) - override def andMask = 0xffffffffffffffffL + override def andMask = 0xFFFFFFFFFFFFFFFFL /** * Converts a [[BigInt]] to a 8 byte hex representation. @@ -178,7 +178,7 @@ sealed abstract class Int32 extends SignedNumber[Int32] { */ sealed abstract class Int64 extends SignedNumber[Int64] { override def apply: A => Int64 = Int64(_) - override def andMask = 0xffffffffffffffffL + override def andMask = 0xFFFFFFFFFFFFFFFFL override def hex: String = BitcoinSUtil.encodeHex(toLong) } diff --git a/core/src/main/scala/org/bitcoins/core/protocol/CompactSizeUInt.scala b/core/src/main/scala/org/bitcoins/core/protocol/CompactSizeUInt.scala index 980a32287e..eeabf12845 100644 --- a/core/src/main/scala/org/bitcoins/core/protocol/CompactSizeUInt.scala +++ b/core/src/main/scala/org/bitcoins/core/protocol/CompactSizeUInt.scala @@ -140,7 +140,7 @@ object CompactSizeUInt extends Factory[CompactSizeUInt] { CompactSizeUInt(UInt64(script.bytes.size), 1) } else if (script.bytes.size <= 0xffff) { CompactSizeUInt(UInt64(script.bytes.size), 3) - } else if (script.bytes.size <= 0xffffffffL) { + } else if (script.bytes.size <= 0xFFFFFFFFL) { CompactSizeUInt(UInt64(script.bytes.size), 5) } else CompactSizeUInt(UInt64(script.bytes.size), 9) } diff --git a/core/src/main/scala/org/bitcoins/core/protocol/ln/PaymentPreimage.scala b/core/src/main/scala/org/bitcoins/core/protocol/ln/PaymentPreimage.scala index 4a7093c064..475f3cfb90 100644 --- a/core/src/main/scala/org/bitcoins/core/protocol/ln/PaymentPreimage.scala +++ b/core/src/main/scala/org/bitcoins/core/protocol/ln/PaymentPreimage.scala @@ -22,4 +22,4 @@ object PaymentPreimage extends Factory[PaymentPreimage] { def random: PaymentPreimage = fromBytes(ECPrivateKey.freshPrivateKey.bytes) -} \ No newline at end of file +} diff --git a/core/src/main/scala/org/bitcoins/core/protocol/ln/ShortChannelId.scala b/core/src/main/scala/org/bitcoins/core/protocol/ln/ShortChannelId.scala index 6b13d4383f..34341ab9ef 100644 --- a/core/src/main/scala/org/bitcoins/core/protocol/ln/ShortChannelId.scala +++ b/core/src/main/scala/org/bitcoins/core/protocol/ln/ShortChannelId.scala @@ -28,9 +28,9 @@ case class ShortChannelId(u64: UInt64) extends NetworkElement { * }}} */ def toHumanReadableString: String = { - val blockHeight = (u64 >> 40) & UInt64(0xFFFFFF) - val txIndex = (u64 >> 16) & UInt64(0xFFFFFF) - val outputIndex = u64 & UInt64(0xFFFF) + val blockHeight = (u64 >> 40) & UInt64(0xFFFFFF) + val txIndex = (u64 >> 16) & UInt64(0xFFFFFF) + val outputIndex = u64 & UInt64(0xFFFF) s"${blockHeight.toInt}x${txIndex.toInt}x${outputIndex.toInt}" } @@ -42,19 +42,24 @@ object ShortChannelId extends Factory[ShortChannelId] { new ShortChannelId(UInt64.fromBytes(byteVector)) } - def fromHumanReadableString(str: String): ShortChannelId = str.split("x") match { - case Array(_blockHeight, _txIndex, _outputIndex) => - val blockHeight = BigInt(_blockHeight) - require(blockHeight >= 0 && blockHeight <= 0xffffff, "ShortChannelId: invalid block height") + def fromHumanReadableString(str: String): ShortChannelId = + str.split("x") match { + case Array(_blockHeight, _txIndex, _outputIndex) => + val blockHeight = BigInt(_blockHeight) + require(blockHeight >= 0 && blockHeight <= 0xffffff, + "ShortChannelId: invalid block height") - val txIndex = _txIndex.toInt - require(txIndex >= 0 && txIndex <= 0xffffff, "ShortChannelId:invalid tx index") + val txIndex = _txIndex.toInt + require(txIndex >= 0 && txIndex <= 0xffffff, + "ShortChannelId:invalid tx index") - val outputIndex = _outputIndex.toInt - require(outputIndex >= 0 && outputIndex <= 0xffff, "ShortChannelId: invalid output index") + val outputIndex = _outputIndex.toInt + require(outputIndex >= 0 && outputIndex <= 0xffff, + "ShortChannelId: invalid output index") - val u64 = UInt64(((blockHeight & 0xffffffL) << 40) | ((txIndex & 0xffffffL) << 16) | (outputIndex & 0xffffL)) - ShortChannelId(u64) - case _: Array[String] => fromHex(str) - } + val u64 = UInt64( + ((blockHeight & 0xFFFFFFL) << 40) | ((txIndex & 0xFFFFFFL) << 16) | (outputIndex & 0xFFFFL)) + ShortChannelId(u64) + case _: Array[String] => fromHex(str) + } } diff --git a/core/src/main/scala/org/bitcoins/core/script/arithmetic/ArithmeticInterpreter.scala b/core/src/main/scala/org/bitcoins/core/script/arithmetic/ArithmeticInterpreter.scala index 8c35f9779d..28897d416b 100644 --- a/core/src/main/scala/org/bitcoins/core/script/arithmetic/ArithmeticInterpreter.scala +++ b/core/src/main/scala/org/bitcoins/core/script/arithmetic/ArithmeticInterpreter.scala @@ -61,7 +61,7 @@ sealed abstract class ArithmeticInterpreter { x match { case ScriptNumber.zero => ScriptNumber.zero case _: ScriptNumber => ScriptNumber(x.toLong.abs) - }) + }) } /** Negates the stack top. */ diff --git a/core/src/main/scala/org/bitcoins/core/script/constant/Constants.scala b/core/src/main/scala/org/bitcoins/core/script/constant/Constants.scala index 43dde34f00..343c9f837b 100644 --- a/core/src/main/scala/org/bitcoins/core/script/constant/Constants.scala +++ b/core/src/main/scala/org/bitcoins/core/script/constant/Constants.scala @@ -59,7 +59,8 @@ sealed abstract class ScriptNumber def *(that: ScriptNumber): ScriptNumber = ScriptNumber(underlying * that.underlying) - override def compare(that: ScriptNumber): Int = underlying compare that.underlying + override def compare(that: ScriptNumber): Int = + underlying compare that.underlying def <(that: Int64): Boolean = underlying < that.toLong diff --git a/core/src/main/scala/org/bitcoins/core/script/interpreter/ScriptInterpreter.scala b/core/src/main/scala/org/bitcoins/core/script/interpreter/ScriptInterpreter.scala index f57852744d..df6bbc8673 100644 --- a/core/src/main/scala/org/bitcoins/core/script/interpreter/ScriptInterpreter.scala +++ b/core/src/main/scala/org/bitcoins/core/script/interpreter/ScriptInterpreter.scala @@ -790,7 +790,7 @@ sealed abstract class ScriptInterpreter { //since this is not a coinbase tx we cannot have any empty previous outs inside of inputs !transaction.inputs.exists(_.previousOutput == EmptyTransactionOutPoint) } - inputOutputsNotZero && txNotLargerThanBlock && outputsSpendValidAmountsOfMoney && + inputOutputsNotZero && txNotLargerThanBlock && outputsSpendValidAmountsOfMoney && allOutputsValidMoneyRange && noDuplicateInputs && isValidScriptSigForCoinbaseTx } diff --git a/core/src/main/scala/org/bitcoins/core/script/stack/StackInterpreter.scala b/core/src/main/scala/org/bitcoins/core/script/stack/StackInterpreter.scala index c1b8447ffb..281792b68c 100644 --- a/core/src/main/scala/org/bitcoins/core/script/stack/StackInterpreter.scala +++ b/core/src/main/scala/org/bitcoins/core/script/stack/StackInterpreter.scala @@ -173,7 +173,7 @@ sealed abstract class StackInterpreter { logger.error( "The index for OP_ROLL would have caused an index out of bounds exception") ScriptProgram(program, ScriptErrorInvalidStackOperation) - } + } ) } diff --git a/core/src/main/scala/org/bitcoins/core/serializers/script/ScriptParser.scala b/core/src/main/scala/org/bitcoins/core/serializers/script/ScriptParser.scala index 15e4601248..2c9adaf2ca 100644 --- a/core/src/main/scala/org/bitcoins/core/serializers/script/ScriptParser.scala +++ b/core/src/main/scala/org/bitcoins/core/serializers/script/ScriptParser.scala @@ -197,7 +197,7 @@ sealed abstract class ScriptParser extends Factory[List[ScriptToken]] { ScriptNumber(g.group(1)) } else { ScriptConstant(g.group(1)) - })) + })) scriptConstants.toList } diff --git a/core/src/main/scala/org/bitcoins/core/util/NumberUtil.scala b/core/src/main/scala/org/bitcoins/core/util/NumberUtil.scala index 05e1380101..61a3a99313 100644 --- a/core/src/main/scala/org/bitcoins/core/util/NumberUtil.scala +++ b/core/src/main/scala/org/bitcoins/core/util/NumberUtil.scala @@ -215,7 +215,7 @@ sealed abstract class NumberUtil extends BitcoinSLogger { nWordNotZero && ((nSize > 34) || (nWord > UInt8.max.toBigInt && nSize > 33) || - (nWord > UInt32(0xffffL).toBigInt && nSize > 32)) + (nWord > UInt32(0xFFFFL).toBigInt && nSize > 32)) } BlockHeader.TargetDifficultyHelper(result.abs(), isNegative, isOverflow) @@ -273,14 +273,14 @@ sealed abstract class NumberUtil extends BitcoinSLogger { } //~0x007fffff = 0xff800000 - require((compact & UInt32(0xff800000L)) == UInt32.zero, + require((compact & UInt32(0xFF800000L)) == UInt32.zero, s"Exponent/sign bit must not be set yet in compact encoding") require(size < 256, "Size of compact encoding can't be more than 2^256") compact = compact | UInt32(size << 24) compact = { - if (isNegative && ((compact & UInt32(0x007fffffL)) != UInt32.zero)) { + if (isNegative && ((compact & UInt32(0x007FFFFFL)) != UInt32.zero)) { compact | negativeFlag } else { compact | UInt32.zero diff --git a/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala b/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala index dc61302cf6..6239e34bb2 100644 --- a/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala +++ b/eclair-rpc-test/src/test/scala/org/bitcoins/eclair/rpc/EclairRpcClientTest.scala @@ -54,7 +54,7 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll { sys.error { val msg = s""""Eclair binary directory (${BitcoindRpcTestUtil.binaryDirectory}) is empty. - |Run 'sbt downloadEclair' to fetch needed binaries""".stripMargin + |Run 'sbt downloadEclair' to fetch needed binaries""".stripMargin msg } } @@ -988,7 +988,7 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll { ourUpdates.flatMap(our => allUpdates.map { all => our != all - }) + }) } val checkedUpatesF: Future[Unit] = diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/json/EclairModels.scala b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/json/EclairModels.scala index 744fef36de..46b02afd1e 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/json/EclairModels.scala +++ b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/json/EclairModels.scala @@ -1,12 +1,22 @@ package org.bitcoins.eclair.rpc.json -import org.bitcoins.core.crypto.{DoubleSha256Digest, DoubleSha256DigestBE, ECDigitalSignature, Sha256Digest} +import org.bitcoins.core.crypto.{ + DoubleSha256Digest, + DoubleSha256DigestBE, + ECDigitalSignature, + Sha256Digest +} import org.bitcoins.core.currency.Satoshis import org.bitcoins.core.protocol.ln.channel.{ChannelState, FundedChannelId} import org.bitcoins.core.protocol.ln.currency.MilliSatoshis import org.bitcoins.core.protocol.ln.fee.FeeProportionalMillionths import org.bitcoins.core.protocol.ln.node.NodeId -import org.bitcoins.core.protocol.ln.{LnHumanReadablePart, LnInvoiceSignature, PaymentPreimage, ShortChannelId} +import org.bitcoins.core.protocol.ln.{ + LnHumanReadablePart, + LnInvoiceSignature, + PaymentPreimage, + ShortChannelId +} import org.bitcoins.eclair.rpc.network.PeerState import play.api.libs.json.JsObject @@ -265,19 +275,20 @@ case class ChannelResult( feeProportionalMillionths: Option[FeeProportionalMillionths], data: JsObject) { import JsonReaders._ - lazy val shortChannelId: Option[ShortChannelId] = (data \ "shortChannelId").validate[ShortChannelId].asOpt + lazy val shortChannelId: Option[ShortChannelId] = + (data \ "shortChannelId").validate[ShortChannelId].asOpt } // ChannelResult ends here case class InvoiceResult( - prefix: LnHumanReadablePart, - timestamp: FiniteDuration, - nodeId: NodeId, - serialized: String, - description: String, - paymentHash: Sha256Digest, - expiry: FiniteDuration) + prefix: LnHumanReadablePart, + timestamp: FiniteDuration, + nodeId: NodeId, + serialized: String, + description: String, + paymentHash: Sha256Digest, + expiry: FiniteDuration) case class PaymentRequest( prefix: LnHumanReadablePart, @@ -288,30 +299,33 @@ case class PaymentRequest( signature: LnInvoiceSignature) case class PaymentResult( - id: String, - paymentHash: Sha256Digest, - preimage: Option[PaymentPreimage], - amountMsat: MilliSatoshis, - createdAt: FiniteDuration, - completedAt: Option[FiniteDuration], - status: PaymentStatus) + id: String, + paymentHash: Sha256Digest, + preimage: Option[PaymentPreimage], + amountMsat: MilliSatoshis, + createdAt: FiniteDuration, + completedAt: Option[FiniteDuration], + status: PaymentStatus) case class ReceivedPaymentResult( - paymentHash: Sha256Digest, - amountMsat: MilliSatoshis, - receivedAt: FiniteDuration) + paymentHash: Sha256Digest, + amountMsat: MilliSatoshis, + receivedAt: FiniteDuration) sealed trait PaymentStatus + object PaymentStatus { case object PENDING extends PaymentStatus case object SUCCEEDED extends PaymentStatus case object FAILED extends PaymentStatus def apply(s: String): PaymentStatus = s match { - case "PENDING" => PENDING + case "PENDING" => PENDING case "SUCCEEDED" => SUCCEEDED - case "FAILED" => FAILED - case err => throw new IllegalArgumentException(s"Unknown payment status code `${err}`") + case "FAILED" => FAILED + case err => + throw new IllegalArgumentException( + s"Unknown payment status code `${err}`") } } @@ -319,29 +333,28 @@ case class PaymentId(value: String) { override def toString: String = value } - sealed trait WebSocketEvent object WebSocketEvent { - case class PaymentRelayed( amountIn: MilliSatoshis, amountOut: MilliSatoshis, paymentHash: Sha256Digest, fromChannelId: FundedChannelId, toChannelId: FundedChannelId, - timestamp: FiniteDuration) extends WebSocketEvent + timestamp: FiniteDuration) + extends WebSocketEvent case class PaymentReceived( amount: MilliSatoshis, paymentHash: Sha256Digest, fromChannelId: FundedChannelId, - timestamp: FiniteDuration) extends WebSocketEvent + timestamp: FiniteDuration) + extends WebSocketEvent - case class PaymentFailed( - paymentHash: Sha256Digest, - failures: Vector[String]) extends WebSocketEvent + case class PaymentFailed(paymentHash: Sha256Digest, failures: Vector[String]) + extends WebSocketEvent case class PaymentSent( amount: MilliSatoshis, @@ -349,11 +362,13 @@ object WebSocketEvent { paymentHash: Sha256Digest, paymentPreimage: PaymentPreimage, toChannelId: FundedChannelId, - timestamp: FiniteDuration) extends WebSocketEvent + timestamp: FiniteDuration) + extends WebSocketEvent case class PaymentSettlingOnchain( amount: MilliSatoshis, paymentHash: Sha256Digest, - timestamp: FiniteDuration) extends WebSocketEvent + timestamp: FiniteDuration) + extends WebSocketEvent -} \ No newline at end of file +} diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/json/JsonReaders.scala b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/json/JsonReaders.scala index f656180f83..e700128e03 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/json/JsonReaders.scala +++ b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/json/JsonReaders.scala @@ -122,14 +122,13 @@ object JsonReaders { description <- (jsValue \ "description").validate[String] paymentHash <- (jsValue \ "paymentHash").validate[Sha256Digest] expiry <- (jsValue \ "expiry").validate[Long] - } yield - InvoiceResult(prefix, - timestamp.seconds, - nodeId, - serialized, - description, - paymentHash, - expiry.seconds) + } yield InvoiceResult(prefix, + timestamp.seconds, + nodeId, + serialized, + description, + paymentHash, + expiry.seconds) } } @@ -145,13 +144,12 @@ object JsonReaders { localMsat <- (jsValue \ "data" \ "commitments" \ "localCommit" \ "spec" \ "toLocalMsat") .validate[MilliSatoshis] - } yield - OpenChannelInfo(nodeId = nodeId, - shortChannelId = shortChannelId, - channelId = channelId, - localMsat = localMsat, - remoteMsat = remoteMsat, - state = state) + } yield OpenChannelInfo(nodeId = nodeId, + shortChannelId = shortChannelId, + channelId = channelId, + localMsat = localMsat, + remoteMsat = remoteMsat, + state = state) } implicit val baseChannelInfoReads: Reads[BaseChannelInfo] = Reads { jsValue => @@ -164,12 +162,11 @@ object JsonReaders { localMsat <- (jsValue \ "data" \ "commitments" \ "localCommit" \ "spec" \ "toLocalMsat") .validate[MilliSatoshis] - } yield - BaseChannelInfo(nodeId = nodeId, - channelId = channelId, - localMsat = localMsat, - remoteMsat = remoteMsat, - state = state) + } yield BaseChannelInfo(nodeId = nodeId, + channelId = channelId, + localMsat = localMsat, + remoteMsat = remoteMsat, + state = state) } implicit val channelInfoReads: Reads[ChannelInfo] = Reads { jsValue => @@ -220,13 +217,12 @@ object JsonReaders { feeProportional <- (js \ "data" \ "channelUpdate" \ "feeProportionalMillionths") .validateOpt[FeeProportionalMillionths] data <- (js \ "data").validate[JsObject] - } yield - ChannelResult(nodeId = nodeId, - state = state, - channelId = channelId, - feeBaseMsat = feeBaseMsat, - feeProportionalMillionths = feeProportional, - data = data) + } yield ChannelResult(nodeId = nodeId, + state = state, + channelId = channelId, + feeBaseMsat = feeBaseMsat, + feeProportionalMillionths = feeProportional, + data = data) } implicit val lnInvoiceReads: Reads[LnInvoice] = diff --git a/node-test/src/test/scala/org/bitcoins/node/NodeAppConfigTest.scala b/node-test/src/test/scala/org/bitcoins/node/NodeAppConfigTest.scala index 77f0c0882b..a444839100 100644 --- a/node-test/src/test/scala/org/bitcoins/node/NodeAppConfigTest.scala +++ b/node-test/src/test/scala/org/bitcoins/node/NodeAppConfigTest.scala @@ -39,15 +39,15 @@ class NodeAppConfigTest extends BitcoinSUnitTest { val tempDir = Files.createTempDirectory("bitcoin-s") val tempFile = Files.createFile(tempDir.resolve("bitcoin-s.conf")) val confStr = """ - | bitcoin-s { - | network = testnet3 - | - | logging { - | level = off - | - | p2p = warn - | } - | } + | bitcoin-s { + | network = testnet3 + | + | logging { + | level = off + | + | p2p = warn + | } + | } """.stripMargin val _ = Files.write(tempFile, confStr.getBytes()) diff --git a/project/plugins.sbt b/project/plugins.sbt index 47a99438a4..344309ac4c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -29,3 +29,5 @@ addSbtPlugin("org.scalameta" % "sbt-mdoc" % "1.3.2") // SQL migrations addSbtPlugin("io.github.davidmweber" % "flyway-sbt" % "6.0.0") + +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.1") diff --git a/testkit/src/main/scala/org/bitcoins/testkit/BitcoinSTestAppConfig.scala b/testkit/src/main/scala/org/bitcoins/testkit/BitcoinSTestAppConfig.scala index ef65d769f2..67fee87815 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/BitcoinSTestAppConfig.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/BitcoinSTestAppConfig.scala @@ -17,11 +17,11 @@ object BitcoinSTestAppConfig { def getTestConfig(config: Config*): BitcoinSAppConfig = { val overrideConf = ConfigFactory.parseString { """ - |bitcoin-s { - | logging { - | level = WARN - | } - |} + |bitcoin-s { + | logging { + | level = WARN + | } + |} """.stripMargin } val tmpDir = Files.createTempDirectory("bitcoin-s-") @@ -47,12 +47,12 @@ object BitcoinSTestAppConfig { def memConfigForProject(project: ProjectType): String = { val name = project.toString().toLowerCase() s""" - | $name.db { - | url = "jdbc:sqlite:file:$name.db:?mode=memory&cache=shared" - | connectionPool = disabled - | keepAliveConnection = true - | } - |""".stripMargin + | $name.db { + | url = "jdbc:sqlite:file:$name.db:?mode=memory&cache=shared" + | connectionPool = disabled + | keepAliveConnection = true + | } + |""".stripMargin } val confStr = project match { @@ -60,10 +60,10 @@ object BitcoinSTestAppConfig { case Some(p) => memConfigForProject(p) } val nestedConfStr = s""" - | bitcoin-s { - | $confStr - | } - |""".stripMargin + | bitcoin-s { + | $confStr + | } + |""".stripMargin ConfigFactory.parseString(nestedConfStr) } diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/BlockchainElementsGenerator.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/BlockchainElementsGenerator.scala index 03c0f39795..232c8bb961 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/BlockchainElementsGenerator.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/BlockchainElementsGenerator.scala @@ -72,13 +72,12 @@ sealed abstract class BlockchainElementsGenerator { merkleRootHash = Merkle.computeMerkleRoot(txs) time <- NumberGenerator.uInt32s nonce <- NumberGenerator.uInt32s - } yield - BlockHeader(version, - previousBlockHash, - merkleRootHash, - time, - nBits, - nonce) + } yield BlockHeader(version, + previousBlockHash, + merkleRootHash, + time, + nBits, + nonce) /** Generates a [[org.bitcoins.core.protocol.blockchain.BlockHeader BlockHeader]] that has a merkle root * hash corresponding to the given txs */ diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/HDGenerators.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/HDGenerators.scala index 9cc0821429..ab6c2af5e6 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/HDGenerators.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/HDGenerators.scala @@ -105,11 +105,10 @@ object HDGenerators { accountIndex <- NumberGenerator.positiveInts addressIndex <- NumberGenerator.positiveInts chainType <- hdChainType - } yield - LegacyHDPath(coinType = coinType, - addressIndex = addressIndex, - accountIndex = accountIndex, - chainType = chainType) + } yield LegacyHDPath(coinType = coinType, + addressIndex = addressIndex, + accountIndex = accountIndex, + chainType = chainType) def segwithHdPath: Gen[SegWitHDPath] = for { @@ -117,11 +116,10 @@ object HDGenerators { accountIndex <- NumberGenerator.positiveInts addressIndex <- NumberGenerator.positiveInts chainType <- hdChainType - } yield - SegWitHDPath(coinType = coinType, - addressIndex = addressIndex, - accountIndex = accountIndex, - chainType = chainType) + } yield SegWitHDPath(coinType = coinType, + addressIndex = addressIndex, + accountIndex = accountIndex, + chainType = chainType) def nestedSegwithHdPath: Gen[NestedSegWitHDPath] = for { @@ -129,11 +127,10 @@ object HDGenerators { accountIndex <- NumberGenerator.positiveInts addressIndex <- NumberGenerator.positiveInts chainType <- hdChainType - } yield - NestedSegWitHDPath(coinType = coinType, - addressIndex = addressIndex, - accountIndex = accountIndex, - chainType = chainType) + } yield NestedSegWitHDPath(coinType = coinType, + addressIndex = addressIndex, + accountIndex = accountIndex, + chainType = chainType) def hdPath: Gen[HDPath] = Gen.oneOf(legacyHdPath, segwithHdPath, nestedSegwithHdPath) @@ -143,12 +140,11 @@ object HDGenerators { def hdPathWithConstructor: Gen[(HDPath, HDPathConstructor)] = for { path <- hdPath - } yield - path match { - case legacy: LegacyHDPath => (legacy, LegacyHDPath(_)) - case nested: NestedSegWitHDPath => (nested, NestedSegWitHDPath(_)) - case segwit: SegWitHDPath => (segwit, SegWitHDPath(_)) - } + } yield path match { + case legacy: LegacyHDPath => (legacy, LegacyHDPath(_)) + case nested: NestedSegWitHDPath => (nested, NestedSegWitHDPath(_)) + case segwit: SegWitHDPath => (segwit, SegWitHDPath(_)) + } /** * Generates a pair of paths that can be diffed. diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ScriptGenerators.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ScriptGenerators.scala index f7c275e799..3f8c26e39b 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ScriptGenerators.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ScriptGenerators.scala @@ -37,11 +37,10 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger { val signatures: Gen[Seq[ECDigitalSignature]] = for { numKeys <- Gen.choose(1, Consensus.maxPublicKeysPerMultiSig) hash <- CryptoGenerators.doubleSha256Digest - } yield - for { - _ <- 0 until numKeys - privKey = ECPrivateKey() - } yield privKey.sign(hash) + } yield for { + _ <- 0 until numKeys + privKey = ECPrivateKey() + } yield privKey.sign(hash) signatures.map(sigs => MultiSignatureScriptSignature(sigs)) } @@ -414,35 +413,34 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger { (scriptPubKey, privKeys) <- randomNonLockTimeNonP2SHScriptPubKey hashType <- CryptoGenerators.hashType cltv = CLTVScriptPubKey(cltvLockTime, scriptPubKey) - } yield - scriptPubKey match { - case m: MultiSignatureScriptPubKey => - val requiredSigs = m.requiredSigs - val cltvScriptSig = lockTimeHelper(Some(lockTime), - sequence, - cltv, - privKeys, - Some(requiredSigs), - hashType) - (cltvScriptSig.asInstanceOf[CLTVScriptSignature], cltv, privKeys) - case _: P2PKHScriptPubKey | _: P2PKScriptPubKey => - val cltvScriptSig = lockTimeHelper(Some(lockTime), - sequence, - cltv, - privKeys, - None, - hashType) - (cltvScriptSig.asInstanceOf[CLTVScriptSignature], cltv, privKeys) - case _: UnassignedWitnessScriptPubKey | _: WitnessScriptPubKeyV0 => - throw new IllegalArgumentException( - "Cannot created a witness scriptPubKey for a CSVScriptSig since we do not have a witness") - case _: P2SHScriptPubKey | _: CLTVScriptPubKey | _: CSVScriptPubKey | - _: NonStandardScriptPubKey | _: WitnessCommitment | - EmptyScriptPubKey => - throw new IllegalArgumentException( - "We only " + - "want to generate P2PK, P2PKH, and MultiSig ScriptSignatures when creating a CSVScriptSignature") - } + } yield scriptPubKey match { + case m: MultiSignatureScriptPubKey => + val requiredSigs = m.requiredSigs + val cltvScriptSig = lockTimeHelper(Some(lockTime), + sequence, + cltv, + privKeys, + Some(requiredSigs), + hashType) + (cltvScriptSig.asInstanceOf[CLTVScriptSignature], cltv, privKeys) + case _: P2PKHScriptPubKey | _: P2PKScriptPubKey => + val cltvScriptSig = lockTimeHelper(Some(lockTime), + sequence, + cltv, + privKeys, + None, + hashType) + (cltvScriptSig.asInstanceOf[CLTVScriptSignature], cltv, privKeys) + case _: UnassignedWitnessScriptPubKey | _: WitnessScriptPubKeyV0 => + throw new IllegalArgumentException( + "Cannot created a witness scriptPubKey for a CSVScriptSig since we do not have a witness") + case _: P2SHScriptPubKey | _: CLTVScriptPubKey | _: CSVScriptPubKey | + _: NonStandardScriptPubKey | _: WitnessCommitment | + EmptyScriptPubKey => + throw new IllegalArgumentException( + "We only " + + "want to generate P2PK, P2PKH, and MultiSig ScriptSignatures when creating a CSVScriptSignature") + } /** * Generates a signed `CLTVScriptSignature` that spends @@ -461,31 +459,30 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger { (scriptPubKey, privKeys) <- randomNonLockTimeNonP2SHScriptPubKey hashType <- CryptoGenerators.hashType csv = CSVScriptPubKey(csvScriptNum, scriptPubKey) - } yield - scriptPubKey match { - case m: MultiSignatureScriptPubKey => - val requiredSigs = m.requiredSigs - val csvScriptSig = lockTimeHelper(None, - sequence, - csv, - privKeys, - Some(requiredSigs), - hashType) - (csvScriptSig.asInstanceOf[CSVScriptSignature], csv, privKeys) - case _: P2PKHScriptPubKey | _: P2PKScriptPubKey => - val csvScriptSig = - lockTimeHelper(None, sequence, csv, privKeys, None, hashType) - (csvScriptSig.asInstanceOf[CSVScriptSignature], csv, privKeys) - case _: UnassignedWitnessScriptPubKey | _: WitnessScriptPubKeyV0 => - throw new IllegalArgumentException( - "Cannot created a witness scriptPubKey for a CSVScriptSig since we do not have a witness") - case _: P2SHScriptPubKey | _: CLTVScriptPubKey | _: CSVScriptPubKey | - _: NonStandardScriptPubKey | _: WitnessCommitment | - EmptyScriptPubKey => - throw new IllegalArgumentException( - "We only " + - "want to generate P2PK, P2PKH, and MultiSig ScriptSignatures when creating a CLTVScriptSignature.") - } + } yield scriptPubKey match { + case m: MultiSignatureScriptPubKey => + val requiredSigs = m.requiredSigs + val csvScriptSig = lockTimeHelper(None, + sequence, + csv, + privKeys, + Some(requiredSigs), + hashType) + (csvScriptSig.asInstanceOf[CSVScriptSignature], csv, privKeys) + case _: P2PKHScriptPubKey | _: P2PKScriptPubKey => + val csvScriptSig = + lockTimeHelper(None, sequence, csv, privKeys, None, hashType) + (csvScriptSig.asInstanceOf[CSVScriptSignature], csv, privKeys) + case _: UnassignedWitnessScriptPubKey | _: WitnessScriptPubKeyV0 => + throw new IllegalArgumentException( + "Cannot created a witness scriptPubKey for a CSVScriptSig since we do not have a witness") + case _: P2SHScriptPubKey | _: CLTVScriptPubKey | _: CSVScriptPubKey | + _: NonStandardScriptPubKey | _: WitnessCommitment | + EmptyScriptPubKey => + throw new IllegalArgumentException( + "We only " + + "want to generate P2PK, P2PKH, and MultiSig ScriptSignatures when creating a CLTVScriptSignature.") + } def signedCSVScriptSignature: Gen[ (CSVScriptSignature, CSVScriptPubKey, Seq[ECPrivateKey])] = @@ -543,10 +540,9 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger { val txSignatures: Seq[ECDigitalSignature] = for { i <- 0 until requiredSigs.getOrElse(1) - } yield - TransactionSignatureCreator.createSig(txSignatureComponent, - privateKeys(i), - hashType) + } yield TransactionSignatureCreator.createSig(txSignatureComponent, + privateKeys(i), + hashType) lock match { case csv: CSVScriptPubKey => @@ -572,12 +568,11 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger { p2shScriptPubKey = P2SHScriptPubKey(wtxSigComponent.scriptPubKey) p2shScriptSig = P2SHScriptSignature( wtxSigComponent.scriptPubKey.asInstanceOf[WitnessScriptPubKey]) - } yield - (p2shScriptSig, - p2shScriptPubKey, - privKeys, - witness, - wtxSigComponent.amount) + } yield (p2shScriptSig, + p2shScriptPubKey, + privKeys, + witness, + wtxSigComponent.amount) def signedP2SHP2WSHScriptSignature: Gen[ ( @@ -590,12 +585,11 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger { (witness, wtxSigComponent, privKeys) <- WitnessGenerators.signedP2WSHTransactionWitness p2shScriptPubKey = P2SHScriptPubKey(wtxSigComponent.scriptPubKey) p2shScriptSig = P2SHScriptSignature(wtxSigComponent.scriptPubKey) - } yield - (p2shScriptSig, - p2shScriptPubKey, - privKeys, - witness, - wtxSigComponent.amount) + } yield (p2shScriptSig, + p2shScriptPubKey, + privKeys, + witness, + wtxSigComponent.amount) /** * This function chooses a random signed `ScriptSignature` diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/TransactionGenerators.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/TransactionGenerators.scala index cc353615af..71e0fe4db3 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/TransactionGenerators.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/TransactionGenerators.scala @@ -355,12 +355,11 @@ object TransactionGenerators extends BitcoinSLogger { for { (signedScriptSig, csvScriptPubKey, privateKeys) <- ScriptGenerators .signedCSVScriptSignature(csvScriptNum, sequence) - } yield - lockTimeTxHelper(signedScriptSig, - csvScriptPubKey, - privateKeys, - sequence, - None) + } yield lockTimeTxHelper(signedScriptSig, + csvScriptPubKey, + privateKeys, + sequence, + None) /** Generates a [[org.bitcoins.core.protocol.transaction.WitnessTransaction WitnessTransaction]] that has all of * it's inputs signed correctly */ diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/WitnessGenerators.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/WitnessGenerators.scala index 9a2e27c47c..3ca884c66b 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/WitnessGenerators.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/WitnessGenerators.scala @@ -192,10 +192,9 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger { val requiredSigs = scriptPubKey.requiredSigs val txSignatures = for { i <- 0 until requiredSigs - } yield - TransactionSignatureCreator.createSig(unsignedWtxSigComponent, - privateKeys(i), - hashType) + } yield TransactionSignatureCreator.createSig(unsignedWtxSigComponent, + privateKeys(i), + hashType) //add the signature to the scriptSig instead of having an empty scriptSig val signedScriptSig = MultiSignatureScriptSignature(txSignatures) diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ln/LnInvoiceGen.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ln/LnInvoiceGen.scala index 1610acec15..6f596b6382 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ln/LnInvoiceGen.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ln/LnInvoiceGen.scala @@ -101,16 +101,15 @@ sealed abstract class LnInvoiceGen { for { paymentHash <- paymentHashTag descOrHashTag <- descriptionOrDescriptionHashTag - } yield - LnTaggedFields( - paymentHash = paymentHash, - descriptionOrHash = descOrHashTag, - expiryTime = None, - cltvExpiry = None, - fallbackAddress = None, - nodeId = None, - routingInfo = None - ) + } yield LnTaggedFields( + paymentHash = paymentHash, + descriptionOrHash = descOrHashTag, + expiryTime = None, + cltvExpiry = None, + fallbackAddress = None, + nodeId = None, + routingInfo = None + ) } def optionalTags(nodeIdOpt: Option[NodeId]): Gen[LnTaggedFields] = { @@ -123,16 +122,15 @@ sealed abstract class LnInvoiceGen { cltvExpiry <- Gen.option(cltvExpiry) fallbackAddress <- Gen.option(fallbackAddress) routes <- Gen.option(routingInfo) - } yield - LnTaggedFields( - paymentHash = paymentHash, - descriptionOrHash = descOrHashTag, - expiryTime = expiryTime, - cltvExpiry = cltvExpiry, - fallbackAddress = fallbackAddress, - nodeId = nodeIdOpt.map(NodeIdTag(_)), - routingInfo = routes - ) + } yield LnTaggedFields( + paymentHash = paymentHash, + descriptionOrHash = descOrHashTag, + expiryTime = expiryTime, + cltvExpiry = cltvExpiry, + fallbackAddress = fallbackAddress, + nodeId = nodeIdOpt.map(NodeIdTag(_)), + routingInfo = routes + ) } def allTags(nodeIdOpt: Option[NodeId]): Gen[LnTaggedFields] = { @@ -145,16 +143,15 @@ sealed abstract class LnInvoiceGen { cltvExpiry <- cltvExpiry fallbackAddress <- fallbackAddress routes <- routingInfo - } yield - LnTaggedFields( - paymentHash = paymentHash, - descriptionOrHash = descOrHashTag, - expiryTime = Some(expiryTime), - cltvExpiry = Some(cltvExpiry), - fallbackAddress = Some(fallbackAddress), - nodeId = nodeIdOpt.map(NodeIdTag(_)), - routingInfo = Some(routes) - ) + } yield LnTaggedFields( + paymentHash = paymentHash, + descriptionOrHash = descOrHashTag, + expiryTime = Some(expiryTime), + cltvExpiry = Some(cltvExpiry), + fallbackAddress = Some(fallbackAddress), + nodeId = nodeIdOpt.map(NodeIdTag(_)), + routingInfo = Some(routes) + ) } /** Generated a tagged fields with an explicit diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ln/LnRouteGen.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ln/LnRouteGen.scala index 30ebcd6445..28ed2e1109 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ln/LnRouteGen.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/ln/LnRouteGen.scala @@ -39,12 +39,11 @@ trait LnRouteGen { baseFee <- feeBaseMSat feeProp <- feeProportionalMillionths cltvExpiryDelta <- NumberGenerator.positiveShort - } yield - LnRoute(pubkey = pubKey, - shortChannelID = id, - feeBaseMsat = baseFee, - feePropMilli = feeProp, - cltvExpiryDelta = cltvExpiryDelta) + } yield LnRoute(pubkey = pubKey, + shortChannelID = id, + feeBaseMsat = baseFee, + feePropMilli = feeProp, + cltvExpiryDelta = cltvExpiryDelta) def routes: Gen[Vector[LnRoute]] = { Gen diff --git a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/p2p/ControlMessageGenerator.scala b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/p2p/ControlMessageGenerator.scala index 92d1ffe86c..a62992d29d 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/core/gen/p2p/ControlMessageGenerator.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/core/gen/p2p/ControlMessageGenerator.scala @@ -38,13 +38,12 @@ object ControlMessageGenerator { for { fee <- CurrencyUnitGenerator.feeUnit.suchThat( !_.isInstanceOf[SatoshisPerVirtualByte]) - } yield - fee match { - case fee: SatoshisPerByte => FeeFilterMessage(fee) - case fee: SatoshisPerKiloByte => FeeFilterMessage(fee) - case SatoshisPerVirtualByte(_) => - throw new RuntimeException(s"We cannot end up here") - } + } yield fee match { + case fee: SatoshisPerByte => FeeFilterMessage(fee) + case fee: SatoshisPerKiloByte => FeeFilterMessage(fee) + case SatoshisPerVirtualByte(_) => + throw new RuntimeException(s"We cannot end up here") + } } /** @@ -67,22 +66,21 @@ object ControlMessageGenerator { userAgent <- StringGenerators.genString startHeight <- NumberGenerator.int32s relay = scala.util.Random.nextInt() % 2 == 0 - } yield - VersionMessage( - version, - identifier, - timestamp, - addressReceiveServices, - addressReceiveIpAddress, - addressReceivePort, - addressTransServices, - addressTransIpAddress, - addressTransPort, - nonce, - userAgent, - startHeight, - relay - ) + } yield VersionMessage( + version, + identifier, + timestamp, + addressReceiveServices, + addressReceiveIpAddress, + addressReceivePort, + addressTransServices, + addressTransIpAddress, + addressTransPort, + nonce, + userAgent, + startHeight, + relay + ) /** * Generates a [[org.bitcoins.core.p2p.PingMessage]] @@ -154,8 +152,10 @@ object ControlMessageGenerator { hashFuncs <- Gen.choose(0, 50) tweak <- NumberGenerator.uInt32s flags <- BloomFilterGenerator.bloomFlag - } yield - FilterLoadMessage(ByteVector(filter), UInt32(hashFuncs), tweak, flags) + } yield FilterLoadMessage(ByteVector(filter), + UInt32(hashFuncs), + tweak, + flags) /** * Creates a [[org.bitcoins.core.p2p.FilterAddMessage]] diff --git a/testkit/src/main/scala/org/bitcoins/testkit/util/BitcoindRpcTest.scala b/testkit/src/main/scala/org/bitcoins/testkit/util/BitcoindRpcTest.scala index 8e85ed3822..7e60ca7b51 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/util/BitcoindRpcTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/util/BitcoindRpcTest.scala @@ -27,7 +27,7 @@ abstract class BitcoindRpcTest extends AsyncFlatSpec with BeforeAndAfterAll { sys.error { val msg = s""""bitcoind binary directory (${BitcoindRpcTestUtil.binaryDirectory}) is empty. - |Run 'sbt downloadBitcoind' to fetch needed binaries""".stripMargin + |Run 'sbt downloadBitcoind' to fetch needed binaries""".stripMargin msg } } diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletAppConfigTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletAppConfigTest.scala index a638dac1a6..4f1ce71539 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletAppConfigTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletAppConfigTest.scala @@ -38,10 +38,10 @@ class WalletAppConfigTest extends BitcoinSUnitTest { it should "not matter how the overrides are passed in" in { val overrider = ConfigFactory.parseString(s""" - |bitcoin-s { - | network = mainnet - |} - |""".stripMargin) + |bitcoin-s { + | network = mainnet + |} + |""".stripMargin) val throughConstuctor = WalletAppConfig(tempDir, overrider) val throughWithOverrides = config.withOverrides(overrider) @@ -82,15 +82,15 @@ class WalletAppConfigTest extends BitcoinSUnitTest { val tempDir = Files.createTempDirectory("bitcoin-s") val tempFile = Files.createFile(tempDir.resolve("bitcoin-s.conf")) val confStr = """ - | bitcoin-s { - | network = testnet3 - | - | logging { - | level = off - | - | p2p = warn - | } - | } + | bitcoin-s { + | network = testnet3 + | + | logging { + | level = off + | + | p2p = warn + | } + | } """.stripMargin val _ = Files.write(tempFile, confStr.getBytes()) diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletStorageTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletStorageTest.scala index dd755485a5..14a8a4dd87 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/WalletStorageTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/WalletStorageTest.scala @@ -91,11 +91,11 @@ class WalletStorageTest it must "fail to read a mnemonic that has bad JSON in it" in { _ => val badJson = """ - | { - | "iv":"ba7722683dad8067df8d069ee04530cc", - | "cipherText":, - | "salt":"2b7e7d718139518070a87fbbda03ea33cdcda83b555020e9344774e6e7d08af2" - | } + | { + | "iv":"ba7722683dad8067df8d069ee04530cc", + | "cipherText":, + | "salt":"2b7e7d718139518070a87fbbda03ea33cdcda83b555020e9344774e6e7d08af2" + | } """.stripMargin Files.write(datadir.resolve(WalletStorage.ENCRYPTED_SEED_FILE_NAME), badJson.getBytes()) diff --git a/wallet-test/src/test/scala/org/bitcoins/wallet/models/SpendingInfoDAOTest.scala b/wallet-test/src/test/scala/org/bitcoins/wallet/models/SpendingInfoDAOTest.scala index f67d9d26a2..05aa59e14f 100644 --- a/wallet-test/src/test/scala/org/bitcoins/wallet/models/SpendingInfoDAOTest.scala +++ b/wallet-test/src/test/scala/org/bitcoins/wallet/models/SpendingInfoDAOTest.scala @@ -25,12 +25,11 @@ class SpendingInfoDAOTest extends BitcoinSWalletTest with WalletDAOFixture { for { created <- WalletTestUtil.insertSegWitUTXO(daos) read <- utxoDAO.read(created.id.get) - } yield - read match { - case None => fail(s"Did not read back a UTXO") - case Some(_: SegwitV0SpendingInfo) => succeed - case Some(other) => fail(s"did not get segwit UTXO: $other") - } + } yield read match { + case None => fail(s"Did not read back a UTXO") + case Some(_: SegwitV0SpendingInfo) => succeed + case Some(other) => fail(s"did not get segwit UTXO: $other") + } } it should "insert a legacy UTXO and read it" in { daos => @@ -38,12 +37,11 @@ class SpendingInfoDAOTest extends BitcoinSWalletTest with WalletDAOFixture { for { created <- WalletTestUtil.insertLegacyUTXO(daos) read <- utxoDAO.read(created.id.get) - } yield - read match { - case None => fail(s"Did not read back a UTXO") - case Some(_: LegacySpendingInfo) => succeed - case Some(other) => fail(s"did not get a legacy UTXO: $other") - } + } yield read match { + case None => fail(s"Did not read back a UTXO") + case Some(_: LegacySpendingInfo) => succeed + case Some(other) => fail(s"did not get a legacy UTXO: $other") + } } it should "find incoming outputs being spent, given a TX" in { daos => diff --git a/wallet/src/main/scala/org/bitcoins/wallet/internal/AddressHandling.scala b/wallet/src/main/scala/org/bitcoins/wallet/internal/AddressHandling.scala index 65266009b7..da3b54fdf8 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/internal/AddressHandling.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/internal/AddressHandling.scala @@ -47,11 +47,10 @@ private[wallet] trait AddressHandling extends KeyHandlingLogger { Vector[(TransactionOutput, TransactionOutPoint)]] = for { spks <- listSPKs() - } yield - transaction.outputs.zipWithIndex.collect { - case (out, index) if spks.contains(out.scriptPubKey) => - (out, TransactionOutPoint(transaction.txId, UInt32(index))) - }.toVector + } yield transaction.outputs.zipWithIndex.collect { + case (out, index) if spks.contains(out.scriptPubKey) => + (out, TransactionOutPoint(transaction.txId, UInt32(index))) + }.toVector /** * Derives a new address in the wallet for the diff --git a/wallet/src/main/scala/org/bitcoins/wallet/internal/UtxoHandling.scala b/wallet/src/main/scala/org/bitcoins/wallet/internal/UtxoHandling.scala index 946b94785e..000858c5d7 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/internal/UtxoHandling.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/internal/UtxoHandling.scala @@ -134,13 +134,12 @@ private[wallet] trait UtxoHandling extends KeyHandlingLogger { addressDbEitherF.flatMap { addressDbE => val biasedE: CompatEither[AddUtxoError, Future[SpendingInfoDb]] = for { addressDb <- addressDbE - } yield - writeUtxo(txid = transaction.txIdBE, - confirmations = confirmations, - spent = spent, - output, - outPoint, - addressDb) + } yield writeUtxo(txid = transaction.txIdBE, + confirmations = confirmations, + spent = spent, + output, + outPoint, + addressDb) EitherUtil.liftRightBiasedFutureE(biasedE) } map { diff --git a/zmq/src/main/scala/org/bitcoins/zmq/ZMQSubscriber.scala b/zmq/src/main/scala/org/bitcoins/zmq/ZMQSubscriber.scala index 6f9831ad5c..3e03c3b6d0 100644 --- a/zmq/src/main/scala/org/bitcoins/zmq/ZMQSubscriber.scala +++ b/zmq/src/main/scala/org/bitcoins/zmq/ZMQSubscriber.scala @@ -19,20 +19,18 @@ import scodec.bits.ByteVector * @param rawBlockListener */ class ZMQSubscriber( - socket: InetSocketAddress, - hashTxListener: Option[ByteVector => Unit], - hashBlockListener: Option[ByteVector => Unit], - rawTxListener: Option[ByteVector => Unit], - rawBlockListener: Option[ByteVector => Unit]) - extends BitcoinSLogger { + socket: InetSocketAddress, + hashTxListener: Option[ByteVector => Unit], + hashBlockListener: Option[ByteVector => Unit], + rawTxListener: Option[ByteVector => Unit], + rawBlockListener: Option[ByteVector => Unit]) + extends BitcoinSLogger { private var running = true private val context = ZMQ.context(1) private val subscriber: ZMQ.Socket = context.socket(SocketType.SUB) - - private val uri = socket.getHostString + ":" + socket.getPort private case object SubscriberRunnable extends Runnable { @@ -91,7 +89,8 @@ class ZMQSubscriber( } private val subscriberThread = new Thread(SubscriberRunnable) - subscriberThread.setName(s"ZMQSubscriber-thread-${System.currentTimeMillis()}") + subscriberThread.setName( + s"ZMQSubscriber-thread-${System.currentTimeMillis()}") subscriberThread.setDaemon(true) def start(): Unit = {