comparison 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
comparison
equal deleted inserted replaced
1:8522a23c82f0 2:5b16e6df6a59
11 11
12 b = file.read(number_of_bytes) 12 b = file.read(number_of_bytes)
13 if bytes_order == 'backward': 13 if bytes_order == 'backward':
14 b = b[::-1] 14 b = b[::-1]
15 15
16 b = b.hex().upper() 16 return b
17 17
18 return b 18
19 def get_variable_int(file):
20 """
21 Get variable int from transaction data
22 More info: https://learnmeabitcoin.com/technical/varint
23 :param file: <class '_io.BufferedReader'>, required
24 :return: int
25 """
26
27 first_byte = read_bytes(file, 1)
28
29 if first_byte == b'\xfd':
30 variable_int_bytes = read_bytes(file, 2)
31 elif first_byte == b'\xfe':
32 variable_int_bytes = read_bytes(file, 4)
33 elif first_byte == b'\xff':
34 variable_int_bytes = read_bytes(file, 8)
35 else:
36 variable_int_bytes = first_byte
37
38 return int.from_bytes(variable_int_bytes, 'little')