Added compile scope scalafmtCheck to travis runs (#1563)

This commit is contained in:
Nadav Kohen 2020-06-16 15:16:43 -05:00 committed by GitHub
parent dec503f561
commit e5bd6e53a3
26 changed files with 232 additions and 146 deletions

View file

@ -8,9 +8,22 @@ import org.bitcoins.core.currency.{Bitcoins, Satoshis}
import org.bitcoins.core.hd.BIP32Path import org.bitcoins.core.hd.BIP32Path
import org.bitcoins.core.number.{Int32, UInt32, UInt64} import org.bitcoins.core.number.{Int32, UInt32, UInt64}
import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader, MerkleBlock} import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader, MerkleBlock}
import org.bitcoins.core.protocol.script.{ScriptPubKey, ScriptSignature, WitnessScriptPubKey} import org.bitcoins.core.protocol.script.{
import org.bitcoins.core.protocol.transaction.{Transaction, TransactionInput, TransactionOutPoint} ScriptPubKey,
import org.bitcoins.core.protocol.{Address, BitcoinAddress, P2PKHAddress, P2SHAddress} ScriptSignature,
WitnessScriptPubKey
}
import org.bitcoins.core.protocol.transaction.{
Transaction,
TransactionInput,
TransactionOutPoint
}
import org.bitcoins.core.protocol.{
Address,
BitcoinAddress,
P2PKHAddress,
P2SHAddress
}
import org.bitcoins.core.script.ScriptType import org.bitcoins.core.script.ScriptType
import org.bitcoins.core.wallet.fee.{ import org.bitcoins.core.wallet.fee.{
BitcoinFeeUnit, BitcoinFeeUnit,
@ -184,7 +197,8 @@ object JsonSerializers {
implicit val doubleSha256DigestWrites: Writes[DoubleSha256Digest] = implicit val doubleSha256DigestWrites: Writes[DoubleSha256Digest] =
DoubleSha256DigestWrites DoubleSha256DigestWrites
implicit val scriptPubKeyWrites: Writes[ScriptPubKey] = ScriptPubKeyWrites implicit val scriptPubKeyWrites: Writes[ScriptPubKey] = ScriptPubKeyWrites
implicit val witnessScriptPubKeyWrites: Writes[WitnessScriptPubKey] = WitnessScriptPubKeyWrites implicit val witnessScriptPubKeyWrites: Writes[WitnessScriptPubKey] =
WitnessScriptPubKeyWrites
implicit val transactionInputWrites: Writes[TransactionInput] = implicit val transactionInputWrites: Writes[TransactionInput] =
TransactionInputWrites TransactionInputWrites
implicit val uInt32Writes: Writes[UInt32] = UInt32Writes implicit val uInt32Writes: Writes[UInt32] = UInt32Writes

View file

@ -57,8 +57,10 @@ object JsonWriters {
JsString(BytesUtil.encodeHex(o.asmBytes)) JsString(BytesUtil.encodeHex(o.asmBytes))
} }
implicit object WitnessScriptPubKeyWrites extends Writes[WitnessScriptPubKey] { implicit object WitnessScriptPubKeyWrites
override def writes(o: WitnessScriptPubKey): JsValue = ScriptPubKeyWrites.writes(o) extends Writes[WitnessScriptPubKey] {
override def writes(o: WitnessScriptPubKey): JsValue =
ScriptPubKeyWrites.writes(o)
} }
implicit object TransactionInputWrites extends Writes[TransactionInput] { implicit object TransactionInputWrites extends Writes[TransactionInput] {

View file

@ -98,7 +98,6 @@ object EclairBench extends App with EclairRpcTestUtil {
}) })
} yield paymentIds.flatten } yield paymentIds.flatten
def runTests(network: EclairNetwork): Future[Vector[PaymentLogEntry]] = { def runTests(network: EclairNetwork): Future[Vector[PaymentLogEntry]] = {
println("Setting up the test network") println("Setting up the test network")
for { for {

View file

@ -17,7 +17,10 @@ import org.bitcoins.core.crypto.ECPrivateKeyUtil
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, StartStop} import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, StartStop}
import org.bitcoins.crypto.ECPrivateKey import org.bitcoins.crypto.ECPrivateKey
import org.bitcoins.rpc.BitcoindException import org.bitcoins.rpc.BitcoindException
import org.bitcoins.rpc.config.BitcoindAuthCredentials.{CookieBased, PasswordBased} import org.bitcoins.rpc.config.BitcoindAuthCredentials.{
CookieBased,
PasswordBased
}
import org.bitcoins.rpc.config.{BitcoindAuthCredentials, BitcoindInstance} import org.bitcoins.rpc.config.{BitcoindAuthCredentials, BitcoindInstance}
import org.bitcoins.rpc.util.AsyncUtil import org.bitcoins.rpc.util.AsyncUtil
import play.api.libs.json._ import play.api.libs.json._

View file

@ -48,7 +48,9 @@ abstract class FilterSync extends ChainVerificationLogger {
getFilterFunc = getFilterFunc, getFilterFunc = getFilterFunc,
batchSize) batchSize)
case None => case None =>
Future.failed(new RuntimeException(s"Cannot sync filters, we don't have any in the database")) Future.failed(
new RuntimeException(
s"Cannot sync filters, we don't have any in the database"))
} }
} }
} yield { } yield {
@ -120,7 +122,8 @@ abstract class FilterSync extends ChainVerificationLogger {
bestFilter, bestFilter,
getFilterFunc) getFilterFunc)
case None => case None =>
Future.failed(new RuntimeException(s"Cannot sync filter headers, we do not have any in the database")) Future.failed(new RuntimeException(
s"Cannot sync filter headers, we do not have any in the database"))
} }
} }

