Bitcoin Asked by FraMog on February 11, 2021
I’m looking for the clearest way to check whether the top element of the stack is numeric or not.
Thank you in advance
The best way that I know is quite involved because bitcoin-core standardness rules around Minimal representation of script ints. If you really need to do this, I can add detail in an updated answer.
Execution vs Satisfaction:
But in almost all cases, you should never really need to check such a thing. Recall that Bitcoin Script satisfaction requires Script executes successfully. At the end of the day, we are not interested in what is execution result, we are interested in whether the witness is valid or not. And the user redeeming the coins knows whether the pushed number is ScriptInt or not, they are let the interpreter know via additional boolean input.
Previous Code: where stack top is element `e`
OP_ISTOPNUMERIC # hypothetical that pushes 1 or 0 onto the stack top
OP_IF
<process_num>
OP_ELSE
<something_else>
OP_ENDIF
can be read written equivalently with two user input elements [e, e_is_num]
where e_is_num
is at stack top denoting whether e
is numeric or not.
New code: with stack as `[e, e_is_num]`
OP_IF
<process_num>
OP_ELSE
<something_else>
OP_ENDIF
Answered by sanket1729 on February 11, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP