* Fix typos

* Collection minor fixes

Removes redundant .headOption on options
Replaces .exists(_ == ???) with .contains(???)
Replaces option == None with option.isEmpty
This commit is contained in:
Aris 2021-02-07 21:00:25 +00:00 committed by GitHub
parent 0c9bba8267
commit f8694eb097
32 changed files with 55 additions and 57 deletions

View file

@ -1,7 +1,7 @@
![Bitcoin-S logo](website/static/img/bitcoin-s-dark-logo.png)
[![Build Status](https://github.com/bitcoin-s/bitcoin-s/workflows/Release/badge.svg)](https://github.com/bitcoin-s/bitcoin-s/actions) [![Coverage Status](https://coveralls.io/repos/github/bitcoin-s/bitcoin-s/badge.svg?branch=master)](https://coveralls.io/github/bitcoin-s/bitcoin-s?branch=master) [![Maven Central](https://img.shields.io/badge/Maven%20Central-0.5.0-brightgreen.svg)](https://mvnrepository.com/artifact/org.bitcoin-s) [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/bitcoin-s-core)
Feature rich toolkit for making Bitcoin and Lightning applications
Feature-rich toolkit for making Bitcoin and Lightning applications
on the JVM.
For a complete guide on how to get started with Bitcoin-S, see our website at

View file

@ -107,7 +107,7 @@ class MempoolRpcTest extends BitcoindRpcTest {
txid = DoubleSha256Digest.empty
result <- client.getMemPoolEntryOpt(txid)
} yield {
assert(result == None)
assert(result.isEmpty)
}
resultF
}

View file

@ -250,7 +250,7 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest {
_ <- client.createWallet("suredbits")
wallets <- client.listWallets
} yield {
assert(wallets.exists(_ == "suredbits"))
assert(wallets.contains("suredbits"))
}
}

View file

