mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-06 02:38:11 +01:00
Load in-progress bids only when unlocked.
This commit is contained in:
@@ -66,7 +66,7 @@ def dumpje(jin):
|
||||
return json.dumps(jin, default=jsonDecimal).replace('"', '\\"')
|
||||
|
||||
|
||||
def SerialiseNum(n):
|
||||
def SerialiseNum(n: int) -> bytes:
|
||||
if n == 0:
|
||||
return bytes((0x00,))
|
||||
if n > 0 and n <= 16:
|
||||
@@ -84,7 +84,7 @@ def SerialiseNum(n):
|
||||
return bytes((len(rv),)) + rv
|
||||
|
||||
|
||||
def DeserialiseNum(b, o=0) -> int:
|
||||
def DeserialiseNum(b: bytes, o: int = 0) -> int:
|
||||
if b[o] == 0:
|
||||
return 0
|
||||
if b[o] > 0x50 and b[o] <= 0x50 + 16:
|
||||
@@ -100,13 +100,13 @@ def DeserialiseNum(b, o=0) -> int:
|
||||
return v
|
||||
|
||||
|
||||
def float_to_str(f):
|
||||
def float_to_str(f: float) -> str:
|
||||
# stackoverflow.com/questions/38847690
|
||||
d1 = decimal_ctx.create_decimal(repr(f))
|
||||
return format(d1, 'f')
|
||||
|
||||
|
||||
def make_int(v, scale=8, r=0): # r = 0, no rounding, fail, r > 0 round up, r < 0 floor
|
||||
def make_int(v, scale=8, r=0) -> int: # r = 0, no rounding, fail, r > 0 round up, r < 0 floor
|
||||
if type(v) == float:
|
||||
v = float_to_str(v)
|
||||
elif type(v) == int:
|
||||
@@ -177,7 +177,7 @@ def format_amount(i, display_scale, scale=None):
|
||||
return rv
|
||||
|
||||
|
||||
def format_timestamp(value: int, with_seconds=False) -> str:
|
||||
def format_timestamp(value: int, with_seconds: bool = False) -> str:
|
||||
str_format = '%Y-%m-%d %H:%M'
|
||||
if with_seconds:
|
||||
str_format += ':%S'
|
||||
@@ -185,7 +185,7 @@ def format_timestamp(value: int, with_seconds=False) -> str:
|
||||
return time.strftime(str_format, time.localtime(value))
|
||||
|
||||
|
||||
def b2i(b) -> int:
|
||||
def b2i(b: bytes) -> int:
|
||||
# bytes32ToInt
|
||||
return int.from_bytes(b, byteorder='big')
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2022 tecnovert
|
||||
# Copyright (c) 2022-2023 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -59,7 +59,7 @@ def b58encode(v):
|
||||
return (__b58chars[0] * nPad) + result
|
||||
|
||||
|
||||
def encodeStealthAddress(prefix_byte, scan_pubkey, spend_pubkey):
|
||||
def encodeStealthAddress(prefix_byte: int, scan_pubkey: bytes, spend_pubkey: bytes) -> str:
|
||||
data = bytes((0x00,))
|
||||
data += scan_pubkey
|
||||
data += bytes((0x01,))
|
||||
@@ -72,14 +72,14 @@ def encodeStealthAddress(prefix_byte, scan_pubkey, spend_pubkey):
|
||||
return b58encode(b)
|
||||
|
||||
|
||||
def decodeWif(encoded_key):
|
||||
def decodeWif(encoded_key: str) -> bytes:
|
||||
key = b58decode(encoded_key)[1:-4]
|
||||
if len(key) == 33:
|
||||
return key[:-1]
|
||||
return key
|
||||
|
||||
|
||||
def toWIF(prefix_byte, b, compressed=True):
|
||||
def toWIF(prefix_byte: int, b: bytes, compressed: bool = True) -> str:
|
||||
b = bytes((prefix_byte,)) + b
|
||||
if compressed:
|
||||
b += bytes((0x01,))
|
||||
@@ -87,9 +87,9 @@ def toWIF(prefix_byte, b, compressed=True):
|
||||
return b58encode(b)
|
||||
|
||||
|
||||
def getKeyID(bytes):
|
||||
data = hashlib.sha256(bytes).digest()
|
||||
return ripemd160(data)
|
||||
def getKeyID(key_data: bytes) -> str:
|
||||
sha256_hash = hashlib.sha256(key_data).digest()
|
||||
return ripemd160(sha256_hash)
|
||||
|
||||
|
||||
def bech32Decode(hrp, addr):
|
||||
@@ -109,7 +109,7 @@ def bech32Encode(hrp, data):
|
||||
return ret
|
||||
|
||||
|
||||
def decodeAddress(address_str):
|
||||
def decodeAddress(address_str: str):
|
||||
b58_addr = b58decode(address_str)
|
||||
if b58_addr is not None:
|
||||
address = b58_addr[:-4]
|
||||
@@ -119,10 +119,10 @@ def decodeAddress(address_str):
|
||||
return None
|
||||
|
||||
|
||||
def encodeAddress(address):
|
||||
def encodeAddress(address: bytes) -> str:
|
||||
checksum = hashlib.sha256(hashlib.sha256(address).digest()).digest()
|
||||
return b58encode(address + checksum[0:4])
|
||||
|
||||
|
||||
def pubkeyToAddress(prefix, pubkey):
|
||||
def pubkeyToAddress(prefix: int, pubkey: bytes) -> str:
|
||||
return encodeAddress(bytes((prefix,)) + getKeyID(pubkey))
|
||||
|
||||
Reference in New Issue
Block a user