mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
Fixing review comments
This commit is contained in:
parent
9012c9acc7
commit
6ebf3fab71
@ -190,6 +190,11 @@ object P2SHScriptSignature extends ScriptFactory[P2SHScriptSignature] {
|
||||
|
||||
|
||||
def fromAsm(asm: Seq[ScriptToken]): P2SHScriptSignature = {
|
||||
//everything can be a P2SHScriptSignature, thus passing the trivially true function
|
||||
//the most important thing to note is we cannot have a P2SHScriptSignature unless
|
||||
//we have a P2SHScriptPubKey
|
||||
//previously P2SHScriptSignature's redeem script had to be standard scriptPubKey's, this
|
||||
//was removed in 0.11 or 0.12 of Bitcoin Core
|
||||
buildScript(asm, P2SHScriptSignatureImpl(_),{ _ => true}, "Given asm tokens are not a p2sh scriptSig, got: " + asm)
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
|
||||
|
||||
/** Helper function to actually run a p2sh script */
|
||||
def run(p: ExecutedScriptProgram, stack : Seq[ScriptToken], s: ScriptPubKey): ExecutedScriptProgram = {
|
||||
logger.info("Running p2sh script: " + stack)
|
||||
logger.debug("Running p2sh script: " + stack)
|
||||
val p2shRedeemScriptProgram = ScriptProgram(p.txSignatureComponent,stack.tail,
|
||||
s.asm)
|
||||
if (ScriptFlagUtil.requirePushOnly(p2shRedeemScriptProgram.flags) && !BitcoinScriptUtil.isPushOnly(s.asm)) {
|
||||
@ -202,7 +202,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
|
||||
|
||||
/** Helper function to run the post segwit execution checks */
|
||||
def postSegWitProgramChecks(evaluated: ExecutedScriptProgram): ExecutedScriptProgram = {
|
||||
logger.info("Stack after evaluating witness: " + evaluated.stack)
|
||||
logger.debug("Stack after evaluating witness: " + evaluated.stack)
|
||||
if (evaluated.error.isDefined) evaluated
|
||||
else if (evaluated.stack.size != 1 || evaluated.stackTopIsFalse) ScriptProgram(evaluated,ScriptErrorEvalFalse)
|
||||
else evaluated
|
||||
@ -497,8 +497,8 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
|
||||
* Return true if witness was NOT used, return false if witness was used. */
|
||||
private def hasUnexpectedWitness(program: ScriptProgram): Boolean = {
|
||||
val txSigComponent = program.txSignatureComponent
|
||||
logger.info("TxSigComponent: " + txSigComponent)
|
||||
val unexpectedWitenss = txSigComponent match {
|
||||
logger.debug("TxSigComponent: " + txSigComponent)
|
||||
val unexpectedWitness = txSigComponent match {
|
||||
case b : BaseTransactionSignatureComponent =>
|
||||
b.transaction match {
|
||||
case wtx : WitnessTransaction =>
|
||||
@ -522,8 +522,8 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
|
||||
!witnessedUsed
|
||||
}
|
||||
|
||||
if (unexpectedWitenss) logger.error("Found unexpected witness that was not used by the ScriptProgram: " + program)
|
||||
unexpectedWitenss
|
||||
if (unexpectedWitness) logger.error("Found unexpected witness that was not used by the ScriptProgram: " + program)
|
||||
unexpectedWitness
|
||||
}
|
||||
}
|
||||
object ScriptInterpreter extends ScriptInterpreter
|
@ -33,8 +33,6 @@ trait RawTransactionWitnessParser {
|
||||
val hex = witness.witnesses.map(_.hex).mkString
|
||||
hex
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
object RawTransactionWitnessParser extends RawTransactionWitnessParser
|
@ -276,9 +276,9 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
|
||||
def calculateScriptForChecking(txSignatureComponent: TransactionSignatureComponent,
|
||||
signature: ECDigitalSignature, script: Seq[ScriptToken]): Seq[ScriptToken] = {
|
||||
val scriptForChecking = calculateScriptForSigning(txSignatureComponent, script)
|
||||
logger.info("sig for removal: " + signature)
|
||||
logger.info("script: " + script)
|
||||
logger.info("scriptWithSigRemoved: " + scriptForChecking)
|
||||
logger.debug("sig for removal: " + signature)
|
||||
logger.debug("script: " + script)
|
||||
logger.debug("scriptWithSigRemoved: " + scriptForChecking)
|
||||
txSignatureComponent.sigVersion match {
|
||||
case SigVersionBase => removeSignatureFromScript(signature,scriptForChecking)
|
||||
case SigVersionWitnessV0 =>
|
||||
@ -351,7 +351,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
|
||||
}
|
||||
|
||||
/** Given a tx, scriptPubKey and the input index we are checking the tx, it derives the appropriate [[SignatureVersion]] to use */
|
||||
def parseSigVersion(tx: Transaction, scriptPubKey: ScriptPubKey, inputIndex: UInt32): SignatureVersion = scriptPubKey match {
|
||||
@tailrec
|
||||
final def parseSigVersion(tx: Transaction, scriptPubKey: ScriptPubKey, inputIndex: UInt32): SignatureVersion = scriptPubKey match {
|
||||
case _ : WitnessScriptPubKeyV0 | _: UnassignedWitnessScriptPubKey =>
|
||||
SigVersionWitnessV0
|
||||
case _: P2SHScriptPubKey =>
|
||||
@ -375,7 +376,9 @@ trait BitcoinScriptUtil extends BitcoinSLogger {
|
||||
def castToBool(token: ScriptToken): Boolean = {
|
||||
token.bytes.zipWithIndex.exists {
|
||||
case (b,index) =>
|
||||
b.toByte != 0 && !(b.toByte == 0x80.toByte && index == token.bytes.size - 1)
|
||||
val byteNotZero = b.toByte != 0
|
||||
val lastByteNotNegativeZero = !(index == token.bytes.size - 1 && b.toByte == 0x80.toByte)
|
||||
byteNotZero && lastByteNotNegativeZero
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,5 +29,4 @@ class ScriptProgramTest extends FlatSpec with MustMatchers {
|
||||
val program3 = ScriptProgram(program, List(ScriptNumber.negativeZero), ScriptProgram.Stack)
|
||||
program3.stackTopIsTrue must be (false)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user