New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ScriptSignature from P2WSH Witness #1605
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK on CI passing
@@ -106,6 +110,21 @@ sealed abstract class P2WSHWitnessV0 extends ScriptWitnessV0 { | |||
relevantStack.map(ECDigitalSignature.fromBytes) | |||
} | |||
|
|||
// Note that this is not guaranteed to work for non-standard script signatures | |||
lazy val scriptSignature: ScriptSignature = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be an Option[ScriptSignature]
?
This throws on the case where the stack
is empty (.tail
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon further evaluation, I believe that this actually does work in all cases, and the thing that doesn't work is the apply method below which takes in a ScriptSignature (which will fail to act as expected if there's anything other than push ops). So no Option
, but you're right that we should require
that there be a redeem script (i.e. stack.nonEmpty
) at the top of this trait
lazy val scriptSignature: ScriptSignature = { | ||
val asm = stack.toVector.tail.reverse.flatMap { bytes => | ||
if (bytes.isEmpty) { | ||
Vector(OP_0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why OP_0
if there is nothing on the stack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not nothing on the stack, an empty element on the stack (a Script zero)
val asm = stack.toVector.tail.reverse.flatMap { bytes => | ||
if (bytes.isEmpty) { | ||
Vector(OP_0) | ||
} else if (bytes.length == 1 && bytes.head <= 16 && bytes.head >= -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just
val numOpt = bytes.headOption.flatMap(byte => ScriptNumberOperation.fromNumber(byte))
...
else if (numOpt.isDefined)) {
Vector(numOpt.get)
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like how it is because it clearly enumerates all cases
Added method to pull script signature out of P2WSH witness