mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 01:29:20 +01:00
Remove logging from core (#2810)
* Remove logging from core * Remove slf4j from testkit core * Remove logback from coretest
This commit is contained in:
parent
c3e952a18b
commit
07514e2348
77 changed files with 245 additions and 522 deletions
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.gui.dlc
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.cli.CliCommand._
|
||||
import org.bitcoins.cli.{CliCommand, Config, ConsoleCli}
|
||||
import org.bitcoins.commons.serializers.Picklers._
|
||||
|
@ -7,7 +8,6 @@ import org.bitcoins.core.config.MainNet
|
|||
import org.bitcoins.core.protocol.dlc._
|
||||
import org.bitcoins.core.protocol.tlv._
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.crypto.{CryptoUtil, ECPrivateKey, Sha256DigestBE}
|
||||
import org.bitcoins.gui.dlc.dialog._
|
||||
import org.bitcoins.gui.{GlobalData, TaskRunner}
|
||||
|
@ -23,7 +23,7 @@ import java.nio.file.Files
|
|||
import scala.util.{Failure, Properties, Success, Try}
|
||||
|
||||
class DLCPaneModel(resultArea: TextArea, oracleInfoArea: TextArea)
|
||||
extends BitcoinSLogger {
|
||||
extends Logging {
|
||||
var taskRunner: TaskRunner = _
|
||||
|
||||
lazy val txPrintFunc: String => String = str => {
|
||||
|
|
|
@ -2,8 +2,9 @@ package org.bitcoins.server.routes
|
|||
|
||||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.{Config, ConfigFactory}
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, EnvUtil}
|
||||
import org.bitcoins.core.util.EnvUtil
|
||||
import org.bitcoins.db.AppConfig
|
||||
import org.bitcoins.db.AppConfig.safePathToString
|
||||
|
||||
|
@ -11,7 +12,7 @@ import java.nio.file.{Path, Paths}
|
|||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.util.Properties
|
||||
|
||||
trait BitcoinSRunner extends BitcoinSLogger {
|
||||
trait BitcoinSRunner extends Logging {
|
||||
|
||||
protected def args: Array[String]
|
||||
|
||||
|
|
|
@ -7,7 +7,9 @@ import akka.actor.{ActorSystem, Cancellable}
|
|||
import org.bitcoins.core.api.node.NodeApi
|
||||
import org.bitcoins.core.protocol.blockchain.Block
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil}
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
import org.bitcoins.crypto.DoubleSha256Digest
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.wallet.Wallet
|
||||
|
@ -18,7 +20,7 @@ import scala.concurrent.{ExecutionContext, Future, Promise}
|
|||
import scala.util.{Failure, Success}
|
||||
|
||||
/** Useful utilities to use in the wallet project for syncing things against bitcoind */
|
||||
object BitcoindRpcBackendUtil extends BitcoinSLogger {
|
||||
object BitcoindRpcBackendUtil extends Logging {
|
||||
|
||||
/** Has the wallet process all the blocks it has not seen up until bitcoind's chain tip */
|
||||
def syncWalletToBitcoind(bitcoind: BitcoindRpcClient, wallet: Wallet)(implicit
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package org.bitcoins.asyncutil
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.asyncutil.AsyncUtil.scheduler
|
||||
import org.bitcoins.core.api.asyncutil.AsyncUtilApi
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
|
||||
import java.util.concurrent.{Executors, TimeUnit}
|
||||
import scala.concurrent._
|
||||
import scala.concurrent.duration.{DurationInt, FiniteDuration}
|
||||
|
||||
abstract class AsyncUtil extends AsyncUtilApi with BitcoinSLogger {
|
||||
abstract class AsyncUtil extends AsyncUtilApi with Logging {
|
||||
import AsyncUtil.DEFAULT_MAX_TRIES
|
||||
|
||||
private def retryRunnable(
|
||||
|
|
|
@ -1,26 +1,19 @@
|
|||
package org.bitcoins.rpc.client.common
|
||||
|
||||
import java.nio.file.{Files, Path}
|
||||
import java.util.UUID
|
||||
import akka.actor.ActorSystem
|
||||
import akka.http.javadsl.model.headers.HttpCredentials
|
||||
import akka.http.scaladsl.{Http, HttpExt}
|
||||
import akka.http.scaladsl.model._
|
||||
import akka.http.scaladsl.unmarshalling.Unmarshal
|
||||
import akka.http.scaladsl.{Http, HttpExt}
|
||||
import akka.stream.StreamTcpException
|
||||
import com.fasterxml.jackson.core.JsonParseException
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.asyncutil.AsyncUtil
|
||||
import org.bitcoins.commons.jsonmodels.bitcoind.RpcOpts
|
||||
import org.bitcoins.commons.serializers.JsonSerializers._
|
||||
import org.bitcoins.core.config.{
|
||||
MainNet,
|
||||
NetworkParameters,
|
||||
RegTest,
|
||||
SigNet,
|
||||
TestNet3
|
||||
}
|
||||
import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.crypto.ECPrivateKeyUtil
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, StartStopAsync}
|
||||
import org.bitcoins.core.util.StartStopAsync
|
||||
import org.bitcoins.crypto.ECPrivateKey
|
||||
import org.bitcoins.rpc.BitcoindException
|
||||
import org.bitcoins.rpc.config.BitcoindAuthCredentials.{
|
||||
|
@ -31,6 +24,8 @@ import org.bitcoins.rpc.config.{BitcoindAuthCredentials, BitcoindInstance}
|
|||
import org.bitcoins.rpc.util.NativeProcessFactory
|
||||
import play.api.libs.json._
|
||||
|
||||
import java.nio.file.{Files, Path}
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import scala.concurrent._
|
||||
import scala.concurrent.duration.DurationInt
|
||||
|
@ -45,7 +40,7 @@ import scala.util.{Failure, Success}
|
|||
* and whether or not the client is started.
|
||||
*/
|
||||
trait Client
|
||||
extends BitcoinSLogger
|
||||
extends Logging
|
||||
with StartStopAsync[BitcoindRpcClient]
|
||||
with NativeProcessFactory {
|
||||
def version: BitcoindVersion
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.io.File
|
|||
import java.nio.file.{Files, Paths}
|
||||
|
||||
import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
/** This trait contains the information we need to authenticate
|
||||
* to a `bitcoind` node.
|
||||
|
@ -15,7 +15,7 @@ sealed trait BitcoindAuthCredentials {
|
|||
def username: String
|
||||
}
|
||||
|
||||
object BitcoindAuthCredentials extends BitcoinSLogger {
|
||||
object BitcoindAuthCredentials extends Logging {
|
||||
import org.bitcoins.core.compat.JavaConverters._
|
||||
|
||||
/** Authenticate by providing a username and password.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package org.bitcoins.rpc.config
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.config._
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
import scala.util.Properties
|
||||
import java.nio.file.Paths
|
||||
import java.net.{InetSocketAddress, URI}
|
||||
|
@ -26,7 +26,7 @@ import java.nio.file.Path
|
|||
case class BitcoindConfig(
|
||||
private[bitcoins] val lines: Seq[String],
|
||||
datadir: File)
|
||||
extends BitcoinSLogger {
|
||||
extends Logging {
|
||||
|
||||
//create datadir and config if it DNE on disk
|
||||
if (!datadir.exists()) {
|
||||
|
@ -288,7 +288,7 @@ case class BitcoindConfig(
|
|||
|
||||
}
|
||||
|
||||
object BitcoindConfig extends BitcoinSLogger {
|
||||
object BitcoindConfig extends Logging {
|
||||
|
||||
/** The empty `bitcoind` config */
|
||||
lazy val empty: BitcoindConfig = BitcoindConfig("", DEFAULT_DATADIR)
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.net.URI
|
|||
import java.nio.file.{Files, Paths}
|
||||
|
||||
import org.bitcoins.core.config.NetworkParameters
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.rpc.client.common.BitcoindVersion
|
||||
|
||||
import scala.sys.process._
|
||||
|
@ -13,7 +13,7 @@ import scala.util.Properties
|
|||
|
||||
/** Created by chris on 4/29/17.
|
||||
*/
|
||||
sealed trait BitcoindInstance extends BitcoinSLogger {
|
||||
sealed trait BitcoindInstance extends Logging {
|
||||
|
||||
require(binary.exists,
|
||||
s"bitcoind binary path (${binary.getAbsolutePath}) does not exist!")
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bitcoins.rpc.config
|
|||
|
||||
import java.net.InetSocketAddress
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
sealed trait ZmqConfig {
|
||||
def hashBlock: Option[InetSocketAddress]
|
||||
|
@ -11,7 +11,7 @@ sealed trait ZmqConfig {
|
|||
def rawTx: Option[InetSocketAddress]
|
||||
}
|
||||
|
||||
object ZmqConfig extends BitcoinSLogger {
|
||||
object ZmqConfig extends Logging {
|
||||
|
||||
private case class ZmqConfigImpl(
|
||||
hashBlock: Option[InetSocketAddress],
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.bitcoins.rpc.util
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.sys.process.{Process, ProcessBuilder}
|
||||
|
||||
/** A trait that helps start bitcoind/eclair when it is started via bitcoin-s */
|
||||
trait NativeProcessFactory extends BitcoinSLogger {
|
||||
trait NativeProcessFactory extends Logging {
|
||||
implicit protected def executionContext: ExecutionContext
|
||||
|
||||
private[this] var processOpt: Option[Process] = None
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import Deps.V
|
||||
import com.typesafe.sbt.SbtGit.GitKeys._
|
||||
|
||||
import scala.util.Properties
|
||||
|
@ -30,8 +29,6 @@ lazy val benchSettings: Seq[Def.SettingsDefinition] = {
|
|||
)
|
||||
}
|
||||
|
||||
import Projects._
|
||||
|
||||
lazy val commonJsSettings = {
|
||||
Seq(
|
||||
scalaJSLinkerConfig ~= {
|
||||
|
@ -88,7 +85,8 @@ lazy val asyncUtils = crossProject(JVMPlatform, JSPlatform)
|
|||
.crossType(CrossType.Pure)
|
||||
.in(file("async-utils"))
|
||||
.settings(CommonSettings.prodSettings: _*)
|
||||
.settings(name := "bitcoin-s-async-utils")
|
||||
.settings(name := "bitcoin-s-async-utils",
|
||||
libraryDependencies ++= Deps.asyncUtils)
|
||||
.jvmSettings(CommonSettings.jvmSettings: _*)
|
||||
.jsSettings(commonJsSettings: _*)
|
||||
.dependsOn(core)
|
||||
|
|
|
@ -18,7 +18,13 @@ trait ChainCallbacks {
|
|||
logger: Logger,
|
||||
height: Int,
|
||||
header: BlockHeader)(implicit ec: ExecutionContext): Future[Unit] = {
|
||||
onBlockHeaderConnected.execute(logger, (height, header))
|
||||
|
||||
onBlockHeaderConnected.execute(
|
||||
(height, header),
|
||||
(err: Throwable) =>
|
||||
logger.error(
|
||||
s"${onBlockHeaderConnected.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.bitcoins.core.crypto
|
|||
import org.bitcoins.core.script.PreExecutionScriptProgram
|
||||
import org.bitcoins.core.script.interpreter.ScriptInterpreter
|
||||
import org.bitcoins.core.script.result._
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.testkitcore.gen.TransactionGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import org.scalacheck.{Prop, Properties}
|
|||
*/
|
||||
class TransactionSignatureCreatorSpec
|
||||
extends Properties("TransactionSignatureCreatorSpec")
|
||||
with BitcoinSLogger {
|
||||
with Logging {
|
||||
|
||||
property("Must generate a valid signature for a p2pk transaction") =
|
||||
Prop.forAll(TransactionGenerators.signedP2PKTransaction) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.number
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.testkitcore.gen.NumberGenerator
|
||||
import org.scalacheck.{Gen, Prop, Properties}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import scala.util.Try
|
|||
|
||||
/** Created by chris on 6/16/16.
|
||||
*/
|
||||
class UInt32Spec extends Properties("UInt32") with BitcoinSLogger {
|
||||
class UInt32Spec extends Properties("UInt32") with Logging {
|
||||
|
||||
property("serialization symmetry") = {
|
||||
Prop.forAll(NumberGenerator.uInt32s) { uInt32: UInt32 =>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.bitcoins.core.number
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.testkitcore.gen.NumberGenerator
|
||||
import org.scalacheck.{Gen, Prop, Properties}
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
class UInt8Spec extends Properties("UInt8Spec") with BitcoinSLogger {
|
||||
class UInt8Spec extends Properties("UInt8Spec") with Logging {
|
||||
|
||||
property("convert uint8 -> byte -> uint8") = {
|
||||
Prop.forAll(NumberGenerator.uInt8) { case u8: UInt8 =>
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.testkitcore.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/** Created by chris on 6/22/16.
|
||||
*/
|
||||
class P2PKScriptSignatureSpec
|
||||
extends Properties("P2PKSpec")
|
||||
with BitcoinSLogger {
|
||||
class P2PKScriptSignatureSpec extends Properties("P2PKSpec") with Logging {
|
||||
|
||||
property("Serialization symmetry") =
|
||||
Prop.forAll(ScriptGenerators.p2pkScriptSignature) { p2pkScriptSig =>
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.testkitcore.gen.{ScriptGenerators, WitnessGenerators}
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
class ScriptWitnessSpec
|
||||
extends Properties("ScriptWitnessSpec")
|
||||
with BitcoinSLogger {
|
||||
class ScriptWitnessSpec extends Properties("ScriptWitnessSpec") with Logging {
|
||||
|
||||
property("serialization symmetry") = {
|
||||
Prop.forAll(WitnessGenerators.scriptWitness) { scriptWit =>
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package org.bitcoins.core.protocol.transaction
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.testkitcore.gen.TransactionGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/** Created by chris on 6/24/16.
|
||||
*/
|
||||
class TransactionInputSpec
|
||||
extends Properties("TranactionInputSpec")
|
||||
with BitcoinSLogger {
|
||||
extends Properties("TransactionInputSpec")
|
||||
with Logging {
|
||||
|
||||
property("Serialization symmetry") = {
|
||||
Prop.forAllNoShrink(TransactionGenerators.input) { input =>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package org.bitcoins.core.script.crypto
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.testkitcore.gen.NumberGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
class HashTypeSpec extends Properties("HashTypeSpec") with BitcoinSLogger {
|
||||
class HashTypeSpec extends Properties("HashTypeSpec") with Logging {
|
||||
|
||||
property("serialization symmetry") = {
|
||||
Prop.forAll(NumberGenerator.int32s) { i32 =>
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package org.bitcoins.core.serializers.p2p.messages
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.number.{UInt32, UInt64}
|
||||
import org.bitcoins.core.protocol.CompactSizeUInt
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BytesUtil}
|
||||
import org.bitcoins.core.util.BytesUtil
|
||||
import org.bitcoins.crypto.DoubleSha256Digest
|
||||
import org.bitcoins.testkitcore.util.BitcoinSUnitTest
|
||||
|
||||
/** Created by chris on 7/5/16.
|
||||
*/
|
||||
class RawHeadersMessageSerializerTest
|
||||
extends BitcoinSUnitTest
|
||||
with BitcoinSLogger {
|
||||
class RawHeadersMessageSerializerTest extends BitcoinSUnitTest with Logging {
|
||||
|
||||
//from this example
|
||||
//https://bitcoin.org/en/developer-reference#headers
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package org.bitcoins.core.util
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.testkitcore.util.BitcoinSJvmTest
|
||||
import org.scalatest.compatible.Assertion
|
||||
|
||||
import scala.concurrent._
|
||||
|
||||
class FutureUtilTest extends BitcoinSJvmTest with BitcoinSLogger {
|
||||
class FutureUtilTest extends BitcoinSJvmTest with Logging {
|
||||
it must "execute futures sequentially in the correct order" in {
|
||||
|
||||
val assertionP = Promise[Assertion]()
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package org.bitcoins.core.util
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.number.UInt8
|
||||
import org.bitcoins.testkitcore.gen.NumberGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/** Created by chris on 6/20/16.
|
||||
*/
|
||||
class NumberUtilSpec extends Properties("NumberUtilSpec") with BitcoinSLogger {
|
||||
class NumberUtilSpec extends Properties("NumberUtilSpec") with Logging {
|
||||
|
||||
property("Serialization symmetry for BigInt") =
|
||||
Prop.forAll(NumberGenerator.bigInts) { bigInt: BigInt =>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bitcoins.core.api
|
||||
|
||||
import grizzled.slf4j.Logger
|
||||
import org.bitcoins.core.util.SeqWrapper
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
@ -59,12 +58,4 @@ case class CallbackHandler[C, T <: Callback[C]](
|
|||
|
||||
Future.sequence(executeFs).map(_ => ())
|
||||
}
|
||||
|
||||
/** Executes the callbacks synchronously, Failures are logged */
|
||||
def execute(logger: Logger, param: C)(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
val recoverFunc = (err: Throwable) =>
|
||||
logger.error(s"$name Callback failed with error: ", err)
|
||||
execute(param, recoverFunc)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.bitcoins.core.protocol.script.{
|
|||
import org.bitcoins.core.protocol.transaction.{Transaction, TransactionOutPoint}
|
||||
import org.bitcoins.core.script.constant.{ScriptConstant, ScriptToken}
|
||||
import org.bitcoins.core.serializers.bloom.RawBloomFilterSerializer
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BytesUtil}
|
||||
import org.bitcoins.core.util.BytesUtil
|
||||
import org.bitcoins.crypto._
|
||||
import scodec.bits.{BitVector, ByteVector}
|
||||
|
||||
|
@ -22,7 +22,7 @@ import scala.util.hashing.MurmurHash3
|
|||
* @see [[https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki BIP37]].
|
||||
* @see [[https://github.com/bitcoin/bitcoin/blob/master/src/bloom.h Bitcoin Core bloom.h]]
|
||||
*/
|
||||
sealed abstract class BloomFilter extends NetworkElement with BitcoinSLogger {
|
||||
sealed abstract class BloomFilter extends NetworkElement {
|
||||
|
||||
/** How large the bloom filter is, in Bytes */
|
||||
def filterSize: CompactSizeUInt
|
||||
|
@ -190,7 +190,6 @@ sealed abstract class BloomFilter extends NetworkElement with BitcoinSLogger {
|
|||
}
|
||||
}
|
||||
|
||||
logger.debug("Inserting outPoints: " + outPoints)
|
||||
val outPointsBytes = outPoints.map(_.bytes)
|
||||
val filterWithOutPoints = insertByteVectors(outPointsBytes)
|
||||
//add txid
|
||||
|
@ -198,9 +197,6 @@ sealed abstract class BloomFilter extends NetworkElement with BitcoinSLogger {
|
|||
filterWithOutPoints.insert(transaction.txId)
|
||||
filterWithTxIdAndOutPoints
|
||||
case BloomUpdateNone =>
|
||||
logger.debug(
|
||||
"You are attempting to update a bloom filter when the flag is set to BloomUpdateNone, " +
|
||||
"no information will be added to the bloom filter, specifically this transaction: " + transaction)
|
||||
this
|
||||
case BloomUpdateP2PKOnly =>
|
||||
//update the filter with the outpoint if the filter matches any of the constants in a p2pkh or multisig script pubkey
|
||||
|
@ -225,7 +221,6 @@ sealed abstract class BloomFilter extends NetworkElement with BitcoinSLogger {
|
|||
accumFilter: BloomFilter): BloomFilter =
|
||||
constantsWithIndex match {
|
||||
case h +: t if accumFilter.contains(h._1.bytes) =>
|
||||
logger.debug("Found constant in bloom filter: " + h._1.hex)
|
||||
val filter =
|
||||
accumFilter.insert(TransactionOutPoint(txId, UInt32(h._2)))
|
||||
loop(t, filter)
|
||||
|
@ -287,7 +282,7 @@ sealed abstract class BloomFilter extends NetworkElement with BitcoinSLogger {
|
|||
override def bytes = RawBloomFilterSerializer.write(this)
|
||||
}
|
||||
|
||||
object BloomFilter extends Factory[BloomFilter] with BitcoinSLogger {
|
||||
object BloomFilter extends Factory[BloomFilter] {
|
||||
|
||||
private case class BloomFilterImpl(
|
||||
filterSize: CompactSizeUInt,
|
||||
|
@ -348,11 +343,9 @@ object BloomFilter extends Factory[BloomFilter] with BitcoinSLogger {
|
|||
//from https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki#bloom-filter-format
|
||||
val optimalFilterSize: Double =
|
||||
(-1 / pow(log(2), 2) * numElements * log(falsePositiveRate)) / 8
|
||||
logger.debug("optimalFilterSize " + optimalFilterSize)
|
||||
//BIP37 places limitations on the filter size, namely it cannot be > 36,000 bytes
|
||||
val actualFilterSize: Int =
|
||||
max(1, min(optimalFilterSize, maxSize.toInt * 8)).toInt
|
||||
logger.debug("actualFilterSize: " + actualFilterSize)
|
||||
val optimalHashFuncs: Double = actualFilterSize * 8 / numElements * log(2)
|
||||
//BIP37 places a limit on the amount of hashFuncs we can use, which is 50
|
||||
val actualHashFuncs: Int =
|
||||
|
|
|
@ -16,7 +16,7 @@ import scala.annotation.tailrec
|
|||
* Mimics this functionality inside of bitcoin core
|
||||
* [[https://github.com/bitcoin/bitcoin/blob/master/src/consensus/merkle.cpp]]
|
||||
*/
|
||||
trait Merkle extends BitcoinSLogger {
|
||||
trait Merkle {
|
||||
|
||||
type MerkleTree = BinaryTree[DoubleSha256Digest]
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.bitcoins.core.script.constant.ScriptToken
|
|||
import org.bitcoins.core.script.crypto._
|
||||
import org.bitcoins.core.script.flag.{ScriptFlag, ScriptFlagUtil}
|
||||
import org.bitcoins.core.script.result.ScriptErrorWitnessPubKeyType
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil, BytesUtil}
|
||||
import org.bitcoins.core.util.BitcoinScriptUtil
|
||||
import org.bitcoins.crypto.{DERSignatureUtil, ECDigitalSignature, ECPublicKey}
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
|
@ -18,7 +18,7 @@ import scala.annotation.tailrec
|
|||
* Responsible for checking digital signatures on inputs against their respective
|
||||
* public keys
|
||||
*/
|
||||
trait TransactionSignatureChecker extends BitcoinSLogger {
|
||||
trait TransactionSignatureChecker {
|
||||
|
||||
def checkSignature(
|
||||
txSignatureComponent: TxSigComponent,
|
||||
|
@ -62,7 +62,6 @@ trait TransactionSignatureChecker extends BitcoinSLogger {
|
|||
signature: ECDigitalSignature,
|
||||
flags: Seq[ScriptFlag] =
|
||||
Policy.standardFlags): TransactionSignatureCheckerResult = {
|
||||
logger.debug("Signature: " + signature)
|
||||
val pubKeyEncodedCorrectly = BitcoinScriptUtil.isValidPubKeyEncoding(
|
||||
pubKey,
|
||||
txSignatureComponent.sigVersion,
|
||||
|
@ -71,21 +70,16 @@ trait TransactionSignatureChecker extends BitcoinSLogger {
|
|||
ScriptFlagUtil.requiresStrictDerEncoding(flags) && !DERSignatureUtil
|
||||
.isValidSignatureEncoding(signature)
|
||||
) {
|
||||
logger.error("Signature was not stricly encoded der: " + signature.hex)
|
||||
SignatureValidationErrorNotStrictDerEncoding
|
||||
} else if (
|
||||
ScriptFlagUtil.requireLowSValue(flags) && !DERSignatureUtil
|
||||
.isLowS(signature)
|
||||
) {
|
||||
logger.error("Signature did not have a low s value")
|
||||
SignatureValidationErrorHighSValue
|
||||
} else if (
|
||||
ScriptFlagUtil.requireStrictEncoding(flags) && signature.bytes.nonEmpty &&
|
||||
!HashType.isDefinedHashtypeSignature(signature)
|
||||
) {
|
||||
logger.error("signature: " + signature.hex)
|
||||
logger.error(
|
||||
"Hash type was not defined on the signature, got: " + signature.bytes.last)
|
||||
SignatureValidationErrorHashType
|
||||
} else if (pubKeyEncodedCorrectly.isDefined) {
|
||||
val err = pubKeyEncodedCorrectly.get
|
||||
|
@ -93,8 +87,6 @@ trait TransactionSignatureChecker extends BitcoinSLogger {
|
|||
if (err == ScriptErrorWitnessPubKeyType)
|
||||
SignatureValidationErrorWitnessPubKeyType
|
||||
else SignatureValidationErrorPubKeyEncoding
|
||||
logger.error(
|
||||
"The public key given for signature checking was not encoded correctly, err: " + result)
|
||||
result
|
||||
} else {
|
||||
val sigsRemovedScript = BitcoinScriptUtil.calculateScriptForChecking(
|
||||
|
@ -130,8 +122,6 @@ trait TransactionSignatureChecker extends BitcoinSLogger {
|
|||
hashType)
|
||||
}
|
||||
|
||||
logger.trace(
|
||||
"Hash for signature: " + BytesUtil.encodeHex(hashForSignature.bytes))
|
||||
val sigWithoutHashType = stripHashType(signature)
|
||||
val isValid = pubKey.verify(hashForSignature, sigWithoutHashType)
|
||||
if (isValid) SignatureValidationSuccess
|
||||
|
@ -162,19 +152,14 @@ trait TransactionSignatureChecker extends BitcoinSLogger {
|
|||
requiredSigs: Long): TransactionSignatureCheckerResult = {
|
||||
require(requiredSigs >= 0,
|
||||
s"requiredSigs cannot be negative, got $requiredSigs")
|
||||
logger.trace("Signatures inside of helper: " + sigs)
|
||||
logger.trace("Public keys inside of helper: " + pubKeys)
|
||||
if (sigs.size > pubKeys.size) {
|
||||
//this is how bitcoin core treats this. If there are ever any more
|
||||
//signatures than public keys remaining we immediately return
|
||||
//false https://github.com/bitcoin/bitcoin/blob/8c1dbc5e9ddbafb77e60e8c4e6eb275a3a76ac12/src/script/interpreter.cpp#L943-L945
|
||||
logger.info("We have more sigs than we have public keys remaining")
|
||||
nullFailCheck(sigs, SignatureValidationErrorIncorrectSignatures, flags)
|
||||
} else if (requiredSigs > sigs.size) {
|
||||
//for the case when we do not have enough sigs left to check to meet the required signature threshold
|
||||
//https://github.com/bitcoin/bitcoin/blob/8c1dbc5e9ddbafb77e60e8c4e6eb275a3a76ac12/src/script/interpreter.cpp#L990-L991
|
||||
logger.info(
|
||||
"We do not have enough sigs to meet the threshold of requireSigs in the multiSignatureScriptPubKey")
|
||||
nullFailCheck(sigs, SignatureValidationErrorSignatureCount, flags)
|
||||
} else if (sigs.nonEmpty && pubKeys.nonEmpty) {
|
||||
val sig = sigs.head
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.bitcoins.core.protocol.transaction._
|
|||
import org.bitcoins.core.script.constant.ScriptToken
|
||||
import org.bitcoins.core.script.crypto._
|
||||
import org.bitcoins.core.serializers.transaction.RawTransactionOutputParser
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil, BytesUtil}
|
||||
import org.bitcoins.core.util.{BitcoinScriptUtil, BytesUtil}
|
||||
import org.bitcoins.core.wallet.utxo.{InputInfo, InputSigningInfo}
|
||||
import org.bitcoins.crypto.{CryptoUtil, DoubleSha256Digest}
|
||||
import scodec.bits.ByteVector
|
||||
|
@ -20,7 +20,7 @@ import scodec.bits.ByteVector
|
|||
* bitcoinj version of this
|
||||
* [[https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/core/Transaction.java#L924-L1008]]
|
||||
*/
|
||||
sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
||||
sealed abstract class TransactionSignatureSerializer {
|
||||
|
||||
/** Bitcoin Core's bug is that SignatureHash was supposed to return a hash and on this codepath it
|
||||
* actually returns the constant "1" to indicate an error
|
||||
|
@ -43,7 +43,6 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
val script = BitcoinScriptUtil.calculateScriptForSigning(
|
||||
txSigComponent,
|
||||
output.scriptPubKey.asm)
|
||||
logger.trace(s"scriptForSigning: $script")
|
||||
val amount = output.value
|
||||
|
||||
serializeForSignature(spendingTransaction,
|
||||
|
@ -63,8 +62,6 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
sigVersion: SignatureVersion): ByteVector = {
|
||||
sigVersion match {
|
||||
case SigVersionBase =>
|
||||
logger.trace("Serializing for signature")
|
||||
logger.trace("Script: " + script)
|
||||
// Clear input scripts in preparation for signing. If we're signing a fresh
|
||||
// CScript's inside the Bitcoin Core codebase retain their compactSizeUInt
|
||||
// while clearing out all of the actual asm operations in the CScript
|
||||
|
@ -88,13 +85,9 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
// OP_CODESEPARATOR instruction having no purpose as it was only meant to be used internally, not actually
|
||||
// ever put into scripts. Deleting OP_CODESEPARATOR is a step that should never be required but if we don't
|
||||
// do it, we could split off the main chain.
|
||||
logger.trace("Before Bitcoin-S Script to be connected: " + script)
|
||||
val scriptWithOpCodeSeparatorsRemoved: Seq[ScriptToken] =
|
||||
removeOpCodeSeparators(script)
|
||||
|
||||
logger.trace(
|
||||
"After Bitcoin-S Script to be connected: " + scriptWithOpCodeSeparatorsRemoved)
|
||||
|
||||
val inputToSign = inputSigsRemoved(inputIndex.toInt)
|
||||
|
||||
// Set the input to the script of its output. Bitcoin Core does this but the step has no obvious purpose as
|
||||
|
@ -102,7 +95,6 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
// already. Perhaps it felt safer to him in some way, or is another leftover from how the code was written.
|
||||
val scriptSig =
|
||||
ScriptSignature.fromAsm(scriptWithOpCodeSeparatorsRemoved)
|
||||
logger.trace(s"scriptSig $scriptSig")
|
||||
val inputWithConnectedScript = TransactionInput(
|
||||
inputToSign.previousOutput,
|
||||
scriptSig,
|
||||
|
@ -222,9 +214,6 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
i.previousOutput.bytes ++ CompactSizeUInt.calc(scriptBytes).bytes ++
|
||||
scriptBytes ++ amount.bytes ++ i.sequence.bytes.reverse ++
|
||||
outputHash ++ spendingTransaction.lockTime.bytes.reverse ++ hashType.num.bytes.reverse
|
||||
logger.debug(
|
||||
"Serialization for signature for WitnessV0Sig: " + BytesUtil
|
||||
.encodeHex(serializationForSig))
|
||||
serializationForSig
|
||||
}
|
||||
}
|
||||
|
@ -242,8 +231,6 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
inputIndex >= UInt32(spendingTransaction.inputs.size) &&
|
||||
txSigComponent.sigVersion != SigVersionWitnessV0
|
||||
) {
|
||||
logger.warn(
|
||||
"Our inputIndex is out of the range of the inputs in the spending transaction")
|
||||
errorHash
|
||||
} else if (
|
||||
(hashType.isInstanceOf[SIGHASH_SINGLE] || hashType
|
||||
|
@ -251,16 +238,10 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
inputIndex >= UInt32(spendingTransaction.outputs.size) &&
|
||||
txSigComponent.sigVersion != SigVersionWitnessV0
|
||||
) {
|
||||
logger.warn(
|
||||
"When we have a SIGHASH_SINGLE we cannot have more inputs than outputs")
|
||||
errorHash
|
||||
} else {
|
||||
val serializedTxForSignature =
|
||||
serializeForSignature(txSigComponent, hashType)
|
||||
logger.trace(
|
||||
"Serialized tx for signature: " + BytesUtil.encodeHex(
|
||||
serializedTxForSignature))
|
||||
logger.trace("HashType: " + hashType.num)
|
||||
CryptoUtil.doubleSHA256(serializedTxForSignature)
|
||||
}
|
||||
}
|
||||
|
@ -286,7 +267,6 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
spendingTransaction,
|
||||
signingInfo,
|
||||
output.scriptPubKey.asm)
|
||||
logger.trace(s"scriptForSigning: $script")
|
||||
val amount = output.value
|
||||
|
||||
serializeForSignature(spendingTransaction,
|
||||
|
@ -309,7 +289,6 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
TxUtil.inputIndexOpt(signingInfo.inputInfo, spendingTransaction)
|
||||
|
||||
if (inputIndexOpt.isEmpty) {
|
||||
logger.warn("Our input is not contained in the spending transaction")
|
||||
errorHash
|
||||
} else if (
|
||||
(hashType.isInstanceOf[SIGHASH_SINGLE] || hashType
|
||||
|
@ -317,16 +296,10 @@ sealed abstract class TransactionSignatureSerializer extends BitcoinSLogger {
|
|||
inputIndexOpt.get >= spendingTransaction.outputs.size &&
|
||||
signingInfo.sigVersion != SigVersionWitnessV0
|
||||
) {
|
||||
logger.warn(
|
||||
"When we have a SIGHASH_SINGLE we cannot have more inputs than outputs")
|
||||
errorHash
|
||||
} else {
|
||||
val serializedTxForSignature =
|
||||
serializeForSignature(spendingTransaction, signingInfo, hashType)
|
||||
logger.trace(
|
||||
"Serialized tx for signature: " + BytesUtil.encodeHex(
|
||||
serializedTxForSignature))
|
||||
logger.trace("HashType: " + hashType.num)
|
||||
CryptoUtil.doubleSHA256(serializedTxForSignature)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import scala.math._
|
|||
* The same depth first decoding procedure is performed, but we consume the
|
||||
* bits and hashes that we used during encoding
|
||||
*/
|
||||
sealed trait PartialMerkleTree extends BitcoinSLogger {
|
||||
sealed trait PartialMerkleTree {
|
||||
|
||||
/** The total number of transactions in this block */
|
||||
def transactionCount: UInt32
|
||||
|
|
|
@ -112,7 +112,7 @@ sealed abstract class LnInvoice {
|
|||
}
|
||||
}
|
||||
|
||||
object LnInvoice extends StringFactory[LnInvoice] with BitcoinSLogger {
|
||||
object LnInvoice extends StringFactory[LnInvoice] {
|
||||
|
||||
private case class LnInvoiceImpl(
|
||||
hrp: LnHumanReadablePart,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.bitcoins.core.protocol.ln.util
|
||||
|
||||
import org.bitcoins.core.number.UInt5
|
||||
import org.bitcoins.core.util.{Bech32, BitcoinSLogger}
|
||||
import org.bitcoins.core.util.Bech32
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
/** Useful utility functions for the Lightning encoding / decoding */
|
||||
abstract class LnUtil extends BitcoinSLogger {
|
||||
abstract class LnUtil {
|
||||
|
||||
/** The formula for this calculation is as follows:
|
||||
* Take the length of the Bech32 encoded input and divide it by 32.
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bitcoins.core.protocol.script
|
|||
|
||||
import org.bitcoins.core.protocol.CompactSizeUInt
|
||||
import org.bitcoins.core.script.constant._
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BytesUtil}
|
||||
import org.bitcoins.core.util.BytesUtil
|
||||
import org.bitcoins.crypto.{CryptoUtil, Sha256Digest, Sha256Hash160Digest}
|
||||
|
||||
import scala.util.{Failure, Success, Try}
|
||||
|
@ -12,7 +12,7 @@ import scala.util.{Failure, Success, Try}
|
|||
* this indicates how a [[org.bitcoins.core.protocol.script.ScriptWitness ScriptWitness]] is rebuilt.
|
||||
* [[https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#witness-program BIP141]]
|
||||
*/
|
||||
sealed trait WitnessVersion extends BitcoinSLogger {
|
||||
sealed trait WitnessVersion {
|
||||
|
||||
/** Rebuilds the full script from the given witness and [[org.bitcoins.core.protocol.script.ScriptPubKey ScriptPubKey]]
|
||||
* Either returns the [[org.bitcoins.core.protocol.script.ScriptPubKey ScriptPubKey]]
|
||||
|
@ -49,9 +49,6 @@ case object WitnessVersion0 extends WitnessVersion {
|
|||
val stackHash = CryptoUtil.sha256(stackTop)
|
||||
val witnessHash = Sha256Digest(witnessProgram.head.bytes)
|
||||
if (stackHash != witnessHash) {
|
||||
logger.debug(
|
||||
"Witness hashes did not match Stack hash: " + stackHash)
|
||||
logger.debug("Witness program: " + witnessProgram)
|
||||
Failure(new IllegalArgumentException(
|
||||
s"Witness hash $witnessHash did not match stack hash $stackHash"))
|
||||
} else {
|
||||
|
@ -62,10 +59,6 @@ case object WitnessVersion0 extends WitnessVersion {
|
|||
}
|
||||
}
|
||||
case _ =>
|
||||
logger.error(
|
||||
"Invalid witness program length for witness version 0, got: " + programBytes.size)
|
||||
logger.error("Witness: " + scriptWitness)
|
||||
logger.error("Witness program: " + witnessProgram)
|
||||
//witness version 0 programs need to be 20 bytes or 32 bytes in size
|
||||
Failure(new IllegalArgumentException(
|
||||
s"Witness program had invalid length (${programBytes.length}) for version 0, must be 20 or 30: $witnessProgram"))
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.bitcoins.core.policy.Policy
|
|||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.script.control.OP_RETURN
|
||||
import org.bitcoins.core.script.crypto.HashType
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.core.wallet.builder.{
|
||||
AddWitnessDataFinalizer,
|
||||
RawTxBuilder,
|
||||
|
@ -22,7 +21,7 @@ import scala.annotation.tailrec
|
|||
import scala.concurrent.{Await, ExecutionContext, Future}
|
||||
import scala.util.{Failure, Success, Try}
|
||||
|
||||
object TxUtil extends BitcoinSLogger {
|
||||
object TxUtil {
|
||||
|
||||
def isRBFEnabled(transaction: Transaction): Boolean = {
|
||||
transaction.inputs.exists(
|
||||
|
@ -339,13 +338,8 @@ object TxUtil extends BitcoinSLogger {
|
|||
val max = Satoshis(acceptableVariance)
|
||||
val difference = estimatedFee - actualFee
|
||||
if (difference <= min) {
|
||||
logger.error(
|
||||
s"Fee was too high. Estimated fee $estimatedFee, actualFee $actualFee, difference $difference, acceptableVariance $acceptableVariance")
|
||||
TxBuilderError.HighFee
|
||||
} else if (difference >= max) {
|
||||
logger.error(
|
||||
s"Fee was too low. Estimated fee $estimatedFee, actualFee $actualFee, difference $difference, acceptableVariance $acceptableVariance")
|
||||
|
||||
TxBuilderError.LowFee
|
||||
} else {
|
||||
Success(())
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.bitcoins.core.protocol.script._
|
|||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.script.crypto.HashType
|
||||
import org.bitcoins.core.script.interpreter.ScriptInterpreter
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil}
|
||||
import org.bitcoins.core.util.BitcoinScriptUtil
|
||||
import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte
|
||||
import org.bitcoins.core.wallet.signer.BitcoinSigner
|
||||
import org.bitcoins.core.wallet.utxo._
|
||||
|
@ -23,8 +23,7 @@ case class PSBT(
|
|||
globalMap: GlobalPSBTMap,
|
||||
inputMaps: Vector[InputPSBTMap],
|
||||
outputMaps: Vector[OutputPSBTMap])
|
||||
extends NetworkElement
|
||||
with BitcoinSLogger {
|
||||
extends NetworkElement {
|
||||
require(
|
||||
inputMaps.size == transaction.inputs.size,
|
||||
s"There must be an input map for every input in the global transaction, inputs: ${transaction.inputs}")
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.bitcoins.core.script.locktime.LocktimeOperation
|
|||
import org.bitcoins.core.script.reserved.ReservedOperation
|
||||
import org.bitcoins.core.script.splice.SpliceOperation
|
||||
import org.bitcoins.core.script.stack.StackOperation
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BytesUtil}
|
||||
import org.bitcoins.core.util.BytesUtil
|
||||
import org.bitcoins.crypto.StringFactory
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
|
@ -17,9 +17,7 @@ import scodec.bits.ByteVector
|
|||
* Responsible for matching script op codes with their given
|
||||
* hexadecimal representation or byte representation
|
||||
*/
|
||||
trait ScriptOperationFactory[T <: ScriptOperation]
|
||||
extends StringFactory[T]
|
||||
with BitcoinSLogger {
|
||||
trait ScriptOperationFactory[T <: ScriptOperation] extends StringFactory[T] {
|
||||
|
||||
/** All of the [[org.bitcoins.core.script.ScriptOperation ScriptOperation]]s for a particular `T`. */
|
||||
def operations: Vector[T]
|
||||
|
|
|
@ -12,13 +12,13 @@ import org.bitcoins.core.script.{
|
|||
ExecutionInProgressScriptProgram,
|
||||
StartedScriptProgram
|
||||
}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil}
|
||||
import org.bitcoins.core.util.BitcoinScriptUtil
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
/** Created by chris on 1/25/16.
|
||||
*/
|
||||
sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class ArithmeticInterpreter {
|
||||
|
||||
/** a is added to b. */
|
||||
def opAdd(program: ExecutionInProgressScriptProgram): StartedScriptProgram = {
|
||||
|
@ -56,11 +56,10 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
"Script top must be OP_ABS")
|
||||
performUnaryArithmeticOperation(
|
||||
program,
|
||||
x =>
|
||||
x match {
|
||||
case ScriptNumber.zero => ScriptNumber.zero
|
||||
case _: ScriptNumber => ScriptNumber(x.toLong.abs)
|
||||
})
|
||||
{
|
||||
case ScriptNumber.zero => ScriptNumber.zero
|
||||
case x @ (_: ScriptNumber) => ScriptNumber(x.toLong.abs)
|
||||
})
|
||||
}
|
||||
|
||||
/** Negates the stack top. */
|
||||
|
@ -131,7 +130,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
require(program.script.headOption.contains(OP_NUMEQUALVERIFY),
|
||||
"Script top must be OP_NUMEQUALVERIFY")
|
||||
if (program.stack.size < 2) {
|
||||
logger.error("OP_NUMEQUALVERIFY requires two stack elements")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
val numEqualProgram = program.updateStackAndScript(
|
||||
|
@ -200,7 +198,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
require(program.script.headOption.contains(OP_MIN),
|
||||
"Script top must be OP_MIN")
|
||||
if (program.stack.size < 2) {
|
||||
logger.error("OP_MAX requires at least two stack elements")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
performComparisonOnTwoStackTopItems(
|
||||
|
@ -214,7 +211,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
require(program.script.headOption.contains(OP_MAX),
|
||||
"Script top must be OP_MAX")
|
||||
if (program.stack.size < 2) {
|
||||
logger.error("OP_MAX requires at least two stack elements")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
performComparisonOnTwoStackTopItems(
|
||||
|
@ -229,7 +225,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
require(program.script.headOption.contains(OP_WITHIN),
|
||||
"Script top must be OP_WITHIN")
|
||||
if (program.stack.size < 3) {
|
||||
logger.error("OP_WITHIN requires at least 3 elements on the stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
val c = ScriptNumber(program.stack.head.bytes)
|
||||
|
@ -241,17 +236,12 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
!BitcoinScriptUtil.isShortestEncoding(b) || !BitcoinScriptUtil
|
||||
.isShortestEncoding(a))
|
||||
) {
|
||||
logger.error(
|
||||
"The constant you gave us is not encoded in the shortest way possible")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else if (
|
||||
isLargerThan4Bytes(c) || isLargerThan4Bytes(b) || isLargerThan4Bytes(a)
|
||||
) {
|
||||
//pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002
|
||||
logger.error(
|
||||
"Cannot perform arithmetic operation on a number larger than 4 bytes, one of these three numbers is larger than 4 bytes: "
|
||||
+ c + " " + b + " " + a)
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else {
|
||||
val isWithinRange = a >= b && a < c
|
||||
|
@ -281,20 +271,14 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
op: ScriptNumber => ScriptNumber): StartedScriptProgram = {
|
||||
program.stack.headOption match {
|
||||
case None =>
|
||||
logger.error(
|
||||
"We need one stack element for performing a unary arithmetic operation")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
case Some(s: ScriptNumber) =>
|
||||
if (
|
||||
ScriptFlagUtil.requireMinimalData(program.flags) && !BitcoinScriptUtil
|
||||
.isShortestEncoding(s)
|
||||
) {
|
||||
logger.error(
|
||||
"The number you gave us is not encoded in the shortest way possible")
|
||||
program.failExecution(ScriptErrorMinimalData)
|
||||
} else if (isLargerThan4Bytes(s)) {
|
||||
logger.error(
|
||||
"Cannot perform arithmetic operation on a number larger than 4 bytes, here is the number: " + s)
|
||||
//pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
|
@ -308,8 +292,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
ScriptFlagUtil.requireMinimalData(program.flags) && !BitcoinScriptUtil
|
||||
.isShortestEncoding(s)
|
||||
) {
|
||||
logger.error(
|
||||
"The number you gave us is not encoded in the shortest way possible")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else {
|
||||
val interpretedNumber = ScriptNumber(ScriptNumberUtil.toLong(s.hex))
|
||||
|
@ -320,8 +302,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
case Some(_: ScriptToken) =>
|
||||
//pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002
|
||||
logger.error(
|
||||
"Stack top must be a script number/script constant to perform an arithmetic operation")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
}
|
||||
}
|
||||
|
@ -338,8 +318,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
ScriptNumber,
|
||||
ScriptNumber) => ScriptNumber): StartedScriptProgram = {
|
||||
if (program.stack.size < 2) {
|
||||
logger.error(
|
||||
"We must have two elements to perform a binary arithmetic operation")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
(program.stack.head, program.stack.tail.head) match {
|
||||
|
@ -350,14 +328,10 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
.isShortestEncoding(x) || !BitcoinScriptUtil.isShortestEncoding(
|
||||
y))
|
||||
) {
|
||||
logger.error(
|
||||
"The constant you gave us is not encoded in the shortest way possible")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else if (isLargerThan4Bytes(x) || isLargerThan4Bytes(y)) {
|
||||
//pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002
|
||||
logger.error(
|
||||
"Cannot perform arithmetic operation on a number larger than 4 bytes, one of these two numbers is larger than 4 bytes: " + x + " " + y)
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else {
|
||||
val newStackTop = op(x, y)
|
||||
|
@ -385,8 +359,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
case (_: ScriptToken, _: ScriptToken) =>
|
||||
//pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002
|
||||
logger.error(
|
||||
"The top two stack items must be script numbers to perform an arithmetic operation")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
}
|
||||
}
|
||||
|
@ -401,7 +373,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
program: ExecutionInProgressScriptProgram,
|
||||
op: (ScriptNumber, ScriptNumber) => Boolean): StartedScriptProgram = {
|
||||
if (program.stack.size < 2) {
|
||||
logger.error("We need two stack elements for a binary boolean operation")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
val (x, y) = parseTopTwoStackElementsAsScriptNumbers(program)
|
||||
|
@ -410,14 +381,10 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
(!BitcoinScriptUtil.isShortestEncoding(x) || !BitcoinScriptUtil
|
||||
.isShortestEncoding(y))
|
||||
) {
|
||||
logger.error(
|
||||
"The constant you gave us is not encoded in the shortest way possible")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else if (isLargerThan4Bytes(x) || isLargerThan4Bytes(y)) {
|
||||
//pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002
|
||||
logger.error(
|
||||
"Cannot perform boolean operation on a number larger than 4 bytes, one of these two numbers is larger than 4 bytes: " + x + " " + y)
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else {
|
||||
val newStackTop = if (op(x, y)) OP_TRUE else OP_FALSE
|
||||
|
@ -466,8 +433,6 @@ sealed abstract class ArithmeticInterpreter extends BitcoinSLogger {
|
|||
case (_: ScriptToken, _: ScriptToken) =>
|
||||
//pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002
|
||||
logger.error(
|
||||
"The top two stack items must be script numbers to perform an arithmetic operation")
|
||||
throw new RuntimeException(
|
||||
"Stack top elements must have be script constants to be interpreted as numbers")
|
||||
}
|
||||
|
|
|
@ -11,11 +11,10 @@ import org.bitcoins.core.script.{
|
|||
ExecutionInProgressScriptProgram,
|
||||
StartedScriptProgram
|
||||
}
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
|
||||
/** Created by chris on 1/6/16.
|
||||
*/
|
||||
sealed abstract class BitwiseInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class BitwiseInterpreter {
|
||||
|
||||
/** Returns 1 if the inputs are exactly equal, 0 otherwise. */
|
||||
def opEqual(
|
||||
|
@ -68,7 +67,6 @@ sealed abstract class BitwiseInterpreter extends BitcoinSLogger {
|
|||
case p: ExecutionInProgressScriptProgram => p
|
||||
}
|
||||
} else {
|
||||
logger.error("OP_EQUALVERIFY requires at least 2 elements on the stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ import org.bitcoins.core.script.{
|
|||
ExecutionInProgressScriptProgram,
|
||||
StartedScriptProgram
|
||||
}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil, BytesUtil}
|
||||
import org.bitcoins.core.util.{BitcoinScriptUtil, BytesUtil}
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
/** Created by chris on 1/24/16.
|
||||
*/
|
||||
sealed abstract class ConstantInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class ConstantInterpreter {
|
||||
|
||||
/** The next byte contains the number of bytes to be pushed onto the stack. */
|
||||
def opPushData1(
|
||||
|
@ -73,8 +73,6 @@ sealed abstract class ConstantInterpreter extends BitcoinSLogger {
|
|||
takeUntilBytesNeeded(program.script.tail.tail, Nil)
|
||||
case _: ScriptToken => takeUntilBytesNeeded(program.script.tail, Nil)
|
||||
}
|
||||
logger.debug("new script: " + newScript)
|
||||
logger.debug("Bytes to push onto stack: " + bytesToPushOntoStack)
|
||||
val constant: ScriptToken =
|
||||
if (bytesToPushOntoStack.size == 1) bytesToPushOntoStack.head
|
||||
else
|
||||
|
@ -82,7 +80,6 @@ sealed abstract class ConstantInterpreter extends BitcoinSLogger {
|
|||
BytesUtil.flipEndianness(
|
||||
BytesUtil.toByteVector(bytesToPushOntoStack)))
|
||||
|
||||
logger.debug("Constant to be pushed onto stack: " + constant)
|
||||
//check to see if we have the exact amount of bytes needed to be pushed onto the stack
|
||||
//if we do not, mark the program as invalid
|
||||
if (bytesNeeded == 0)
|
||||
|
@ -92,24 +89,13 @@ sealed abstract class ConstantInterpreter extends BitcoinSLogger {
|
|||
ScriptFlagUtil.requireMinimalData(program.flags) && bytesNeeded == 1 &&
|
||||
constant.isInstanceOf[ScriptNumber] && constant.toLong <= 16
|
||||
) {
|
||||
logger.error(
|
||||
"We can push this constant onto the stack with OP_0 - OP_16 instead of using a script constant")
|
||||
program.failExecution(ScriptErrorMinimalData)
|
||||
} else if (bytesNeeded != bytesToPushOntoStack.map(_.bytes.size).sum) {
|
||||
logger.error("Incorrect amount of bytes being pushed onto the stack")
|
||||
logger.error("Bytes needed: " + bytesNeeded)
|
||||
logger.error(
|
||||
"Number of byte received: " + bytesToPushOntoStack
|
||||
.map(_.bytes.size)
|
||||
.sum)
|
||||
program.failExecution(ScriptErrorBadOpCode)
|
||||
} else if (
|
||||
ScriptFlagUtil.requireMinimalData(program.flags) && !BitcoinScriptUtil
|
||||
.isMinimalPush(program.script.head, constant)
|
||||
) {
|
||||
logger.debug("Pushing operation: " + program.script.head)
|
||||
logger.debug("Constant parsed: " + constant)
|
||||
logger.debug("Constant size: " + constant.bytes.size)
|
||||
program.failExecution(ScriptErrorMinimalData)
|
||||
} else program.updateStackAndScript(constant :: program.stack, newScript)
|
||||
}
|
||||
|
@ -140,8 +126,6 @@ sealed abstract class ConstantInterpreter extends BitcoinSLogger {
|
|||
program.flags) && program.script.size > 2 && !BitcoinScriptUtil
|
||||
.isMinimalPush(program.script.head, program.script(2))
|
||||
) {
|
||||
logger.error(
|
||||
s"Non-minimal push where minimal push was required: $program")
|
||||
program.failExecution(ScriptErrorMinimalData)
|
||||
} else {
|
||||
pushScriptNumberBytesToStack(program)
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.bitcoins.core.util._
|
|||
|
||||
/** Created by chris on 1/6/16.
|
||||
*/
|
||||
sealed abstract class ControlOperationsInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class ControlOperationsInterpreter {
|
||||
|
||||
/** Factors out the similarities between OP_IF and OP_NOTIF */
|
||||
private def opConditional(conditional: ConditionalOperation)(
|
||||
|
@ -28,18 +28,12 @@ sealed abstract class ControlOperationsInterpreter extends BitcoinSLogger {
|
|||
|
||||
stackTopOpt match {
|
||||
case None =>
|
||||
logger.error(
|
||||
s"We do not have any stack elements for our $conditional")
|
||||
program.failExecution(ScriptErrorUnbalancedConditional)
|
||||
case Some(stackTop) =>
|
||||
if (isNotMinimalStackTop(stackTop, sigVersion, minimalIfEnabled)) {
|
||||
logger.error(
|
||||
s"$conditional argument was not minimally encoded, got: " + stackTop)
|
||||
program.failExecution(ScriptErrorMinimalIf)
|
||||
} else {
|
||||
val stackTopTrue: Boolean = program.stackTopIsTrue
|
||||
logger.debug(s"$conditional stack top was $stackTopTrue")
|
||||
logger.debug(s"Stack top: ${program.stack}")
|
||||
|
||||
val conditionToAdd = conditional match {
|
||||
case OP_IF => stackTopTrue
|
||||
|
@ -120,12 +114,10 @@ sealed abstract class ControlOperationsInterpreter extends BitcoinSLogger {
|
|||
"Script top must be OP_VERIFY")
|
||||
program.stack.nonEmpty match {
|
||||
case true =>
|
||||
logger.debug("Stack for OP_VERIFY: " + program.stack)
|
||||
if (program.stackTopIsFalse) program.failExecution(ScriptErrorVerify)
|
||||
else
|
||||
program.updateStackAndScript(program.stack.tail, program.script.tail)
|
||||
case false =>
|
||||
logger.error("OP_VERIFY requires an element to be on the stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.bitcoins.core.script.control.{
|
|||
}
|
||||
import org.bitcoins.core.script.flag.ScriptFlagUtil
|
||||
import org.bitcoins.core.script.result._
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil}
|
||||
import org.bitcoins.core.util.BitcoinScriptUtil
|
||||
import org.bitcoins.crypto.{
|
||||
CryptoUtil,
|
||||
ECDigitalSignature,
|
||||
|
@ -21,7 +21,7 @@ import scodec.bits.ByteVector
|
|||
|
||||
/** Created by chris on 1/6/16.
|
||||
*/
|
||||
sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class CryptoInterpreter {
|
||||
|
||||
/** The input is hashed twice: first with SHA-256 and then with RIPEMD-160. */
|
||||
def opHash160(
|
||||
|
@ -75,19 +75,14 @@ sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
|||
require(program.script.headOption.contains(OP_CHECKSIG),
|
||||
"Script top must be OP_CHECKSIG")
|
||||
if (program.stack.size < 2) {
|
||||
logger.error("OP_CHECKSIG requires at lest two stack elements")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
val pubKey = ECPublicKey(program.stack.head.bytes)
|
||||
val signature = ECDigitalSignature(program.stack.tail.head.bytes)
|
||||
val flags = program.flags
|
||||
val restOfStack = program.stack.tail.tail
|
||||
logger.debug(
|
||||
"Program before removing OP_CODESEPARATOR: " + program.originalScript)
|
||||
val removedOpCodeSeparatorsScript =
|
||||
BitcoinScriptUtil.removeOpCodeSeparator(program)
|
||||
logger.debug(
|
||||
"Program after removing OP_CODESEPARATOR: " + removedOpCodeSeparatorsScript)
|
||||
val result = TransactionSignatureChecker.checkSignature(
|
||||
program.txSignatureComponent,
|
||||
removedOpCodeSeparatorsScript,
|
||||
|
@ -106,14 +101,11 @@ sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
|||
require(program.script.headOption.contains(OP_CHECKSIGVERIFY),
|
||||
"Script top must be OP_CHECKSIGVERIFY")
|
||||
if (program.stack.size < 2) {
|
||||
logger.error("Stack must contain at least 3 items for OP_CHECKSIGVERIFY")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
val newScript = OP_CHECKSIG :: OP_VERIFY :: program.script.tail
|
||||
val newProgram = program.updateScript(newScript)
|
||||
val programFromOpCheckSig = opCheckSig(newProgram)
|
||||
logger.debug(
|
||||
"Stack after OP_CHECKSIG execution: " + programFromOpCheckSig.stack)
|
||||
programFromOpCheckSig match {
|
||||
case _: ExecutedScriptProgram =>
|
||||
programFromOpCheckSig
|
||||
|
@ -157,25 +149,19 @@ sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
|||
val flags = program.flags
|
||||
|
||||
if (program.stack.size < 1) {
|
||||
logger.error("OP_CHECKMULTISIG requires at least 1 stack elements")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
//these next lines remove the appropriate stack/script values after the signatures have been checked
|
||||
val nPossibleSignatures: ScriptNumber =
|
||||
BitcoinScriptUtil.numPossibleSignaturesOnStack(program)
|
||||
if (nPossibleSignatures < ScriptNumber.zero) {
|
||||
logger.error(
|
||||
"We cannot have the number of pubkeys in the script be negative")
|
||||
program.failExecution(ScriptErrorPubKeyCount)
|
||||
} else if (
|
||||
ScriptFlagUtil.requireMinimalData(
|
||||
flags) && !nPossibleSignatures.isShortestEncoding
|
||||
) {
|
||||
logger.error(
|
||||
"The required signatures and the possible signatures must be encoded as the shortest number possible")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else if (program.stack.size < 2) {
|
||||
logger.error("We need at least 2 operations on the stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
val mRequiredSignatures: ScriptNumber =
|
||||
|
@ -185,26 +171,18 @@ sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
|||
ScriptFlagUtil.requireMinimalData(
|
||||
flags) && !mRequiredSignatures.isShortestEncoding
|
||||
) {
|
||||
logger.error(
|
||||
"The required signatures val must be the shortest encoding as possible")
|
||||
return program.failExecution(ScriptErrorUnknownError)
|
||||
}
|
||||
|
||||
if (mRequiredSignatures < ScriptNumber.zero) {
|
||||
logger.error(
|
||||
"We cannot have the number of signatures specified in the script be negative")
|
||||
return program.failExecution(ScriptErrorSigCount)
|
||||
}
|
||||
logger.debug("nPossibleSignatures: " + nPossibleSignatures)
|
||||
val (pubKeysScriptTokens, stackWithoutPubKeys) =
|
||||
(program.stack.tail.slice(0, nPossibleSignatures.toInt),
|
||||
program.stack.tail
|
||||
.slice(nPossibleSignatures.toInt, program.stack.tail.size))
|
||||
|
||||
val pubKeys = pubKeysScriptTokens.map(key => ECPublicKey(key.bytes))
|
||||
logger.debug("Public keys on the stack: " + pubKeys)
|
||||
logger.debug("Stack without pubkeys: " + stackWithoutPubKeys)
|
||||
logger.debug("mRequiredSignatures: " + mRequiredSignatures)
|
||||
|
||||
//+1 is for the fact that we have the # of sigs + the script token indicating the # of sigs
|
||||
val signaturesScriptTokens = program.stack.tail.slice(
|
||||
|
@ -212,24 +190,15 @@ sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
|||
nPossibleSignatures.toInt + mRequiredSignatures.toInt + 1)
|
||||
val signatures =
|
||||
signaturesScriptTokens.map(token => ECDigitalSignature(token.bytes))
|
||||
logger.debug("Signatures on the stack: " + signatures)
|
||||
|
||||
//this contains the extra Script OP that is required for OP_CHECKMULTISIG
|
||||
val stackWithoutPubKeysAndSignatures = stackWithoutPubKeys.tail
|
||||
.slice(mRequiredSignatures.toInt, stackWithoutPubKeys.tail.size)
|
||||
logger.debug(
|
||||
"stackWithoutPubKeysAndSignatures: " + stackWithoutPubKeysAndSignatures)
|
||||
if (pubKeys.size > Consensus.maxPublicKeysPerMultiSig) {
|
||||
logger.error(
|
||||
"We have more public keys than the maximum amount of public keys allowed")
|
||||
program.failExecution(ScriptErrorPubKeyCount)
|
||||
} else if (signatures.size > pubKeys.size) {
|
||||
logger.error(
|
||||
"We have more signatures than public keys inside OP_CHECKMULTISIG")
|
||||
program.failExecution(ScriptErrorSigCount)
|
||||
} else if (stackWithoutPubKeysAndSignatures.size < 1) {
|
||||
logger.error(
|
||||
"OP_CHECKMULTISIG must have a remaining element on the stack afterk execution")
|
||||
//this is because of a bug in bitcoin core for the implementation of OP_CHECKMULTISIG
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L966
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
|
@ -237,8 +206,6 @@ sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
|||
ScriptFlagUtil.requireNullDummy(flags) &&
|
||||
(stackWithoutPubKeysAndSignatures.nonEmpty && stackWithoutPubKeysAndSignatures.head.bytes.nonEmpty)
|
||||
) {
|
||||
logger.error(
|
||||
"Script flag null dummy was set however the first element in the script signature was not an OP_0, stackWithoutPubKeysAndSignatures: " + stackWithoutPubKeysAndSignatures)
|
||||
program.failExecution(ScriptErrorSigNullDummy)
|
||||
} else {
|
||||
//remove the last OP_CODESEPARATOR
|
||||
|
@ -270,15 +237,11 @@ sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
|||
require(program.script.headOption.contains(OP_CHECKMULTISIGVERIFY),
|
||||
"Script top must be OP_CHECKMULTISIGVERIFY")
|
||||
if (program.stack.size < 3) {
|
||||
logger.error(
|
||||
"Stack must contain at least 3 items for OP_CHECKMULTISIGVERIFY")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
val newScript = OP_CHECKMULTISIG :: OP_VERIFY :: program.script.tail
|
||||
val newProgram = program.updateScript(newScript)
|
||||
val programFromOpCheckMultiSig = opCheckMultiSig(newProgram)
|
||||
logger.debug(
|
||||
"Stack after OP_CHECKMULTSIG execution: " + programFromOpCheckMultiSig.stack)
|
||||
programFromOpCheckMultiSig match {
|
||||
case _: ExecutedScriptProgram =>
|
||||
programFromOpCheckMultiSig
|
||||
|
@ -304,8 +267,6 @@ sealed abstract class CryptoInterpreter extends BitcoinSLogger {
|
|||
program.updateStackAndScript(hash :: program.stack.tail,
|
||||
program.script.tail)
|
||||
} else {
|
||||
logger.error(
|
||||
"We must have the stack top defined to execute a hash function")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ import org.bitcoins.core.script.reserved._
|
|||
import org.bitcoins.core.script.result._
|
||||
import org.bitcoins.core.script.splice._
|
||||
import org.bitcoins.core.script.stack._
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BitcoinScriptUtil, BytesUtil}
|
||||
import org.bitcoins.core.util._
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.util.{Failure, Success, Try}
|
||||
|
||||
/** Created by chris on 1/6/16.
|
||||
*/
|
||||
sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class ScriptInterpreter {
|
||||
|
||||
/** Currently bitcoin core limits the maximum number of non-push operations per script
|
||||
* to 201
|
||||
|
@ -57,7 +57,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
case Some(err) => program.failExecution(err)
|
||||
case None =>
|
||||
val scriptSigExecutedProgram = executeProgram(program)
|
||||
logger.trace(s"scriptSigExecutedProgram $scriptSigExecutedProgram")
|
||||
|
||||
val sigComponent = scriptSigExecutedProgram.txSignatureComponent
|
||||
val scriptPubKeyProgram = PreExecutionScriptProgram(
|
||||
|
@ -71,8 +70,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
|
||||
val scriptPubKeyExecutedProgram: ExecutedScriptProgram =
|
||||
executeProgram(scriptPubKeyProgram)
|
||||
logger.trace(
|
||||
s"scriptPubKeyExecutedProgram $scriptPubKeyExecutedProgram")
|
||||
if (scriptSigExecutedProgram.error.isDefined) {
|
||||
scriptSigExecutedProgram
|
||||
} else if (
|
||||
|
@ -99,8 +96,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
}
|
||||
}
|
||||
|
||||
logger.trace("Executed Script Program: " + executedProgram)
|
||||
|
||||
evaluateExecutedScriptProgram(program, executedProgram)
|
||||
}
|
||||
|
||||
|
@ -114,15 +109,11 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
ScriptFlagUtil.requirePushOnly(flags)
|
||||
&& !BitcoinScriptUtil.isPushOnly(program.script)
|
||||
) {
|
||||
logger.error(
|
||||
"We can only have push operations inside of the script sig when the SIGPUSHONLY flag is set")
|
||||
Some(ScriptErrorSigPushOnly)
|
||||
} else {
|
||||
scriptSig match {
|
||||
case _: P2SHScriptSignature
|
||||
if p2shEnabled && !BitcoinScriptUtil.isPushOnly(scriptSig.asm) =>
|
||||
logger.error(
|
||||
"P2SH scriptSigs are required to be push only by definition - see BIP16, got: " + scriptSig.asm)
|
||||
Some(ScriptErrorSigPushOnly)
|
||||
case _: ScriptSignature => None
|
||||
}
|
||||
|
@ -236,8 +227,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
p2shRedeemScriptProgram.flags) && !BitcoinScriptUtil
|
||||
.isPushOnly(s.asm)
|
||||
) {
|
||||
logger.error(
|
||||
"p2sh redeem script must be push only operations whe SIGPUSHONLY flag is set")
|
||||
p2shRedeemScriptProgram.failExecution(ScriptErrorSigPushOnly)
|
||||
} else executeProgram(p2shRedeemScriptProgram)
|
||||
}
|
||||
|
@ -253,8 +242,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
scriptPubKeyExecutedProgram
|
||||
} else {
|
||||
if (scriptPubKeyExecutedProgram.stackTopIsTrue) {
|
||||
logger.debug(
|
||||
"Hashes matched between the p2shScriptSignature & the p2shScriptPubKey")
|
||||
|
||||
//we need to run the deserialized redeemScript & the scriptSignature without the serialized redeemScript
|
||||
val stack = scriptPubKeyExecutedProgram.stack
|
||||
|
@ -307,23 +294,14 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
if (segwitEnabled && isExpectedScriptBytes) {
|
||||
// The scriptSig must be _exactly_ a single push of the redeemScript. Otherwise we
|
||||
// reintroduce malleability.
|
||||
logger.debug(
|
||||
"redeem script was witness script pubkey, segwit was enabled, scriptSig was single push of redeemScript")
|
||||
//TODO: remove .get here
|
||||
executeSegWitScript(scriptPubKeyExecutedProgram, p2wsh).get
|
||||
} else if (
|
||||
segwitEnabled && (scriptSig.asmBytes != expectedScriptBytes)
|
||||
) {
|
||||
logger.error(
|
||||
"Segwit was enabled, but p2sh redeem script was malleated")
|
||||
logger.error("ScriptSig bytes: " + scriptSig.hex)
|
||||
logger.error(
|
||||
"expected scriptsig bytes: " + expectedScriptBytes.toHex)
|
||||
scriptPubKeyExecutedProgram.failExecution(
|
||||
ScriptErrorWitnessMalleatedP2SH)
|
||||
} else {
|
||||
logger.warn(
|
||||
"redeem script was witness script pubkey, segwit was NOT enabled")
|
||||
//treat the segwit scriptpubkey as any other redeem script
|
||||
run(scriptPubKeyExecutedProgram, p2wsh)
|
||||
}
|
||||
|
@ -336,8 +314,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
run(scriptPubKeyExecutedProgram, s)
|
||||
}
|
||||
} else {
|
||||
logger.warn(
|
||||
"P2SH scriptPubKey hash did not match the hash for the serialized redeemScript")
|
||||
scriptPubKeyExecutedProgram
|
||||
}
|
||||
}
|
||||
|
@ -384,8 +360,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
case (EmptyScriptSignature, _) | (_, _: P2SHScriptPubKey) =>
|
||||
witnessScriptPubKey.witnessVersion match {
|
||||
case WitnessVersion0 =>
|
||||
logger.error(
|
||||
"Cannot verify witness program with a BaseTxSigComponent")
|
||||
Success(
|
||||
scriptPubKeyExecutedProgram.failExecution(
|
||||
ScriptErrorWitnessProgramWitnessEmpty))
|
||||
|
@ -415,7 +389,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
/** Helper function to run the post segwit execution checks */
|
||||
def postSegWitProgramChecks(
|
||||
evaluated: ExecutedScriptProgram): ExecutedScriptProgram = {
|
||||
logger.trace("Stack after evaluating witness: " + evaluated.stack)
|
||||
if (evaluated.error.isDefined) evaluated
|
||||
else if (evaluated.stack.size != 1) {
|
||||
// Scripts inside witness implicitly require cleanstack behaviour
|
||||
|
@ -453,10 +426,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
}
|
||||
}
|
||||
case _ =>
|
||||
logger.error(
|
||||
"Invalid witness program length for witness version 0, got: " + programBytes.size)
|
||||
logger.error("Witness: " + scriptWitness)
|
||||
logger.error("Witness program: " + witnessProgram)
|
||||
//witness version 0 programs need to be 20 bytes or 32 bytes in size
|
||||
Left(ScriptErrorWitnessProgramWrongLength)
|
||||
}
|
||||
|
@ -500,11 +469,8 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
/** Executes a PreExecutionScriptProgram */
|
||||
private def executeProgram(
|
||||
program: PreExecutionScriptProgram): ExecutedScriptProgram = {
|
||||
logger.trace("Stack: " + program.stack)
|
||||
logger.trace("Script: " + program.script)
|
||||
val scriptByteVector = BytesUtil.toByteVector(program.script)
|
||||
if (scriptByteVector.length > 10000) {
|
||||
logger.error("We cannot run a script that is larger than 10,000 bytes")
|
||||
program.failExecution(ScriptErrorScriptSize)
|
||||
} else {
|
||||
loop(program.toExecutionInProgress, 0)
|
||||
|
@ -519,8 +485,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
program: ExecutedScriptProgram): ExecutedScriptProgram = {
|
||||
val countedOps = program.originalScript
|
||||
.count(BitcoinScriptUtil.countsTowardsScriptOpLimit)
|
||||
logger.trace("Counted ops: " + countedOps)
|
||||
|
||||
if (countedOps > MAX_SCRIPT_OPS && program.error.isEmpty) {
|
||||
completeProgramExecution(program.failExecution(ScriptErrorOpCount))
|
||||
} else {
|
||||
|
@ -538,18 +502,11 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
program: ExecutionInProgressScriptProgram,
|
||||
opCount: Int): ExecutedScriptProgram = {
|
||||
|
||||
logger.trace("Stack: " + program.stack)
|
||||
logger.trace("Script: " + program.script)
|
||||
val scriptByteVector = BytesUtil.toByteVector(program.script)
|
||||
|
||||
if (opCount > MAX_SCRIPT_OPS) {
|
||||
logger.error(
|
||||
"We have reached the maximum amount of script operations allowed")
|
||||
logger.error(
|
||||
"Here are the remaining operations in the script: " + program.script)
|
||||
completeProgramExecution(program.failExecution(ScriptErrorOpCount))
|
||||
} else if (scriptByteVector.length > 10000) {
|
||||
logger.error("We cannot run a script that is larger than 10,000 bytes")
|
||||
completeProgramExecution(program.failExecution(ScriptErrorScriptSize))
|
||||
} else {
|
||||
val (nextProgram, nextOpCount) = program.script match {
|
||||
|
@ -557,24 +514,18 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
//cease script execution
|
||||
case _
|
||||
if program.script.intersect(Seq(OP_VERIF, OP_VERNOTIF)).nonEmpty =>
|
||||
logger.error(
|
||||
"Script is invalid even when a OP_VERIF or OP_VERNOTIF occurs in an unexecuted OP_IF branch")
|
||||
(program.failExecution(ScriptErrorBadOpCode), opCount)
|
||||
//disabled splice operation
|
||||
case _
|
||||
if program.script
|
||||
.intersect(Seq(OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT))
|
||||
.nonEmpty =>
|
||||
logger.error(
|
||||
"Script is invalid because it contains a disabled splice operation")
|
||||
(program.failExecution(ScriptErrorDisabledOpCode), opCount)
|
||||
//disabled bitwise operations
|
||||
case _
|
||||
if program.script
|
||||
.intersect(Seq(OP_INVERT, OP_AND, OP_OR, OP_XOR))
|
||||
.nonEmpty =>
|
||||
logger.error(
|
||||
"Script is invalid because it contains a disabled bitwise operation")
|
||||
(program.failExecution(ScriptErrorDisabledOpCode), opCount)
|
||||
//disabled arithmetic operations
|
||||
case _
|
||||
|
@ -588,20 +539,14 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
OP_LSHIFT,
|
||||
OP_RSHIFT))
|
||||
.nonEmpty =>
|
||||
logger.error(
|
||||
"Script is invalid because it contains a disabled arithmetic operation")
|
||||
(program.failExecution(ScriptErrorDisabledOpCode), opCount)
|
||||
//program cannot contain a push operation > 520 bytes
|
||||
case _
|
||||
if program.script.exists(token =>
|
||||
token.bytes.size > MAX_PUSH_SIZE) =>
|
||||
logger.error(
|
||||
"We have a script constant that is larger than 520 bytes, this is illegal: " + program.script)
|
||||
(program.failExecution(ScriptErrorPushSize), opCount)
|
||||
//program stack size cannot be greater than 1000 elements
|
||||
case _ if (program.stack.size + program.altStack.size) > 1000 =>
|
||||
logger.error(
|
||||
"We cannot have a stack + alt stack size larger than 1000 elements")
|
||||
(program.failExecution(ScriptErrorStackSize), opCount)
|
||||
|
||||
//no more script operations to run, return whether the program is valid and the final state of the program
|
||||
|
@ -1043,8 +988,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
//if we see an OP_NOP and the DISCOURAGE_UPGRADABLE_OP_NOPS flag is set we must fail our program
|
||||
case (nop: NOP) :: _
|
||||
if ScriptFlagUtil.discourageUpgradableNOPs(program.flags) =>
|
||||
logger.error(
|
||||
"We cannot execute a NOP when the ScriptVerifyDiscourageUpgradableNOPs is set")
|
||||
(program.failExecution(ScriptErrorDiscourageUpgradableNOPs),
|
||||
calcOpCount(opCount, nop))
|
||||
case (nop: NOP) :: t =>
|
||||
|
@ -1054,25 +997,19 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
(programOrError, newOpCount)
|
||||
|
||||
case OP_RESERVED :: _ =>
|
||||
logger.error("OP_RESERVED automatically marks transaction invalid")
|
||||
(program.failExecution(ScriptErrorBadOpCode),
|
||||
calcOpCount(opCount, OP_RESERVED))
|
||||
case OP_VER :: _ =>
|
||||
logger.error("Transaction is invalid when executing OP_VER")
|
||||
(program.failExecution(ScriptErrorBadOpCode),
|
||||
calcOpCount(opCount, OP_VER))
|
||||
case OP_RESERVED1 :: _ =>
|
||||
logger.error("Transaction is invalid when executing OP_RESERVED1")
|
||||
(program.failExecution(ScriptErrorBadOpCode),
|
||||
calcOpCount(opCount, OP_RESERVED1))
|
||||
case OP_RESERVED2 :: _ =>
|
||||
logger.error("Transaction is invalid when executing OP_RESERVED2")
|
||||
(program.failExecution(ScriptErrorBadOpCode),
|
||||
calcOpCount(opCount, OP_RESERVED2))
|
||||
|
||||
case (reservedOperation: ReservedOperation) :: _ =>
|
||||
logger.error(
|
||||
"Undefined operation found which automatically fails the script: " + reservedOperation)
|
||||
(program.failExecution(ScriptErrorBadOpCode),
|
||||
calcOpCount(opCount, reservedOperation))
|
||||
//splice operations
|
||||
|
@ -1094,8 +1031,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
|
||||
} //if not, check to see if we should discourage p
|
||||
else if (ScriptFlagUtil.discourageUpgradableNOPs(program.flags)) {
|
||||
logger.error(
|
||||
"We cannot execute a NOP when the ScriptVerifyDiscourageUpgradableNOPs is set")
|
||||
(program.failExecution(ScriptErrorDiscourageUpgradableNOPs),
|
||||
calcOpCount(opCount, OP_CHECKLOCKTIMEVERIFY))
|
||||
} //in this case, just reat OP_CLTV just like a NOP and remove it from the stack
|
||||
|
@ -1117,8 +1052,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
|
||||
} //if not, check to see if we should discourage p
|
||||
else if (ScriptFlagUtil.discourageUpgradableNOPs(program.flags)) {
|
||||
logger.error(
|
||||
"We cannot execute a NOP when the ScriptVerifyDiscourageUpgradableNOPs is set")
|
||||
(program.failExecution(ScriptErrorDiscourageUpgradableNOPs),
|
||||
calcOpCount(opCount, OP_CHECKSEQUENCEVERIFY))
|
||||
} //in this case, just read OP_CSV just like a NOP and remove it from the stack
|
||||
|
@ -1189,7 +1122,7 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
*/
|
||||
private def hasUnexpectedWitness(program: ScriptProgram): Boolean = {
|
||||
val txSigComponent = program.txSignatureComponent
|
||||
val unexpectedWitness = txSigComponent match {
|
||||
txSigComponent match {
|
||||
case _: WitnessTxSigComponentRaw => false
|
||||
case w: WitnessTxSigComponentP2SH =>
|
||||
w.scriptSignature.redeemScript match {
|
||||
|
@ -1205,11 +1138,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
case r: WitnessTxSigComponentRebuilt =>
|
||||
r.transaction.witness(txSigComponent.inputIndex.toInt).stack.nonEmpty
|
||||
}
|
||||
|
||||
if (unexpectedWitness)
|
||||
logger.error(
|
||||
"Found unexpected witness that was not used by the ScriptProgram: " + program)
|
||||
unexpectedWitness
|
||||
}
|
||||
|
||||
/** Helper function used to rebuild a
|
||||
|
@ -1246,7 +1174,6 @@ sealed abstract class ScriptInterpreter extends BitcoinSLogger {
|
|||
/** Logic to evaluate a witnesss version that has not been assigned yet */
|
||||
private def evaluateUnassignedWitness(
|
||||
txSigComponent: TxSigComponent): Try[ExecutedScriptProgram] = {
|
||||
logger.warn("Unassigned witness inside of witness script pubkey")
|
||||
val flags = txSigComponent.flags
|
||||
val discourageUpgradableWitnessVersion =
|
||||
ScriptFlagUtil.discourageUpgradableWitnessProgram(flags)
|
||||
|
|
|
@ -13,13 +13,12 @@ import org.bitcoins.core.script.{
|
|||
ExecutionInProgressScriptProgram,
|
||||
StartedScriptProgram
|
||||
}
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
/** Created by chris on 2/8/16.
|
||||
*/
|
||||
sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class LockTimeInterpreter {
|
||||
|
||||
/** Marks transaction as invalid if the top stack item is greater than the transaction's `nLockTime` field,
|
||||
* otherwise script evaluation continues as though an `OP_NOP` was executed. Transaction is also invalid if
|
||||
|
@ -39,30 +38,20 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
|||
.inputs(program.txSignatureComponent.inputIndex.toInt)
|
||||
val transaction = program.txSignatureComponent.transaction
|
||||
if (program.stack.isEmpty) {
|
||||
logger.error(
|
||||
"Transaction validation failing in OP_CHECKLOCKTIMEVERIFY because we have no stack items")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else if (input.sequence == TransactionConstants.sequence) {
|
||||
logger.error(
|
||||
"Transaction validation failing in OP_CHECKLOCKTIMEVERIFY because the sequence number is 0xffffffff")
|
||||
program.failExecution(ScriptErrorUnsatisfiedLocktime)
|
||||
} else {
|
||||
program.stack.head match {
|
||||
case s: ScriptNumber if s < ScriptNumber.zero =>
|
||||
logger.error(
|
||||
"OP_CHECKLOCKTIMEVERIFY marks tx as invalid if the stack top is negative")
|
||||
program.failExecution(ScriptErrorNegativeLockTime)
|
||||
case s: ScriptNumber
|
||||
if s >= ScriptNumber(500000000) && transaction.lockTime < UInt32(
|
||||
500000000) =>
|
||||
logger.error(
|
||||
"OP_CHECKLOCKTIMEVERIFY marks the tx as invalid if stack top >= 500000000 & tx locktime < 500000000")
|
||||
program.failExecution(ScriptErrorUnsatisfiedLocktime)
|
||||
case s: ScriptNumber
|
||||
if s < ScriptNumber(500000000) && transaction.lockTime >= UInt32(
|
||||
500000000) =>
|
||||
logger.error(
|
||||
"OP_CHECKLOCKTIMEVERIFY marks the tx as invalid if stack top < 500000000 & tx locktime >= 500000000")
|
||||
program.failExecution(ScriptErrorUnsatisfiedLocktime)
|
||||
case s: ScriptNumber =>
|
||||
if (s.bytes.size > 5) {
|
||||
|
@ -71,8 +60,6 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
|||
} else if (checkLockTime(program, s)) {
|
||||
program.updateScript(program.script.tail)
|
||||
} else {
|
||||
logger.error(
|
||||
"Stack top locktime and transaction locktime number comparison failed")
|
||||
program.failExecution(ScriptErrorUnsatisfiedLocktime)
|
||||
}
|
||||
case s: ScriptConstant =>
|
||||
|
@ -98,7 +85,6 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
|||
final def opCheckSequenceVerify(
|
||||
program: ExecutionInProgressScriptProgram): StartedScriptProgram = {
|
||||
if (program.stack.isEmpty) {
|
||||
logger.error("Cannot execute OP_CHECKSEQUENCEVERIFY on an empty stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
} else {
|
||||
program.stack.head match {
|
||||
|
@ -107,25 +93,17 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
|||
case s: ScriptNumber
|
||||
if ScriptFlagUtil.requireMinimalData(
|
||||
program.flags) && !s.isShortestEncoding =>
|
||||
logger.error(
|
||||
"Sequence number is not encoded in the shortest way possible")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
case s: ScriptNumber if !isLockTimeBitOff(s) =>
|
||||
//see BIP68 for semantic of locktimeDisableFlag
|
||||
logger.info(
|
||||
"Locktime disable flag was set so OP_CHECKSEQUENCEVERIFY is treated as a NOP")
|
||||
program.updateScript(program.script.tail)
|
||||
case s: ScriptNumber
|
||||
if isLockTimeBitOff(
|
||||
s) && program.txSignatureComponent.transaction.version < TransactionConstants.validLockVersion =>
|
||||
logger.error(
|
||||
"OP_CSV fails if locktime bit is not set and the tx version < 2")
|
||||
program.failExecution(ScriptErrorUnsatisfiedLocktime)
|
||||
case s: ScriptNumber =>
|
||||
if (s.bytes.size > 5) {
|
||||
//if the number size is larger than 5 bytes the number is invalid
|
||||
logger.error(
|
||||
"The OP_CSV value in the script was larger than 5 bytes in size.")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
} else if (checkSequence(program, s)) {
|
||||
program.updateScript(program.script.tail)
|
||||
|
@ -157,7 +135,6 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
|||
program: ExecutionInProgressScriptProgram,
|
||||
nSequence: ScriptNumber): Boolean = {
|
||||
val inputIndex = program.txSignatureComponent.inputIndex.toInt
|
||||
logger.debug("inputIndex: " + inputIndex)
|
||||
val transaction = program.txSignatureComponent.transaction
|
||||
|
||||
// Relative lock times are supported by comparing the passed
|
||||
|
@ -169,8 +146,6 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
|||
if (
|
||||
program.txSignatureComponent.transaction.version < TransactionConstants.validLockVersion
|
||||
) {
|
||||
logger.error(
|
||||
"OP_CSV fails the script if the transaction's version is less than 2.")
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -183,14 +158,6 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
|||
val (nSequenceMasked, txToSequenceMasked) =
|
||||
(maskScriptNumber(nSequence), maskSequenceNumber(txToSequence))
|
||||
|
||||
logger.debug(
|
||||
"tx sequence number: " + transaction.inputs(inputIndex).sequence)
|
||||
logger.debug("txToSequenceMasked: " + txToSequenceMasked)
|
||||
logger.debug("nSequence: " + nSequence)
|
||||
logger.debug("nSequenceMasked: " + nSequenceMasked)
|
||||
logger.debug(
|
||||
"Sequence locktime flag: " + TransactionConstants.sequenceLockTimeTypeFlag)
|
||||
|
||||
// There are two kinds of nSequence: lock-by-blockheight
|
||||
// and lock-by-blocktime, distinguished by whether
|
||||
// nSequenceMasked < CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG.
|
||||
|
@ -203,16 +170,12 @@ sealed abstract class LockTimeInterpreter extends BitcoinSLogger {
|
|||
nSequence,
|
||||
txToSequence) || isCSVLockByRelativeLockTime(nSequence, txToSequence))
|
||||
) {
|
||||
logger.error(
|
||||
"The txSequence and nSequence (OP_CSV value) are not of the same type (timestamp/block-height).")
|
||||
return false
|
||||
}
|
||||
|
||||
// Now that we know we're comparing apples-to-apples, the
|
||||
// comparison is a simple numeric one.
|
||||
if (nSequenceMasked > Int64(txToSequenceMasked.toLong)) {
|
||||
logger.error("OP_CSV fails because relative locktime in transaction has not been met yet. " +
|
||||
"(OP_CSV value was greater than the txInput's sequence) script number: " + nSequenceMasked + " tx sequence no: " + txToSequenceMasked)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,10 @@ import org.bitcoins.core.script.{
|
|||
ExecutionInProgressScriptProgram,
|
||||
StartedScriptProgram
|
||||
}
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
|
||||
/** Created by chris on 2/4/16.
|
||||
*/
|
||||
sealed abstract class SpliceInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class SpliceInterpreter {
|
||||
|
||||
/** Pushes the string length of the top element of the stack (without popping it). */
|
||||
def opSize(
|
||||
|
@ -29,7 +28,6 @@ sealed abstract class SpliceInterpreter extends BitcoinSLogger {
|
|||
program.script.tail)
|
||||
}
|
||||
} else {
|
||||
logger.error("Must have at least 1 element on the stack for OP_SIZE")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.bitcoins.core.script.{
|
|||
ExecutionInProgressScriptProgram,
|
||||
StartedScriptProgram
|
||||
}
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
|
||||
import scala.util.{Failure, Success, Try}
|
||||
|
||||
|
@ -15,7 +14,7 @@ import scala.util.{Failure, Success, Try}
|
|||
* Stack operations implemented in the script programming language
|
||||
* https://en.bitcoin.it/wiki/Script#Stack
|
||||
*/
|
||||
sealed abstract class StackInterpreter extends BitcoinSLogger {
|
||||
sealed abstract class StackInterpreter {
|
||||
|
||||
/** Duplicates the element on top of the stack
|
||||
* expects the first element in script to be the OP_DUP operation.
|
||||
|
@ -27,7 +26,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
case h :: _ =>
|
||||
program.updateStackAndScript(h :: program.stack, program.script.tail)
|
||||
case Nil =>
|
||||
logger.error("Cannot duplicate the top element on an empty stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +41,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
program.updateStackAndScript(program.stack.head :: program.stack,
|
||||
program.script.tail)
|
||||
} else {
|
||||
logger.error("Cannot duplicate the top element on an empty stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +67,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
.updateScript(program.script.tail)
|
||||
.updateAltStack(program.stack.head :: program.altStack)
|
||||
} else {
|
||||
logger.error("OP_TOALTSTACK requires an element to be on the stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -86,8 +82,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
.updateScript(program.script.tail)
|
||||
.updateAltStack(program.altStack.tail)
|
||||
} else {
|
||||
logger.error(
|
||||
"Alt Stack must have at least one item on it for OP_FROMALTSTACK")
|
||||
program.failExecution(ScriptErrorInvalidAltStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +94,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
if (program.stack.nonEmpty) {
|
||||
program.updateStackAndScript(program.stack.tail, program.script.tail)
|
||||
} else {
|
||||
logger.error("Stack must have at least one item on it for OP_DROP")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -113,10 +106,8 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
case h :: _ :: t =>
|
||||
program.updateStackAndScript(h :: t, program.script.tail)
|
||||
case _ :: _ =>
|
||||
logger.error("Stack must have at least two items on it for OP_NIP")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
case Nil =>
|
||||
logger.error("Stack must have at least two items on it for OP_NIP")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -130,10 +121,8 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
case _ :: h1 :: _ =>
|
||||
program.updateStackAndScript(h1 :: program.stack, program.script.tail)
|
||||
case _ :: _ =>
|
||||
logger.error("Stack must have at least two items on it for OP_OVER")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
case Nil =>
|
||||
logger.error("Stack must have at least two items on it for OP_OVER")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -156,8 +145,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
program.updateStackAndScript(newStackTop :: program.stack.tail,
|
||||
program.script.tail)
|
||||
} else {
|
||||
logger.error(
|
||||
"The index for OP_PICK would have caused an index out of bounds exception")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -183,8 +170,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
.diff(List(newStackTop))
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
} else {
|
||||
logger.error(
|
||||
"The index for OP_ROLL would have caused an index out of bounds exception")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
)
|
||||
|
@ -201,7 +186,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
val newStack = h2 :: h :: h1 :: t
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
case _ =>
|
||||
logger.error("Stack must have at least 3 items on it for OP_ROT")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +202,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
val newStack = h4 :: h5 :: h :: h1 :: h2 :: h3 :: t
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
case _ =>
|
||||
logger.error("OP_2ROT requires 6 elements on the stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +214,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
if (program.stack.size > 1) {
|
||||
program.updateStackAndScript(program.stack.tail.tail, program.script.tail)
|
||||
} else {
|
||||
logger.error("OP_2DROP requires two elements to be on the stack")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +228,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
program.stack.tail.head :: program.stack.head :: program.stack.tail.tail
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
} else {
|
||||
logger.error("Stack must have at least 2 items on it for OP_SWAP")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +242,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
val newStack = h :: h1 :: h :: t
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
case _ =>
|
||||
logger.error("Stack must have at least 2 items on it for OP_TUCK")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +256,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
val newStack = h :: h1 :: h :: h1 :: t
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
case _ =>
|
||||
logger.error("Stack must have at least 2 items on it for OP_2DUP")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +270,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
val newStack = h :: h1 :: h2 :: h :: h1 :: h2 :: t
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
case _ =>
|
||||
logger.error("Stack must have at least 3 items on it for OP_3DUP")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -306,7 +284,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
val newStack = h2 :: h3 :: h :: h1 :: h2 :: h3 :: t
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
case _ =>
|
||||
logger.error("Stack must have at least 4 items on it for OP_2OVER")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +298,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
val newStack = h2 :: h3 :: h :: h1 :: t
|
||||
program.updateStackAndScript(newStack, program.script.tail)
|
||||
case _ =>
|
||||
logger.error("Stack must have at least 4 items on it for OP_2SWAP")
|
||||
program.failExecution(ScriptErrorInvalidStackOperation)
|
||||
}
|
||||
}
|
||||
|
@ -344,7 +320,6 @@ sealed abstract class StackInterpreter extends BitcoinSLogger {
|
|||
number match {
|
||||
case Success(n) => op(n)
|
||||
case Failure(_) =>
|
||||
logger.error("Script number was not minimally encoded")
|
||||
program.failExecution(ScriptErrorUnknownError)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.bitcoins.core.serializers
|
||||
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, BytesUtil}
|
||||
import org.bitcoins.core.util.BytesUtil
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
/** Created by chris on 1/11/16.
|
||||
* A common trait for reading/writing bitcoin objects to/from bytes/hex
|
||||
*/
|
||||
abstract class RawBitcoinSerializer[T] extends BitcoinSLogger {
|
||||
abstract class RawBitcoinSerializer[T] {
|
||||
|
||||
/** Reads a hexadecimal value and transforms it into the native scala type T. */
|
||||
def read(hex: String): T = read(BytesUtil.decodeHex(hex))
|
||||
|
|
|
@ -5,15 +5,13 @@ import java.net.InetAddress
|
|||
import org.bitcoins.core.number.UInt32
|
||||
import org.bitcoins.core.p2p._
|
||||
import org.bitcoins.core.serializers.RawBitcoinSerializer
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
/** Responsible for serializing and deserializing network ip address objects on the p2p network
|
||||
* @see https://bitcoin.org/en/developer-reference#addr
|
||||
*/
|
||||
trait RawNetworkIpAddressSerializer
|
||||
extends RawBitcoinSerializer[NetworkIpAddress]
|
||||
with BitcoinSLogger {
|
||||
extends RawBitcoinSerializer[NetworkIpAddress] {
|
||||
|
||||
def read(bytes: ByteVector): NetworkIpAddress = {
|
||||
val time = UInt32(bytes.take(4).reverse)
|
||||
|
|
|
@ -4,15 +4,12 @@ import org.bitcoins.core.config._
|
|||
import org.bitcoins.core.number.UInt32
|
||||
import org.bitcoins.core.p2p.NetworkHeader
|
||||
import org.bitcoins.core.serializers.RawBitcoinSerializer
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
/** Reads and writes a message header on the peer-to-peer network
|
||||
* @see https://bitcoin.org/en/developer-reference#message-headers
|
||||
*/
|
||||
trait RawNetworkHeaderSerializer
|
||||
extends RawBitcoinSerializer[NetworkHeader]
|
||||
with BitcoinSLogger {
|
||||
trait RawNetworkHeaderSerializer extends RawBitcoinSerializer[NetworkHeader] {
|
||||
|
||||
/** Transforms a sequence of bytes into a message header
|
||||
* @param bytes the byte representation for a MessageHeader on the peer-to-peer network
|
||||
|
|
|
@ -3,15 +3,13 @@ package org.bitcoins.core.serializers.p2p.messages
|
|||
import org.bitcoins.core.p2p.MerkleBlockMessage
|
||||
import org.bitcoins.core.protocol.blockchain.MerkleBlock
|
||||
import org.bitcoins.core.serializers.RawBitcoinSerializer
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
/** Responsible for serialization and deserialization of MerkleBlockMessages
|
||||
* @see https://bitcoin.org/en/developer-reference#merkleblock
|
||||
*/
|
||||
trait RawMerkleBlockMessageSerializer
|
||||
extends RawBitcoinSerializer[MerkleBlockMessage]
|
||||
with BitcoinSLogger {
|
||||
extends RawBitcoinSerializer[MerkleBlockMessage] {
|
||||
|
||||
def read(bytes: ByteVector): MerkleBlockMessage = {
|
||||
val merkleBlock = MerkleBlock(bytes)
|
||||
|
|
|
@ -6,15 +6,12 @@ import org.bitcoins.core.number.{Int32, Int64, UInt32, UInt64}
|
|||
import org.bitcoins.core.p2p._
|
||||
import org.bitcoins.core.protocol.CompactSizeUInt
|
||||
import org.bitcoins.core.serializers.RawBitcoinSerializer
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
/** Responsible for serialization and deserialization of VersionMessages on the p2p network
|
||||
* @see https://bitcoin.org/en/developer-reference#version
|
||||
*/
|
||||
trait RawVersionMessageSerializer
|
||||
extends RawBitcoinSerializer[VersionMessage]
|
||||
with BitcoinSLogger {
|
||||
trait RawVersionMessageSerializer extends RawBitcoinSerializer[VersionMessage] {
|
||||
|
||||
def read(bytes: ByteVector): VersionMessage = {
|
||||
val version = ProtocolVersion(bytes.take(4))
|
||||
|
|
|
@ -43,7 +43,7 @@ import scala.util.{Failure, Success, Try}
|
|||
|
||||
/** Created by chris on 3/2/16.
|
||||
*/
|
||||
trait BitcoinScriptUtil extends BitcoinSLogger {
|
||||
trait BitcoinScriptUtil {
|
||||
|
||||
/** Takes in a sequence of script tokens and converts them to their hexadecimal value */
|
||||
def asmToHex(asm: Seq[ScriptToken]): String = {
|
||||
|
@ -394,9 +394,6 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
|
|||
script: Seq[ScriptToken]): Seq[ScriptToken] = {
|
||||
val scriptForChecking =
|
||||
calculateScriptForSigning(txSignatureComponent, script)
|
||||
logger.debug("sig for removal: " + signature)
|
||||
logger.debug("script: " + script)
|
||||
logger.debug("scriptWithSigRemoved: " + scriptForChecking)
|
||||
txSignatureComponent.sigVersion match {
|
||||
case SigVersionBase =>
|
||||
removeSignatureFromScript(signature, scriptForChecking)
|
||||
|
@ -515,11 +512,9 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
|
|||
//replicates this line in bitcoin core
|
||||
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L872
|
||||
val sigIndex = script.indexOf(ScriptConstant(signature.hex))
|
||||
logger.debug("SigIndex: " + sigIndex)
|
||||
//remove sig and it's corresponding BytesToPushOntoStack
|
||||
val sigRemoved =
|
||||
script.slice(0, sigIndex - 1) ++ script.slice(sigIndex + 1, script.size)
|
||||
logger.debug("sigRemoved: " + sigRemoved)
|
||||
sigRemoved
|
||||
} else script
|
||||
}
|
||||
|
@ -558,11 +553,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
|
|||
|
||||
private def parseScriptTry(scriptT: Try[ScriptPubKey]): Seq[ScriptToken] =
|
||||
scriptT match {
|
||||
case Success(scriptPubKey) =>
|
||||
logger.debug(
|
||||
"Script pubkey asm inside calculateForSigning: " + scriptPubKey.asm)
|
||||
scriptPubKey.asm
|
||||
case Failure(err) => throw err
|
||||
case Success(scriptPubKey) => scriptPubKey.asm
|
||||
case Failure(err) => throw err
|
||||
}
|
||||
|
||||
/** Casts the given script token to a boolean value
|
||||
|
|
|
@ -14,7 +14,7 @@ import scala.util.{Failure, Success, Try}
|
|||
|
||||
/** Created by chris on 2/8/16.
|
||||
*/
|
||||
sealed abstract class NumberUtil extends BitcoinSLogger {
|
||||
sealed abstract class NumberUtil {
|
||||
|
||||
/** Takes 2^^num. */
|
||||
def pow2(exponent: Int): BigInt = {
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.bitcoins.core.wallet.builder
|
|||
import org.bitcoins.core.crypto.TxSigComponent
|
||||
import org.bitcoins.core.protocol.script.ScriptWitness
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.core.wallet.fee.FeeUnit
|
||||
import org.bitcoins.core.wallet.signer.BitcoinSigner
|
||||
import org.bitcoins.core.wallet.utxo.{
|
||||
|
@ -21,7 +20,7 @@ import scala.util.{Success, Try}
|
|||
* In the future sign methods specific to multi-party protocols will be added
|
||||
* here to support PSBT and signed transaction construction between multiple parties.
|
||||
*/
|
||||
object RawTxSigner extends BitcoinSLogger {
|
||||
object RawTxSigner {
|
||||
|
||||
val emptyInvariant: (
|
||||
Vector[ScriptSignatureParams[InputInfo]],
|
||||
|
|
|
@ -3,7 +3,8 @@ package org.bitcoins.db
|
|||
import com.typesafe.config._
|
||||
import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.protocol.blockchain.BitcoinChainParams
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, StartStopAsync}
|
||||
import org.bitcoins.core.util.StartStopAsync
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
import java.nio.file.{Files, Path, Paths}
|
||||
import scala.concurrent.Future
|
||||
|
@ -16,7 +17,7 @@ import scala.util.matching.Regex
|
|||
* @see [[https://github.com/bitcoin-s/bitcoin-s-core/blob/master/doc/configuration.md `configuration.md`]]
|
||||
* for more information.
|
||||
*/
|
||||
abstract class AppConfig extends StartStopAsync[Unit] with BitcoinSLogger {
|
||||
abstract class AppConfig extends StartStopAsync[Unit] with Logging {
|
||||
|
||||
/** Starts this project.
|
||||
* After this future resolves, all operations should be
|
||||
|
@ -156,7 +157,7 @@ abstract class AppConfig extends StartStopAsync[Unit] with BitcoinSLogger {
|
|||
}
|
||||
}
|
||||
|
||||
object AppConfig extends BitcoinSLogger {
|
||||
object AppConfig extends Logging {
|
||||
|
||||
def safePathToString(path: Path): String = {
|
||||
val pathStr = path.toString.replace("\\", "/")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bitcoins.db
|
||||
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil}
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import slick.dbio.{DBIOAction, NoStream}
|
||||
import slick.lifted.AbstractTable
|
||||
|
||||
|
@ -177,7 +178,7 @@ abstract class CRUD[T, PrimaryKeyType](implicit
|
|||
}
|
||||
|
||||
case class SafeDatabase(jdbcProfile: JdbcProfileComponent[DbAppConfig])
|
||||
extends BitcoinSLogger {
|
||||
extends Logging {
|
||||
|
||||
import jdbcProfile.database
|
||||
import jdbcProfile.profile.api.actionBasedSQLInterpolation
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bitcoins.db
|
||||
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil}
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.db.DatabaseDriver._
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.flywaydb.core.api.{FlywayException, MigrationInfoService}
|
||||
|
@ -8,7 +9,7 @@ import org.flywaydb.core.api.{FlywayException, MigrationInfoService}
|
|||
import java.nio.file.Files
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
trait DbManagement extends BitcoinSLogger {
|
||||
trait DbManagement extends Logging {
|
||||
_: JdbcProfileComponent[DbAppConfig] =>
|
||||
import profile.api._
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ package org.bitcoins.db
|
|||
|
||||
import com.codahale.metrics.{Histogram, MetricRegistry}
|
||||
import com.zaxxer.hikari.{HikariDataSource, HikariPoolMXBean}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, StartStop}
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.util._
|
||||
import slick.jdbc.JdbcDataSource
|
||||
import slick.jdbc.hikaricp.HikariCPJdbcDataSource
|
||||
import slick.util.AsyncExecutorMXBean
|
||||
|
@ -16,7 +17,7 @@ case class HikariLogging(
|
|||
hikariDataSource: HikariDataSource,
|
||||
moduleName: String,
|
||||
interval: Duration
|
||||
) extends BitcoinSLogger
|
||||
) extends Logging
|
||||
with StartStop[HikariLogging] {
|
||||
|
||||
/** Logs thread activity */
|
||||
|
@ -207,7 +208,7 @@ case class HikariLogging(
|
|||
}
|
||||
}
|
||||
|
||||
object HikariLogging extends BitcoinSLogger {
|
||||
object HikariLogging extends Logging {
|
||||
private[db] val scheduler = Executors.newScheduledThreadPool(1)
|
||||
|
||||
/** Returns a started hikari logger if configuration is correct, else None
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.bitcoins.db
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import slick.basic.DatabaseConfig
|
||||
import slick.jdbc.JdbcProfile
|
||||
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
trait JdbcProfileComponent[+ConfigType <: DbAppConfig] extends BitcoinSLogger {
|
||||
trait JdbcProfileComponent[+ConfigType <: DbAppConfig] extends Logging {
|
||||
|
||||
def appConfig: ConfigType
|
||||
|
||||
|
|
|
@ -11,12 +11,13 @@ import org.bitcoins.core.protocol.Bech32Address
|
|||
import org.bitcoins.core.protocol.dlc.SigningVersion
|
||||
import org.bitcoins.core.protocol.script.P2WPKHWitnessSPKV0
|
||||
import org.bitcoins.core.protocol.tlv._
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil, NumberUtil, TimeUtil}
|
||||
import org.bitcoins.core.util.{FutureUtil, NumberUtil, TimeUtil}
|
||||
import org.bitcoins.crypto._
|
||||
import org.bitcoins.dlc.oracle.config.DLCOracleAppConfig
|
||||
import org.bitcoins.dlc.oracle.storage._
|
||||
import org.bitcoins.dlc.oracle.util.EventDbUtil
|
||||
import org.bitcoins.keymanager.{DecryptedMnemonic, WalletStorage}
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
import java.time.Instant
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
@ -24,7 +25,7 @@ import scala.concurrent.{ExecutionContext, Future}
|
|||
class DLCOracle(private[this] val extPrivateKey: ExtPrivateKeyHardened)(implicit
|
||||
val conf: DLCOracleAppConfig)
|
||||
extends DLCOracleApi
|
||||
with BitcoinSLogger {
|
||||
with Logging {
|
||||
|
||||
implicit val ec: ExecutionContext = conf.ec
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.keymanager.bip39
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.api.keymanager.{
|
||||
BIP39KeyManagerApi,
|
||||
BIP39KeyManagerCreateApi,
|
||||
|
@ -7,7 +8,7 @@ import org.bitcoins.core.api.keymanager.{
|
|||
}
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.hd.{HDAccount, HDPath}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, HDUtil, TimeUtil}
|
||||
import org.bitcoins.core.util.{HDUtil, TimeUtil}
|
||||
import org.bitcoins.core.wallet.keymanagement.KeyManagerUnlockError._
|
||||
import org.bitcoins.core.wallet.keymanagement.{
|
||||
InitializeKeyManagerError,
|
||||
|
@ -68,7 +69,7 @@ class BIP39KeyManager(
|
|||
|
||||
object BIP39KeyManager
|
||||
extends BIP39KeyManagerCreateApi[BIP39KeyManager]
|
||||
with BitcoinSLogger {
|
||||
with Logging {
|
||||
|
||||
def fromMnemonic(
|
||||
mnemonic: MnemonicCode,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bitcoins.keymanager.bip39
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.core.wallet.keymanagement.{
|
||||
KeyManagerParams,
|
||||
KeyManagerUnlockError
|
||||
|
@ -11,9 +10,10 @@ import org.bitcoins.keymanager.ReadMnemonicError.{
|
|||
JsonParsingError
|
||||
}
|
||||
import org.bitcoins.keymanager._
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
/** Represents a */
|
||||
object BIP39LockedKeyManager extends BitcoinSLogger {
|
||||
object BIP39LockedKeyManager extends Logging {
|
||||
|
||||
/** Unlock the wallet by decrypting the [[EncryptedMnemonic]] seed
|
||||
* @param passphrase the password to decrypt the wallet
|
||||
|
|
|
@ -35,33 +35,55 @@ trait NodeCallbacks {
|
|||
|
||||
def executeOnTxReceivedCallbacks(logger: Logger, tx: Transaction)(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
onTxReceived.execute(logger, tx)
|
||||
onTxReceived.execute(
|
||||
tx,
|
||||
(err: Throwable) =>
|
||||
logger.error(s"${onTxReceived.name} Callback failed with error: ", err))
|
||||
}
|
||||
|
||||
def executeOnBlockReceivedCallbacks(logger: Logger, block: Block)(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
onBlockReceived.execute(logger, block)
|
||||
onBlockReceived.execute(
|
||||
block,
|
||||
(err: Throwable) =>
|
||||
logger.error(s"${onBlockReceived.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
|
||||
def executeOnMerkleBlockReceivedCallbacks(
|
||||
logger: Logger,
|
||||
merkleBlock: MerkleBlock,
|
||||
txs: Vector[Transaction])(implicit ec: ExecutionContext): Future[Unit] = {
|
||||
onMerkleBlockReceived.execute(logger, (merkleBlock, txs))
|
||||
onMerkleBlockReceived.execute(
|
||||
(merkleBlock, txs),
|
||||
(err: Throwable) =>
|
||||
logger.error(
|
||||
s"${onMerkleBlockReceived.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
|
||||
def executeOnCompactFiltersReceivedCallbacks(
|
||||
logger: Logger,
|
||||
blockFilters: Vector[(DoubleSha256Digest, GolombFilter)])(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
onCompactFiltersReceived.execute(logger, blockFilters)
|
||||
onCompactFiltersReceived.execute(
|
||||
blockFilters,
|
||||
(err: Throwable) =>
|
||||
logger.error(
|
||||
s"${onCompactFiltersReceived.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
|
||||
def executeOnBlockHeadersReceivedCallbacks(
|
||||
logger: Logger,
|
||||
headers: Vector[BlockHeader])(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
onBlockHeadersReceived.execute(logger, headers)
|
||||
onBlockHeadersReceived.execute(
|
||||
headers,
|
||||
(err: Throwable) =>
|
||||
logger.error(
|
||||
s"${onBlockHeadersReceived.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -249,15 +249,14 @@ object Deps {
|
|||
List(
|
||||
Compile.newMicroPickle,
|
||||
Compile.playJson,
|
||||
Compile.slf4j
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j
|
||||
)
|
||||
|
||||
def core = Def.setting {
|
||||
List(
|
||||
Compile.bouncycastle,
|
||||
Compile.scodec.value,
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j
|
||||
Compile.scodec.value
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -283,7 +282,6 @@ object Deps {
|
|||
def coreTest = Def.setting {
|
||||
List(
|
||||
Test.junitInterface,
|
||||
Test.logback,
|
||||
Test.scalaTest.value,
|
||||
Test.spray,
|
||||
Test.playJson,
|
||||
|
@ -302,6 +300,7 @@ object Deps {
|
|||
List(
|
||||
Compile.zeromq,
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j,
|
||||
Test.logback,
|
||||
Test.scalacheck.value,
|
||||
Test.scalaTest.value
|
||||
|
@ -341,6 +340,8 @@ object Deps {
|
|||
Compile.sqlite,
|
||||
Compile.postgres,
|
||||
Compile.slickHikari,
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j,
|
||||
Test.scalaTest.value,
|
||||
Test.pgEmbedded
|
||||
)
|
||||
|
@ -432,8 +433,7 @@ object Deps {
|
|||
Compile.scalaCollectionCompat,
|
||||
Compile.scalacheck.value,
|
||||
Compile.scalaTest.value,
|
||||
Compile.scalaTestPlus.value,
|
||||
Compile.slf4j
|
||||
Compile.scalaTestPlus.value
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -444,6 +444,8 @@ object Deps {
|
|||
Compile.scalaTest.value,
|
||||
Compile.scalaTestPlus.value,
|
||||
Compile.pgEmbedded,
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j,
|
||||
Test.akkaTestkit
|
||||
)
|
||||
}
|
||||
|
@ -461,7 +463,9 @@ object Deps {
|
|||
def wallet(scalaVersion: String) =
|
||||
List(
|
||||
Compile.newMicroJson,
|
||||
Compile.logback
|
||||
Compile.logback,
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j
|
||||
)
|
||||
|
||||
val walletTest = List(
|
||||
|
@ -487,7 +491,9 @@ object Deps {
|
|||
val dlcOracle =
|
||||
List(
|
||||
Compile.newMicroJson,
|
||||
Compile.logback
|
||||
Compile.logback,
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j
|
||||
)
|
||||
|
||||
val dlcOracleTest =
|
||||
|
@ -500,6 +506,13 @@ object Deps {
|
|||
Compile.akkaHttp,
|
||||
Compile.akkaActor,
|
||||
Compile.akkaSlf4j,
|
||||
Compile.akkaStream
|
||||
Compile.akkaStream,
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j
|
||||
)
|
||||
|
||||
val asyncUtils = List(
|
||||
Compile.slf4j,
|
||||
Compile.grizzledSlf4j
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package org.bitcoins.testkitcore.gen
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.consensus.Consensus
|
||||
import org.bitcoins.core.crypto.{TransactionSignatureCreator, _}
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.currency.{CurrencyUnit, CurrencyUnits}
|
||||
import org.bitcoins.core.number.{UInt32, UInt64}
|
||||
import org.bitcoins.core.policy.Policy
|
||||
import org.bitcoins.core.protocol.CompactSizeUInt
|
||||
import org.bitcoins.core.protocol.script.{P2SHScriptPubKey, _}
|
||||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.script.constant.ScriptNumber
|
||||
import org.bitcoins.core.script.control.{ConditionalOperation, OP_IF, OP_NOTIF}
|
||||
import org.bitcoins.core.script.crypto.HashType
|
||||
import org.bitcoins.core.script.interpreter.ScriptInterpreter
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.core.wallet.signer.{
|
||||
MultiSigSigner,
|
||||
P2PKHSigner,
|
||||
|
@ -35,7 +35,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
|
|||
import scala.concurrent.duration.DurationInt
|
||||
|
||||
//TODO: Need to provide generators for [[NonStandardScriptSignature]] and [[NonStandardScriptPubKey]]
|
||||
sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
||||
sealed abstract class ScriptGenerators extends Logging {
|
||||
val timeout = 30.seconds
|
||||
val defaultMaxDepth: Int = 2
|
||||
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
package org.bitcoins.testkitcore.gen
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.currency._
|
||||
import org.bitcoins.core.number.{Int32, UInt32}
|
||||
import org.bitcoins.core.policy.Policy
|
||||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.protocol.transaction.{
|
||||
TransactionInput,
|
||||
TransactionOutPoint,
|
||||
TransactionOutput,
|
||||
_
|
||||
}
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.script.constant.ScriptNumber
|
||||
import org.bitcoins.core.script.locktime.LockTimeInterpreter
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.crypto.ECPrivateKey
|
||||
import org.bitcoins.testkitcore.Implicits._
|
||||
import org.scalacheck.Gen
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
object TransactionGenerators extends BitcoinSLogger {
|
||||
object TransactionGenerators extends Logging {
|
||||
|
||||
/** Responsible for generating [[org.bitcoins.core.protocol.transaction.TransactionOutPoint TransactionOutPoint]] */
|
||||
def outPoint: Gen[TransactionOutPoint] =
|
||||
|
|
|
@ -7,13 +7,13 @@ import org.bitcoins.core.policy.Policy
|
|||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.script.crypto.HashType
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.crypto.ECPrivateKey
|
||||
import org.scalacheck.Gen
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
/** Created by chris on 11/28/16.
|
||||
*/
|
||||
sealed abstract class WitnessGenerators extends BitcoinSLogger {
|
||||
sealed abstract class WitnessGenerators extends Logging {
|
||||
|
||||
/** Generates a random [[org.bitcoins.core.protocol.script.ScriptWitness]] */
|
||||
def scriptWitness: Gen[ScriptWitness] = {
|
||||
|
|
|
@ -1,27 +1,22 @@
|
|||
package org.bitcoins.testkitcore.util
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.asyncutil.AsyncUtil
|
||||
import org.bitcoins.core.config.{NetworkParameters, RegTest}
|
||||
import org.bitcoins.core.protocol.blockchain.ChainParams
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Gen, Shrink}
|
||||
import org.scalactic.anyvals.PosInt
|
||||
import org.scalatest.{
|
||||
Assertion,
|
||||
AsyncTestSuite,
|
||||
BeforeAndAfter,
|
||||
BeforeAndAfterAll
|
||||
}
|
||||
import org.scalatest.concurrent.AsyncTimeLimitedTests
|
||||
import org.scalatest.flatspec.AsyncFlatSpec
|
||||
import org.scalatest.matchers.must.Matchers
|
||||
import org.scalatest.time.Span
|
||||
import org.scalatest._
|
||||
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
|
||||
|
||||
import scala.annotation.nowarn
|
||||
import scala.collection.JavaConverters.iterableAsScalaIterableConverter
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
/** This is a base trait in bitcoin-s for async tests
|
||||
*/
|
||||
|
@ -31,7 +26,7 @@ trait BaseAsyncTest
|
|||
with Matchers
|
||||
with ScalaCheckPropertyChecks
|
||||
with AsyncTimeLimitedTests
|
||||
with BitcoinSLogger { this: AsyncTestSuite =>
|
||||
with Logging { this: AsyncTestSuite =>
|
||||
|
||||
implicit def np: NetworkParameters = RegTest
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.testkitcore.util
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.scalacheck.Shrink
|
||||
import org.scalactic.anyvals.PosInt
|
||||
import org.scalatest.concurrent.TimeLimitedTests
|
||||
|
@ -17,7 +17,7 @@ abstract class BitcoinSUnitTest
|
|||
with Matchers
|
||||
with ScalaCheckPropertyChecks
|
||||
with TimeLimitedTests
|
||||
with BitcoinSLogger {
|
||||
with Logging {
|
||||
|
||||
override val timeLimit: Span = 120.seconds
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package org.bitcoins.testkitcore.util
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.crypto.ECPrivateKeyUtil
|
||||
import org.bitcoins.core.currency.{CurrencyUnit, CurrencyUnits}
|
||||
import org.bitcoins.core.number.{Int32, UInt32}
|
||||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.core.psbt.PSBT
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.crypto.{DoubleSha256Digest, ECPublicKey}
|
||||
|
||||
/** Created by chris on 2/12/16.
|
||||
*/
|
||||
trait TransactionTestUtil extends BitcoinSLogger {
|
||||
trait TransactionTestUtil extends Logging {
|
||||
|
||||
/** Raw multisignature script pub key output
|
||||
* @return
|
||||
|
|
|
@ -7,17 +7,18 @@ import org.bitcoins.core.api.node.{NodeApi, NodeChainQueryApi}
|
|||
import org.bitcoins.core.gcs.FilterType
|
||||
import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader}
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil}
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.crypto.{DoubleSha256Digest, DoubleSha256DigestBE}
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.rpc.client.v19.BitcoindV19RpcClient
|
||||
import org.bitcoins.wallet.Wallet
|
||||
import org.bitcoins.wallet.sync.WalletSync
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
/** Useful utilities to use in the chain project for syncing things against bitcoind */
|
||||
abstract class SyncUtil extends BitcoinSLogger {
|
||||
abstract class SyncUtil extends Logging {
|
||||
|
||||
/** Creates a function that will retrun bitcoin's best block hash when called */
|
||||
def getBestBlockHashFunc(
|
||||
|
|
|
@ -17,7 +17,7 @@ import org.bitcoins.core.protocol.ln.channel.{
|
|||
}
|
||||
import org.bitcoins.core.protocol.ln.currency.MilliSatoshis
|
||||
import org.bitcoins.core.protocol.ln.node.NodeId
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.crypto.Sha256Digest
|
||||
import org.bitcoins.eclair.rpc.api._
|
||||
import org.bitcoins.eclair.rpc.client.EclairRpcClient
|
||||
|
@ -46,7 +46,7 @@ import scala.util.{Failure, Success}
|
|||
* Each double sided arrow represents a P2P connection as well as a funded
|
||||
* channel
|
||||
*/
|
||||
trait EclairRpcTestUtil extends BitcoinSLogger {
|
||||
trait EclairRpcTestUtil extends Logging {
|
||||
|
||||
def randomEclairDatadir(): File =
|
||||
new File(s"/tmp/eclair-test/${FileUtil.randomDirName}/.eclair/")
|
||||
|
|
|
@ -23,7 +23,8 @@ import org.bitcoins.core.protocol.transaction.{
|
|||
TransactionInput,
|
||||
TransactionOutPoint
|
||||
}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, EnvUtil}
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.util.EnvUtil
|
||||
import org.bitcoins.crypto.{
|
||||
DoubleSha256Digest,
|
||||
DoubleSha256DigestBE,
|
||||
|
@ -56,7 +57,7 @@ import scala.util._
|
|||
import scala.util.control.NonFatal
|
||||
|
||||
//noinspection AccessorLikeMethodIsEmptyParen
|
||||
trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
||||
trait BitcoindRpcTestUtil extends Logging {
|
||||
|
||||
lazy val network: RegTest.type = RegTest
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package org.bitcoins.testkit.util
|
||||
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.{Path, Paths}
|
||||
import scala.annotation.tailrec
|
||||
import scala.util.{Properties, Random}
|
||||
|
||||
object FileUtil extends BitcoinSLogger {
|
||||
object FileUtil extends Logging {
|
||||
|
||||
/** Returns a `BufferedSource` for any file on the classpath */
|
||||
def getFileAsSource(fileName: String): scala.io.BufferedSource = {
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package org.bitcoins.testkit.util
|
||||
|
||||
import org.bitcoins.core.config.RegTest
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, StartStopAsync}
|
||||
import org.bitcoins.core.util.StartStopAsync
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
/** A utility trait for handling binaries like bitcoind/eclair.
|
||||
* All common utility methods should go in this trait
|
||||
*/
|
||||
trait RpcBinaryUtil[T] extends StartStopAsync[T] with BitcoinSLogger {
|
||||
trait RpcBinaryUtil[T] extends StartStopAsync[T] with Logging {
|
||||
|
||||
/** The path to the binary, an example is
|
||||
* '/home/suredbits/.bitcoin-s/binaries/bitcoind/bitcoin-0.20.1/bin/bitcoind'
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.bitcoins.core.currency.CurrencyUnit
|
|||
import org.bitcoins.core.hd.HDAccount
|
||||
import org.bitcoins.core.protocol.BitcoinAddress
|
||||
import org.bitcoins.core.protocol.transaction.TransactionOutput
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.rpc.client.common.BitcoindRpcClient
|
||||
import org.bitcoins.server.BitcoinSAppConfig
|
||||
|
@ -18,7 +18,7 @@ import org.bitcoins.wallet.Wallet
|
|||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
trait FundWalletUtil extends BitcoinSLogger {
|
||||
trait FundWalletUtil extends Logging {
|
||||
|
||||
def fundAccountForWallet(
|
||||
amts: Vector[CurrencyUnit],
|
||||
|
|
|
@ -31,22 +31,41 @@ trait WalletCallbacks {
|
|||
|
||||
def executeOnTransactionProcessed(logger: Logger, tx: Transaction)(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
onTransactionProcessed.execute(logger, tx)
|
||||
onTransactionProcessed.execute(
|
||||
tx,
|
||||
(err: Throwable) =>
|
||||
logger.error(
|
||||
s"${onTransactionProcessed.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
|
||||
def executeOnTransactionBroadcast(logger: Logger, tx: Transaction)(implicit
|
||||
ec: ExecutionContext): Future[Unit] = {
|
||||
onTransactionBroadcast.execute(logger, tx)
|
||||
onTransactionBroadcast.execute(
|
||||
tx,
|
||||
(err: Throwable) =>
|
||||
logger.error(
|
||||
s"${onTransactionProcessed.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
|
||||
def executeOnReservedUtxos(logger: Logger, utxos: Vector[SpendingInfoDb])(
|
||||
implicit ec: ExecutionContext): Future[Unit] = {
|
||||
onReservedUtxos.execute(logger, utxos)
|
||||
onReservedUtxos.execute(
|
||||
utxos,
|
||||
(err: Throwable) =>
|
||||
logger.error(s"${onReservedUtxos.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
|
||||
def executeOnNewAddressGenerated(logger: Logger, address: BitcoinAddress)(
|
||||
implicit ec: ExecutionContext): Future[Unit] = {
|
||||
onNewAddressGenerated.execute(logger, address)
|
||||
onNewAddressGenerated.execute(
|
||||
address,
|
||||
(err: Throwable) =>
|
||||
logger.error(
|
||||
s"${onNewAddressGenerated.name} Callback failed with error: ",
|
||||
err))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package org.bitcoins.wallet.sync
|
||||
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.core.protocol.blockchain.{Block, BlockHeader}
|
||||
import org.bitcoins.core.util.{BitcoinSLogger, FutureUtil}
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.wallet.Wallet
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
trait WalletSync extends BitcoinSLogger {
|
||||
trait WalletSync extends Logging {
|
||||
|
||||
/** Synchronizes the bitcoin-s' wallet by retrieving each block and then calling
|
||||
* [[Wallet.processBlock()]] on the block retrieved
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.net.InetSocketAddress
|
|||
|
||||
import org.bitcoins.core.protocol.blockchain.Block
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.zeromq.{SocketType, ZMQ, ZMQException, ZMsg}
|
||||
import scodec.bits.ByteVector
|
||||
|
@ -26,7 +26,7 @@ class ZMQSubscriber(
|
|||
hashBlockListener: Option[DoubleSha256DigestBE => Unit],
|
||||
rawTxListener: Option[Transaction => Unit],
|
||||
rawBlockListener: Option[Block => Unit])
|
||||
extends BitcoinSLogger {
|
||||
extends Logging {
|
||||
|
||||
private var running = true
|
||||
private val context = ZMQ.context(1)
|
||||
|
|
|
@ -5,14 +5,14 @@ import java.net.InetSocketAddress
|
|||
import org.bitcoins.core.config.MainNet
|
||||
import org.bitcoins.core.protocol.blockchain.Block
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import grizzled.slf4j.Logging
|
||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.scalatest.flatspec.AsyncFlatSpec
|
||||
import org.zeromq.{SocketType, ZFrame, ZMQ, ZMsg}
|
||||
|
||||
import scala.concurrent.Promise
|
||||
|
||||
class ZMQSubscriberTest extends AsyncFlatSpec with BitcoinSLogger {
|
||||
class ZMQSubscriberTest extends AsyncFlatSpec with Logging {
|
||||
|
||||
behavior of "ZMQSubscriber"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue