mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-06 02:38:11 +01:00
Reformat with black.
This commit is contained in:
@@ -7,25 +7,25 @@
|
||||
|
||||
def decode_compactsize(b: bytes, offset: int = 0) -> (int, int):
|
||||
i = b[offset]
|
||||
if i < 0xfd:
|
||||
if i < 0xFD:
|
||||
return i, 1
|
||||
offset += 1
|
||||
if i == 0xfd:
|
||||
return int.from_bytes(b[offset: offset + 2], 'little'), 3
|
||||
if i == 0xfe:
|
||||
return int.from_bytes(b[offset: offset + 4], 'little'), 5
|
||||
if i == 0xFD:
|
||||
return int.from_bytes(b[offset : offset + 2], "little"), 3
|
||||
if i == 0xFE:
|
||||
return int.from_bytes(b[offset : offset + 4], "little"), 5
|
||||
# 0xff
|
||||
return int.from_bytes(b[offset: offset + 8], 'little'), 9
|
||||
return int.from_bytes(b[offset : offset + 8], "little"), 9
|
||||
|
||||
|
||||
def encode_compactsize(i: int) -> bytes:
|
||||
if i < 0xfd:
|
||||
if i < 0xFD:
|
||||
return bytes((i,))
|
||||
if i <= 0xffff:
|
||||
return bytes((0xfd,)) + i.to_bytes(2, 'little')
|
||||
if i <= 0xffffffff:
|
||||
return bytes((0xfe,)) + i.to_bytes(4, 'little')
|
||||
return bytes((0xff,)) + i.to_bytes(8, 'little')
|
||||
if i <= 0xFFFF:
|
||||
return bytes((0xFD,)) + i.to_bytes(2, "little")
|
||||
if i <= 0xFFFFFFFF:
|
||||
return bytes((0xFE,)) + i.to_bytes(4, "little")
|
||||
return bytes((0xFF,)) + i.to_bytes(8, "little")
|
||||
|
||||
|
||||
def decode_varint(b: bytes, offset: int = 0) -> (int, int):
|
||||
@@ -38,7 +38,7 @@ def decode_varint(b: bytes, offset: int = 0) -> (int, int):
|
||||
if not c & 0x80:
|
||||
break
|
||||
if num_bytes > 8:
|
||||
raise ValueError('Too many bytes')
|
||||
raise ValueError("Too many bytes")
|
||||
return i, num_bytes
|
||||
|
||||
|
||||
@@ -46,6 +46,6 @@ def encode_varint(i: int) -> bytes:
|
||||
b = bytearray()
|
||||
while i > 0x7F:
|
||||
b += bytes(((i & 0x7F) | 0x80,))
|
||||
i = (i >> 7)
|
||||
i = i >> 7
|
||||
b += bytes((i,))
|
||||
return b
|
||||
|
||||
Reference in New Issue
Block a user