MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / encode_op_pushdata

Method encode_op_pushdata

test/functional/test_framework/script.py:32–43  ·  view source on GitHub ↗

Encode a PUSHDATA op, returning bytes

(d)

Source from the content-addressed store, hash-verified

30
31 @staticmethod
32 def encode_op_pushdata(d):
33 """Encode a PUSHDATA op, returning bytes"""
34 if len(d) < 0x4c:
35 return b'' + bytes([len(d)]) + d # OP_PUSHDATA
36 elif len(d) <= 0xff:
37 return b'\x4c' + bytes([len(d)]) + d # OP_PUSHDATA1
38 elif len(d) <= 0xffff:
39 return b'\x4d' + struct.pack(b'<H', len(d)) + d # OP_PUSHDATA2
40 elif len(d) <= 0xffffffff:
41 return b'\x4e' + struct.pack(b'<I', len(d)) + d # OP_PUSHDATA4
42 else:
43 raise ValueError("Data too long to encode in a PUSHDATA op")
44
45 @staticmethod
46 def encode_op_n(n):

Callers 1

__coerce_instanceMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected