Scaladoc formatting (#287)

This commit is contained in:
Torkel Rogstad 2019-01-08 12:55:33 +01:00 committed by Chris Stewart
parent a2504ba6d7
commit aa65b783cc
13 changed files with 149 additions and 93 deletions

View File

@ -19,11 +19,11 @@ import scodec.bits.ByteVector
*/
trait ScriptOperationFactory[T <: ScriptOperation] extends BitcoinSLogger {
/** All of the [[ScriptOperation]]s for a particular T. */
/** All of the [[org.bitcoins.core.script.ScriptOperation ScriptOperation]]s for a particular `T`. */
def operations: Seq[T]
/**
* Finds a [[ScriptOperation]] from a given string
* Finds a [[org.bitcoins.core.script.ScriptOperation ScriptOperation]] from a given string
*/
def fromString(str: String): Option[T] = {
val result: Option[T] = operations.find(_.toString == str)
@ -35,7 +35,7 @@ trait ScriptOperationFactory[T <: ScriptOperation] extends BitcoinSLogger {
}
/**
* Finds a [[ScriptOperation]] from its hexadecimal representation.
* Finds a [[org.bitcoins.core.script.ScriptOperation ScriptOperation]] from its hexadecimal representation.
*/
def fromHex(hex: String): Option[T] = {
val bytes = BitcoinSUtil.decodeHex(hex)
@ -44,13 +44,13 @@ trait ScriptOperationFactory[T <: ScriptOperation] extends BitcoinSLogger {
/**
* Removes the 'OP_' prefix from a given operation.
* Example: OP_EQUALVERIFY would be transformed into EQUALVERIFY
* Example: `OP_EQUALVERIFY` would be transformed into `EQUALVERIFY`
*/
private def removeOP_Prefix(str: String): String = {
str.replace("OP_", "")
}
/** Finds a [[ScriptOperation]] from a given [[Byte]]. */
/** Finds a [[org.bitcoins.core.script.ScriptOperation ScriptOperation]] from a given [[Byte]]. */
def fromByte(byte: Byte): T = {
operations.find(_.toByte == byte).get
}

View File

@ -13,12 +13,13 @@ sealed trait ScriptProgram {
/**
* This contains all relevant information for hashing and checking a
* [[org.bitcoins.core.protocol.script.ScriptSignature]] for
* a [[org.bitcoins.core.protocol.transaction.Transaction]].
* [[org.bitcoins.core.protocol.script.ScriptSignature ScriptSignature]] for
* a [[org.bitcoins.core.protocol.transaction.Transaction Transaction]].
*/
def txSignatureComponent: TxSigComponent
/** The current state of the stack for execution of the [[ScriptProgram]]. */
/** The current state of the stack for execution of the
* [[org.bitcoins.core.script.ScriptProgram ScriptProgram]]. */
def stack: List[ScriptToken]
/** The script operations that need to still be executed. */
@ -31,7 +32,7 @@ sealed trait ScriptProgram {
def altStack: List[ScriptToken]
/**
* [[ScriptFlag]] that are run with the script.
* [[org.bitcoins.core.script.flag.ScriptFlag ScriptFlag]] that are run with the script.
* These flags indicate special conditions that a script needs to be run with.
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.h#L31]]
* @return
@ -47,24 +48,27 @@ sealed trait ScriptProgram {
}
/**
* This represents a [[ScriptProgram]] before any script operations have been executed in the [[org.bitcoins.core.script.interpreter.ScriptInterpreter]].
* This represents a [[org.bitcoins.core.script.ScriptProgram ScriptProgram]]
* before any script operations have been executed in the
* [[org.bitcoins.core.script.interpreter.ScriptInterpreter ScriptInterpreter]].
*/
sealed trait PreExecutionScriptProgram extends ScriptProgram
sealed trait ExecutionInProgressScriptProgram extends ScriptProgram {
/** The index of the last [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR]] */
/** The index of the last [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR OP_CODESEPARATOR]] */
def lastCodeSeparator: Option[Int]
}
sealed trait ExecutedScriptProgram extends ScriptProgram {
/** Indicates if the [[ScriptProgram]] has encountered a [[ScriptError]] in its execution.*/
/** Indicates if the [[org.bitcoins.core.script.ScriptProgram ScriptProgram]]
* has encountered a [[org.bitcoins.core.script.result.ScriptError ScriptError]] in its execution.*/
def error: Option[ScriptError]
}
/**
* Factory companion object for [[ScriptProgram]]
* Factory companion object for [[org.bitcoins.core.script.ScriptProgram ScriptProgram]]
*/
object ScriptProgram extends BitcoinSLogger {
@ -76,7 +80,8 @@ object ScriptProgram extends BitcoinSLogger {
case object OriginalScript extends UpdateIndicator
/**
* Sets a [[ScriptError]] on a given [[ScriptProgram]].
* Sets a [[org.bitcoins.core.script.result.ScriptError ScriptError]] on a given
* [[org.bitcoins.core.script.ScriptProgram ScriptProgram]].
* @param oldProgram the program who has hit an invalid state
* @param error the error that the program hit while being executed in the script interpreter
* @return the ExecutedScriptProgram with the given error set inside of the trait
@ -231,7 +236,7 @@ object ScriptProgram extends BitcoinSLogger {
updatedScript
}
/** Updates the last [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR]] index. */
/** Updates the last [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR OP_CODESEPARATOR]] index. */
def apply(
oldProgram: ExecutionInProgressScriptProgram,
lastCodeSeparator: Int): ExecutionInProgressScriptProgram = {
@ -246,7 +251,9 @@ object ScriptProgram extends BitcoinSLogger {
)
}
/** Updates the [[ScriptToken]]s in either the stack or script and the last [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR]] index */
/** Updates the [[org.bitcoins.core.script.constant.ScriptToken ScriptToken]]s
* in either the stack or script and the last
* [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR OP_CODESEPARATOR]] index */
def apply(
oldProgram: ExecutionInProgressScriptProgram,
tokens: Seq[ScriptToken],
@ -262,7 +269,10 @@ object ScriptProgram extends BitcoinSLogger {
}
}
/** Updates the [[Stack]], [[Script]], [[AltStack]] of the given [[ScriptProgram]]. */
/** Updates the [[org.bitcoins.core.script.ScriptProgram.Stack Stack]],
* [[org.bitcoins.core.script.ScriptProgram.Script Script]],
* [[org.bitcoins.core.script.ScriptProgram.AltStack AltStack]] of the given
* [[org.bitcoins.core.script.ScriptProgram ScriptProgram]]. */
def apply(
oldProgram: ScriptProgram,
stack: Seq[ScriptToken],
@ -276,7 +286,9 @@ object ScriptProgram extends BitcoinSLogger {
updatedProgramAltStack
}
/** Changes a [[ScriptProgram]] that is a [[ExecutionInProgressScriptProgram]] and changes it to an [[ExecutedScriptProgram]].*/
/** Changes a [[org.bitcoins.core.script.ScriptProgram ScriptProgram]] that is a
* [[org.bitcoins.core.script.ExecutionInProgressScriptProgram ExecutionInProgressScriptProgram]]
* and changes it to an [[org.bitcoins.core.script.ExecutedScriptProgram ExecutedScriptProgram]].*/
def toExecutedProgram(
executionInProgressScriptProgram: ExecutionInProgressScriptProgram): ExecutedScriptProgram = {
ExecutedScriptProgram(
@ -290,13 +302,18 @@ object ScriptProgram extends BitcoinSLogger {
)
}
/** Changes a [[ScriptProgram]] that is a [[PreExecutionScriptProgram]] and changes it to an [[ExecutionInProgressScriptProgram]].*/
/** Changes a [[org.bitcoins.core.script.ScriptProgram ScriptProgram]] that is a
* [[org.bitcoins.core.script.PreExecutionScriptProgram PreExecutionScriptProgram]] and changes it to an
* [[org.bitcoins.core.script.ExecutionInProgressScriptProgram ExecutionInProgressScriptProgram]].*/
def toExecutionInProgress(
preExecutionScriptProgram: PreExecutionScriptProgram): ExecutionInProgressScriptProgram = {
toExecutionInProgress(preExecutionScriptProgram, None)
}
/** Changes a [[ScriptProgram]] that is a [[PreExecutionScriptProgram]] and changes it to an [[ExecutionInProgressScriptProgram]] given the stack state. */
/** Changes a [[org.bitcoins.core.script.ScriptProgram ScriptProgram]] that is a
* [[org.bitcoins.core.script.PreExecutionScriptProgram PreExecutionScriptProgram]] and changes it to an
* [[org.bitcoins.core.script.ExecutionInProgressScriptProgram ExecutionInProgressScriptProgram]]
* given the stack state. */
def toExecutionInProgress(
preExecutionScriptProgram: PreExecutionScriptProgram,
stack: Option[Seq[ScriptToken]]): ExecutionInProgressScriptProgram = {
@ -328,8 +345,9 @@ object ScriptProgram extends BitcoinSLogger {
object PreExecutionScriptProgram {
/**
* Implementation type for a [[PreExecutionScriptProgram]] - a [[ScriptProgram]] that has not yet begun being
* evaluated by the [[org.bitcoins.core.script.interpreter.ScriptInterpreter]].
* Implementation type for a [[org.bitcoins.core.script.PreExecutionScriptProgram PreExecutionScriptProgram]] - a
* [[org.bitcoins.core.script.ScriptProgram ScriptProgram]] that has not yet begun being
* evaluated by the [[org.bitcoins.core.script.interpreter.ScriptInterpreter ScriptInterpreter]].
*/
private case class PreExecutionScriptProgramImpl(
txSignatureComponent: TxSigComponent,
@ -370,8 +388,10 @@ object PreExecutionScriptProgram {
object ExecutionInProgressScriptProgram {
/**
* Implementation type for a [[ExecutionInProgressScriptProgram]] - a [[ScriptProgram]] that is currently being
* evaluated by the [[org.bitcoins.core.script.interpreter.ScriptInterpreter]].
* Implementation type for a
* [[org.bitcoins.core.script.ExecutionInProgressScriptProgram ExecutionInProgressScriptProgram]] - a
* [[org.bitcoins.core.script.ScriptProgram ScriptProgram]] that is currently being
* evaluated by the [[org.bitcoins.core.script.interpreter.ScriptInterpreter ScriptInterpreter]].
*/
private case class ExecutionInProgressScriptProgramImpl(
txSignatureComponent: TxSigComponent,
@ -404,8 +424,9 @@ object ExecutionInProgressScriptProgram {
object ExecutedScriptProgram {
/**
* The implementation type for a [[ExecutedScriptProgram]] - a [[ScriptProgram]] that has been evaluated completely
* by the [[org.bitcoins.core.script.interpreter.ScriptInterpreter]].
* The implementation type for a [[org.bitcoins.core.script.ExecutedScriptProgram ExecutedScriptProgram]] - a
* [[org.bitcoins.core.script.ScriptProgram ScriptProgram]] that has been evaluated completely
* by the [[org.bitcoins.core.script.interpreter.ScriptInterpreter ScriptInterpreter]].
*/
private case class ExecutedScriptProgramImpl(
txSignatureComponent: TxSigComponent,

View File

@ -116,7 +116,8 @@ sealed abstract class ArithmeticInterpreter {
performBinaryBooleanOperation(program, (x, y) => x.numEqual(y))
}
/** Same as [[OP_NUMEQUAL]], but runs [[OP_VERIFY]] afterward. */
/** Same as [[org.bitcoins.core.script.arithmetic.OP_NUMEQUAL OP_NUMEQUAL]], but runs
* [[org.bitcoins.core.script.control.OP_VERIFY OP_VERIFY]] afterward. */
def opNumEqualVerify(program: ScriptProgram): ScriptProgram = {
require(program.script.headOption.contains(OP_NUMEQUALVERIFY),
"Script top must be OP_NUMEQUALVERIFY")

View File

@ -47,7 +47,8 @@ sealed abstract class BitwiseInterpreter {
}
}
/** Same as [[OP_EQUAL]], but runs [[OP_VERIFY]] afterward. */
/** Same as [[org.bitcoins.core.script.bitwise.OP_EQUAL OP_EQUAL]], but runs
* [[org.bitcoins.core.script.control.OP_VERIFY OP_VERIFY]] afterward. */
def opEqualVerify(program: ScriptProgram): ScriptProgram = {
require(program.script.headOption.contains(OP_EQUALVERIFY),
"Script operation must be OP_EQUALVERIFY")

View File

@ -19,8 +19,8 @@ case object OP_NOTIF extends ControlOperations {
}
/**
* If the preceding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and
* if the preceding OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not.
* If the preceding `OP_IF` or `OP_NOTIF` or `OP_ELSE` was not executed then these statements are and
* if the preceding `OP_IF` or `OP_NOTIF` or `OP_ELSE` was executed then these statements are not.
*/
case object OP_ELSE extends ControlOperations {
override val opCode: Int = 103
@ -28,7 +28,7 @@ case object OP_ELSE extends ControlOperations {
/**
* Ends an if/else block. All blocks must end, or the transaction is invalid.
* An OP_ENDIF without OP_IF earlier is also invalid.
* An `OP_ENDIF` without `OP_IF` earlier is also invalid.
*/
case object OP_ENDIF extends ControlOperations {
override val opCode: Int = 104
@ -41,10 +41,10 @@ case object OP_VERIFY extends ControlOperations {
/**
* Marks transaction as invalid. A standard way of attaching extra data to transactions is to add a zero-value
* output with a scriptPubKey consisting of OP_RETURN followed by exactly one pushdata op.
* output with a scriptPubKey consisting of `OP_RETURN` followed by exactly one pushdata op.
* Such outputs are provably unspendable, reducing their cost to the network.
* Currently it is usually considered non-standard
* (though valid) for a transaction to have more than one OP_RETURN output or an OP_RETURN output
* (though valid) for a transaction to have more than one `OP_RETURN` output or an `OP_RETURN` output
* with more than one pushdata op.
*/
case object OP_RETURN extends ControlOperations {

View File

@ -60,7 +60,9 @@ sealed abstract class CryptoInterpreter {
/**
* The entire transaction's outputs, inputs, and script (from the most
* recently-executed OP_CODESEPARATOR to the end) are hashed.
* The signature used by [[OP_CHECKSIG]] must be a valid signature for this hash and public key.
* The signature used by
* [[org.bitcoins.core.script.crypto.OP_CHECKSIG OP_CHECKSIG]]
* must be a valid signature for this hash and public key.
* [[https://github.com/bitcoin/bitcoin/blob/528472111b4965b1a99c4bcf08ac5ec93d87f10f/src/script/interpreter.cpp#L880]]
*/
def opCheckSig(program: ScriptProgram): ScriptProgram = {
@ -101,7 +103,8 @@ sealed abstract class CryptoInterpreter {
}
}
/** Runs [[OP_CHECKSIG]] with an [[OP_VERIFY]] afterwards. */
/** Runs [[org.bitcoins.core.script.crypto.OP_CHECKSIG OP_CHECKSIG]] with an
* [[org.bitcoins.core.script.control.OP_VERIFY OP_VERIFY]] afterwards. */
def opCheckSigVerify(program: ScriptProgram): ScriptProgram = {
require(program.script.headOption.contains(OP_CHECKSIGVERIFY),
"Script top must be OP_CHECKSIGVERIFY")
@ -125,7 +128,8 @@ sealed abstract class CryptoInterpreter {
/**
* All of the signature checking words will only match signatures to the data
* after the most recently-executed [[OP_CODESEPARATOR]].
* after the most recently-executed
* [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR OP_CODESEPARATOR]].
*/
def opCodeSeparator(program: ScriptProgram): ScriptProgram = {
require(program.script.headOption.contains(OP_CODESEPARATOR),
@ -276,7 +280,9 @@ sealed abstract class CryptoInterpreter {
}
}
/** Runs [[OP_CHECKMULTISIG]] with an [[OP_VERIFY]] afterwards */
/** Runs
* [[org.bitcoins.core.script.crypto.OP_CHECKMULTISIG OP_CHECKMULTISIG]] with an
* [[org.bitcoins.core.script.control.OP_VERIFY OP_VERIFY]] afterwards */
def opCheckMultiSigVerify(program: ScriptProgram): ScriptProgram = {
require(program.script.headOption.contains(OP_CHECKMULTISIGVERIFY),
"Script top must be OP_CHECKMULTISIGVERIFY")
@ -301,7 +307,7 @@ sealed abstract class CryptoInterpreter {
/**
* This is a higher order function designed to execute a hash function on the stack top of the program
* For instance, we could pass in CryptoUtil.sha256 function as the 'hashFunction' argument, which would then
* For instance, we could pass in CryptoUtil.sha256 function as the `hashFunction` argument, which would then
* apply sha256 to the stack top
* @param program the script program whose stack top needs to be hashed
* @param hashFunction the hash function which needs to be used on the stack top (sha256,ripemd160,etc..)

View File

@ -22,13 +22,13 @@ sealed abstract class LockTimeInterpreter {
private def logger = BitcoinSLogger.logger
/**
* 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
* 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
* 1. the stack is empty; or
* 2. the top stack item is negative; or
* 3. the top stack item is greater than or equal to 500000000 while the transaction's nLockTime field is less than 500000000,
* or vice versa; or
* 4. the input's nSequence field is equal to 0xffffffff.
* 4. the input's `nSequence` field is equal to 0xffffffff.
* The precise semantics are described in BIP 0065
*/
@tailrec
@ -94,9 +94,8 @@ sealed abstract class LockTimeInterpreter {
* the transaction input sequence number disable flag (1 << 31) is set; or
* the relative lock-time type is not the same; or
* the top stack item is greater than the transaction sequence (when masked according to the BIP68);
* Otherwise, script execution will continue as if a NOP had been executed.
* See BIP112 for more information
* [[https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki]]
* Otherwise, script execution will continue as if a `NOP` had been executed.
* See [[https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki BIP112]] for more information
*/
@tailrec
final def opCheckSequenceVerify(program: ScriptProgram): ScriptProgram = {
@ -217,7 +216,9 @@ sealed abstract class LockTimeInterpreter {
}
/**
* Checks if the given [[ScriptNumber]] and [[UInt32]] are valid values for spending
* Checks if the given
* [[org.bitcoins.core.script.constant.ScriptNumber ScriptNumber]] and
* [[org.bitcoins.core.number.UInt32 UInt32]] are valid values for spending
* a OP_CSV value by block height
*/
def isCSVLockByBlockHeight(
@ -233,7 +234,8 @@ sealed abstract class LockTimeInterpreter {
!isCSVLockByRelativeLockTime(scriptNumber)
/**
* Checks if the given [[ScriptNumber]] and [[UInt32]] are valid values
* Checks if the given [[org.bitcoins.core.script.constant.ScriptNumber ScriptNumber]] and
* [[org.bitcoins.core.number.UInt32 UInt32]] are valid values
* for spending an OP_CSV value by time based relative lock time
*/
def isCSVLockByRelativeLockTime(
@ -253,7 +255,7 @@ sealed abstract class LockTimeInterpreter {
result
}
/** Masks the given [[ScriptNumber]] according to BIP112 */
/** Masks the given [[org.bitcoins.core.script.constant.ScriptNumber ScriptNumber]] according to BIP112 */
def maskScriptNumber(scriptNumber: ScriptNumber): ScriptNumber = {
val nSequenceMasked: ScriptNumber = scriptNumber & Int64(
TransactionConstants.fullSequenceLockTimeMask.toLong)
@ -308,7 +310,7 @@ sealed abstract class LockTimeInterpreter {
} else true
}
/** The [[ScriptNumber]] on the stack has the disable flag (1 << 31) unset. */
/** The [[org.bitcoins.core.script.constant.ScriptNumber ScriptNumber]] on the stack has the disable flag (1 << 31) unset. */
def isLockTimeBitOff(s: ScriptNumber): Boolean =
(s.toLong & TransactionConstants.locktimeDisabledFlag.toLong) == 0

View File

@ -11,7 +11,7 @@ import scodec.bits.ByteVector
/**
* Created by chris on 1/11/16.
* https://bitcoin.org/en/developer-reference#txout
* [[https://bitcoin.org/en/developer-reference#txout]]
*/
sealed abstract class RawTransactionOutputParser
extends RawBitcoinSerializer[TransactionOutput] {
@ -23,8 +23,10 @@ sealed abstract class RawTransactionOutputParser
}
/**
* Reads a single output from the given bytes, note this is different than [[org.bitcoins.core.serializers.transaction.RawTransactionOutputParser.read]]
* because it does NOT expect a [[org.bitcoins.core.protocol.CompactSizeUInt]] to be the first element in the byte array indicating how many outputs we have
* Reads a single output from the given bytes, note this is different than
* [[org.bitcoins.core.serializers.transaction.RawTransactionOutputParser.read RawTransactionOutputParser.read]]
* because it does NOT expect a [[org.bitcoins.core.protocol.CompactSizeUInt CompactSizeUInt]]
* to be the first element in the byte array indicating how many outputs we have
*/
override def read(bytes: ByteVector): TransactionOutput = {
val satoshisBytes = bytes.take(8)

View File

@ -9,14 +9,15 @@ import scala.annotation.tailrec
/**
* Created by chris on 11/21/16.
* Serialization of [[TransactionWitness]] as defined inside of BIP141
* [[https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#specification]]
* Serialization of
* [[org.bitcoins.core.protocol.transaction.TransactionWitness TransactionWitness]] as defined inside of
* [[https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#specification BIP141]]
* [[https://github.com/bitcoin/bitcoin/blob/b4e4ba475a5679e09f279aaf2a83dcf93c632bdb/src/primitives/transaction.h#L232-L268]]
*/
sealed abstract class RawTransactionWitnessParser {
/**
* We can only tell how many [[ScriptWitness]]
* We can only tell how many [[org.bitcoins.core.protocol.script.ScriptWitness ScriptWitness]]
* we have if we have the number of inputs the transaction creates
*/
def read(bytes: ByteVector, numInputs: Int): TransactionWitness = {

View File

@ -9,7 +9,7 @@ import scala.util.{Failure, Success, Try}
/**
* Created by chris on 5/16/16.
* source of values: https://en.bitcoin.it/wiki/Base58Check_encoding
* source of values: [[https://en.bitcoin.it/wiki/Base58Check_encoding]]
*/
sealed abstract class Base58 {
import Base58Type._
@ -18,7 +18,8 @@ sealed abstract class Base58 {
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
val base58Pairs = base58Characters.zipWithIndex.toMap
/** Verifies a given [[Base58Type]] string against its checksum (last 4 decoded bytes). */
/** Verifies a given [[org.bitcoins.core.protocol.blockchain.Base58Type Base58Type]]
* string against its checksum (last 4 decoded bytes). */
def decodeCheck(input: String): Try[ByteVector] = {
val decodedTry: Try[ByteVector] = Try(decode(input))
decodedTry.flatMap { decoded =>
@ -36,7 +37,7 @@ sealed abstract class Base58 {
}
}
/** Encodes a sequence of bytes to a [[Base58Type]] string. */
/** Encodes a sequence of bytes to a [[org.bitcoins.core.protocol.blockchain.Base58Type Base58Type]] string. */
def encode(bytes: ByteVector): String = {
val ones: String = bytes.toSeq.takeWhile(_ == 0).map(_ => '1').mkString
@tailrec
@ -57,18 +58,19 @@ sealed abstract class Base58 {
}
}
/** Encodes a hex string to its [[Base58Type]] representation. */
/** Encodes a hex string to its [[org.bitcoins.core.protocol.blockchain.Base58Type Base58Type]] representation. */
def encode(hex: String): String = {
val bytes = BitcoinSUtil.decodeHex(hex)
encode(bytes)
}
/** Encodes a [[Byte]] to its [[Base58Type]] representation. */
/** Encodes a [[Byte]] to its [[org.bitcoins.core.protocol.blockchain.Base58Type Base58Type]] representation. */
def encode(byte: Byte): String = encode(ByteVector.fromByte(byte))
/**
* Takes in [[Base58Type]] string and returns sequence of [[Byte]]s
* https://github.com/ACINQ/bitcoin-lib/blob/master/src/main/scala/fr/acinq/bitcoin/Base58.scala.
* Takes in [[org.bitcoins.core.protocol.blockchain.Base58Type Base58Type]]
* string and returns sequence of [[Byte]]s.
* [[https://github.com/ACINQ/bitcoin-lib/blob/master/src/main/scala/fr/acinq/bitcoin/Base58.scala]]
*/
def decode(input: String): ByteVector = {
val zeroes = ByteVector(input.takeWhile(_ == '1').map(_ => 0: Byte))
@ -79,7 +81,7 @@ sealed abstract class Base58 {
else zeroes ++ ByteVector(decoded.toByteArray.dropWhile(_ == 0))
}
/** Determines if a string is a valid [[Base58Type]] string. */
/** Determines if a string is a valid [[org.bitcoins.core.protocol.blockchain.Base58Type Base58Type]] string. */
def isValid(base58: String): Boolean = validityChecks(base58) match {
case Success(bool) => bool
case Failure(_) => false
@ -120,7 +122,8 @@ sealed abstract class Base58 {
}
/**
* Checks the validity of a [[Base58Type]] string. A [[Base58Type]] string must not contain ('0', 'O', 'l', 'I').
* Checks the validity of a [[org.bitcoins.core.protocol.blockchain.Base58Type Base58Type]] string.
* A [[org.bitcoins.core.protocol.blockchain.Base58Type Base58Type]] string must not contain ('0', 'O', 'l', 'I').
* If the string is an address: it must have a valid address prefix byte and must be between 26-35 characters in length.
* If the string is a private key: it must have a valid private key prefix byte and must have a byte size of 32.
* If the string is a private key corresponding to a compressed public key, the 5th-to-last byte must be 0x01.

View File

@ -46,7 +46,8 @@ trait BinaryTree[+T] {
loop(this, List(), List()).reverse
}
/** A function to find the first occurrence of a predicate inside a [[BinaryTree]]. */
/** A function to find the first occurrence of a predicate inside a
* [[org.bitcoins.core.util.BinaryTree BinaryTree]]. */
def findFirstDFS[T](t: T)(f: T => Boolean = (x: T) => x == t)(
implicit tree: BinaryTree[T] = this): Option[BinaryTree[T]] = {
@tailrec
@ -68,7 +69,7 @@ trait BinaryTree[+T] {
loop(tree, List())
}
/** Checks if the [[BinaryTree]] contains a certain element. */
/** Checks if the [[org.bitcoins.core.util.BinaryTree BinaryTree]] contains a certain element. */
def contains[T](t: T)(f: T => Boolean = (x: T) => x == t)(
implicit tree: BinaryTree[T] = this): Boolean =
findFirstDFS(t)(f)(tree).isDefined
@ -76,7 +77,7 @@ trait BinaryTree[+T] {
def count[T](t: T): Int = toSeq.count(_ == t)
/**
* Inserts an element into one of the two branches in a [[BinaryTree]].
* Inserts an element into one of the two branches in a [[org.bitcoins.core.util.BinaryTree BinaryTree]].
* If it cannot insert it because the branches are not empty,
* it throws a [[RuntimeException]].
*/
@ -85,7 +86,7 @@ trait BinaryTree[+T] {
}
/**
* Inserts a tree into one of the two branches in a [[BinaryTree]]
* Inserts a tree into one of the two branches in a [[org.bitcoins.core.util.BinaryTree BinaryTree]]
* If it cannot insert it because the branches are not empty,
* it throws a [[RuntimeException]].
*/

View File

@ -50,7 +50,11 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
/**
* Filters out push operations in our sequence of script tokens
* this removes OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4 and all ByteToPushOntoStack tokens
* this removes
* [[org.bitcoins.core.script.constant.OP_PUSHDATA1 OP_PUSHDATA1]],
* [[org.bitcoins.core.script.constant.OP_PUSHDATA2 OP_PUSHDATA2]],
* [[org.bitcoins.core.script.constant.OP_PUSHDATA4 OP_PUSHDATA4]],
* and all [[org.bitcoins.core.script.constant.BytesToPushOntoStack ByteToPushOntoStack]] tokens
*/
def filterPushOps(asm: Seq[ScriptToken]): Seq[ScriptToken] = {
//TODO: This does not remove the following script number after a OP_PUSHDATA
@ -64,8 +68,9 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
/**
* Returns true if the given script token counts towards our max script operations in a script
* See https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L269-L271
* which is how bitcoin core handles this
* See
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L269-L271 interpreter.cpp#L269-L271]]
* which is how Bitcoin Core handles this
*/
def countsTowardsScriptOpLimit(token: ScriptToken): Boolean = token match {
case scriptOp: ScriptOperation if (scriptOp.opCode > OP_16.opCode) => true
@ -73,8 +78,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
}
/**
* Counts the amount of sigops in a script
* https://github.com/bitcoin/bitcoin/blob/master/src/script/script.cpp#L156-L202
* Counts the amount of sigops in a script.
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/script.cpp#L156-L202 Bitcoin Core script.cpp]]
* @param script the script whose sigops are being counted
* @return the number of signature operations in the script
*/
@ -98,7 +103,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
/**
* Parses the number of signatures on the stack
* This can only be called when an OP_CHECKMULTISIG operation is about to be executed
* This can only be called when an [[org.bitcoins.core.script.crypto.OP_CHECKMULTISIG OP_CHECKMULTISIG]]
* operation is about to be executed
* on the stack
* For instance if this was a 2/3 multisignature script, it would return the number 3
*/
@ -144,7 +150,7 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
/**
* Determines if a script contains only script operations
* This is equivalent to
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/script.cpp#L213]]
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/script.cpp#L213 Bitcoin Core script.cpp#L213]]
*/
def isPushOnly(script: Seq[ScriptToken]): Boolean = {
@tailrec
@ -168,7 +174,7 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
/**
* Determines if the token being pushed onto the stack is being pushed by the SMALLEST push operation possible
* This is equivalent to
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L209]]
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L209 Bitcoin Core interpreter.cpp#L209]]
* @param pushOp the operation that is pushing the data onto the stack
* @param token the token that is being pushed onto the stack by the pushOp
* @return
@ -201,7 +207,7 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
}
}
/** Calculates the push operation for the given [[ScriptToken]] */
/** Calculates the push operation for the given [[org.bitcoins.core.script.constant.ScriptToken ScriptToken]] */
def calculatePushOp(scriptToken: ScriptToken): Seq[ScriptToken] = {
//push ops following an OP_PUSHDATA operation are interpreted as unsigned numbers
val scriptTokenSize = UInt32(scriptToken.bytes.size)
@ -233,7 +239,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
calculatePushOp(ScriptConstant(bytes))
/**
* Whenever a [[ScriptConstant]] is interpreted to a number BIP62 could enforce that number to be encoded
* Whenever a [[org.bitcoins.core.script.constant.ScriptConstant ScriptConstant]] is interpreted to a number
* BIP62 could enforce that number to be encoded
* in the smallest encoding possible
* [[https://github.com/bitcoin/bitcoin/blob/a6a860796a44a2805a58391a009ba22752f64e32/src/script/script.h#L220-L237]]
*/
@ -259,13 +266,13 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
/**
* Whenever a script constant is interpreted to a number BIP62 should enforce that number to be encoded
* in the smallest encoding possible
* https://github.com/bitcoin/bitcoin/blob/a6a860796a44a2805a58391a009ba22752f64e32/src/script/script.h#L220-L237
* [[https://github.com/bitcoin/bitcoin/blob/a6a860796a44a2805a58391a009ba22752f64e32/src/script/script.h#L220-L237]]
*/
def isShortestEncoding(hex: String): Boolean =
isShortestEncoding(BitcoinSUtil.decodeHex(hex))
/**
* Checks the [[ECPublicKey]] encoding according to bitcoin core's function:
* Checks the [[org.bitcoins.core.crypto.ECPublicKey ECPublicKey]] encoding according to bitcoin core's function:
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L202]].
*/
def checkPubKeyEncoding(key: ECPublicKey, program: ScriptProgram): Boolean =
@ -279,7 +286,7 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
/**
* Returns true if the key is compressed or uncompressed, false otherwise
* https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L66
* [[https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L66]]
* @param key the public key that is being checked
* @return true if the key is compressed/uncompressed otherwise false
*/
@ -313,8 +320,10 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
}
/**
* Determines if the given pubkey is valid in accordance to the given [[ScriptFlag]]s
* and [[SignatureVersion]]. Mimics this function inside of Bitcoin Core
* Determines if the given pubkey is valid in accordance to the given
* [[org.bitcoins.core.script.flag.ScriptFlag ScriptFlag]]s
* and [[org.bitcoins.core.protocol.script.SignatureVersion SignatureVersion]].
* Mimics this function inside of Bitcoin Core
* [[https://github.com/bitcoin/bitcoin/blob/528472111b4965b1a99c4bcf08ac5ec93d87f10f/src/script/interpreter.cpp#L214-L223]]
*/
def isValidPubKeyEncoding(
@ -335,8 +344,11 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
* We need to check if the scriptSignature has a redeemScript
* In that case, we need to pass the redeemScript to the TransactionSignatureChecker
*
* In the case we have a P2SH(P2WSH) we need to pass the witness's redeem script to the [[TransactionSignatureChecker]]
* instead of passing the [[WitnessScriptPubKey]] inside of the [[P2SHScriptSignature]]'s redeem script.
* In the case we have a P2SH(P2WSH) we need to pass the witness's redeem script to the
* [[org.bitcoins.core.crypto.TransactionSignatureChecker TransactionSignatureChecker]]
* instead of passing the
* [[org.bitcoins.core.protocol.script.WitnessScriptPubKey WitnessScriptPubKey]] inside of the
* [[org.bitcoins.core.protocol.script.P2SHScriptSignature P2SHScriptSignature]]'s redeem script.
*/
def calculateScriptForChecking(
txSignatureComponent: TxSigComponent,
@ -412,7 +424,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
script
}
/** Removes the given [[ECDigitalSignature]] from the list of [[ScriptToken]] if it exists. */
/** Removes the given [[org.bitcoins.core.crypto.ECDigitalSignature ECDigitalSignature]] from the list of
* [[org.bitcoins.core.script.constant.ScriptToken ScriptToken]] if it exists. */
def removeSignatureFromScript(
signature: ECDigitalSignature,
script: Seq[ScriptToken]): Seq[ScriptToken] = {
@ -430,7 +443,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
} else script
}
/** Removes the list of [[ECDigitalSignature]] from the list of [[ScriptToken]] */
/** Removes the list of [[org.bitcoins.core.crypto.ECDigitalSignature ECDigitalSignature]] from the list of
* [[org.bitcoins.core.script.constant.ScriptToken ScriptToken]] */
def removeSignaturesFromScript(
sigs: Seq[ECDigitalSignature],
script: Seq[ScriptToken]): Seq[ScriptToken] = {
@ -449,7 +463,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
}
/**
* Removes the [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR]] in the original script according to
* Removes the [[org.bitcoins.core.script.crypto.OP_CODESEPARATOR OP_CODESEPARATOR]]
* in the original script according to
* the last code separator index in the script.
*/
def removeOpCodeSeparator(
@ -486,7 +501,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
}
}
/** Since witnesses are not run through the interpreter, replace OP_0/OP_1 with ScriptNumber.zero/ScriptNumber.one */
/** Since witnesses are not run through the interpreter, replace
* `OP_0`/`OP_1` with `ScriptNumber.zero`/`ScriptNumber.one` */
def minimalIfOp(asm: Seq[ScriptToken]): Seq[ScriptToken] = {
if (asm == Nil) asm
else if (asm.last == OP_0) {
@ -497,14 +513,16 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
}
/** Replaces the OP_0 dummy for OP_CHECKMULTISIG with ScriptNumber.zero */
/** Replaces the [[org.bitcoins.core.script.constant.OP_0 OP_0]] dummy for
* [[org.bitcoins.core.script.crypto.OP_CHECKMULTISIG OP_CHECKMULTISIG]] with
* [[org.bitcoins.core.script.constant.ScriptNumber.zero ScriptNumber.zero]] */
def minimalDummy(asm: Seq[ScriptToken]): Seq[ScriptToken] = {
if (asm.headOption == Some(OP_0)) ScriptNumber.zero +: asm.tail
else asm
}
/**
* Checks that all the [[org.bitcoins.core.crypto.ECPublicKey]] in this script
* Checks that all the [[org.bitcoins.core.crypto.ECPublicKey ECPublicKey]] in this script
* is compressed public keys, this is required for BIP143
* @param spk
* @return

View File

@ -26,7 +26,7 @@ trait NumberUtil extends BitcoinSLogger {
BigInt(new BigInteger(1, bytes.toArray))
}
/** Takes a hex string and parses it to a [[BigInt]]. */
/** Takes a hex string and parses it to a [[scala.math.BigInt BigInt]]. */
def toBigInt(hex: String): BigInt = toBigInt(BitcoinSUtil.decodeHex(hex))
/** Converts a sequence of bytes to twos complement signed number. */
@ -49,10 +49,10 @@ trait NumberUtil extends BitcoinSLogger {
}
}
/** Converts a sequence of [[Byte]] to a [[Int]]. */
/** Converts a sequence of [[Byte]] to a [[scala.Int Int]]. */
def toInt(bytes: ByteVector): Int = toBigInt(bytes).toInt
/** Converts a hex string to a [[Int]]. */
/** Converts a hex string to a [[scala.Int Int]]. */
def toInt(hex: String): Int = toInt(BitcoinSUtil.decodeHex(hex))
/** Converts a sequence of [[Byte]] to a [[Long]]. */