MCPcopy Index your code
hub / github.com/jimmysong/programmingbitcoin / encode_varint

Function encode_varint

code-ch08/helper.py:91–102  ·  view source on GitHub ↗

encodes an integer as a varint

(i)

Source from the content-addressed store, hash-verified

89
90
91def encode_varint(i):
92 '''encodes an integer as a varint'''
93 if i < 0xfd:
94 return bytes([i])
95 elif i < 0x10000:
96 return b'\xfd' + int_to_little_endian(i, 2)
97 elif i < 0x100000000:
98 return b'\xfe' + int_to_little_endian(i, 4)
99 elif i < 0x10000000000000000:
100 return b'\xff' + int_to_little_endian(i, 8)
101 else:
102 raise ValueError('integer too large: {}'.format(i))
103
104
105def h160_to_p2pkh_address(h160, testnet=False):

Callers 6

serializeMethod · 0.90
sig_hashMethod · 0.90
serializeMethod · 0.90
evaluateMethod · 0.90
sig_hashFunction · 0.90
verify_inputFunction · 0.90

Calls 1

int_to_little_endianFunction · 0.70

Tested by

no test coverage detected