mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-06 02:38:11 +01:00
Add Decred transaction to and from bytes.
This commit is contained in:
@@ -5,13 +5,18 @@
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
||||
def decode_varint(b: bytes) -> int:
|
||||
i = 0
|
||||
shift = 0
|
||||
for c in b:
|
||||
i += (c & 0x7F) << shift
|
||||
shift += 7
|
||||
return i
|
||||
def decode_varint(b: bytes, offset: int = 0) -> (int, int):
|
||||
i: int = 0
|
||||
num_bytes: int = 0
|
||||
while True:
|
||||
c = b[offset + num_bytes]
|
||||
i += (c & 0x7F) << (num_bytes * 7)
|
||||
num_bytes += 1
|
||||
if not c & 0x80:
|
||||
break
|
||||
if num_bytes > 8:
|
||||
raise ValueError('Too many bytes')
|
||||
return i, num_bytes
|
||||
|
||||
|
||||
def encode_varint(i: int) -> bytes:
|
||||
|
||||
Reference in New Issue
Block a user