Scaladoc formatting (#292)

This commit is contained in:
Torkel Rogstad 2019-01-09 15:57:30 +01:00 committed by Chris Stewart
parent 268e235b4d
commit edcf097b2a
7 changed files with 158 additions and 93 deletions

View File

@ -25,7 +25,7 @@ sealed abstract class BlockchainElementsGenerator {
} yield Block(header, allTxs)
/**
* Generates a random [[Block]], note that we limit this
* Generates a random [[org.bitcoins.core.protocol.blockchain.Block Block]], note that we limit this
* to 10 transactions currently
*/
def block: Gen[Block] =
@ -34,21 +34,23 @@ sealed abstract class BlockchainElementsGenerator {
txs <- TransactionGenerators.smallTransactions
} yield Block(header, txs)
/** Generates a random [[BlockHeader]] */
/** Generates a random [[org.bitcoins.core.protocol.blockchain.BlockHeader BlockHeader]] */
def blockHeader: Gen[BlockHeader] =
for {
previousBlockHash <- CryptoGenerators.doubleSha256Digest
b <- blockHeader(previousBlockHash)
} yield b
/** Generates a random [[BlockHeader]] with the specified previousBlockHash */
/** Generates a random
* [[org.bitcoins.core.protocol.blockchain.BlockHeader BlockHeader]] with the specified previousBlockHash */
def blockHeader(previousBlockHash: DoubleSha256Digest): Gen[BlockHeader] =
for {
nBits <- NumberGenerator.uInt32s
b <- blockHeader(previousBlockHash, nBits)
} yield b
/** Generates a random [[BlockHeader]] where you can specify the previousBlockHash and nBits */
/** Generates a random [[org.bitcoins.core.protocol.blockchain.BlockHeader BlockHeader]] where you can specify
* the previousBlockHash and nBits */
def blockHeader(
previousBlockHash: DoubleSha256Digest,
nBits: UInt32): Gen[BlockHeader] =
@ -58,7 +60,8 @@ sealed abstract class BlockchainElementsGenerator {
header <- blockHeader(previousBlockHash, nBits, txs)
} yield header
/** Generates a [[BlockHeader]]] that has the fields set to the given values */
/** Generates a [[org.bitcoins.core.protocol.blockchain.BlockHeader BlockHeader]]] that has the fields
* set to the given values */
def blockHeader(
previousBlockHash: DoubleSha256Digest,
nBits: UInt32,
@ -76,7 +79,8 @@ sealed abstract class BlockchainElementsGenerator {
nBits,
nonce)
/** Generates a [[BlockHeader]] that has a merkle root hash corresponding to the given txs */
/** Generates a [[org.bitcoins.core.protocol.blockchain.BlockHeader BlockHeader]] that has a merkle root
* hash corresponding to the given txs */
def blockHeader(txs: Seq[Transaction]): Gen[BlockHeader] =
for {
previousBlockHash <- CryptoGenerators.doubleSha256Digest

View File

@ -15,7 +15,8 @@ import org.scalacheck.Gen
*/
abstract class MerkleGenerator {
/** Generates a merkle block with the given txs matched inside the [[PartialMerkleTree]] */
/** Generates a merkle block with the given txs matched inside the
* [[org.bitcoins.core.protocol.blockchain.PartialMerkleTree PartialMerkleTree]] */
def merkleBlockWithInsertedTxIds(txs: Seq[Transaction]): Gen[
(MerkleBlock, Block, Seq[DoubleSha256Digest])] =
for {
@ -24,7 +25,7 @@ abstract class MerkleGenerator {
merkleBlock = MerkleBlock(block, txIds)
} yield (merkleBlock, block, txIds)
/** Returns a [[MerkleBlock]] including the sequence of hashes inserted in to the bloom filter */
/** Returns a [[org.bitcoins.core.protocol.blockchain.MerkleBlock MerkleBlock]] including the sequence of hashes inserted in to the bloom filter */
def merkleBlockWithInsertedTxIds: Gen[
(MerkleBlock, Block, Seq[DoubleSha256Digest])] =
for {
@ -35,7 +36,7 @@ abstract class MerkleGenerator {
} yield result
/**
* Returns a [[MerkleBlock]] created with a [[org.bitcoins.core.bloom.BloomFilter]], with the block it was created from
* Returns a [[org.bitcoins.core.protocol.blockchain.MerkleBlock MerkleBlock]] created with a [[org.bitcoins.core.bloom.BloomFilter BloomFilter]], with the block it was created from
* and the transactions that were matched inside of that block
* NOTE: Since bloom filters can produce false positives, it is possible that there will be
* matches in the parital merkle tree that SHOULD NOT be matched. Bloom filters do not guaratnee no

View File

@ -51,9 +51,9 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
def emptyScriptSignature = p2pkhScriptSignature.map(_ => EmptyScriptSignature)
/**
* Generates a [[org.bitcoins.core.protocol.script.P2SHScriptSignature]]
* Generates a [[org.bitcoins.core.protocol.script.P2SHScriptSignature P2SHScriptSignature]]
* WARNING: the redeem script and the script signature DO NOT evaluate to true
* if executed by [[org.bitcoins.core.script.interpreter.ScriptInterpreter]]
* if executed by [[org.bitcoins.core.script.interpreter.ScriptInterpreter ScriptInterpreter]]
*/
def p2shScriptSignature: Gen[P2SHScriptSignature] =
for {
@ -159,8 +159,9 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
Gen.oneOf(p2wpkhSPKV0, p2wshSPKV0)
/**
* Creates an [[UnassignedWitnessScriptPubKey]],
* currently this is any witness script pubkey besides [[org.bitcoins.core.protocol.script.WitnessScriptPubKeyV0]
* Creates an [[org.bitcoins.core.protocol.script.UnassignedWitnessScriptPubKey UnassignedWitnessScriptPubKey]],
* currently this is any witness script pubkey besides
* [[org.bitcoins.core.protocol.script.WitnessScriptPubKeyV0 WitnessScriptPubKeyV0]]
*/
def unassignedWitnessScriptPubKey: Gen[
(UnassignedWitnessScriptPubKey, Seq[ECPrivateKey])] =
@ -170,7 +171,7 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
unassignedAsm = version +: witV0.asm.tail
} yield (UnassignedWitnessScriptPubKey(unassignedAsm), privKeys)
/** Generates an arbitrary [[org.bitcoins.core.protocol.script.WitnessScriptPubKey]] */
/** Generates an arbitrary [[org.bitcoins.core.protocol.script.WitnessScriptPubKey WitnessScriptPubKey]] */
def witnessScriptPubKey: Gen[(WitnessScriptPubKey, Seq[ECPrivateKey])] =
Gen.oneOf(assignedWitnessScriptPubKey, unassignedWitnessScriptPubKey)
@ -223,7 +224,7 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
def lockTimeScriptSig: Gen[LockTimeScriptSignature] =
Gen.oneOf(csvScriptSignature, cltvScriptSignature)
/** Generates an arbitrary [[ScriptPubKey]] */
/** Generates an arbitrary [[org.bitcoins.core.protocol.script.ScriptPubKey ScriptPubKey]] */
def scriptPubKey: Gen[(ScriptPubKey, Seq[ECPrivateKey])] = {
Gen.oneOf(
p2pkScriptPubKey.map(privKeyToSeq(_)),
@ -240,7 +241,7 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
)
}
/** Generates an arbitrary [[ScriptSignature]] */
/** Generates an arbitrary [[org.bitcoins.core.protocol.script.ScriptSignature ScriptSignature]] */
def scriptSignature: Gen[ScriptSignature] = {
Gen.oneOf(
p2pkScriptSignature,
@ -255,7 +256,8 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
}
/**
* Generates a [[ScriptSignature]] corresponding to the type of [[ScriptPubKey]] given.
* Generates a [[org.bitcoins.core.protocol.script.ScriptSignature ScriptSignature]] corresponding to the type of
* [[org.bitcoins.core.protocol.script.ScriptPubKey ScriptPubKey]] given.
* Note: Does NOT generate a correct/valid signature
*/
private def pickCorrespondingScriptSignature(
@ -276,10 +278,12 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
}
/**
* Generates a signed [[P2PKScriptSignature]] that spends the [[P2PKScriptPubKey]] correctly
* Generates a signed [[org.bitcoins.core.protocol.script.P2PKScriptSignature P2PKScriptSignature]] that spends the
* [[org.bitcoins.core.protocol.script.P2PKScriptPubKey P2PKScriptPubKey]] correctly
*
* @return the signed [[P2PKScriptSignature]], the [[P2PKScriptPubKey]] it spends, and the
* [[ECPrivateKey]] used to sign the scriptSig
* @return the signed [[org.bitcoins.core.protocol.script.P2PKScriptSignature P2PKScriptSignature]],
* the [[org.bitcoins.core.protocol.script.P2PKScriptPubKey P2PKScriptPubKey]] it spends, and the
* [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]] used to sign the scriptSig
*/
def signedP2PKScriptSignature: Gen[
(P2PKScriptSignature, P2PKScriptPubKey, ECPrivateKey)] =
@ -309,10 +313,12 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
} yield (signedScriptSig, scriptPubKey, privateKey)
/**
* Generates a signed [[P2PKHScriptSignature]] that spends the [[P2PKHScriptPubKey]] correctly
* Generates a signed [[org.bitcoins.core.protocol.script.P2PKHScriptSignature P2PKHScriptSignature]] that
* spends the [[org.bitcoins.core.protocol.script.P2PKHScriptPubKey P2PKHScriptPubKey]] correctly
*
* @return the signed [[P2PKHScriptSignature]], the [[P2PKHScriptPubKey]] it spends, and the
* [[ECPrivateKey]] used to sign the scriptSig
* @return the signed [[org.bitcoins.core.protocol.script.P2PKHScriptSignature P2PKHScriptSignature]], the
* [[org.bitcoins.core.protocol.script.P2PKHScriptPubKey P2PKHScriptPubKey]] it spends, and the
* [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]] used to sign the scriptSig
*/
def signedP2PKHScriptSignature: Gen[
(P2PKHScriptSignature, P2PKHScriptPubKey, ECPrivateKey)] =
@ -340,10 +346,13 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
} yield (signedScriptSig, scriptPubKey, privateKey)
/**
* Generates a signed [[MultiSignatureScriptSignature]] that spends the [[MultiSignatureScriptPubKey]] correctly
* Generates a signed
* [[org.bitcoins.core.protocol.script.MultiSignatureScriptSignature MultiSignatureScriptSignature]] that spends the
* [[org.bitcoins.core.protocol.script.MultiSignatureScriptPubKey MultiSignatureScriptPubKey]] correctly
* ti
* @return the signed [[MultiSignatureScriptSignature]], the [[MultiSignatureScriptPubKey]] it spends and the
* sequence of [[ECPrivateKey]] used to sign the scriptSig
* @return the signed [[org.bitcoins.core.protocol.script.MultiSignatureScriptSignature MultiSignatureScriptSignature]],
* the [[org.bitcoins.core.protocol.script.MultiSignatureScriptPubKey MultiSignatureScriptPubKey]] it spends and the
* sequence of [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]] used to sign the scriptSig
*/
def signedMultiSignatureScriptSignature: Gen[(
MultiSignatureScriptSignature,
@ -376,9 +385,12 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
} yield (signedScriptSig, multiSigScriptPubKey, privateKeys)
/**
* Generates a signed [[P2SHScriptSignature]] that spends from a [[P2SHScriptPubKey]] correctly
* Generates a signed [[org.bitcoins.core.protocol.script.P2SHScriptSignature P2SHScriptSignature]]
* that spends from a [[org.bitcoins.core.protocol.script.P2SHScriptPubKey P2SHScriptPubKey]] correctly
*
* @return the signed [[P2SHScriptSignature]], the [[P2SHScriptPubKey]] it spends, and the sequence of [[ECPrivateKey]]
* @return the signed [[org.bitcoins.core.protocol.script.P2SHScriptSignature P2SHScriptSignature]],
* the [[org.bitcoins.core.protocol.script.P2SHScriptPubKey P2SHScriptPubKey]] it spends, and the
* sequence of [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]]
* used to sign the scriptSig
*/
def signedP2SHScriptSignature: Gen[
@ -390,9 +402,12 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
} yield (p2SHScriptSignature, p2SHScriptPubKey, privateKeys)
/**
* Generates a signed [[CLTVScriptSignature]] that spends from a [[CLTVScriptPubKey]] correctly
* Generates a signed [[org.bitcoins.core.protocol.script.P2SHScriptSignature CLTVScriptSignature]] that spends
* from a [[org.bitcoins.core.protocol.script.P2SHScriptSignature CLTVScriptPubKey]] correctly
*
* @return the signed [[CLTVScriptSignature]], the [[CLTVScriptPubKey]] it spends, and the sequences of [[ECPrivateKey]]
* @return the signed [[org.bitcoins.core.protocol.script.CLTVScriptSignature CLTVScriptSignature]], the
* [[org.bitcoins.core.protocol.script.CLTVScriptPubKey CLTVScriptPubKey]] it spends, and the
* sequences of [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]]
* used to sign the scriptSig
*/
def signedCLTVScriptSignature(
@ -435,9 +450,12 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
}
/**
* Generates a signed [[CSVScriptSignature]] that spends from a [[CSVScriptPubKey]] correctly
* Generates a signed [[org.bitcoins.core.protocol.script.CLTVScriptSignature CSVScriptSignature]] that spends
* from a [[org.bitcoins.core.protocol.script.CLTVScriptSignature CSVScriptPubKey]] correctly
*
* @return the signed [[CSVScriptSignature]], the [[CSVScriptPubKey]] it spends, and the sequences of [[ECPrivateKey]]
* @return the signed [[org.bitcoins.core.protocol.script.CSVScriptSignature CSVScriptSignature]], the
* [[org.bitcoins.core.protocol.script.CSVScriptPubKey CSVScriptPubKey]] it spends, and the
* sequences of [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]]
* used to sign the scriptSig
*/
def signedCSVScriptSignature(
@ -493,13 +511,15 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
sequence)
} yield scriptSig
/** Generates a [[LockTimeScriptSignature]] and [[LockTimeScriptPubKey]] pair that are valid when run through the interpreter */
/** Generates a [[org.bitcoins.core.protocol.script.LockTimeScriptSignature LockTimeScriptSignature]] and
* [[org.bitcoins.core.protocol.script.LockTimeScriptPubKey LockTimeScriptPubKey]] pair that are valid when
* run through the interpreter */
def signedLockTimeScriptSignature: Gen[
(LockTimeScriptSignature, LockTimeScriptPubKey, Seq[ECPrivateKey])] = {
Gen.oneOf(signedCSVScriptSignature, signedCLTVScriptSignature)
}
/** Helper function to generate [[LockTimeScriptSignature]]s */
/** Helper function to generate [[org.bitcoins.core.protocol.script.LockTimeScriptSignature LockTimeScriptSignature]]s */
private def lockTimeHelper(
lockTime: Option[UInt32],
sequence: UInt32,
@ -583,11 +603,14 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
wtxSigComponent.amount)
/**
* This function chooses a random signed [[ScriptSignature]] that is NOT a [[P2SHScriptSignature]], [[CSVScriptSignature]],
* [[CLTVScriptSignature]], or any witness type
* This function chooses a random signed [[org.bitcoins.core.protocol.script.ScriptSignature ScriptSignature]]
* that is NOT a [[org.bitcoins.core.protocol.script.P2SHScriptSignature P2SHScriptSignature]],
* [[org.bitcoins.core.protocol.script.CSVScriptSignature CSVScriptSignature]],
* [[org.bitcoins.core.protocol.script.CLTVScriptSignature CLTVScriptSignature]], or any witness type
*
* @return the signed [[ScriptSignature]], the [[ScriptPubKey]] it is spending,
* and the sequence of[[ECPrivateKey]] used to sign it
* @return the signed [[org.bitcoins.core.protocol.script.ScriptSignature ScriptSignature]],
* the [[org.bitcoins.core.protocol.script.ScriptPubKey ScriptPubKey]] it is spending,
* and the sequence of [[org.bitcoins.core.crypto.ECPublicKey ECPrivateKey]] used to sign it
*/
def chooseSignedScriptSig: Gen[
(ScriptSignature, ScriptPubKey, Seq[ECPrivateKey])] = {
@ -598,7 +621,9 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
)
}
/** Generates a random [[ScriptSignature]], the [[ScriptPubKey]] it is spending, and the [[ECPrivateKey]] needed to spend it. */
/** Generates a random [[org.bitcoins.core.protocol.script.ScriptSignature ScriptSignature]], the
* [[org.bitcoins.core.protocol.script.ScriptPubKey ScriptPubKey]] it is spending, and the
* [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]] needed to spend it. */
def randomScriptSig: Gen[(ScriptSignature, ScriptPubKey, Seq[ECPrivateKey])] = {
val witP2SHP2WPKH =
signedP2SHP2WPKHScriptSignature.map(x => (x._1, x._2, x._3))

View File

@ -23,14 +23,14 @@ import scala.annotation.tailrec
*/
trait TransactionGenerators extends BitcoinSLogger {
/** Responsible for generating [[org.bitcoins.core.protocol.transaction.TransactionOutPoint]] */
/** Responsible for generating [[org.bitcoins.core.protocol.transaction.TransactionOutPoint TransactionOutPoint]] */
def outPoint: Gen[TransactionOutPoint] =
for {
txId <- CryptoGenerators.doubleSha256Digest
vout <- NumberGenerator.uInt32s
} yield TransactionOutPoint(txId, vout)
/** Generates a random [[org.bitcoins.core.protocol.transaction.TransactionOutput]] */
/** Generates a random [[org.bitcoins.core.protocol.transaction.TransactionOutput TransactionOutput]] */
def output: Gen[TransactionOutput] =
for {
satoshis <- CurrencyUnitGenerator.satoshis
@ -51,7 +51,7 @@ trait TransactionGenerators extends BitcoinSLogger {
def realisticOutputs: Gen[Seq[TransactionOutput]] =
Gen.choose(0, 5).flatMap(n => Gen.listOfN(n, realisticOutput))
/** Generates a small list of [[TransactionOutput]] */
/** Generates a small list of [[org.bitcoins.core.protocol.transaction.TransactionOutput TransactionOutput]] */
def smallOutputs: Gen[Seq[TransactionOutput]] =
Gen.choose(0, 5).flatMap(i => Gen.listOfN(i, output))
@ -84,7 +84,7 @@ trait TransactionGenerators extends BitcoinSLogger {
}
}
/** Generates a random [[org.bitcoins.core.protocol.transaction.TransactionInput]] */
/** Generates a random [[org.bitcoins.core.protocol.transaction.TransactionInput TransactionInput]] */
def input: Gen[TransactionInput] =
for {
outPoint <- outPoint
@ -100,22 +100,24 @@ trait TransactionGenerators extends BitcoinSLogger {
def inputs: Gen[List[TransactionInput]] = Gen.nonEmptyListOf(input)
/** Generates a small list of [[TransactionInput]] */
/** Generates a small list of [[org.bitcoins.core.protocol.transaction.TransactionInput TransactionInput]] */
def smallInputs: Gen[Seq[TransactionInput]] =
Gen.choose(1, 5).flatMap(i => Gen.listOfN(i, input))
/** Generates a small non empty list of [[TransactionInput]] */
/** Generates a small non empty list of
* [[org.bitcoins.core.protocol.transaction.TransactionInput TransactionInput]] */
def smallInputsNonEmpty: Gen[Seq[TransactionInput]] =
Gen.choose(1, 5).flatMap(i => Gen.listOfN(i, input))
/**
* Generates an arbitrary [[org.bitcoins.core.protocol.transaction.Transaction]]
* This transaction's [[TransactionInput]]s will not evaluate to true
* inside of the [[org.bitcoins.core.script.interpreter.ScriptInterpreter]]
* Generates an arbitrary [[org.bitcoins.core.protocol.transaction.Transaction Transaction]]
* This transaction's [[org.bitcoins.core.protocol.transaction.TransactionInput TransactionInput]]s
* will not evaluate to true inside of the
* [[org.bitcoins.core.script.interpreter.ScriptInterpreter ScriptInterpreter]]
*/
def transactions: Gen[Seq[Transaction]] = Gen.listOf(transaction)
/** Generates a small list of [[Transaction]] */
/** Generates a small list of [[org.bitcoins.core.protocol.transaction.Transaction Transaction]] */
def smallTransactions: Gen[Seq[Transaction]] =
Gen.choose(0, 10).flatMap(i => Gen.listOfN(i, transaction))
@ -130,7 +132,7 @@ trait TransactionGenerators extends BitcoinSLogger {
lockTime <- NumberGenerator.uInt32s
} yield BaseTransaction(version, is, os, lockTime)
/** Generates a random [[WitnessTransaction]] */
/** Generates a random [[org.bitcoins.core.protocol.transaction.WitnessTransaction WitnessTransaction]] */
def witnessTransaction: Gen[WitnessTransaction] =
for {
version <- NumberGenerator.int32s
@ -142,15 +144,17 @@ trait TransactionGenerators extends BitcoinSLogger {
//we have to have atleast one NON `EmptyScriptWitness` for a tx to be a valid WitnessTransaction, otherwise we
//revert to using the `BaseTransaction` serialization format
//notice we use the old serialization format if all witnesses are empty
//[[https://github.com/bitcoin/bitcoin/blob/e8cfe1ee2d01c493b758a67ad14707dca15792ea/src/primitives/transaction.h#L276-L281]]
//https://github.com/bitcoin/bitcoin/blob/e8cfe1ee2d01c493b758a67ad14707dca15792ea/src/primitives/transaction.h#L276-L281
witness <- WitnessGenerators
.transactionWitness(is.size)
.suchThat(_.witnesses.exists(_ != EmptyScriptWitness))
} yield WitnessTransaction(version, is, os, lockTime, witness)
/**
* Creates a [[ECPrivateKey]], then creates a [[P2PKScriptPubKey]] from that private key
* Finally creates a [[Transaction]] that spends the [[P2PKScriptPubKey]] correctly
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
* [[org.bitcoins.core.protocol.script.P2PKScriptPubKey P2PKScriptPubKey]] from that private key
* Finally creates a [[org.bitcoins.core.protocol.transaction.Transaction Transaction]]
* that spends the [[org.bitcoins.core.protocol.script.P2PKScriptPubKey P2PKScriptPubKey]] correctly
*/
def signedP2PKTransaction: Gen[(BaseTxSigComponent, ECPrivateKey)] =
for {
@ -169,8 +173,10 @@ trait TransactionGenerators extends BitcoinSLogger {
} yield (signedTxSignatureComponent, privateKey)
/**
* Creates a [[ECPrivateKey]], then creates a [[P2PKHScriptPubKey]] from that private key
* Finally creates a [[Transaction]] that spends the [[P2PKHScriptPubKey]] correctly
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
* [[org.bitcoins.core.protocol.script.P2PKScriptPubKey P2PKHScriptPubKey]] from that private key
* Finally creates [[org.bitcoins.core.protocol.transaction.Transaction Transaction]] that spends the
* [[org.bitcoins.core.protocol.script.P2PKScriptPubKey P2PKHScriptPubKey]] correctly
*/
def signedP2PKHTransaction: Gen[(BaseTxSigComponent, ECPrivateKey)] =
for {
@ -189,8 +195,10 @@ trait TransactionGenerators extends BitcoinSLogger {
} yield (signedTxSignatureComponent, privateKey)
/**
* Creates a sequence of [[ECPrivateKey]], then creates a [[MultiSignatureScriptPubKey]] from those private keys,
* Finally creates a [[Transaction]] that spends the [[MultiSignatureScriptPubKey]] correctly
* Creates a sequence of [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
* [[org.bitcoins.core.protocol.script.MultiSignatureScriptPubKey MultiSignatureScriptPubKey]] from those
* private keys. Finally creates a [[org.bitcoins.core.protocol.transaction.Transaction Transaction]] that
* spends the [[org.bitcoins.core.protocol.script.MultiSignatureScriptPubKey MultiSignatureScriptPubKey]] correctly
*/
def signedMultiSigTransaction: Gen[(BaseTxSigComponent, Seq[ECPrivateKey])] =
for {
@ -209,7 +217,9 @@ trait TransactionGenerators extends BitcoinSLogger {
} yield (signedTxSignatureComponent, privateKey)
/**
* Creates a transaction which contains a [[P2SHScriptSignature]] that correctly spends a [[P2SHScriptPubKey]]
* Creates a transaction which contains a
* [[org.bitcoins.core.protocol.script.P2SHScriptSignature P2SHScriptSignature]] that correctly spends a
* [[org.bitcoins.core.protocol.script.P2SHScriptPubKey P2SHScriptPubKey]]
*/
def signedP2SHTransaction: Gen[(BaseTxSigComponent, Seq[ECPrivateKey])] =
for {
@ -235,9 +245,12 @@ trait TransactionGenerators extends BitcoinSLogger {
}
/**
* Creates a [[ECPrivateKey]], then creates a [[CLTVScriptPubKey]] from that private key
* Finally creates a [[Transaction]] that CANNNOT spend the [[CLTVScriptPubKey]] because the LockTime requirement
* is not satisfied (i.e. the transaction's lockTime has not surpassed the CLTV value in the [[CLTVScriptPubKey]])
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
* [[org.bitcoins.core.protocol.script.CLTVScriptPubKey CLTVScriptPubKey]] from that private key
* Finally creates a [[org.bitcoins.core.protocol.transaction.Transaction Transaction]] that CANNNOT spend the
* [[org.bitcoins.core.protocol.script.CLTVScriptPubKey CLTVScriptPubKey]] because the LockTime requirement
* is not satisfied (i.e. the transaction's lockTime has not surpassed the CLTV value in the
* [[org.bitcoins.core.protocol.script.CLTVScriptPubKey CLTVScriptPubKey]])
*
* @return
*/
@ -255,8 +268,10 @@ trait TransactionGenerators extends BitcoinSLogger {
} yield unspendable
/**
* Creates a [[ECPrivateKey]], then creates a [[CLTVScriptPubKey]] from that private key
* Finally creates a [[Transaction]] that can successfully spend the [[CLTVScriptPubKey]]
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
* [[org.bitcoins.core.protocol.script.CLTVScriptPubKey CLTVScriptPubKey]] from that private key.
* Finally creates a [[org.bitcoins.core.protocol.transaction.Transaction Transaction]] that can successfully
* spend the [[org.bitcoins.core.protocol.script.CLTVScriptPubKey CLTVScriptPubKey]]
*/
def spendableCLTVTransaction: Gen[(BaseTxSigComponent, Seq[ECPrivateKey])] =
for {
@ -272,8 +287,10 @@ trait TransactionGenerators extends BitcoinSLogger {
} yield spendable
/**
* Creates a [[ECPrivateKey]], then creates a [[CSVScriptPubKey]] from that private key
* Finally creates a [[Transaction]] that can successfully spend the [[CSVScriptPubKey]]
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
* [[org.bitcoins.core.protocol.script.CSVScriptPubKey CSVScriptPubKey]] from that private key.
* Finally creates a [[org.bitcoins.core.protocol.transaction.Transaction Transaction]] that can
* successfully spend the [[org.bitcoins.core.protocol.script.CSVScriptPubKey CSVScriptPubKey]]
*/
def spendableCSVTransaction: Gen[(BaseTxSigComponent, Seq[ECPrivateKey])] =
for {
@ -301,20 +318,23 @@ trait TransactionGenerators extends BitcoinSLogger {
sequence,
None)
/** Generates a [[WitnessTransaction]] that has all of it's inputs signed correctly */
/** Generates a [[org.bitcoins.core.protocol.transaction.WitnessTransaction WitnessTransaction]] that has all of
* it's inputs signed correctly */
def signedP2WPKHTransaction: Gen[(WitnessTxSigComponent, Seq[ECPrivateKey])] =
for {
(_, wBaseTxSigComponent, privKeys) <- WitnessGenerators.signedP2WPKHTransactionWitness
} yield (wBaseTxSigComponent, privKeys)
/** Generates a [[WitnessTransaction]] that has an input spends a raw P2WSH [[WitnessScriptPubKey]] */
/** Generates a [[org.bitcoins.core.protocol.transaction.WitnessTransaction WitnessTransaction]] that has an input
* spends a raw P2WSH [[org.bitcoins.core.protocol.script.WitnessScriptPubKey WitnessScriptPubKey]] */
def signedP2WSHP2PKTransaction: Gen[
(WitnessTxSigComponentRaw, Seq[ECPrivateKey])] =
for {
(_, wBaseTxSigComponent, privKeys) <- WitnessGenerators.signedP2WSHP2PKTransactionWitness
} yield (wBaseTxSigComponent, privKeys)
/** Generates a [[WitnessTransaction]] that has an input spends a raw P2WSH [[WitnessScriptPubKey]] */
/** Generates a [[org.bitcoins.core.protocol.transaction.WitnessTransaction WitnessTransaction]] that has an
* input spends a raw P2WSH [[org.bitcoins.core.protocol.script.WitnessScriptPubKey WitnessScriptPubKey]] */
def signedP2WSHP2PKHTransaction: Gen[
(WitnessTxSigComponentRaw, Seq[ECPrivateKey])] =
for {
@ -446,7 +466,7 @@ trait TransactionGenerators extends BitcoinSLogger {
TransactionConstants.sequence)
}
/** Builds a spending [[WitnessTransaction]] with the given parameters */
/** Builds a spending [[org.bitcoins.core.protocol.transaction.WitnessTransaction WitnessTransaction]] with the given parameters */
def buildSpendingTransaction(
creditingTx: Transaction,
scriptSignature: ScriptSignature,
@ -631,12 +651,13 @@ trait TransactionGenerators extends BitcoinSLogger {
}
/**
* To indicate that we should evaulate a OP_CSV operation based on
* To indicate that we should evaulate a [[org.bitcoins.core.script.locktime.OP_CHECKSEQUENCEVERIFY OP_CSV]]
* operation based on
* blockheight we need 1 << 22 bit turned off. See BIP68 for more details
*/
private def lockByBlockHeightBitSet: UInt32 = UInt32("ffbfffff")
/** Generates a [[UInt32]] s.t. the block height bit is set according to BIP68 */
/** Generates a [[org.bitcoins.core.number.UInt32 UInt32]] s.t. the block height bit is set according to BIP68 */
private def sequenceForBlockHeight: Gen[UInt32] = validCSVSequence.map { n =>
val result: UInt32 = n & lockByBlockHeightBitSet
require(LockTimeInterpreter.isCSVLockByBlockHeight(result),
@ -644,7 +665,8 @@ trait TransactionGenerators extends BitcoinSLogger {
result
}
/** Generates a [[ScriptNumber]] and [[UInt32]] s.t. the pair can be spent by an OP_CSV operation */
/** Generates a [[org.bitcoins.core.script.constant.ScriptNumber ScriptNumber]] and
* [[org.bitcoins.core.number.UInt32 UInt32]] s.t. the pair can be spent by an OP_CSV operation */
private def validScriptNumberAndSequenceForBlockHeight: Gen[
(ScriptNumber, UInt32)] = {
sequenceForBlockHeight.flatMap { s =>
@ -659,7 +681,7 @@ trait TransactionGenerators extends BitcoinSLogger {
}
}
/** Generates a [[UInt32]] with the locktime bit set according to BIP68 */
/** Generates a [[org.bitcoins.core.number.UInt32 UInt32]] with the locktime bit set according to BIP68 */
private def sequenceForRelativeLockTime: Gen[UInt32] = validCSVSequence.map {
n =>
val result = n | TransactionConstants.sequenceLockTimeTypeFlag
@ -668,7 +690,8 @@ trait TransactionGenerators extends BitcoinSLogger {
result
}
/** Generates a valid [[ScriptNumber]] and [[UInt32]] s.t. the pair will evaluate to true by a OP_CSV operation */
/** Generates a valid [[org.bitcoins.core.script.constant.ScriptNumber ScriptNumber]] and
* [[org.bitcoins.core.number.UInt32 UInt32]] s.t. the pair will evaluate to true by a OP_CSV operation */
private def validScriptNumberAndSequenceForRelativeLockTime: Gen[
(ScriptNumber, UInt32)] = {
sequenceForRelativeLockTime.flatMap { s =>
@ -684,7 +707,8 @@ trait TransactionGenerators extends BitcoinSLogger {
}
}
/** Generates a [[UInt32]] s.t. the locktime enabled flag is set. See BIP68 for more info */
/** Generates a [[org.bitcoins.core.number.UInt32 UInt32]] s.t. the locktime enabled flag is set.
* See [[https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki BIP68]] for more info */
private def validCSVSequence: Gen[UInt32] = NumberGenerator.uInt32s.map { n =>
//makes sure the 1 << 31 is TURNED OFF,
//need this to generate spendable CSV values without discarding a bunch of test cases
@ -694,8 +718,9 @@ trait TransactionGenerators extends BitcoinSLogger {
}
/**
* Generates a pair of CSV values: a transaction input sequence, and a CSV script sequence value, such that the txInput
* sequence mask is always less than the script sequence mask (i.e. generates values for a validly constructed and NOT spendable CSV transaction).
* Generates a pair of CSV values: a transaction input sequence, and a CSV script sequence value, such that
* the txInput sequence mask is always less than the script sequence mask (i.e. generates values for a validly
* constructed and NOT spendable CSV transaction).
*/
def unspendableCSVValues: Gen[(ScriptNumber, UInt32)] =
(for {
@ -705,14 +730,16 @@ trait TransactionGenerators extends BitcoinSLogger {
.suchThat(x => LockTimeInterpreter.isLockTimeBitOff(x))
} yield (csvScriptNum, sequence)).suchThat(x => !csvLockTimesOfSameType(x))
/** generates a [[ScriptNumber]] and [[UInt32]] locktime for a transaction such that the tx will be spendable */
/** generates a [[org.bitcoins.core.script.constant.ScriptNumber ScriptNumber]] and
* [[org.bitcoins.core.number.UInt32 UInt32]] locktime for a transaction such that the tx will be spendable */
def spendableCLTVValues: Gen[(ScriptNumber, UInt32)] =
for {
txLockTime <- NumberGenerator.uInt32s
cltvLockTime <- sameLockTimeTypeSpendable(txLockTime)
} yield (cltvLockTime, txLockTime)
/** Generates a [[ScriptNumber]] and [[UInt32]] locktime for a transaction such that the tx will be unspendable */
/** Generates a [[org.bitcoins.core.script.constant.ScriptNumber ScriptNumber]] and
* [[org.bitcoins.core.number.UInt32 UInt32]] locktime for a transaction such that the tx will be unspendable */
def unspendableCLTVValues: Gen[(ScriptNumber, UInt32)] =
for {
txLockTime <- NumberGenerator.uInt32s

View File

@ -15,7 +15,7 @@ import org.scalacheck.Gen
*/
sealed abstract class WitnessGenerators extends BitcoinSLogger {
/** Generates a random [[org.bitcoins.core.protocol.script.ScriptWitness]] */
/** Generates a random [[org.bitcoins.core.protocol.script.ScriptWitness ScriptWitness]] */
def scriptWitness: Gen[ScriptWitness] = {
//TODO: I need to come back and uncomment out this code after fixing
@ -38,7 +38,8 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
Gen.oneOf(p2wpkhWitnessV0, p2wshWitnessV0)
}
/** Generates a [[TransactionWitness]] with the specified number of witnesses */
/** Generates a [[org.bitcoins.core.protocol.transaction.TransactionWitness TransactionWitness]] with
* the specified number of witnesses */
def transactionWitness(numWitnesses: Int): Gen[TransactionWitness] =
for {
inputWitnesses <- Gen.listOfN(numWitnesses, Gen.option(scriptWitness))
@ -50,7 +51,7 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
wit <- transactionWitness(num)
} yield wit
/** Generates a validly signed [[TransactionWitness]] */
/** Generates a validly signed [[org.bitcoins.core.protocol.transaction.TransactionWitness TransactionWitness]] */
def signedP2WPKHTransactionWitness: Gen[
(TransactionWitness, WitnessTxSigComponent, Seq[ECPrivateKey])] =
for {
@ -170,8 +171,9 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
} yield (txWitness, signedWtxSigComponent, privKeys)
/**
* Generates a random signed [[TransactionWitness]] with the corresponding [[WitnessTxSigComponent]]
* and [[ECPrivateKey]]s
* Generates a random signed [[org.bitcoins.core.protocol.transaction.TransactionWitness TransactionWitness]]
* with the corresponding [[org.bitcoins.core.crypto.WitnessTxSigComponent WitnessTxSigComponent]]
* and [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]]s
*/
def signedP2WSHTransactionWitness: Gen[
(TransactionWitness, WitnessTxSigComponentRaw, Seq[ECPrivateKey])] = {
@ -180,7 +182,8 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
signedP2WSHMultiSigTransactionWitness)
}
/** Helps generate a signed [[MultiSignatureScriptSignature]] */
/** Helps generate a signed
* [[org.bitcoins.core.protocol.script.MultiSignatureScriptSignature MultiSignatureScriptSignature]] */
private def multiSigScriptSigGenHelper(
privateKeys: Seq[ECPrivateKey],
scriptPubKey: MultiSignatureScriptPubKey,
@ -199,21 +202,23 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
signedScriptSig
}
/** Generates a random [[org.bitcoins.core.protocol.script.P2WPKHWitnessV0]] */
/** Generates a random [[org.bitcoins.core.protocol.script.P2WPKHWitnessV0 P2WPKHWitnessV0]] */
def p2wpkhWitnessV0: Gen[P2WPKHWitnessV0] =
for {
publicKey <- CryptoGenerators.publicKey
sig <- CryptoGenerators.digitalSignature
} yield P2WPKHWitnessV0(publicKey, sig)
/** Generates a random [[org.bitcoins.core.protocol.script.P2WSHWitnessV0]] */
/** Generates a random [[org.bitcoins.core.protocol.script.P2WSHWitnessV0 P2WSHWitnessV0]] */
def p2wshWitnessV0: Gen[P2WSHWitnessV0] =
for {
(redeem, _) <- ScriptGenerators.scriptPubKey
scriptSig <- ScriptGenerators.scriptSignature
} yield P2WSHWitnessV0(redeem, scriptSig)
/** Takes a signed [[ScriptWitness]] and an unsignedTx and adds the witness to the unsigned [[WitnessTransaction]] */
/** Takes a signed [[org.bitcoins.core.protocol.script.ScriptWitness ScriptWitness]] and an unsignedTx
* and adds the witness to the unsigned
* [[org.bitcoins.core.protocol.transaction.WitnessTransaction WitnessTransaction]] */
def createSignedWTxComponent(
witness: ScriptWitness,
unsignedWTxComponent: WitnessTxSigComponent): (
@ -242,7 +247,8 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
(signedTxWitness, signedWtxSigComponent)
}
/** Creates a unsigned [[WitnessTxSigComponent]] from the given parameters */
/** Creates a unsigned [[org.bitcoins.core.crypto.WitnessTxSigComponent WitnessTxSigComponent]] from
* the given parameters */
def createUnsignedRawWTxSigComponent(
witScriptPubKey: WitnessScriptPubKey,
amount: CurrencyUnit,

View File

@ -11,7 +11,7 @@ import org.scalacheck.Gen
sealed abstract class LnInvoiceGen {
/**
* Generates a [[org.bitcoins.core.protocol.ln.LnHumanReadablePart]]
* Generates a [[org.bitcoins.core.protocol.ln.LnHumanReadablePart LnHumanReadablePart]]
* that does not contain a amount
* @return
*/
@ -22,7 +22,7 @@ sealed abstract class LnInvoiceGen {
}
/**
* Generates a [[org.bitcoins.core.protocol.ln.LnHumanReadablePart]]
* Generates a [[org.bitcoins.core.protocol.ln.LnHumanReadablePart LnHumanReadablePart]]
* with an amount encoded
*/
def lnHrpAmt: Gen[LnHumanReadablePart] = {
@ -97,7 +97,8 @@ sealed abstract class LnInvoiceGen {
.map(rs => LnTag.RoutingInfo(rs))
}
/** Generated a tagged fields with an explicit [[LnTag.NodeIdTag]]
/** Generated a tagged fields with an explicit
* [[org.bitcoins.core.protocol.ln.LnTag.NodeIdTag LnTag.NodeIdTag]]
* */
def taggedFields(nodeIdOpt: Option[NodeId]): Gen[LnTaggedFields] =
for {

View File

@ -176,7 +176,8 @@ trait EclairTestUtil extends BitcoinSLogger {
/**
* Doesn't return until the given channelId
* is in the [[ChannelState.NORMAL]] for this [[EclairRpcClient]]
* is in the [[org.bitcoins.core.protocol.ln.channel.ChannelState ChannelState.NORMAL]]
* for this [[org.bitcoins.eclair.rpc.client.EclairRpcClient EclairRpcClient]]
* @param client
* @param chanId
*/