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