(s)
| 21 | from bitcoin.core.scripteval import * |
| 22 | |
| 23 | def parse_script(s): |
| 24 | def ishex(s): |
| 25 | return set(s).issubset(set('0123456789abcdefABCDEF')) |
| 26 | |
| 27 | r = [] |
| 28 | |
| 29 | # Create an opcodes_by_name table with both OP_ prefixed names and |
| 30 | # shortened ones with the OP_ dropped. |
| 31 | opcodes_by_name = {} |
| 32 | for name, code in OPCODES_BY_NAME.items(): |
| 33 | opcodes_by_name[name] = code |
| 34 | opcodes_by_name[name[3:]] = code |
| 35 | |
| 36 | for word in s.split(): |
| 37 | if word.isdigit() or (word[0] == '-' and word[1:].isdigit()): |
| 38 | r.append(CScript([int(word)])) |
| 39 | elif word.startswith('0x') and ishex(word[2:]): |
| 40 | # Raw ex data, inserted NOT pushed onto stack: |
| 41 | r.append(unhexlify(word[2:].encode('utf8'))) |
| 42 | elif len(word) >= 2 and word[0] == "'" and word[-1] == "'": |
| 43 | r.append(CScript([bytes(word[1:-1].encode('utf8'))])) |
| 44 | elif word in opcodes_by_name: |
| 45 | r.append(CScript([opcodes_by_name[word]])) |
| 46 | else: |
| 47 | raise ValueError("Error parsing script: %r" % s) |
| 48 | |
| 49 | return CScript(b''.join(r)) |
| 50 | |
| 51 | |
| 52 | def load_test_vectors(name): |
no test coverage detected