mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
change logback level to warn, implement | for UInt32 and add spec, replace underlying.toInt with override toInt function
This commit is contained in:
parent
32b2da3f28
commit
350a41b5be
@ -78,6 +78,8 @@ sealed trait UInt32 extends UnsignedNumber with NumberOperations[UInt32] {
|
||||
|
||||
override def <= (num : UInt32): Boolean = underlying <= num.underlying
|
||||
|
||||
def | (num : UInt32) : UInt32 = UInt32(underlying | num.underlying)
|
||||
|
||||
override def hex = BitcoinSUtil.encodeHex(underlying).slice(8,16)
|
||||
|
||||
override def toInt = {
|
||||
|
@ -53,7 +53,7 @@ object TransactionOutPoint extends Factory[TransactionOutPoint] {
|
||||
*/
|
||||
private def factory(output : TransactionOutput, parentTransaction : Transaction) : TransactionOutPoint = {
|
||||
val indexOfOutput = UInt32(parentTransaction.outputs.indexOf(output))
|
||||
if (indexOfOutput.underlying.toInt == (-1)) throw new RuntimeException("This output is not contained in the parent transaction")
|
||||
if (indexOfOutput.toInt == (-1)) throw new RuntimeException("This output is not contained in the parent transaction")
|
||||
else factory(parentTransaction.txId,indexOfOutput)
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ trait LockTimeInterpreter extends BitcoinSLogger {
|
||||
final def opCheckLockTimeVerify(program : ScriptProgram) : ScriptProgram = {
|
||||
require(program.script.headOption.isDefined && program.script.head == OP_CHECKLOCKTIMEVERIFY,
|
||||
"Script top must be OP_CHECKLOCKTIMEVERIFY")
|
||||
val input = program.txSignatureComponent.transaction.inputs(program.txSignatureComponent.inputIndex.underlying.toInt)
|
||||
val input = program.txSignatureComponent.transaction.inputs(program.txSignatureComponent.inputIndex.toInt)
|
||||
val transaction = program.txSignatureComponent.transaction
|
||||
if (program.stack.size == 0) {
|
||||
logger.error("Transaction validation failing in OP_CHECKLOCKTIMEVERIFY because we have no stack items")
|
||||
@ -141,7 +141,7 @@ trait LockTimeInterpreter extends BitcoinSLogger {
|
||||
return false
|
||||
}
|
||||
|
||||
val nLockTimeMask : UInt32 = UInt32(TransactionConstants.sequenceLockTimeTypeFlag.underlying | TransactionConstants.sequenceLockTimeMask.underlying)
|
||||
val nLockTimeMask : UInt32 = TransactionConstants.sequenceLockTimeTypeFlag | TransactionConstants.sequenceLockTimeMask
|
||||
val txToSequenceMasked : Int64 = Int64(txToSequence.underlying & nLockTimeMask.underlying)
|
||||
val nSequenceMasked : ScriptNumber = nSequence & Int64(nLockTimeMask.underlying)
|
||||
|
||||
|
@ -222,7 +222,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with
|
||||
val rawTx = TestUtil.simpleRawTransaction
|
||||
val rawParentTx = TestUtil.parentSimpleRawTransaction
|
||||
val bitcoinjTx = new org.bitcoinj.core.Transaction(params,Utils.HEX.decode(rawTx))
|
||||
val input = bitcoinjTx.getInput(inputIndex.underlying.toInt)
|
||||
val input = bitcoinjTx.getInput(inputIndex.toInt)
|
||||
val scriptSig = input.getScriptSig
|
||||
val parentTx = new org.bitcoinj.core.Transaction(params,Utils.HEX.decode(rawParentTx))
|
||||
val parentOutput = parentTx.getOutput(input.getOutpoint.getIndex)
|
||||
@ -232,7 +232,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with
|
||||
val pubKey : Array[Byte] = scriptSig.getPubKey
|
||||
val signature : Array[Byte] = scriptSig.getChunks().get(0).data
|
||||
val bitcoinjSerializeForSig : Seq[Byte] =
|
||||
BitcoinJSignatureSerialization.serializeForSignature(bitcoinjTx,inputIndex.underlying.toInt,
|
||||
BitcoinJSignatureSerialization.serializeForSignature(bitcoinjTx,inputIndex.toInt,
|
||||
parentOutput.getScriptBytes, SIGHASH_ALL().byte)
|
||||
|
||||
|
||||
@ -253,13 +253,13 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with
|
||||
val rawTx = TestUtil.simpleRawTransaction
|
||||
val rawParentTx = TestUtil.parentSimpleRawTransaction
|
||||
val bitcoinjTx = new org.bitcoinj.core.Transaction(params,Utils.HEX.decode(rawTx))
|
||||
val input = bitcoinjTx.getInput(inputIndex.underlying.toInt)
|
||||
val input = bitcoinjTx.getInput(inputIndex.toInt)
|
||||
val scriptSig = input.getScriptSig
|
||||
val parentTx = new org.bitcoinj.core.Transaction(params,Utils.HEX.decode(rawParentTx))
|
||||
val parentOutput = parentTx.getOutput(input.getOutpoint.getIndex)
|
||||
|
||||
val bitcoinjSerializeForSig : Seq[Byte] =
|
||||
BitcoinJSignatureSerialization.serializeForSignature(bitcoinjTx,inputIndex.underlying.toInt,
|
||||
BitcoinJSignatureSerialization.serializeForSignature(bitcoinjTx,inputIndex.toInt,
|
||||
parentOutput.getScriptBytes, SIGHASH_ALL().byte)
|
||||
|
||||
val hashType = spendingInput.scriptSignature.hashType(spendingInput.scriptSignature.signatures.head)
|
||||
@ -283,7 +283,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with
|
||||
val bitcoinjTx = BitcoinjConversions.transaction(spendingTx)
|
||||
val hashType = spendingInput.scriptSignature.hashType(spendingInput.scriptSignature.signatures.head)
|
||||
val bitcoinjHashForSig : Seq[Byte] = BitcoinJSignatureSerialization.serializeForSignature(
|
||||
bitcoinjTx, inputIndex.underlying.toInt, creditingOutput.scriptPubKey.bytes.toArray, hashType.byte
|
||||
bitcoinjTx, inputIndex.toInt, creditingOutput.scriptPubKey.bytes.toArray, hashType.byte
|
||||
)
|
||||
val hashedTxForSig : String = BitcoinSUtil.encodeHex(
|
||||
TransactionSignatureSerializer.serializeForSignature(spendingTx,inputIndex,creditingOutput.scriptPubKey.asm,hashType
|
||||
@ -304,7 +304,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with
|
||||
val bitcoinjTx = BitcoinjConversions.transaction(spendingTx)
|
||||
val hashType = spendingInput.scriptSignature.hashType(spendingInput.scriptSignature.signatures.head)
|
||||
val bitcoinjHashForSig : Seq[Byte] = BitcoinJSignatureSerialization.hashForSignature(
|
||||
bitcoinjTx, inputIndex.underlying.toInt, creditingOutput.scriptPubKey.bytes.toArray, hashType.byte
|
||||
bitcoinjTx, inputIndex.toInt, creditingOutput.scriptPubKey.bytes.toArray, hashType.byte
|
||||
)
|
||||
val hashedTxForSig =
|
||||
TransactionSignatureSerializer.hashForSignature(spendingTx,inputIndex,creditingOutput.scriptPubKey.asm, hashType)
|
||||
@ -329,7 +329,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with
|
||||
|
||||
val bitcoinjTx = BitcoinjConversions.transaction(spendingTx)
|
||||
val bitcoinjHashForSig : Seq[Byte] = BitcoinJSignatureSerialization.hashForSignature(
|
||||
bitcoinjTx, inputIndex.underlying.toInt, scriptPubKey.bytes.toArray, SIGHASH_ALL(0x01).byte
|
||||
bitcoinjTx, inputIndex.toInt, scriptPubKey.bytes.toArray, SIGHASH_ALL(0x01).byte
|
||||
)
|
||||
|
||||
val hashedTxForSig =
|
||||
@ -344,7 +344,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with
|
||||
val rawTx = "01000000020001000000000000000000000000000000000000000000000000000000000000000000004948304502203a0f5f0e1f2bdbcd04db3061d18f3af70e07f4f467cbc1b8116f267025f5360b022100c792b6e215afc5afc721a351ec413e714305cb749aae3d7fee76621313418df101010000000002000000000000000000000000000000000000000000000000000000000000000000004847304402205f7530653eea9b38699e476320ab135b74771e1c48b81a5d041e2ca84b9be7a802200ac8d1f40fb026674fe5a5edd3dea715c27baa9baca51ed45ea750ac9dc0a55e81ffffffff010100000000000000015100000000"
|
||||
val inputIndex = UInt32.zero
|
||||
val spendingTx = Transaction(rawTx)
|
||||
require(spendingTx.inputs(inputIndex.underlying.toInt).scriptSignature.hex == "48304502203a0f5f0e1f2bdbcd04db3061d18f3af70e07f4f467cbc1b8116f267025f5360b022100c792b6e215afc5afc721a351ec413e714305cb749aae3d7fee76621313418df101",
|
||||
require(spendingTx.inputs(inputIndex.toInt).scriptSignature.hex == "48304502203a0f5f0e1f2bdbcd04db3061d18f3af70e07f4f467cbc1b8116f267025f5360b022100c792b6e215afc5afc721a351ec413e714305cb749aae3d7fee76621313418df101",
|
||||
"Script sig not right")
|
||||
val scriptPubKeyFromString = ScriptParser.fromString("0x21 0x035e7f0d4d0841bcd56c39337ed086b1a633ee770c1ffdd94ac552a95ac2ce0efc CHECKSIG")
|
||||
val scriptPubKey = ScriptPubKey.fromAsm(scriptPubKeyFromString)
|
||||
@ -369,7 +369,7 @@ class TransactionSignatureSerializerTest extends FlatSpec with MustMatchers with
|
||||
|
||||
val bitcoinjTx = BitcoinjConversions.transaction(spendingTx)
|
||||
val bitcoinjHashForSig : Seq[Byte] = BitcoinJSignatureSerialization.hashForSignature(
|
||||
bitcoinjTx, inputIndex.underlying.toInt, scriptPubKey.bytes.toArray, SIGHASH_ALL_ANYONECANPAY.byte
|
||||
bitcoinjTx, inputIndex.toInt, scriptPubKey.bytes.toArray, SIGHASH_ALL_ANYONECANPAY.byte
|
||||
)
|
||||
val hashedTxForSig =
|
||||
TransactionSignatureSerializer.hashForSignature(spendingTx,inputIndex,scriptPubKey.asm,SIGHASH_ALL_ANYONECANPAY)
|
||||
|
@ -87,6 +87,11 @@ class UInt32Spec extends Properties("UInt32") with BitcoinSLogger {
|
||||
}
|
||||
}
|
||||
|
||||
property("|") =
|
||||
Prop.forAll(NumberGenerator.uInt32s, NumberGenerator.uInt32s) { (num1 : UInt32, num2 : UInt32) =>
|
||||
UInt32(num1.underlying | num2.underlying) == (num1 | num2)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user