| 632 | yield CScriptOp(opcode) |
| 633 | |
| 634 | def __repr__(self): |
| 635 | # For Python3 compatibility add b before strings so testcases don't |
| 636 | # need to change |
| 637 | def _repr(o): |
| 638 | if isinstance(o, bytes): |
| 639 | return "x('%s')" % bitcoin.core.b2x(o) |
| 640 | else: |
| 641 | return repr(o) |
| 642 | |
| 643 | ops = [] |
| 644 | i = iter(self) |
| 645 | while True: |
| 646 | op = None |
| 647 | try: |
| 648 | op = _repr(next(i)) |
| 649 | except CScriptTruncatedPushDataError as err: |
| 650 | op = '%s...<ERROR: %s>' % (_repr(err.data), err) |
| 651 | break |
| 652 | except CScriptInvalidError as err: |
| 653 | op = '<ERROR: %s>' % err |
| 654 | break |
| 655 | except StopIteration: |
| 656 | break |
| 657 | finally: |
| 658 | if op is not None: |
| 659 | ops.append(op) |
| 660 | |
| 661 | return "CScript([%s])" % ', '.join(ops) |
| 662 | |
| 663 | def is_p2sh(self): |
| 664 | """Test if the script is a p2sh scriptPubKey |