MCPcopy Create free account
hub / github.com/ElementsProject/lightning / _add_number

Function _add_number

tests/test_opening.py:106–116  ·  view source on GitHub ↗

Push an integer the way CLN's add_number() (bitcoin/script.c) does.

(num)

Source from the content-addressed store, hash-verified

104
105
106def _add_number(num):
107 """Push an integer the way CLN's add_number() (bitcoin/script.c) does."""
108 if num == 0:
109 return bytes([0x00]) # OP_0
110 if num <= 16:
111 return bytes([0x50 + num]) # OP_1 .. OP_16
112 # Minimal little-endian, signed (to_self_delay never needs the sign byte).
113 length = (num.bit_length() + 7) // 8
114 if num >> (length * 8 - 1) & 1:
115 length += 1 # high bit set: pad to stay positive
116 return bytes([length]) + num.to_bytes(length, 'little')
117
118
119def _push_bytes(data):

Callers 1

wscript_to_localFunction · 0.85

Calls 1

to_bytesMethod · 0.45

Tested by

no test coverage detected