mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 18:02:54 +01:00
Scaladoc formatting (#292)
This commit is contained in:
parent
268e235b4d
commit
edcf097b2a
@ -25,7 +25,7 @@ sealed abstract class BlockchainElementsGenerator {
|
|||||||
} yield Block(header, allTxs)
|
} 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
|
* to 10 transactions currently
|
||||||
*/
|
*/
|
||||||
def block: Gen[Block] =
|
def block: Gen[Block] =
|
||||||
@ -34,21 +34,23 @@ sealed abstract class BlockchainElementsGenerator {
|
|||||||
txs <- TransactionGenerators.smallTransactions
|
txs <- TransactionGenerators.smallTransactions
|
||||||
} yield Block(header, txs)
|
} yield Block(header, txs)
|
||||||
|
|
||||||
/** Generates a random [[BlockHeader]] */
|
/** Generates a random [[org.bitcoins.core.protocol.blockchain.BlockHeader BlockHeader]] */
|
||||||
def blockHeader: Gen[BlockHeader] =
|
def blockHeader: Gen[BlockHeader] =
|
||||||
for {
|
for {
|
||||||
previousBlockHash <- CryptoGenerators.doubleSha256Digest
|
previousBlockHash <- CryptoGenerators.doubleSha256Digest
|
||||||
b <- blockHeader(previousBlockHash)
|
b <- blockHeader(previousBlockHash)
|
||||||
} yield b
|
} 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] =
|
def blockHeader(previousBlockHash: DoubleSha256Digest): Gen[BlockHeader] =
|
||||||
for {
|
for {
|
||||||
nBits <- NumberGenerator.uInt32s
|
nBits <- NumberGenerator.uInt32s
|
||||||
b <- blockHeader(previousBlockHash, nBits)
|
b <- blockHeader(previousBlockHash, nBits)
|
||||||
} yield b
|
} 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(
|
def blockHeader(
|
||||||
previousBlockHash: DoubleSha256Digest,
|
previousBlockHash: DoubleSha256Digest,
|
||||||
nBits: UInt32): Gen[BlockHeader] =
|
nBits: UInt32): Gen[BlockHeader] =
|
||||||
@ -58,7 +60,8 @@ sealed abstract class BlockchainElementsGenerator {
|
|||||||
header <- blockHeader(previousBlockHash, nBits, txs)
|
header <- blockHeader(previousBlockHash, nBits, txs)
|
||||||
} yield header
|
} 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(
|
def blockHeader(
|
||||||
previousBlockHash: DoubleSha256Digest,
|
previousBlockHash: DoubleSha256Digest,
|
||||||
nBits: UInt32,
|
nBits: UInt32,
|
||||||
@ -76,7 +79,8 @@ sealed abstract class BlockchainElementsGenerator {
|
|||||||
nBits,
|
nBits,
|
||||||
nonce)
|
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] =
|
def blockHeader(txs: Seq[Transaction]): Gen[BlockHeader] =
|
||||||
for {
|
for {
|
||||||
previousBlockHash <- CryptoGenerators.doubleSha256Digest
|
previousBlockHash <- CryptoGenerators.doubleSha256Digest
|
||||||
|
@ -15,7 +15,8 @@ import org.scalacheck.Gen
|
|||||||
*/
|
*/
|
||||||
abstract class MerkleGenerator {
|
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[
|
def merkleBlockWithInsertedTxIds(txs: Seq[Transaction]): Gen[
|
||||||
(MerkleBlock, Block, Seq[DoubleSha256Digest])] =
|
(MerkleBlock, Block, Seq[DoubleSha256Digest])] =
|
||||||
for {
|
for {
|
||||||
@ -24,7 +25,7 @@ abstract class MerkleGenerator {
|
|||||||
merkleBlock = MerkleBlock(block, txIds)
|
merkleBlock = MerkleBlock(block, txIds)
|
||||||
} yield (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[
|
def merkleBlockWithInsertedTxIds: Gen[
|
||||||
(MerkleBlock, Block, Seq[DoubleSha256Digest])] =
|
(MerkleBlock, Block, Seq[DoubleSha256Digest])] =
|
||||||
for {
|
for {
|
||||||
@ -35,7 +36,7 @@ abstract class MerkleGenerator {
|
|||||||
} yield result
|
} 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
|
* 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
|
* 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
|
* matches in the parital merkle tree that SHOULD NOT be matched. Bloom filters do not guaratnee no
|
||||||
|
@ -51,9 +51,9 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
def emptyScriptSignature = p2pkhScriptSignature.map(_ => EmptyScriptSignature)
|
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
|
* 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] =
|
def p2shScriptSignature: Gen[P2SHScriptSignature] =
|
||||||
for {
|
for {
|
||||||
@ -159,8 +159,9 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
Gen.oneOf(p2wpkhSPKV0, p2wshSPKV0)
|
Gen.oneOf(p2wpkhSPKV0, p2wshSPKV0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an [[UnassignedWitnessScriptPubKey]],
|
* Creates an [[org.bitcoins.core.protocol.script.UnassignedWitnessScriptPubKey UnassignedWitnessScriptPubKey]],
|
||||||
* currently this is any witness script pubkey besides [[org.bitcoins.core.protocol.script.WitnessScriptPubKeyV0]
|
* currently this is any witness script pubkey besides
|
||||||
|
* [[org.bitcoins.core.protocol.script.WitnessScriptPubKeyV0 WitnessScriptPubKeyV0]]
|
||||||
*/
|
*/
|
||||||
def unassignedWitnessScriptPubKey: Gen[
|
def unassignedWitnessScriptPubKey: Gen[
|
||||||
(UnassignedWitnessScriptPubKey, Seq[ECPrivateKey])] =
|
(UnassignedWitnessScriptPubKey, Seq[ECPrivateKey])] =
|
||||||
@ -170,7 +171,7 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
unassignedAsm = version +: witV0.asm.tail
|
unassignedAsm = version +: witV0.asm.tail
|
||||||
} yield (UnassignedWitnessScriptPubKey(unassignedAsm), privKeys)
|
} 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])] =
|
def witnessScriptPubKey: Gen[(WitnessScriptPubKey, Seq[ECPrivateKey])] =
|
||||||
Gen.oneOf(assignedWitnessScriptPubKey, unassignedWitnessScriptPubKey)
|
Gen.oneOf(assignedWitnessScriptPubKey, unassignedWitnessScriptPubKey)
|
||||||
|
|
||||||
@ -223,7 +224,7 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
def lockTimeScriptSig: Gen[LockTimeScriptSignature] =
|
def lockTimeScriptSig: Gen[LockTimeScriptSignature] =
|
||||||
Gen.oneOf(csvScriptSignature, cltvScriptSignature)
|
Gen.oneOf(csvScriptSignature, cltvScriptSignature)
|
||||||
|
|
||||||
/** Generates an arbitrary [[ScriptPubKey]] */
|
/** Generates an arbitrary [[org.bitcoins.core.protocol.script.ScriptPubKey ScriptPubKey]] */
|
||||||
def scriptPubKey: Gen[(ScriptPubKey, Seq[ECPrivateKey])] = {
|
def scriptPubKey: Gen[(ScriptPubKey, Seq[ECPrivateKey])] = {
|
||||||
Gen.oneOf(
|
Gen.oneOf(
|
||||||
p2pkScriptPubKey.map(privKeyToSeq(_)),
|
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] = {
|
def scriptSignature: Gen[ScriptSignature] = {
|
||||||
Gen.oneOf(
|
Gen.oneOf(
|
||||||
p2pkScriptSignature,
|
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
|
* Note: Does NOT generate a correct/valid signature
|
||||||
*/
|
*/
|
||||||
private def pickCorrespondingScriptSignature(
|
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
|
* @return the signed [[org.bitcoins.core.protocol.script.P2PKScriptSignature P2PKScriptSignature]],
|
||||||
* [[ECPrivateKey]] used to sign the scriptSig
|
* 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[
|
def signedP2PKScriptSignature: Gen[
|
||||||
(P2PKScriptSignature, P2PKScriptPubKey, ECPrivateKey)] =
|
(P2PKScriptSignature, P2PKScriptPubKey, ECPrivateKey)] =
|
||||||
@ -309,10 +313,12 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
} yield (signedScriptSig, scriptPubKey, privateKey)
|
} 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
|
* @return the signed [[org.bitcoins.core.protocol.script.P2PKHScriptSignature P2PKHScriptSignature]], the
|
||||||
* [[ECPrivateKey]] used to sign the scriptSig
|
* [[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[
|
def signedP2PKHScriptSignature: Gen[
|
||||||
(P2PKHScriptSignature, P2PKHScriptPubKey, ECPrivateKey)] =
|
(P2PKHScriptSignature, P2PKHScriptPubKey, ECPrivateKey)] =
|
||||||
@ -340,10 +346,13 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
} yield (signedScriptSig, scriptPubKey, privateKey)
|
} 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
|
* ti
|
||||||
* @return the signed [[MultiSignatureScriptSignature]], the [[MultiSignatureScriptPubKey]] it spends and the
|
* @return the signed [[org.bitcoins.core.protocol.script.MultiSignatureScriptSignature MultiSignatureScriptSignature]],
|
||||||
* sequence of [[ECPrivateKey]] used to sign the scriptSig
|
* 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[(
|
def signedMultiSignatureScriptSignature: Gen[(
|
||||||
MultiSignatureScriptSignature,
|
MultiSignatureScriptSignature,
|
||||||
@ -376,9 +385,12 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
} yield (signedScriptSig, multiSigScriptPubKey, privateKeys)
|
} 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
|
* used to sign the scriptSig
|
||||||
*/
|
*/
|
||||||
def signedP2SHScriptSignature: Gen[
|
def signedP2SHScriptSignature: Gen[
|
||||||
@ -390,9 +402,12 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
} yield (p2SHScriptSignature, p2SHScriptPubKey, privateKeys)
|
} 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
|
* used to sign the scriptSig
|
||||||
*/
|
*/
|
||||||
def signedCLTVScriptSignature(
|
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
|
* used to sign the scriptSig
|
||||||
*/
|
*/
|
||||||
def signedCSVScriptSignature(
|
def signedCSVScriptSignature(
|
||||||
@ -493,13 +511,15 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
sequence)
|
sequence)
|
||||||
} yield scriptSig
|
} 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[
|
def signedLockTimeScriptSignature: Gen[
|
||||||
(LockTimeScriptSignature, LockTimeScriptPubKey, Seq[ECPrivateKey])] = {
|
(LockTimeScriptSignature, LockTimeScriptPubKey, Seq[ECPrivateKey])] = {
|
||||||
Gen.oneOf(signedCSVScriptSignature, signedCLTVScriptSignature)
|
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(
|
private def lockTimeHelper(
|
||||||
lockTime: Option[UInt32],
|
lockTime: Option[UInt32],
|
||||||
sequence: UInt32,
|
sequence: UInt32,
|
||||||
@ -583,11 +603,14 @@ sealed abstract class ScriptGenerators extends BitcoinSLogger {
|
|||||||
wtxSigComponent.amount)
|
wtxSigComponent.amount)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function chooses a random signed [[ScriptSignature]] that is NOT a [[P2SHScriptSignature]], [[CSVScriptSignature]],
|
* This function chooses a random signed [[org.bitcoins.core.protocol.script.ScriptSignature ScriptSignature]]
|
||||||
* [[CLTVScriptSignature]], or any witness type
|
* 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,
|
* @return the signed [[org.bitcoins.core.protocol.script.ScriptSignature ScriptSignature]],
|
||||||
* and the sequence of[[ECPrivateKey]] used to sign it
|
* 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[
|
def chooseSignedScriptSig: Gen[
|
||||||
(ScriptSignature, ScriptPubKey, Seq[ECPrivateKey])] = {
|
(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])] = {
|
def randomScriptSig: Gen[(ScriptSignature, ScriptPubKey, Seq[ECPrivateKey])] = {
|
||||||
val witP2SHP2WPKH =
|
val witP2SHP2WPKH =
|
||||||
signedP2SHP2WPKHScriptSignature.map(x => (x._1, x._2, x._3))
|
signedP2SHP2WPKHScriptSignature.map(x => (x._1, x._2, x._3))
|
||||||
|
@ -23,14 +23,14 @@ import scala.annotation.tailrec
|
|||||||
*/
|
*/
|
||||||
trait TransactionGenerators extends BitcoinSLogger {
|
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] =
|
def outPoint: Gen[TransactionOutPoint] =
|
||||||
for {
|
for {
|
||||||
txId <- CryptoGenerators.doubleSha256Digest
|
txId <- CryptoGenerators.doubleSha256Digest
|
||||||
vout <- NumberGenerator.uInt32s
|
vout <- NumberGenerator.uInt32s
|
||||||
} yield TransactionOutPoint(txId, vout)
|
} 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] =
|
def output: Gen[TransactionOutput] =
|
||||||
for {
|
for {
|
||||||
satoshis <- CurrencyUnitGenerator.satoshis
|
satoshis <- CurrencyUnitGenerator.satoshis
|
||||||
@ -51,7 +51,7 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
def realisticOutputs: Gen[Seq[TransactionOutput]] =
|
def realisticOutputs: Gen[Seq[TransactionOutput]] =
|
||||||
Gen.choose(0, 5).flatMap(n => Gen.listOfN(n, realisticOutput))
|
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]] =
|
def smallOutputs: Gen[Seq[TransactionOutput]] =
|
||||||
Gen.choose(0, 5).flatMap(i => Gen.listOfN(i, output))
|
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] =
|
def input: Gen[TransactionInput] =
|
||||||
for {
|
for {
|
||||||
outPoint <- outPoint
|
outPoint <- outPoint
|
||||||
@ -100,22 +100,24 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
|
|
||||||
def inputs: Gen[List[TransactionInput]] = Gen.nonEmptyListOf(input)
|
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]] =
|
def smallInputs: Gen[Seq[TransactionInput]] =
|
||||||
Gen.choose(1, 5).flatMap(i => Gen.listOfN(i, input))
|
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]] =
|
def smallInputsNonEmpty: Gen[Seq[TransactionInput]] =
|
||||||
Gen.choose(1, 5).flatMap(i => Gen.listOfN(i, input))
|
Gen.choose(1, 5).flatMap(i => Gen.listOfN(i, input))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an arbitrary [[org.bitcoins.core.protocol.transaction.Transaction]]
|
* Generates an arbitrary [[org.bitcoins.core.protocol.transaction.Transaction Transaction]]
|
||||||
* This transaction's [[TransactionInput]]s will not evaluate to true
|
* This transaction's [[org.bitcoins.core.protocol.transaction.TransactionInput TransactionInput]]s
|
||||||
* inside of the [[org.bitcoins.core.script.interpreter.ScriptInterpreter]]
|
* will not evaluate to true inside of the
|
||||||
|
* [[org.bitcoins.core.script.interpreter.ScriptInterpreter ScriptInterpreter]]
|
||||||
*/
|
*/
|
||||||
def transactions: Gen[Seq[Transaction]] = Gen.listOf(transaction)
|
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]] =
|
def smallTransactions: Gen[Seq[Transaction]] =
|
||||||
Gen.choose(0, 10).flatMap(i => Gen.listOfN(i, transaction))
|
Gen.choose(0, 10).flatMap(i => Gen.listOfN(i, transaction))
|
||||||
|
|
||||||
@ -130,7 +132,7 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
lockTime <- NumberGenerator.uInt32s
|
lockTime <- NumberGenerator.uInt32s
|
||||||
} yield BaseTransaction(version, is, os, lockTime)
|
} yield BaseTransaction(version, is, os, lockTime)
|
||||||
|
|
||||||
/** Generates a random [[WitnessTransaction]] */
|
/** Generates a random [[org.bitcoins.core.protocol.transaction.WitnessTransaction WitnessTransaction]] */
|
||||||
def witnessTransaction: Gen[WitnessTransaction] =
|
def witnessTransaction: Gen[WitnessTransaction] =
|
||||||
for {
|
for {
|
||||||
version <- NumberGenerator.int32s
|
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
|
//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
|
//revert to using the `BaseTransaction` serialization format
|
||||||
//notice we use the old serialization format if all witnesses are empty
|
//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
|
witness <- WitnessGenerators
|
||||||
.transactionWitness(is.size)
|
.transactionWitness(is.size)
|
||||||
.suchThat(_.witnesses.exists(_ != EmptyScriptWitness))
|
.suchThat(_.witnesses.exists(_ != EmptyScriptWitness))
|
||||||
} yield WitnessTransaction(version, is, os, lockTime, witness)
|
} yield WitnessTransaction(version, is, os, lockTime, witness)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [[ECPrivateKey]], then creates a [[P2PKScriptPubKey]] from that private key
|
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
|
||||||
* Finally creates a [[Transaction]] that spends the [[P2PKScriptPubKey]] correctly
|
* [[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)] =
|
def signedP2PKTransaction: Gen[(BaseTxSigComponent, ECPrivateKey)] =
|
||||||
for {
|
for {
|
||||||
@ -169,8 +173,10 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
} yield (signedTxSignatureComponent, privateKey)
|
} yield (signedTxSignatureComponent, privateKey)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [[ECPrivateKey]], then creates a [[P2PKHScriptPubKey]] from that private key
|
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
|
||||||
* Finally creates a [[Transaction]] that spends the [[P2PKHScriptPubKey]] correctly
|
* [[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)] =
|
def signedP2PKHTransaction: Gen[(BaseTxSigComponent, ECPrivateKey)] =
|
||||||
for {
|
for {
|
||||||
@ -189,8 +195,10 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
} yield (signedTxSignatureComponent, privateKey)
|
} yield (signedTxSignatureComponent, privateKey)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a sequence of [[ECPrivateKey]], then creates a [[MultiSignatureScriptPubKey]] from those private keys,
|
* Creates a sequence of [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
|
||||||
* Finally creates a [[Transaction]] that spends the [[MultiSignatureScriptPubKey]] correctly
|
* [[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])] =
|
def signedMultiSigTransaction: Gen[(BaseTxSigComponent, Seq[ECPrivateKey])] =
|
||||||
for {
|
for {
|
||||||
@ -209,7 +217,9 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
} yield (signedTxSignatureComponent, privateKey)
|
} 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])] =
|
def signedP2SHTransaction: Gen[(BaseTxSigComponent, Seq[ECPrivateKey])] =
|
||||||
for {
|
for {
|
||||||
@ -235,9 +245,12 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [[ECPrivateKey]], then creates a [[CLTVScriptPubKey]] from that private key
|
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
|
||||||
* Finally creates a [[Transaction]] that CANNNOT spend the [[CLTVScriptPubKey]] because the LockTime requirement
|
* [[org.bitcoins.core.protocol.script.CLTVScriptPubKey CLTVScriptPubKey]] from that private key
|
||||||
* is not satisfied (i.e. the transaction's lockTime has not surpassed the CLTV value in the [[CLTVScriptPubKey]])
|
* 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
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -255,8 +268,10 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
} yield unspendable
|
} yield unspendable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [[ECPrivateKey]], then creates a [[CLTVScriptPubKey]] from that private key
|
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
|
||||||
* Finally creates a [[Transaction]] that can successfully spend the [[CLTVScriptPubKey]]
|
* [[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])] =
|
def spendableCLTVTransaction: Gen[(BaseTxSigComponent, Seq[ECPrivateKey])] =
|
||||||
for {
|
for {
|
||||||
@ -272,8 +287,10 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
} yield spendable
|
} yield spendable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [[ECPrivateKey]], then creates a [[CSVScriptPubKey]] from that private key
|
* Creates a [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]], then creates a
|
||||||
* Finally creates a [[Transaction]] that can successfully spend the [[CSVScriptPubKey]]
|
* [[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])] =
|
def spendableCSVTransaction: Gen[(BaseTxSigComponent, Seq[ECPrivateKey])] =
|
||||||
for {
|
for {
|
||||||
@ -301,20 +318,23 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
sequence,
|
sequence,
|
||||||
None)
|
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])] =
|
def signedP2WPKHTransaction: Gen[(WitnessTxSigComponent, Seq[ECPrivateKey])] =
|
||||||
for {
|
for {
|
||||||
(_, wBaseTxSigComponent, privKeys) <- WitnessGenerators.signedP2WPKHTransactionWitness
|
(_, wBaseTxSigComponent, privKeys) <- WitnessGenerators.signedP2WPKHTransactionWitness
|
||||||
} yield (wBaseTxSigComponent, privKeys)
|
} 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[
|
def signedP2WSHP2PKTransaction: Gen[
|
||||||
(WitnessTxSigComponentRaw, Seq[ECPrivateKey])] =
|
(WitnessTxSigComponentRaw, Seq[ECPrivateKey])] =
|
||||||
for {
|
for {
|
||||||
(_, wBaseTxSigComponent, privKeys) <- WitnessGenerators.signedP2WSHP2PKTransactionWitness
|
(_, wBaseTxSigComponent, privKeys) <- WitnessGenerators.signedP2WSHP2PKTransactionWitness
|
||||||
} yield (wBaseTxSigComponent, privKeys)
|
} 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[
|
def signedP2WSHP2PKHTransaction: Gen[
|
||||||
(WitnessTxSigComponentRaw, Seq[ECPrivateKey])] =
|
(WitnessTxSigComponentRaw, Seq[ECPrivateKey])] =
|
||||||
for {
|
for {
|
||||||
@ -446,7 +466,7 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
TransactionConstants.sequence)
|
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(
|
def buildSpendingTransaction(
|
||||||
creditingTx: Transaction,
|
creditingTx: Transaction,
|
||||||
scriptSignature: ScriptSignature,
|
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
|
* blockheight we need 1 << 22 bit turned off. See BIP68 for more details
|
||||||
*/
|
*/
|
||||||
private def lockByBlockHeightBitSet: UInt32 = UInt32("ffbfffff")
|
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 =>
|
private def sequenceForBlockHeight: Gen[UInt32] = validCSVSequence.map { n =>
|
||||||
val result: UInt32 = n & lockByBlockHeightBitSet
|
val result: UInt32 = n & lockByBlockHeightBitSet
|
||||||
require(LockTimeInterpreter.isCSVLockByBlockHeight(result),
|
require(LockTimeInterpreter.isCSVLockByBlockHeight(result),
|
||||||
@ -644,7 +665,8 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
result
|
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[
|
private def validScriptNumberAndSequenceForBlockHeight: Gen[
|
||||||
(ScriptNumber, UInt32)] = {
|
(ScriptNumber, UInt32)] = {
|
||||||
sequenceForBlockHeight.flatMap { s =>
|
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 {
|
private def sequenceForRelativeLockTime: Gen[UInt32] = validCSVSequence.map {
|
||||||
n =>
|
n =>
|
||||||
val result = n | TransactionConstants.sequenceLockTimeTypeFlag
|
val result = n | TransactionConstants.sequenceLockTimeTypeFlag
|
||||||
@ -668,7 +690,8 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
result
|
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[
|
private def validScriptNumberAndSequenceForRelativeLockTime: Gen[
|
||||||
(ScriptNumber, UInt32)] = {
|
(ScriptNumber, UInt32)] = {
|
||||||
sequenceForRelativeLockTime.flatMap { s =>
|
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 =>
|
private def validCSVSequence: Gen[UInt32] = NumberGenerator.uInt32s.map { n =>
|
||||||
//makes sure the 1 << 31 is TURNED OFF,
|
//makes sure the 1 << 31 is TURNED OFF,
|
||||||
//need this to generate spendable CSV values without discarding a bunch of test cases
|
//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
|
* Generates a pair of CSV values: a transaction input sequence, and a CSV script sequence value, such that
|
||||||
* sequence mask is always less than the script sequence mask (i.e. generates values for a validly constructed and NOT spendable CSV transaction).
|
* 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)] =
|
def unspendableCSVValues: Gen[(ScriptNumber, UInt32)] =
|
||||||
(for {
|
(for {
|
||||||
@ -705,14 +730,16 @@ trait TransactionGenerators extends BitcoinSLogger {
|
|||||||
.suchThat(x => LockTimeInterpreter.isLockTimeBitOff(x))
|
.suchThat(x => LockTimeInterpreter.isLockTimeBitOff(x))
|
||||||
} yield (csvScriptNum, sequence)).suchThat(x => !csvLockTimesOfSameType(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)] =
|
def spendableCLTVValues: Gen[(ScriptNumber, UInt32)] =
|
||||||
for {
|
for {
|
||||||
txLockTime <- NumberGenerator.uInt32s
|
txLockTime <- NumberGenerator.uInt32s
|
||||||
cltvLockTime <- sameLockTimeTypeSpendable(txLockTime)
|
cltvLockTime <- sameLockTimeTypeSpendable(txLockTime)
|
||||||
} yield (cltvLockTime, 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)] =
|
def unspendableCLTVValues: Gen[(ScriptNumber, UInt32)] =
|
||||||
for {
|
for {
|
||||||
txLockTime <- NumberGenerator.uInt32s
|
txLockTime <- NumberGenerator.uInt32s
|
||||||
|
@ -15,7 +15,7 @@ import org.scalacheck.Gen
|
|||||||
*/
|
*/
|
||||||
sealed abstract class WitnessGenerators extends BitcoinSLogger {
|
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] = {
|
def scriptWitness: Gen[ScriptWitness] = {
|
||||||
|
|
||||||
//TODO: I need to come back and uncomment out this code after fixing
|
//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)
|
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] =
|
def transactionWitness(numWitnesses: Int): Gen[TransactionWitness] =
|
||||||
for {
|
for {
|
||||||
inputWitnesses <- Gen.listOfN(numWitnesses, Gen.option(scriptWitness))
|
inputWitnesses <- Gen.listOfN(numWitnesses, Gen.option(scriptWitness))
|
||||||
@ -50,7 +51,7 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
|
|||||||
wit <- transactionWitness(num)
|
wit <- transactionWitness(num)
|
||||||
} yield wit
|
} yield wit
|
||||||
|
|
||||||
/** Generates a validly signed [[TransactionWitness]] */
|
/** Generates a validly signed [[org.bitcoins.core.protocol.transaction.TransactionWitness TransactionWitness]] */
|
||||||
def signedP2WPKHTransactionWitness: Gen[
|
def signedP2WPKHTransactionWitness: Gen[
|
||||||
(TransactionWitness, WitnessTxSigComponent, Seq[ECPrivateKey])] =
|
(TransactionWitness, WitnessTxSigComponent, Seq[ECPrivateKey])] =
|
||||||
for {
|
for {
|
||||||
@ -170,8 +171,9 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
|
|||||||
} yield (txWitness, signedWtxSigComponent, privKeys)
|
} yield (txWitness, signedWtxSigComponent, privKeys)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a random signed [[TransactionWitness]] with the corresponding [[WitnessTxSigComponent]]
|
* Generates a random signed [[org.bitcoins.core.protocol.transaction.TransactionWitness TransactionWitness]]
|
||||||
* and [[ECPrivateKey]]s
|
* with the corresponding [[org.bitcoins.core.crypto.WitnessTxSigComponent WitnessTxSigComponent]]
|
||||||
|
* and [[org.bitcoins.core.crypto.ECPrivateKey ECPrivateKey]]s
|
||||||
*/
|
*/
|
||||||
def signedP2WSHTransactionWitness: Gen[
|
def signedP2WSHTransactionWitness: Gen[
|
||||||
(TransactionWitness, WitnessTxSigComponentRaw, Seq[ECPrivateKey])] = {
|
(TransactionWitness, WitnessTxSigComponentRaw, Seq[ECPrivateKey])] = {
|
||||||
@ -180,7 +182,8 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
|
|||||||
signedP2WSHMultiSigTransactionWitness)
|
signedP2WSHMultiSigTransactionWitness)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helps generate a signed [[MultiSignatureScriptSignature]] */
|
/** Helps generate a signed
|
||||||
|
* [[org.bitcoins.core.protocol.script.MultiSignatureScriptSignature MultiSignatureScriptSignature]] */
|
||||||
private def multiSigScriptSigGenHelper(
|
private def multiSigScriptSigGenHelper(
|
||||||
privateKeys: Seq[ECPrivateKey],
|
privateKeys: Seq[ECPrivateKey],
|
||||||
scriptPubKey: MultiSignatureScriptPubKey,
|
scriptPubKey: MultiSignatureScriptPubKey,
|
||||||
@ -199,21 +202,23 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
|
|||||||
signedScriptSig
|
signedScriptSig
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Generates a random [[org.bitcoins.core.protocol.script.P2WPKHWitnessV0]] */
|
/** Generates a random [[org.bitcoins.core.protocol.script.P2WPKHWitnessV0 P2WPKHWitnessV0]] */
|
||||||
def p2wpkhWitnessV0: Gen[P2WPKHWitnessV0] =
|
def p2wpkhWitnessV0: Gen[P2WPKHWitnessV0] =
|
||||||
for {
|
for {
|
||||||
publicKey <- CryptoGenerators.publicKey
|
publicKey <- CryptoGenerators.publicKey
|
||||||
sig <- CryptoGenerators.digitalSignature
|
sig <- CryptoGenerators.digitalSignature
|
||||||
} yield P2WPKHWitnessV0(publicKey, sig)
|
} 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] =
|
def p2wshWitnessV0: Gen[P2WSHWitnessV0] =
|
||||||
for {
|
for {
|
||||||
(redeem, _) <- ScriptGenerators.scriptPubKey
|
(redeem, _) <- ScriptGenerators.scriptPubKey
|
||||||
scriptSig <- ScriptGenerators.scriptSignature
|
scriptSig <- ScriptGenerators.scriptSignature
|
||||||
} yield P2WSHWitnessV0(redeem, scriptSig)
|
} 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(
|
def createSignedWTxComponent(
|
||||||
witness: ScriptWitness,
|
witness: ScriptWitness,
|
||||||
unsignedWTxComponent: WitnessTxSigComponent): (
|
unsignedWTxComponent: WitnessTxSigComponent): (
|
||||||
@ -242,7 +247,8 @@ sealed abstract class WitnessGenerators extends BitcoinSLogger {
|
|||||||
(signedTxWitness, signedWtxSigComponent)
|
(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(
|
def createUnsignedRawWTxSigComponent(
|
||||||
witScriptPubKey: WitnessScriptPubKey,
|
witScriptPubKey: WitnessScriptPubKey,
|
||||||
amount: CurrencyUnit,
|
amount: CurrencyUnit,
|
||||||
|
@ -11,7 +11,7 @@ import org.scalacheck.Gen
|
|||||||
sealed abstract class LnInvoiceGen {
|
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
|
* that does not contain a amount
|
||||||
* @return
|
* @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
|
* with an amount encoded
|
||||||
*/
|
*/
|
||||||
def lnHrpAmt: Gen[LnHumanReadablePart] = {
|
def lnHrpAmt: Gen[LnHumanReadablePart] = {
|
||||||
@ -97,7 +97,8 @@ sealed abstract class LnInvoiceGen {
|
|||||||
.map(rs => LnTag.RoutingInfo(rs))
|
.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] =
|
def taggedFields(nodeIdOpt: Option[NodeId]): Gen[LnTaggedFields] =
|
||||||
for {
|
for {
|
||||||
|
@ -176,7 +176,8 @@ trait EclairTestUtil extends BitcoinSLogger {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Doesn't return until the given channelId
|
* 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 client
|
||||||
* @param chanId
|
* @param chanId
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user