encodes an integer as a varint
(i)
| 95 | |
| 96 | |
| 97 | def encode_varint(i): |
| 98 | '''encodes an integer as a varint''' |
| 99 | if i < 0xfd: |
| 100 | return bytes([i]) |
| 101 | elif i < 0x10000: |
| 102 | return b'\xfd' + int_to_little_endian(i, 2) |
| 103 | elif i < 0x100000000: |
| 104 | return b'\xfe' + int_to_little_endian(i, 4) |
| 105 | elif i < 0x10000000000000000: |
| 106 | return b'\xff' + int_to_little_endian(i, 8) |
| 107 | else: |
| 108 | raise ValueError('integer too large: {}'.format(i)) |
| 109 | |
| 110 | |
| 111 | def h160_to_p2pkh_address(h160, testnet=False): |
no test coverage detected