mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-19 13:35:17 +01:00
2020 12 18 enable lint options (#2454)
* Enable -Xlint:adapted-args,nullary-unit on our for compile scope * Add Xlint:infer-any compiler option * Fix build so test compiler options are actually enabled * Enable more scalac linting options * Add '-Xlint:eta-sam' * Add 'Xlint:inaccessible,Xlint:missing-interpolator'
This commit is contained in:
parent
8e6a37e988
commit
b0b56dd5da
22 changed files with 75 additions and 39 deletions
|
@ -186,7 +186,7 @@ object InitNumericContractDialog {
|
|||
) {
|
||||
val outcome = BigDecimal(outcomeTF.text.value.toDouble)
|
||||
val level = roundingLevelTF.text.value.toLong
|
||||
Some(outcome, level)
|
||||
Some((outcome, level))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ case class Server(
|
|||
|
||||
val route: Route =
|
||||
// TODO implement better logging
|
||||
DebuggingDirectives.logRequestResult("http-rpc-server", Logging.InfoLevel) {
|
||||
DebuggingDirectives.logRequestResult(
|
||||
("http-rpc-server", Logging.InfoLevel)) {
|
||||
withErrorHandling {
|
||||
pathSingleSlash {
|
||||
post {
|
||||
|
|
|
@ -164,10 +164,17 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger {
|
|||
}
|
||||
|
||||
val batchSize = 25
|
||||
val batchedExecutedF = FutureUtil.batchExecute(elements = blockHashes,
|
||||
f = f,
|
||||
init = Vector.empty,
|
||||
batchSize = batchSize)
|
||||
val batchedExecutedF = {
|
||||
for {
|
||||
wallet <- walletF
|
||||
wallet <- FutureUtil.batchExecute[DoubleSha256Digest, Wallet](
|
||||
elements = blockHashes,
|
||||
f = f,
|
||||
init = wallet,
|
||||
batchSize = batchSize)
|
||||
} yield wallet
|
||||
|
||||
}
|
||||
|
||||
batchedExecutedF.map { _ =>
|
||||
logger.info(
|
||||
|
|
|
@ -289,6 +289,7 @@ lazy val oracleServer = project
|
|||
lazy val serverRoutes = project
|
||||
.in(file("app/server-routes"))
|
||||
.settings(CommonSettings.prodSettings: _*)
|
||||
.settings(name := "bitcoin-s-server-routes")
|
||||
.settings(libraryDependencies ++= Deps.serverRoutes)
|
||||
.dependsOn(appCommons, dbCommons)
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ object CoreTestCaseProtocol extends DefaultJsonProtocol with BitcoinSLogger {
|
|||
expectedResult,
|
||||
"",
|
||||
elements.toString,
|
||||
Some(witness, amount)))
|
||||
Some((witness, amount))))
|
||||
} else if (elements.size == 5) {
|
||||
val scriptPubKeyBytes: ByteVector = parseScriptPubKey(elements(1))
|
||||
val scriptPubKey = ScriptPubKey(scriptPubKeyBytes)
|
||||
|
@ -112,7 +112,7 @@ object CoreTestCaseProtocol extends DefaultJsonProtocol with BitcoinSLogger {
|
|||
expectedResult,
|
||||
comments,
|
||||
elements.toString,
|
||||
Some(witness, amount)))
|
||||
Some((witness, amount))))
|
||||
} else None
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.bitcoins.crypto.StringFactory
|
|||
|
||||
import scala.util.{Failure, Success, Try}
|
||||
|
||||
private[bitcoins] trait HDPath extends BIP32Path {
|
||||
trait HDPath extends BIP32Path {
|
||||
|
||||
/**
|
||||
* This type is to give a cleaner return
|
||||
|
|
|
@ -392,7 +392,7 @@ object DLCMessage {
|
|||
val offerPayout = offerContractInfo(msg)
|
||||
val acceptPayout = (totalCollateral - offerPayout).satoshis
|
||||
|
||||
builder.+=(msg -> (oracleInfo.sigPoint(msg), offerPayout, acceptPayout))
|
||||
builder.+=((msg, (oracleInfo.sigPoint(msg), offerPayout, acceptPayout)))
|
||||
}
|
||||
|
||||
builder.result()
|
||||
|
|
|
@ -172,7 +172,7 @@ object BaseTransaction extends Factory[BaseTransaction] {
|
|||
|
||||
def unapply(tx: NonWitnessTransaction): Option[
|
||||
(Int32, Seq[TransactionInput], Seq[TransactionOutput], UInt32)] = {
|
||||
Some(tx.version, tx.inputs, tx.outputs, tx.lockTime)
|
||||
Some((tx.version, tx.inputs, tx.outputs, tx.lockTime))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,10 @@ sealed abstract class Base58 {
|
|||
val decoded = decode(base58)
|
||||
val firstByte = decoded.head
|
||||
val compressedPubKey = List('K', 'L', 'c').contains(base58.head)
|
||||
if (base58.contains(List('0', 'O', 'l', 'I'))) false
|
||||
val hasInvalidChar: Boolean = {
|
||||
Vector('0', 'O', 'l', 'I').exists(c => base58.contains(c))
|
||||
}
|
||||
if (hasInvalidChar) false
|
||||
else if (compressedPubKey) checkCompressedPubKeyValidity(base58)
|
||||
else if (isValidAddressPreFixByte(firstByte))
|
||||
base58.length >= 26 && base58.length <= 35
|
||||
|
|
|
@ -193,7 +193,7 @@ object AesKey {
|
|||
* and must be 16, 24 or 32 bytes long.
|
||||
*/
|
||||
def fromBytes(bytes: ByteVector): Option[AesKey] = {
|
||||
if (keylengths.contains(bytes.length)) {
|
||||
if (keylengths.exists(k => k == bytes.length)) {
|
||||
Some(AesKey(bytes))
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -860,7 +860,7 @@ class EclairRpcClient(
|
|||
.get()} for paymentId=${paymentId} for interval=${interval}"))
|
||||
} else {
|
||||
val resultsF = getSentInfo(paymentId)
|
||||
resultsF.recover {
|
||||
resultsF.failed.foreach {
|
||||
case e: Throwable =>
|
||||
logger.error(
|
||||
s"Cannot check payment status for paymentId=${paymentId}",
|
||||
|
|
|
@ -49,7 +49,7 @@ abstract class CachedHttpFeeRateProvider extends HttpFeeRateProvider {
|
|||
private def updateFeeRate(): Future[FeeUnit] = {
|
||||
implicit val ec: ExecutionContextExecutor = system.dispatcher
|
||||
super.getFeeRate.map { feeRate =>
|
||||
cachedFeeRateOpt = Some(feeRate, TimeUtil.now)
|
||||
cachedFeeRateOpt = Some((feeRate, TimeUtil.now))
|
||||
feeRate
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class NeutrinoNodeTest extends NodeUnitTest {
|
|||
}
|
||||
|
||||
def callbacks: NodeCallbacks = {
|
||||
NodeCallbacks(onBlockReceived = Vector(blockCallback))
|
||||
NodeCallbacks(onBlockReceived = Vector(blockCallback(_)))
|
||||
}
|
||||
|
||||
behavior of "NeutrinoNode"
|
||||
|
|
|
@ -60,7 +60,7 @@ class DataMessageHandlerTest extends NodeUnitTest {
|
|||
_ <- dataMessageHandler.handleDataPayload(payload1, sender)
|
||||
_ <- dataMessageHandler.handleDataPayload(payload2, sender)
|
||||
result <- resultP.future
|
||||
} yield assert(result == (merkleBlock, Vector(tx)))
|
||||
} yield assert(result == ((merkleBlock, Vector(tx))))
|
||||
}
|
||||
|
||||
it must "verify OnBlockReceived callbacks are executed" in {
|
||||
|
|
|
@ -68,7 +68,7 @@ final case class BroadcastAbleTransactionDAO()(implicit
|
|||
}
|
||||
|
||||
private val toTuple: BroadcastAbleTransaction => Option[Tuple] = tx =>
|
||||
Some(tx.transaction.txId.flip, tx.transaction.bytes)
|
||||
Some((tx.transaction.txId.flip, tx.transaction.bytes))
|
||||
|
||||
def txid: Rep[DoubleSha256DigestBE] = column("txid", O.PrimaryKey)
|
||||
def bytes: Rep[ByteVector] = column("tx_bytes")
|
||||
|
|
|
@ -41,7 +41,8 @@ object CommonSettings {
|
|||
apiURL := homepage.value.map(_.toString + "/api").map(url(_)),
|
||||
// scaladoc settings end
|
||||
////
|
||||
scalacOptions in Compile := compilerOpts(scalaVersion.value),
|
||||
scalacOptions in Compile := compilerOpts(scalaVersion = scalaVersion.value),
|
||||
Test / scalacOptions := testCompilerOpts(scalaVersion = scalaVersion.value),
|
||||
//remove annoying import unused things in the scala console
|
||||
//https://stackoverflow.com/questions/26940253/in-sbt-how-do-you-override-scalacoptions-for-console-in-all-configurations
|
||||
scalacOptions in (Compile, console) ~= (_ filterNot (s =>
|
||||
|
@ -75,7 +76,23 @@ object CommonSettings {
|
|||
)
|
||||
}
|
||||
|
||||
private val scala2_13CompilerOpts = Seq("-Xlint:unused", "-Xfatal-warnings")
|
||||
/** Linting options for scalac */
|
||||
private val scala2_13CompilerLinting = {
|
||||
Seq(
|
||||
"-Xlint:unused",
|
||||
"-Xlint:adapted-args",
|
||||
"-Xlint:nullary-unit",
|
||||
"-Xlint:inaccessible",
|
||||
"-Xlint:infer-any",
|
||||
"-Xlint:missing-interpolator",
|
||||
"-Xlint:eta-sam"
|
||||
)
|
||||
}
|
||||
|
||||
/** Compiler options for source code */
|
||||
private val scala2_13SourceCompilerOpts = {
|
||||
Seq("-Xfatal-warnings") ++ scala2_13CompilerLinting
|
||||
}
|
||||
|
||||
private val nonScala2_13CompilerOpts = Seq(
|
||||
"-Xmax-classfile-name",
|
||||
|
@ -85,10 +102,8 @@ object CommonSettings {
|
|||
)
|
||||
|
||||
//https://docs.scala-lang.org/overviews/compiler-options/index.html
|
||||
def compilerOpts(scalaVersion: String): Seq[String] =
|
||||
def compilerOpts(scalaVersion: String): Seq[String] = {
|
||||
Seq(
|
||||
"-encoding",
|
||||
"UTF-8",
|
||||
"-unchecked",
|
||||
"-feature",
|
||||
"-deprecation",
|
||||
|
@ -101,9 +116,11 @@ object CommonSettings {
|
|||
"-Ypatmat-exhaust-depth",
|
||||
"off"
|
||||
) ++ commonCompilerOpts ++ {
|
||||
if (scalaVersion.startsWith("2.13")) scala2_13CompilerOpts
|
||||
else nonScala2_13CompilerOpts
|
||||
if (scalaVersion.startsWith("2.13")) {
|
||||
scala2_13SourceCompilerOpts
|
||||
} else nonScala2_13CompilerOpts
|
||||
}
|
||||
}
|
||||
|
||||
def testCompilerOpts(scalaVersion: String): Seq[String] = {
|
||||
commonCompilerOpts ++
|
||||
|
|
|
@ -115,10 +115,18 @@ abstract class SyncUtil extends BitcoinSLogger {
|
|||
}
|
||||
|
||||
val batchSize = 25
|
||||
val batchedExecutedF = FutureUtil.batchExecute(elements = blockHashes,
|
||||
f = f,
|
||||
init = Vector.empty,
|
||||
batchSize = batchSize)
|
||||
val batchedExecutedF = {
|
||||
for {
|
||||
wallet <- walletF
|
||||
updatedWallet <-
|
||||
FutureUtil.batchExecute[DoubleSha256Digest, Wallet](
|
||||
elements = blockHashes,
|
||||
f = f,
|
||||
init = wallet,
|
||||
batchSize = batchSize)
|
||||
} yield updatedWallet
|
||||
|
||||
}
|
||||
|
||||
batchedExecutedF.map { _ =>
|
||||
logger.info(
|
||||
|
|
|
@ -184,7 +184,7 @@ sealed abstract class CryptoGenerators {
|
|||
*/
|
||||
def privateKeySeqWithRequiredSigs(num: Int): Gen[(Seq[ECPrivateKey], Int)] = {
|
||||
if (num <= 0) {
|
||||
Gen.const(Nil, 0)
|
||||
Gen.const((Nil, 0))
|
||||
} else {
|
||||
val privateKeys = privateKeySeq(num)
|
||||
for {
|
||||
|
|
|
@ -156,9 +156,7 @@ object PSBTGenerators {
|
|||
}
|
||||
|
||||
Future.successful(
|
||||
PSBT(psbt.globalMap, newInputsMaps, psbt.outputMaps),
|
||||
infos,
|
||||
fee)
|
||||
(PSBT(psbt.globalMap, newInputsMaps, psbt.outputMaps), infos, fee))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ trait EclairRpcTestUtil extends BitcoinSLogger {
|
|||
port: Int = RpcUtil.randomPort,
|
||||
apiPort: Int = RpcUtil.randomPort): Config = {
|
||||
val configMap = {
|
||||
Map(
|
||||
Map[String, Any](
|
||||
"eclair.chain" -> "regtest",
|
||||
"eclair.spv" -> false,
|
||||
"eclair.server.public-ips.1" -> "127.0.0.1",
|
||||
|
|
|
@ -121,7 +121,7 @@ abstract class Wallet
|
|||
// safe since we're deriving from a priv
|
||||
val xpub = keyManager.deriveXPub(account).get
|
||||
|
||||
accountDAO.read(account.coin, account.index).flatMap {
|
||||
accountDAO.read((account.coin, account.index)).flatMap {
|
||||
case Some(account) =>
|
||||
if (account.xpub != xpub) {
|
||||
val errorMsg =
|
||||
|
@ -918,7 +918,7 @@ object Wallet extends WalletLogger {
|
|||
//2. We already have this account in our database, so we do nothing
|
||||
//3. We have this account in our database, with a DIFFERENT xpub. This is bad. Fail with an exception
|
||||
// this most likely means that we have a different key manager than we expected
|
||||
wallet.accountDAO.read(account.coin, account.index).flatMap {
|
||||
wallet.accountDAO.read((account.coin, account.index)).flatMap {
|
||||
case Some(account) =>
|
||||
if (account.xpub != xpub) {
|
||||
val errorMsg =
|
||||
|
|
|
@ -61,9 +61,10 @@ case class ScriptPubKeyDAO()(implicit
|
|||
|
||||
private val toTuple: ScriptPubKeyDb => Option[ScriptPubKeyTuple] = {
|
||||
scriptPubKeyDb =>
|
||||
Some(scriptPubKeyDb.id,
|
||||
scriptPubKeyDb.scriptPubKey,
|
||||
scriptPubKeyDb.scriptPubKey.scriptType)
|
||||
Some(
|
||||
(scriptPubKeyDb.id,
|
||||
scriptPubKeyDb.scriptPubKey,
|
||||
scriptPubKeyDb.scriptPubKey.scriptType))
|
||||
}
|
||||
|
||||
override def * =
|
||||
|
|
Loading…
Add table
Reference in a new issue