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

Method encode_op_pushdata

qa/rpc-tests/test_framework/script.py:44–55  ·  view source on GitHub ↗

Encode a PUSHDATA op, returning bytes

(d)

Source from the content-addressed store, hash-verified

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):

Callers 1

__coerce_instanceMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected