Encode a PUSHDATA op, returning bytes
(d)
| 42 | |
| 43 | @staticmethod |
| 44 | def encode_op_pushdata(d): |
| 45 | """Encode a PUSHDATA op, returning bytes""" |
| 46 | if len(d) < 0x4c: |
| 47 | return b'' + bchr(len(d)) + d # OP_PUSHDATA |
| 48 | elif len(d) <= 0xff: |
| 49 | return b'\x4c' + bchr(len(d)) + d # OP_PUSHDATA1 |
| 50 | elif len(d) <= 0xffff: |
| 51 | return b'\x4d' + struct.pack(b'<H', len(d)) + d # OP_PUSHDATA2 |
| 52 | elif len(d) <= 0xffffffff: |
| 53 | return b'\x4e' + struct.pack(b'<I', len(d)) + d # OP_PUSHDATA4 |
| 54 | else: |
| 55 | raise ValueError("Data too long to encode in a PUSHDATA op") |
| 56 | |
| 57 | @staticmethod |
| 58 | def encode_op_n(n): |