Mercurial > public > bitcaviar-plus
diff src/helpers.py @ 2:5b16e6df6a59
get txid hashing transaction data
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sun, 17 Oct 2021 11:14:46 +0200 |
parents | 2327b9eda10f |
children |
line wrap: on
line diff
--- a/src/helpers.py Sat Oct 16 18:59:23 2021 +0200 +++ b/src/helpers.py Sun Oct 17 11:14:46 2021 +0200 @@ -13,6 +13,26 @@ if bytes_order == 'backward': b = b[::-1] - b = b.hex().upper() + return b + + +def get_variable_int(file): + """ + Get variable int from transaction data + More info: https://learnmeabitcoin.com/technical/varint + :param file: <class '_io.BufferedReader'>, required + :return: int + """ - return b + first_byte = read_bytes(file, 1) + + if first_byte == b'\xfd': + variable_int_bytes = read_bytes(file, 2) + elif first_byte == b'\xfe': + variable_int_bytes = read_bytes(file, 4) + elif first_byte == b'\xff': + variable_int_bytes = read_bytes(file, 8) + else: + variable_int_bytes = first_byte + + return int.from_bytes(variable_int_bytes, 'little')