Encode a PUSHDATA op, returning bytes
(d)
| 56 | |
| 57 | @staticmethod |
| 58 | def encode_op_pushdata(d): |
| 59 | """Encode a PUSHDATA op, returning bytes""" |
| 60 | if len(d) < 0x4c: |
| 61 | return b'' + bytes([len(d)]) + d # OP_PUSHDATA |
| 62 | elif len(d) <= 0xff: |
| 63 | return b'\x4c' + bytes([len(d)]) + d # OP_PUSHDATA1 |
| 64 | elif len(d) <= 0xffff: |
| 65 | return b'\x4d' + len(d).to_bytes(2, "little") + d # OP_PUSHDATA2 |
| 66 | elif len(d) <= 0xffffffff: |
| 67 | return b'\x4e' + len(d).to_bytes(4, "little") + d # OP_PUSHDATA4 |
| 68 | else: |
| 69 | raise ValueError("Data too long to encode in a PUSHDATA op") |
| 70 | |
| 71 | @staticmethod |
| 72 | def encode_op_n(n): |
no test coverage detected