@ -234,7 +234,7 @@ object BitcoindRpcClient {
/** Creates an RPC client from the given instance,
* together with the given actor system. This is for
* advanced users, wher you need fine grained control
* advanced users, where you need fine grained control
* over the RPC client.
*/
def withActorSystem(instance: BitcoindInstance)(implicit

View file

@ -115,7 +115,7 @@ object BitcoindV16RpcClient {
/** Creates an RPC client from the given instance,
* together with the given actor system. This is for
* advanced users, wher you need fine grained control
* advanced users, where you need fine grained control
* over the RPC client.
*/
def withActorSystem(instance: BitcoindInstance)(implicit

View file

@ -124,7 +124,7 @@ object BitcoindV17RpcClient {
/** Creates an RPC client from the given instance,
* together with the given actor system. This is for
* advanced users, wher you need fine grained control
* advanced users, where you need fine grained control
* over the RPC client.
*/
def withActorSystem(instance: BitcoindInstance)(implicit

View file

@ -190,7 +190,7 @@ case class BitcoindConfig(
} yield result
}
/** Searches the config for a key matchinng the provided
/** Searches the config for a key matching the provided
* string that's _not_ in a section header or prefixed
* by a network.
*/

View file

@ -156,7 +156,7 @@ class BlockHeaderDAOTest extends ChainDbUnitTest {
blockHeaderDAO: BlockHeaderDAO =>
val chainTipsF = blockHeaderDAO.getBestChainTips
chainTipsF.map { tips =>
assert(tips.headOption == Some(genesisHeaderDb))
assert(tips.headOption.contains(genesisHeaderDb))
}
}

View file

@ -21,7 +21,7 @@ class CompactFilterHeaderDAOTest extends ChainDbUnitTest {
it must "get the best filter header with a table with zero rows in it" in {
filterHeaderDAO =>
filterHeaderDAO.getBestFilterHeader.map { opt =>
assert(opt == None)
assert(opt.isEmpty)
}
}

View file

@ -157,8 +157,6 @@ case class CompactFilterDAO()(implicit
}
def getBestFilterHeight: Future[Int] = {
safeDatabase.run(bestFilterHeightQuery).map { filterHeightOpt =>
filterHeightOpt.headOption.getOrElse(0)
}
safeDatabase.run(bestFilterHeightQuery).map(_.getOrElse(0))
}
}

View file

@ -155,7 +155,7 @@ case class CompactFilterHeaderDAO()(implicit
def getBestFilterHeaderHeight: Future[Int] = {
safeDatabase.run(bestFilterHeaderHeightQuery).map { filterHeaderHeightOpt =>
filterHeaderHeightOpt.headOption.getOrElse(0)
filterHeaderHeightOpt.getOrElse(0)
}
}

View file

@ -53,7 +53,7 @@ class ArithmeticInterpreterTest extends BitcoinSUnitTest {
}
it must "perform an OP_1SUB corectly" in {
it must "perform an OP_1SUB correctly" in {
val stack = List(ScriptNumber.zero)
val script = List(OP_1SUB)
val program =
@ -77,7 +77,7 @@ class ArithmeticInterpreterTest extends BitcoinSUnitTest {
newProgram.error must be(Some(ScriptErrorInvalidStackOperation))
}
it must "perform an OP_SUB corectly" in {
it must "perform an OP_SUB correctly" in {
val stack = List(ScriptNumber.one, ScriptNumber.zero)
val script = List(OP_SUB)
val program =
@ -100,7 +100,7 @@ class ArithmeticInterpreterTest extends BitcoinSUnitTest {
newProgram.error must be(Some(ScriptErrorInvalidStackOperation))
}
it must "perform an OP_ABS on a negative number corectly" in {
it must "perform an OP_ABS on a negative number correctly" in {
val stack = List(ScriptNumber(-1))
val script = List(OP_ABS)
val program =
@ -299,7 +299,7 @@ class ArithmeticInterpreterTest extends BitcoinSUnitTest {
newProgram.script.isEmpty must be(true)
}
it must "evaulate an OP_NUMEQUAL for two zeros" in {
it must "evaluate an OP_NUMEQUAL for two zeros" in {
val stack = List(ScriptNumber.zero, ScriptNumber.zero)
val script = List(OP_NUMEQUAL)
val program =

View file

@ -6,7 +6,7 @@ import org.bitcoins.testkit.util.BitcoinSUnitTest
*/
class ArithmeticOperationsTest extends BitcoinSUnitTest {
"ArithmeticOperatoins" must "define OP_1ADD" in {
"ArithmeticOperations" must "define OP_1ADD" in {
OP_1ADD.opCode must be(139)
}

View file

@ -7,10 +7,10 @@ import org.bitcoins.testkit.util.BitcoinSUnitTest
class BytesToPushOntoStackFactoryTest extends BitcoinSUnitTest {
"ScriptNumberFactory" must "represent the number 1" in {
BytesToPushOntoStack.operations.exists(
_ == BytesToPushOntoStack(1)) must be(true)
BytesToPushOntoStack.operations.exists(
_ == BytesToPushOntoStack(75)) must be(true)
BytesToPushOntoStack.operations.contains(BytesToPushOntoStack(1)) must be(
true)
BytesToPushOntoStack.operations.contains(BytesToPushOntoStack(75)) must be(
true)
}
it must "find the number two" in {
@ -29,8 +29,8 @@ class BytesToPushOntoStackFactoryTest extends BitcoinSUnitTest {
it must "not allow creation of the script number -2" in {
intercept[IllegalArgumentException] {
BytesToPushOntoStack.operations.exists(
_ == BytesToPushOntoStack(-2)) must be(false)
BytesToPushOntoStack.operations.contains(
BytesToPushOntoStack(-2)) must be(false)
}
}

View file

@ -42,7 +42,7 @@ class LockTimeInterpreterTest extends BitcoinSUnitTest {
it must "mark the transaction as invalid if the stack top is negative" in {
val stack = Seq(ScriptNumber(-1))
val script = Seq(OP_CHECKLOCKTIMEVERIFY)
val oldInput = TestUtil.transaction.inputs(0)
val oldInput = TestUtil.transaction.inputs.head
val txInputAdjustedSequenceNumber =
TransactionInput(oldInput.previousOutput,
oldInput.scriptSignature,
@ -75,7 +75,7 @@ class LockTimeInterpreterTest extends BitcoinSUnitTest {
it must "mark the transaction as invalid if the locktime on the tx is < 500000000 && stack top is >= 500000000" in {
val stack = Seq(ScriptNumber(500000000))
val script = Seq(OP_CHECKLOCKTIMEVERIFY)
val oldInput = TestUtil.transaction.inputs(0)
val oldInput = TestUtil.transaction.inputs.head
val txInputAdjustedSequenceNumber =
TransactionInput(oldInput.previousOutput,
oldInput.scriptSignature,
@ -101,7 +101,7 @@ class LockTimeInterpreterTest extends BitcoinSUnitTest {
it must "mark the transaction as invalid if the locktime on the tx is >= 500000000 && stack top is < 500000000" in {
val stack = Seq(ScriptNumber(499999999))
val script = Seq(OP_CHECKLOCKTIMEVERIFY)
val oldInput = TestUtil.transaction.inputs(0)
val oldInput = TestUtil.transaction.inputs.head
val txInputAdjustedSequenceNumber =
TransactionInput(oldInput.previousOutput,
oldInput.scriptSignature,
@ -127,7 +127,7 @@ class LockTimeInterpreterTest extends BitcoinSUnitTest {
it must "mark the transaction as invalid if the stack top item is greater than the tx locktime" in {
val stack = Seq(ScriptNumber(499999999))
val script = Seq(OP_CHECKLOCKTIMEVERIFY)
val oldInput = TestUtil.transaction.inputs(0)
val oldInput = TestUtil.transaction.inputs.head
val txInputAdjustedSequenceNumber =
TransactionInput(oldInput.previousOutput,
oldInput.scriptSignature,
@ -157,7 +157,7 @@ class LockTimeInterpreterTest extends BitcoinSUnitTest {
it must "mark the transaction as valid if the locktime on the tx is < 500000000 && stack top is < 500000000" in {
val stack = Seq(ScriptNumber(0))
val script = Seq(OP_CHECKLOCKTIMEVERIFY)
val oldInput = TestUtil.transaction.inputs(0)
val oldInput = TestUtil.transaction.inputs.head
val txInputAdjustedSequenceNumber =
TransactionInput(oldInput.previousOutput,
oldInput.scriptSignature,
@ -185,7 +185,7 @@ class LockTimeInterpreterTest extends BitcoinSUnitTest {
it must "mark the transaction as valid if the locktime on the tx is >= 500000000 && stack top is >= 500000000" in {
val stack = Seq(ScriptNumber(500000000))
val script = Seq(OP_CHECKLOCKTIMEVERIFY)
val oldInput = TestUtil.transaction.inputs(0)
val oldInput = TestUtil.transaction.inputs.head
val txInputAdjustedSequenceNumber =
TransactionInput(oldInput.previousOutput,
oldInput.scriptSignature,

View file

@ -321,8 +321,8 @@ class BitcoinScriptUtilTest extends BitcoinSUnitTest {
BitcoinScriptUtil.removeSignaturesFromScript(signatures,
p2shScriptSig.asm)
val sigExists =
signatures.map(sig => asmWithoutSigs.exists(_ == ScriptConstant(sig.hex)))
sigExists.exists(_ == true) must be(false)
signatures.map(sig => asmWithoutSigs.contains(ScriptConstant(sig.hex)))
sigExists.contains(true) must be(false)
}
it must "cast a script token to a boolean value" in {

View file

@ -108,7 +108,7 @@ sealed abstract class BloomFilter extends NetworkElement with BitcoinSLogger {
@tailrec
def loop(remainingBitIndexes: Seq[Int], accum: BitVector): Boolean = {
if (remainingBitIndexes.isEmpty) {
!accum.toIndexedSeq.exists(_ == false)
!accum.toIndexedSeq.contains(false)
} else {
val currentIndex = remainingBitIndexes.head
val byteIndex = currentIndex >>> 3

View file

@ -349,7 +349,7 @@ object PartialMerkleTree {
//require(remainingBits.isEmpty, s"Remainging bits should be empty, got ${remainingBits}")
//we must have used all the hashes provided to us to reconstruct the partial merkle tree as per BIP37
require(
remainingHashes.size == 0,
remainingHashes.isEmpty,
"We should not have any left over hashes after building our partial merkle tree, got: " + remainingHashes)
//we must not have any matches remaining, unless the remaining bits were use to pad our byte vector to 8 bits
//for instance, we could have had 5 bits to indicate how to build the merkle tree, but we need to pad it with 3 bits

View file

@ -120,7 +120,7 @@ case class ContractInfo(
.flatMap { oracles =>
vec.map { case MultiOracleOutcome(digitsVec, amt) =>
val outcomesVec =
digitsVec.toVector.map(UnsignedNumericOutcome.apply)
digitsVec.map(UnsignedNumericOutcome.apply)
(NumericOracleOutcome(oracles.zip(outcomesVec)), amt)
}
}

View file

@ -148,7 +148,7 @@ object LnTaggedFields {
val dataLength = LnUtil.decodeDataLength(dataLengthU5s)
//t is the actual possible payload
val payload: Vector[UInt5] = t.take(dataLength.toInt).toVector
val payload: Vector[UInt5] = t.take(dataLength.toInt)
val tag = LnTag.fromLnTagPrefix(prefix, payload)

View file

@ -272,7 +272,7 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
/** Performs the given arithmetic operation on the stack head
* @param program the program whose stack top is used as an argument for the arithmetic operation
* @param op the arithmetic ooperation that needs to be executed on the number, for instance incrementing by 1
* @param op the arithmetic operation that needs to be executed on the number, for instance incrementing by 1
* @return the program with the result from performing the arithmetic operation pushed onto the top of the stack
*/
@tailrec
@ -328,7 +328,7 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
/** Performs the given arithmetic operation on the top two stack items
* @param program the program whose stack top is used as an argument for the arithmetic operation
* @param op the arithmetic ooperation that needs to be executed on the number, for instance incrementing by 1
* @param op the arithmetic operation that needs to be executed on the number, for instance incrementing by 1
* @return the program with the result from performing the arithmetic operation pushed onto the top of the stack
*/
@tailrec

View file

@ -38,7 +38,7 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
val input = program.txSignatureComponent.transaction
.inputs(program.txSignatureComponent.inputIndex.toInt)
val transaction = program.txSignatureComponent.transaction
if (program.stack.size == 0) {
if (program.stack.isEmpty) {
logger.error(
"Transaction validation failing in OP_CHECKLOCKTIMEVERIFY because we have no stack items")
program.failExecution(ScriptErrorInvalidStackOperation)

View file

@ -54,9 +54,9 @@ sealed abstract class ScriptParser
operations match {
//for parsing strings like 'Az', need to remove single quotes
//example: [[https://github.com/bitcoin/bitcoin/blob/master/src/test/data/script_valid.json#L24]]
case h +: t if h.size > 0 && h.head == '\'' && h.last == '\'' =>
case h +: t if h.nonEmpty && h.head == '\'' && h.last == '\'' =>
val strippedQuotes = h.replace("\'", "")
if (strippedQuotes.size == 0) {
if (strippedQuotes.isEmpty) {
loop(t, OP_0.bytes ++ accum)
} else {
val bytes: ByteVector = {

View file

@ -26,7 +26,7 @@ class AesCryptTest extends BitcoinSUnitTest {
*
* Here's a link to the first test vector:
* https://gchq.github.io/CyberChef/#recipe=AES_Encrypt(%7B'option':'Hex','string':'2eefdf6ee2dbca83e7b7648a8f9d1897'%7D,%7B'option':'Hex','string':'889dc64377f6d993ef713c995f9c1ee5'%7D,'CFB','Hex','Hex')&input=NzZmZTM1ODgwMDU1ZTFmYWM5NTBmNDg0YTgxNWNkMjI
* The other vectors can be repliacted by tweaking the values
* The other vectors can be replicated by tweaking the values
* in the UI.
*/
it must "decrypt and encrypt some hard coded test vectors" in {

View file

@ -133,7 +133,7 @@ If you're looking to set up a DLC Oracle instead go to the [oracle server docs](
We are finally ready to start running some programs! Follow the [instructions here](applications/server.md#building-the-server) to build the server. Then, follow [these instructions](applications/cli.md) to setup the CLI.
There are 2 ways to use the bitcoin-s server. It can either can be as a neutrino node or use bitcoind as a backend.
There are 2 ways to use the bitcoin-s server. It can either be as a neutrino node or use bitcoind as a backend.
This can be configured by the configuration option `bitcoin-s.node.mode` choosing either `neutrino` or `bitcoind`.
### Option A: Neutrino Server
@ -150,7 +150,7 @@ Testnet:
`bitcoin-s.node.peers = ["neutrino.testnet3.suredbits.com:18333"]`
If you would like to use your own node you can either use the bitcoind backend option or connect to your own compatible node.
There is no released version of bitcoind that is neutrino compatible so you will either have to compile the latest `master` yourself, or use the experimental version provided by running `sbt downloadBitcoind`.
There is no released version of bitcoind that is neutrino compatible, so you will either have to compile the latest `master` yourself, or use the experimental version provided by running `sbt downloadBitcoind`.
After building your bitcoin-s server, properly configuring it to be in `neutrino` mode you can start your server with:

View file

@ -305,7 +305,7 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
.lnbcrt(Some(12345.msats.toLnCurrencyUnit))
.toString)
assert(invoice.network == LnBitcoinRegTest)
assert(invoice.amount == Some(123450.pBTC))
assert(invoice.amount.contains(123450.pBTC))
assert(invoice.isValidSignature)
assert(
invoice.timestamp > UInt64(1561063731)
@ -328,7 +328,7 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
.lnbcrt(Some(12345.msats.toLnCurrencyUnit))
.toString)
assert(invoice.network == LnBitcoinRegTest)
assert(invoice.amount == Some(123450.pBTC))
assert(invoice.amount.contains(123450.pBTC))
assert(invoice.isValidSignature)
assert(
invoice.timestamp > UInt64(1561063731)
@ -355,7 +355,7 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
.lnbcrt(Some(123450.pBTC))
.toString)
assert(invoice.network == LnBitcoinRegTest)
assert(invoice.amount == Some(123450.pBTC))
assert(invoice.amount.contains(123450.pBTC))
assert(invoice.isValidSignature)
assert(
invoice.timestamp > UInt64(1561063731)
@ -385,7 +385,7 @@ class EclairRpcClientTest extends BitcoinSAsyncTest {
.lnbcrt(Some(12345.msats.toLnCurrencyUnit))
.toString)
assert(invoice.network == LnBitcoinRegTest)
assert(invoice.amount == Some(123450.pBTC))
assert(invoice.amount.contains(123450.pBTC))
assert(invoice.isValidSignature)
assert(
invoice.timestamp > UInt64(1561063731)

View file

@ -67,7 +67,7 @@ private[peer] object MerkleBuffers extends P2PLogger {
logger.trace(
s"Block=${block.blockHeader.hashBE} has matches=${matches.map(_.flip)}")
matches.exists(_ == tx.txId)
matches.contains(tx.txId)
} match {
case None =>
logger.debug(

View file

@ -254,7 +254,7 @@ class TrezorAddressTest extends BitcoinSWalletTest with EmptyFixture {
accountsWithVectors = {
assert(accounts.length == testVectors.length)
val accountsWithVectors = testVectors.map { vec =>
assert(accounts.filter(_.hdAccount.index == vec.account).length == 1)
assert(accounts.count(_.hdAccount.index == vec.account) == 1)
accounts.find(_.hdAccount.index == vec.account) match {
case None =>
fail(

View file

@ -2,5 +2,5 @@ package org.bitcoins.wallet
import grizzled.slf4j.Logging
/** Exposes acccess to the wallet logger */
/** Exposes access to the wallet logger */
private[bitcoins] trait WalletLogger extends Logging

View file

@ -215,7 +215,7 @@ private[wallet] trait TransactionProcessing extends WalletLogger {
}
processed <- FutureUtil.sequentially(outputsToUse)(markAsPendingSpent)
} yield processed.flatten.toVector
} yield processed.flatten
}

View file

@ -160,7 +160,7 @@ case class AddressTagDAO()(implicit
spks.map(spk => BitcoinAddress.fromScriptPubKey(spk, network))
val findByAddressFs = addresses.map(address => findByAddress(address))
FutureUtil.collect(findByAddressFs).map(_.toVector.flatten)
FutureUtil.collect(findByAddressFs).map(_.flatten)
}
}
}

View file

@ -43,22 +43,22 @@ class ZMQSubscriber(
val isConnected = subscriber.connect(uri)
if (isConnected) {
hashTxListener.map { _ =>
hashTxListener.foreach { _ =>
subscriber.subscribe(HashTx.topic.getBytes(ZMQ.CHARSET))
logger.debug("subscribed to the transaction hashes from zmq")
}
rawTxListener.map { _ =>
rawTxListener.foreach { _ =>
subscriber.subscribe(RawTx.topic.getBytes(ZMQ.CHARSET))
logger.debug("subscribed to raw transactions from zmq")
}
hashBlockListener.map { _ =>
hashBlockListener.foreach { _ =>
subscriber.subscribe(HashBlock.topic.getBytes(ZMQ.CHARSET))
logger.debug("subscribed to the hashblock stream from zmq")
}
rawBlockListener.map { _ =>
rawBlockListener.foreach { _ =>
subscriber.subscribe(RawBlock.topic.getBytes(ZMQ.CHARSET))
logger.debug("subscribed to raw block stream from zmq")
}