View file

@ -127,7 +127,8 @@ case class CompactFilterDAO()(
/** Gets the heaviest filter from the database */ /** Gets the heaviest filter from the database */
def getBestFilter: Future[Option[CompactFilterDb]] = { def getBestFilter: Future[Option[CompactFilterDb]] = {
val join = (table.join(blockHeaderTable)) val join = (table
.join(blockHeaderTable))
.on(_.blockHash === _.hash) .on(_.blockHash === _.hash)
val query = join.groupBy(_._1).map { val query = join.groupBy(_._1).map {
case (filter, headers) => case (filter, headers) =>

View file

@ -123,10 +123,12 @@ case class CompactFilterHeaderDAO()(
case (filter, headers) => case (filter, headers) =>
filter -> headers.map(_._2.chainWork).max filter -> headers.map(_._2.chainWork).max
} }
val headersWithWorkF: Future[Vector[(CompactFilterHeaderDb,Option[BigInt])]] = { val headersWithWorkF: Future[
Vector[(CompactFilterHeaderDb, Option[BigInt])]] = {
safeDatabase.runVec(query.result) safeDatabase.runVec(query.result)
} }
headersWithWorkF.map { headersWithWork: Vector[(CompactFilterHeaderDb,Option[BigInt])] => headersWithWorkF.map {
headersWithWork: Vector[(CompactFilterHeaderDb, Option[BigInt])] =>
if (headersWithWork.isEmpty) { if (headersWithWork.isEmpty) {
None None
} else { } else {

View file

@ -331,7 +331,6 @@ object UInt32
lazy val min = zero lazy val min = zero
lazy val max = UInt32(maxUnderlying) lazy val max = UInt32(maxUnderlying)
override def isInBound(num: A): Boolean = override def isInBound(num: A): Boolean =
num <= maxUnderlying && num >= minUnderlying num <= maxUnderlying && num >= minUnderlying
@ -491,7 +490,6 @@ object Int64
def apply(bigInt: BigInt): Int64 = Int64Impl(bigInt) def apply(bigInt: BigInt): Int64 = Int64Impl(bigInt)
private def checkCached(long: Long): Int64 = { private def checkCached(long: Long): Int64 = {
if (long < 256 && long >= 0) cached(long.toInt) if (long < 256 && long >= 0) cached(long.toInt)
else Int64(BigInt(long)) else Int64(BigInt(long))

View file

@ -24,7 +24,9 @@ abstract class AddressFactory[T <: Address] extends StringFactory[T] {
*/ */
def fromScriptPubKeyT(spk: ScriptPubKey, np: NetworkParameters): Try[T] def fromScriptPubKeyT(spk: ScriptPubKey, np: NetworkParameters): Try[T]
def fromScriptPubKeyOpt(spk: ScriptPubKey, np: NetworkParameters): Option[T] = { def fromScriptPubKeyOpt(
spk: ScriptPubKey,
np: NetworkParameters): Option[T] = {
fromScriptPubKeyT(spk, np).toOption fromScriptPubKeyT(spk, np).toOption
} }

View file

@ -5,7 +5,12 @@ import org.bitcoins.core.protocol.ln.currency.{LnCurrencyUnit, PicoBitcoins}
import org.bitcoins.core.protocol.ln.node.NodeId import org.bitcoins.core.protocol.ln.node.NodeId
import org.bitcoins.core.protocol.ln.util.LnUtil import org.bitcoins.core.protocol.ln.util.LnUtil
import org.bitcoins.core.util._ import org.bitcoins.core.util._
import org.bitcoins.crypto.{CryptoUtil, ECPrivateKey, Sha256Digest, StringFactory} import org.bitcoins.crypto.{
CryptoUtil,
ECPrivateKey,
Sha256Digest,
StringFactory
}
import scodec.bits.ByteVector import scodec.bits.ByteVector
import scala.util.{Failure, Success, Try} import scala.util.{Failure, Success, Try}

View file

@ -251,11 +251,11 @@ object MultiSignatureScriptPubKey
(hasRequiredSignaturesTry, hasMaximumSignaturesTry) match { (hasRequiredSignaturesTry, hasMaximumSignaturesTry) match {
case (Success(hasRequiredSignatures), Success(hasMaximumSignatures)) => case (Success(hasRequiredSignatures), Success(hasMaximumSignatures)) =>
val isStandardOps = asm.forall( val isStandardOps = asm.forall(
op => op =>
op.isInstanceOf[ScriptConstant] || op op.isInstanceOf[ScriptConstant] || op
.isInstanceOf[BytesToPushOntoStack] || op.isInstanceOf[ScriptNumber] || op == OP_CHECKMULTISIG || .isInstanceOf[BytesToPushOntoStack] || op
.isInstanceOf[ScriptNumber] || op == OP_CHECKMULTISIG ||
op == OP_CHECKMULTISIGVERIFY) op == OP_CHECKMULTISIGVERIFY)
val result = isNotEmpty && containsMultiSigOp && hasRequiredSignatures && val result = isNotEmpty && containsMultiSigOp && hasRequiredSignatures &&

View file

@ -20,6 +20,7 @@ import scala.util.Try
* while under Policy only OP_TRUE is True. * while under Policy only OP_TRUE is True.
*/ */
sealed abstract class ScriptSignature extends Script { sealed abstract class ScriptSignature extends Script {
/** /**
* The digital signatures contained inside of the script signature * The digital signatures contained inside of the script signature
* p2pkh script signatures only have one sig * p2pkh script signatures only have one sig
@ -242,8 +243,8 @@ object P2SHScriptSignature extends ScriptFactory[P2SHScriptSignature] {
case _: P2PKHScriptPubKey | _: MultiSignatureScriptPubKey | case _: P2PKHScriptPubKey | _: MultiSignatureScriptPubKey |
_: P2SHScriptPubKey | _: P2PKScriptPubKey | _: P2SHScriptPubKey | _: P2PKScriptPubKey |
_: P2PKWithTimeoutScriptPubKey | _: ConditionalScriptPubKey | _: P2PKWithTimeoutScriptPubKey | _: ConditionalScriptPubKey |
_: CLTVScriptPubKey | _: CSVScriptPubKey | _: CLTVScriptPubKey | _: CSVScriptPubKey | _: WitnessScriptPubKeyV0 |
_: WitnessScriptPubKeyV0 | _: UnassignedWitnessScriptPubKey => _: UnassignedWitnessScriptPubKey =>
true true
case _: NonStandardScriptPubKey | _: WitnessCommitment => false case _: NonStandardScriptPubKey | _: WitnessCommitment => false
case EmptyScriptPubKey => false case EmptyScriptPubKey => false
@ -330,11 +331,12 @@ object MultiSignatureScriptSignature
} }
} }
/** Iterates through the given given script tokens and return false if /** Iterates through the given given script tokens and return false if
* one of the elements is NOT [[ScriptConstant]] or a push operation */ * one of the elements is NOT [[ScriptConstant]] or a push operation */
private def isPushOpsOrScriptConstants(asm: Seq[ScriptToken]): Boolean = { private def isPushOpsOrScriptConstants(asm: Seq[ScriptToken]): Boolean = {
asm.forall(token => token.isInstanceOf[ScriptConstant] || asm.forall(
token =>
token.isInstanceOf[ScriptConstant] ||
StackPushOperationFactory.isPushOperation(token)) StackPushOperationFactory.isPushOperation(token))
} }
} }

View file

@ -56,7 +56,8 @@ sealed abstract class RawSerializerHelper {
} }
/** Serializes a [[scala.Seq Seq]] of [[NetworkElement]] to a [[scodec.bits.ByteVector]] */ /** Serializes a [[scala.Seq Seq]] of [[NetworkElement]] to a [[scodec.bits.ByteVector]] */
final def writeNetworkElements[T <: NetworkElement](ts: Seq[T]): ByteVector = { final def writeNetworkElements[T <: NetworkElement](
ts: Seq[T]): ByteVector = {
val f = { t: T => val f = { t: T =>
t.bytes t.bytes
} }

View file

@ -14,8 +14,7 @@ sealed abstract class RawScriptSignatureParser
def read(bytes: ByteVector): ScriptSignature = { def read(bytes: ByteVector): ScriptSignature = {
if (bytes.isEmpty) EmptyScriptSignature if (bytes.isEmpty) EmptyScriptSignature
else { else {
BitcoinScriptUtil.parseScript(bytes = bytes, BitcoinScriptUtil.parseScript(bytes = bytes, f = ScriptSignature.fromAsm)
f = ScriptSignature.fromAsm)
} }
} }

View file

@ -8,10 +8,15 @@ import scala.concurrent.ExecutionContext
trait AppConfigFactory[C <: AppConfig] { trait AppConfigFactory[C <: AppConfig] {
def fromDefaultDatadir(useLogbackConf: Boolean, confs: Vector[Config] = Vector.empty)( def fromDefaultDatadir(
useLogbackConf: Boolean,
confs: Vector[Config] = Vector.empty)(
implicit ec: ExecutionContext): C = { implicit ec: ExecutionContext): C = {
fromDatadir(AppConfig.DEFAULT_BITCOIN_S_DATADIR, useLogbackConf, confs) fromDatadir(AppConfig.DEFAULT_BITCOIN_S_DATADIR, useLogbackConf, confs)
} }
def fromDatadir(datadir: Path, useLogbackConf: Boolean, confs: Vector[Config] = Vector.empty)(implicit ec: ExecutionContext): C def fromDatadir(
datadir: Path,
useLogbackConf: Boolean,
confs: Vector[Config] = Vector.empty)(implicit ec: ExecutionContext): C
} }

View file

@ -401,7 +401,8 @@ class EclairRpcClient(val instance: EclairInstance, binary: Option[File] = None)
} }
} }
val cancellable = system.scheduler.scheduleAtFixedRate(interval, interval)(runnable) val cancellable =
system.scheduler.scheduleAtFixedRate(interval, interval)(runnable)
p.future.onComplete(_ => cancellable.cancel()) p.future.onComplete(_ => cancellable.cancel())
@ -864,7 +865,8 @@ class EclairRpcClient(val instance: EclairInstance, binary: Option[File] = None)
} }
} }
val cancellable = system.scheduler.scheduleAtFixedRate(interval, interval)(runnable) val cancellable =
system.scheduler.scheduleAtFixedRate(interval, interval)(runnable)
val f = p.future val f = p.future

View file

@ -74,7 +74,9 @@ case class NodeAppConfig(
} }
/** Creates either a neutrino node or a spv node based on the [[NodeAppConfig]] given */ /** Creates either a neutrino node or a spv node based on the [[NodeAppConfig]] given */
def createNode(peer: Peer)(chainConf: ChainAppConfig, system: ActorSystem): Future[Node] = { def createNode(peer: Peer)(
chainConf: ChainAppConfig,
system: ActorSystem): Future[Node] = {
NodeAppConfig.createNode(peer)(this, chainConf, system) NodeAppConfig.createNode(peer)(this, chainConf, system)
} }
} }
@ -84,14 +86,17 @@ object NodeAppConfig extends AppConfigFactory[NodeAppConfig] {
/** Constructs a node configuration from the default Bitcoin-S /** Constructs a node configuration from the default Bitcoin-S
* data directory and given list of configuration overrides. * data directory and given list of configuration overrides.
*/ */
override def fromDatadir(datadir: Path, useLogbackConf: Boolean, confs: Vector[Config])( override def fromDatadir(
implicit ec: ExecutionContext): NodeAppConfig = datadir: Path,
NodeAppConfig(datadir, useLogbackConf: Boolean,
useLogbackConf, confs: Vector[Config])(implicit ec: ExecutionContext): NodeAppConfig =
confs: _*) NodeAppConfig(datadir, useLogbackConf, confs: _*)
/** Creates either a neutrino node or a spv node based on the [[NodeAppConfig]] given */ /** Creates either a neutrino node or a spv node based on the [[NodeAppConfig]] given */
def createNode(peer: Peer)(implicit nodeConf: NodeAppConfig, chainConf: ChainAppConfig, system: ActorSystem): Future[Node] = { def createNode(peer: Peer)(
implicit nodeConf: NodeAppConfig,
chainConf: ChainAppConfig,
system: ActorSystem): Future[Node] = {
if (nodeConf.isSPVEnabled) { if (nodeConf.isSPVEnabled) {
Future.successful(SpvNode(peer, nodeConf, chainConf, system)) Future.successful(SpvNode(peer, nodeConf, chainConf, system))
} else if (nodeConf.isNeutrinoEnabled) { } else if (nodeConf.isNeutrinoEnabled) {

View file

@ -161,7 +161,6 @@ trait ChainUnitTest
destroy = ChainUnitTest.destroyAllTables)(test) destroy = ChainUnitTest.destroyAllTables)(test)
} }
/** Creates a compact filter DAO with zero rows in it */ /** Creates a compact filter DAO with zero rows in it */
def withCompactFilterDAO(test: OneArgAsyncTest): FutureOutcome = { def withCompactFilterDAO(test: OneArgAsyncTest): FutureOutcome = {
makeFixture(build = () => ChainUnitTest.createFilterDAO(), makeFixture(build = () => ChainUnitTest.createFilterDAO(),

View file

@ -28,4 +28,3 @@ case class NeutrinoNodeFundedWalletBitcoind(
bitcoindRpc: BitcoindRpcClient, bitcoindRpc: BitcoindRpcClient,
bip39PasswordOpt: Option[String]) bip39PasswordOpt: Option[String])
extends NodeFundedWalletBitcoind extends NodeFundedWalletBitcoind

View file

@ -10,7 +10,12 @@ import org.bitcoins.db.AppConfig
import org.bitcoins.node._ import org.bitcoins.node._
import org.bitcoins.node.config.NodeAppConfig import org.bitcoins.node.config.NodeAppConfig
import org.bitcoins.node.models.Peer import org.bitcoins.node.models.Peer
import org.bitcoins.node.networking.peer.{PeerHandler, PeerMessageReceiver, PeerMessageReceiverState, PeerMessageSender} import org.bitcoins.node.networking.peer.{
PeerHandler,
PeerMessageReceiver,
PeerMessageReceiverState,
PeerMessageSender
}
import org.bitcoins.rpc.client.common.BitcoindVersion.V18 import org.bitcoins.rpc.client.common.BitcoindVersion.V18
import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion} import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion}
import org.bitcoins.server.BitcoinSAppConfig import org.bitcoins.server.BitcoinSAppConfig
@ -19,7 +24,11 @@ import org.bitcoins.testkit.EmbeddedPg
import org.bitcoins.testkit.chain.ChainUnitTest import org.bitcoins.testkit.chain.ChainUnitTest
import org.bitcoins.testkit.fixtures.BitcoinSFixture import org.bitcoins.testkit.fixtures.BitcoinSFixture
import org.bitcoins.testkit.keymanager.KeyManagerTestUtil import org.bitcoins.testkit.keymanager.KeyManagerTestUtil
import org.bitcoins.testkit.node.fixture.{NeutrinoNodeConnectedWithBitcoind, NodeConnectedWithBitcoind, SpvNodeConnectedWithBitcoind} import org.bitcoins.testkit.node.fixture.{
NeutrinoNodeConnectedWithBitcoind,
NodeConnectedWithBitcoind,
SpvNodeConnectedWithBitcoind
}
import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil
import org.bitcoins.testkit.wallet.{BitcoinSWalletTest, WalletWithBitcoindRpc} import org.bitcoins.testkit.wallet.{BitcoinSWalletTest, WalletWithBitcoindRpc}
import org.scalatest.FutureOutcome import org.scalatest.FutureOutcome
@ -106,10 +115,13 @@ trait NodeUnitTest extends BitcoinSFixture with EmbeddedPg {
appConfig: BitcoinSAppConfig): FutureOutcome = { appConfig: BitcoinSAppConfig): FutureOutcome = {
makeDependentFixture( makeDependentFixture(
build = () => build =
() =>
NodeUnitTest.createSpvNodeFundedWalletBitcoind(callbacks = callbacks, NodeUnitTest.createSpvNodeFundedWalletBitcoind(callbacks = callbacks,
bip39PasswordOpt = bip39PasswordOpt, bip39PasswordOpt =
versionOpt = Option(V18))( bip39PasswordOpt,
versionOpt =
Option(V18))(
system, // Force V18 because Spv is disabled on versions after system, // Force V18 because Spv is disabled on versions after
appConfig), appConfig),
destroy = NodeUnitTest.destroyNodeFundedWalletBitcoind( destroy = NodeUnitTest.destroyNodeFundedWalletBitcoind(
@ -128,9 +140,10 @@ trait NodeUnitTest extends BitcoinSFixture with EmbeddedPg {
makeDependentFixture( makeDependentFixture(
build = () => build = () =>
NodeUnitTest NodeUnitTest
.createNeutrinoNodeFundedWalletBitcoind(callbacks, bip39PasswordOpt, versionOpt)( .createNeutrinoNodeFundedWalletBitcoind(
system, callbacks,
appConfig), bip39PasswordOpt,
versionOpt)(system, appConfig),
destroy = NodeUnitTest.destroyNodeFundedWalletBitcoind( destroy = NodeUnitTest.destroyNodeFundedWalletBitcoind(
_: NodeFundedWalletBitcoind)(system, appConfig) _: NodeFundedWalletBitcoind)(system, appConfig)
)(test) )(test)
@ -157,7 +170,8 @@ trait NodeUnitTest extends BitcoinSFixture with EmbeddedPg {
() ()
} }
def getBIP39PasswordOpt(): Option[String] = KeyManagerTestUtil.bip39PasswordOpt def getBIP39PasswordOpt(): Option[String] =
KeyManagerTestUtil.bip39PasswordOpt
} }
object NodeUnitTest extends P2PLogger { object NodeUnitTest extends P2PLogger {
@ -235,7 +249,8 @@ object NodeUnitTest extends P2PLogger {
for { for {
bitcoind <- BitcoinSFixture.createBitcoindWithFunds(versionOpt) bitcoind <- BitcoinSFixture.createBitcoindWithFunds(versionOpt)
node <- createSpvNode(bitcoind, callbacks) node <- createSpvNode(bitcoind, callbacks)
fundedWallet <- BitcoinSWalletTest.fundedWalletAndBitcoind(bitcoind, fundedWallet <- BitcoinSWalletTest.fundedWalletAndBitcoind(
bitcoind,
node, node,
node, node,
bip39PasswordOpt) bip39PasswordOpt)
@ -259,7 +274,8 @@ object NodeUnitTest extends P2PLogger {
for { for {
bitcoind <- BitcoinSFixture.createBitcoindWithFunds(versionOpt) bitcoind <- BitcoinSFixture.createBitcoindWithFunds(versionOpt)
node <- createNeutrinoNode(bitcoind, callbacks) node <- createNeutrinoNode(bitcoind, callbacks)
fundedWallet <- BitcoinSWalletTest.fundedWalletAndBitcoind(bitcoindRpcClient = bitcoind, fundedWallet <- BitcoinSWalletTest.fundedWalletAndBitcoind(
bitcoindRpcClient = bitcoind,
nodeApi = node, nodeApi = node,
chainQueryApi = node, chainQueryApi = node,
bip39PasswordOpt = bip39PasswordOpt) bip39PasswordOpt = bip39PasswordOpt)

View file

@ -157,16 +157,23 @@ trait BitcoinSWalletTest
/** Creates a wallet that is funded with some bitcoin, this wallet is NOT /** Creates a wallet that is funded with some bitcoin, this wallet is NOT
* peered with a bitcoind so the funds in the wallet are not tied to an * peered with a bitcoind so the funds in the wallet are not tied to an
* underlying blockchain */ * underlying blockchain */
def withFundedWallet(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { def withFundedWallet(
test: OneArgAsyncTest,
bip39PasswordOpt: Option[String]): FutureOutcome = {
makeDependentFixture( makeDependentFixture(
build = () => FundWalletUtil.createFundedWallet(nodeApi, chainQueryApi, bip39PasswordOpt), build = () =>
FundWalletUtil.createFundedWallet(nodeApi,
chainQueryApi,
bip39PasswordOpt),
destroy = { funded: FundedWallet => destroy = { funded: FundedWallet =>
destroyWallet(funded.wallet) destroyWallet(funded.wallet)
} }
)(test) )(test)
} }
def withFundedSegwitWallet(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { def withFundedSegwitWallet(
test: OneArgAsyncTest,
bip39PasswordOpt: Option[String]): FutureOutcome = {
makeDependentFixture( makeDependentFixture(
build = () => build = () =>
FundWalletUtil.createFundedWallet(nodeApi, FundWalletUtil.createFundedWallet(nodeApi,
@ -189,12 +196,16 @@ trait BitcoinSWalletTest
withNewConfiguredWallet(segwitWalletConf)(test) withNewConfiguredWallet(segwitWalletConf)(test)
} }
def withNewWallet(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = def withNewWallet(
test: OneArgAsyncTest,
bip39PasswordOpt: Option[String]): FutureOutcome =
makeDependentFixture(build = { () => makeDependentFixture(build = { () =>
createDefaultWallet(nodeApi, chainQueryApi, bip39PasswordOpt) createDefaultWallet(nodeApi, chainQueryApi, bip39PasswordOpt)
}, destroy = destroyWallet)(test) }, destroy = destroyWallet)(test)
def withNewWallet2Accounts(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { def withNewWallet2Accounts(
test: OneArgAsyncTest,
bip39PasswordOpt: Option[String]): FutureOutcome = {
makeDependentFixture(build = { () => makeDependentFixture(build = { () =>
createWallet2Accounts(nodeApi, chainQueryApi, bip39PasswordOpt) createWallet2Accounts(nodeApi, chainQueryApi, bip39PasswordOpt)
}, destroy = destroyWallet)(test) }, destroy = destroyWallet)(test)
@ -215,7 +226,9 @@ trait BitcoinSWalletTest
makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test) makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test)
} }
def withNewWalletAndBitcoindV19(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { def withNewWalletAndBitcoindV19(
test: OneArgAsyncTest,
bip39PasswordOpt: Option[String]): FutureOutcome = {
val builder: () => Future[WalletWithBitcoind] = composeBuildersAndWrap( val builder: () => Future[WalletWithBitcoind] = composeBuildersAndWrap(
builder = { () => builder = { () =>
BitcoinSFixture BitcoinSFixture
@ -233,13 +246,16 @@ trait BitcoinSWalletTest
makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test) makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test)
} }
def withFundedWalletAndBitcoind(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { def withFundedWalletAndBitcoind(
test: OneArgAsyncTest,
bip39PasswordOpt: Option[String]): FutureOutcome = {
val builder: () => Future[WalletWithBitcoind] = { () => val builder: () => Future[WalletWithBitcoind] = { () =>
for { for {
bitcoind <- BitcoinSFixture bitcoind <- BitcoinSFixture
.createBitcoindWithFunds(None) .createBitcoindWithFunds(None)
wallet <- createWalletWithBitcoindCallbacks(bitcoind = bitcoind, wallet <- createWalletWithBitcoindCallbacks(bitcoind = bitcoind,
bip39PasswordOpt = bip39PasswordOpt) bip39PasswordOpt =
bip39PasswordOpt)
fundedWallet <- fundWalletWithBitcoind(wallet) fundedWallet <- fundWalletWithBitcoind(wallet)
} yield fundedWallet } yield fundedWallet
} }
@ -247,7 +263,9 @@ trait BitcoinSWalletTest
makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test) makeDependentFixture(builder, destroy = destroyWalletWithBitcoind)(test)
} }
def withFundedWalletAndBitcoindV19(test: OneArgAsyncTest, bip39PasswordOpt: Option[String]): FutureOutcome = { def withFundedWalletAndBitcoindV19(
test: OneArgAsyncTest,
bip39PasswordOpt: Option[String]): FutureOutcome = {
val builder: () => Future[WalletWithBitcoindV19] = { () => val builder: () => Future[WalletWithBitcoindV19] = { () =>
for { for {
bitcoind <- BitcoinSFixture bitcoind <- BitcoinSFixture
@ -277,8 +295,8 @@ trait BitcoinSWalletTest
makeDependentFixture(builder, destroy = destroy)(test) makeDependentFixture(builder, destroy = destroy)(test)
} }
def getBIP39PasswordOpt(): Option[String] =
def getBIP39PasswordOpt(): Option[String] = KeyManagerTestUtil.bip39PasswordOpt KeyManagerTestUtil.bip39PasswordOpt
} }
object BitcoinSWalletTest extends WalletLogger { object BitcoinSWalletTest extends WalletLogger {
@ -433,7 +451,8 @@ object BitcoinSWalletTest extends WalletLogger {
val walletWithBitcoindF = for { val walletWithBitcoindF = for {
wallet <- BitcoinSWalletTest.createWallet2Accounts(bitcoind, wallet <- BitcoinSWalletTest.createWallet2Accounts(bitcoind,
bitcoind, bitcoind,
bip39PasswordOpt = bip39PasswordOpt, bip39PasswordOpt =
bip39PasswordOpt,
extraConfig) extraConfig)
_ = wallet.stopWalletThread() _ = wallet.stopWalletThread()
@ -514,7 +533,9 @@ object BitcoinSWalletTest extends WalletLogger {
created.bitcoind.asInstanceOf[BitcoindV19RpcClient]) created.bitcoind.asInstanceOf[BitcoindV19RpcClient])
} }
def createWalletWithBitcoindV19(bitcoind: BitcoindV19RpcClient, bip39PasswordOpt: Option[String])( def createWalletWithBitcoindV19(
bitcoind: BitcoindV19RpcClient,
bip39PasswordOpt: Option[String])(
implicit system: ActorSystem, implicit system: ActorSystem,
config: BitcoinSAppConfig): Future[WalletWithBitcoindV19] = { config: BitcoinSAppConfig): Future[WalletWithBitcoindV19] = {
import system.dispatcher import system.dispatcher
@ -541,7 +562,9 @@ object BitcoinSWalletTest extends WalletLogger {
system: ActorSystem): Future[WalletWithBitcoind] = { system: ActorSystem): Future[WalletWithBitcoind] = {
import system.dispatcher import system.dispatcher
for { for {
wallet <- BitcoinSWalletTest.createWallet2Accounts(nodeApi, chainQueryApi, bip39PasswordOpt) wallet <- BitcoinSWalletTest.createWallet2Accounts(nodeApi,
chainQueryApi,
bip39PasswordOpt)
withBitcoind <- createWalletWithBitcoind(wallet, versionOpt) withBitcoind <- createWalletWithBitcoind(wallet, versionOpt)
funded <- fundWalletWithBitcoind(withBitcoind) funded <- fundWalletWithBitcoind(withBitcoind)
} yield funded } yield funded

View file

@ -135,7 +135,8 @@ object FundWalletUtil extends FundWalletUtil {
import system.dispatcher import system.dispatcher
for { for {
wallet <- BitcoinSWalletTest.createWallet2Accounts(nodeApi = nodeApi, wallet <- BitcoinSWalletTest.createWallet2Accounts(
nodeApi = nodeApi,
chainQueryApi = chainQueryApi, chainQueryApi = chainQueryApi,
bip39PasswordOpt = bip39PasswordOpt, bip39PasswordOpt = bip39PasswordOpt,
extraConfig = extraConfig) extraConfig = extraConfig)

View file

@ -4,14 +4,11 @@ import org.bitcoins.rpc.client.common.BitcoindRpcClient
import org.bitcoins.rpc.client.v19.BitcoindV19RpcClient import org.bitcoins.rpc.client.v19.BitcoindV19RpcClient
import org.bitcoins.wallet.Wallet import org.bitcoins.wallet.Wallet
sealed trait WalletWithBitcoind { sealed trait WalletWithBitcoind {
def wallet: Wallet def wallet: Wallet
def bitcoind: BitcoindRpcClient def bitcoind: BitcoindRpcClient
} }
case class WalletWithBitcoindRpc(wallet: Wallet, bitcoind: BitcoindRpcClient) case class WalletWithBitcoindRpc(wallet: Wallet, bitcoind: BitcoindRpcClient)
extends WalletWithBitcoind extends WalletWithBitcoind
case class WalletWithBitcoindV19( case class WalletWithBitcoindV19(wallet: Wallet, bitcoind: BitcoindV19RpcClient)
wallet: Wallet,
bitcoind: BitcoindV19RpcClient)
extends WalletWithBitcoind extends WalletWithBitcoind

View file

@ -5,8 +5,16 @@ import org.bitcoins.core.hd.HDAccount
import org.bitcoins.core.number.UInt32 import org.bitcoins.core.number.UInt32
import org.bitcoins.core.protocol.BitcoinAddress import org.bitcoins.core.protocol.BitcoinAddress
import org.bitcoins.core.protocol.blockchain.BlockHeader import org.bitcoins.core.protocol.blockchain.BlockHeader
import org.bitcoins.core.protocol.script.{P2WPKHWitnessSPKV0, P2WPKHWitnessV0, ScriptPubKey} import org.bitcoins.core.protocol.script.{
import org.bitcoins.core.protocol.transaction.{Transaction, TransactionOutPoint, TransactionOutput} P2WPKHWitnessSPKV0,
P2WPKHWitnessV0,
ScriptPubKey
}
import org.bitcoins.core.protocol.transaction.{
Transaction,
TransactionOutPoint,
TransactionOutput
}
import org.bitcoins.core.util.{EitherUtil, FutureUtil} import org.bitcoins.core.util.{EitherUtil, FutureUtil}
import org.bitcoins.core.wallet.utxo.TxoState import org.bitcoins.core.wallet.utxo.TxoState
import org.bitcoins.crypto.DoubleSha256DigestBE import org.bitcoins.crypto.DoubleSha256DigestBE
@ -202,7 +210,6 @@ private[wallet] trait UtxoHandling extends WalletLogger {
} }
} }
override def markUTXOsAsReserved( override def markUTXOsAsReserved(
utxos: Vector[SpendingInfoDb]): Future[Vector[SpendingInfoDb]] = { utxos: Vector[SpendingInfoDb]): Future[Vector[SpendingInfoDb]] = {
val updated = utxos.map(_.copyWithState(TxoState.Reserved)) val updated = utxos.map(_.copyWithState(TxoState.Reserved))
@ -241,7 +248,8 @@ private[wallet] trait UtxoHandling extends WalletLogger {
} }
/** @inheritdoc */ /** @inheritdoc */
override def unmarkUTXOsAsReserved(tx: Transaction): Future[Vector[SpendingInfoDb]] = { override def unmarkUTXOsAsReserved(
tx: Transaction): Future[Vector[SpendingInfoDb]] = {
val utxosF = listUtxos() val utxosF = listUtxos()
val utxosInTxF = for { val utxosInTxF = for {
utxos <- utxosF utxos <- utxosF