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