diff --git a/torba/torba/client/baseaccount.py b/torba/torba/client/baseaccount.py index 8b9ff838c..4c7644fe6 100644 --- a/torba/torba/client/baseaccount.py +++ b/torba/torba/client/baseaccount.py @@ -85,7 +85,7 @@ class AddressManager: class HierarchicalDeterministic(AddressManager): """ Implements simple version of Bitcoin Hierarchical Deterministic key management. """ - name = "deterministic-chain" + name: str = "deterministic-chain" __slots__ = 'gap', 'maximum_uses_per_address' @@ -164,7 +164,7 @@ class HierarchicalDeterministic(AddressManager): class SingleKey(AddressManager): """ Single Key address manager always returns the same address for all operations. """ - name = "single-address" + name: str = "single-address" __slots__ = () diff --git a/torba/torba/client/basedatabase.py b/torba/torba/client/basedatabase.py index bb43150eb..d0dd07503 100644 --- a/torba/torba/client/basedatabase.py +++ b/torba/torba/client/basedatabase.py @@ -102,20 +102,20 @@ def constraints_to_sql(constraints, joiner=' AND ', prepend_key=''): if not key: sql.append(constraint) continue - elif key.startswith('$'): + if key.startswith('$'): values[key] = constraint continue - elif key.endswith('__not'): + if key.endswith('__not'): col, op = col[:-len('__not')], '!=' elif key.endswith('__is_null'): col = col[:-len('__is_null')] sql.append(f'{col} IS NULL') continue - elif key.endswith('__is_not_null'): + if key.endswith('__is_not_null'): col = col[:-len('__is_not_null')] sql.append(f'{col} IS NOT NULL') continue - elif key.endswith('__lt'): + if key.endswith('__lt'): col, op = col[:-len('__lt')], '<' elif key.endswith('__lte'): col, op = col[:-len('__lte')], '<=' @@ -149,7 +149,7 @@ def constraints_to_sql(constraints, joiner=' AND ', prepend_key=''): sql.append(f'({where})') values.update(subvalues) continue - elif key.endswith('__and'): + if key.endswith('__and'): where, subvalues = constraints_to_sql(constraint, ' AND ', key+tag+'_') sql.append(f'({where})') values.update(subvalues) @@ -554,7 +554,7 @@ class BaseDatabase(SQLiteMixin): row[1], height=row[2], position=row[3], is_verified=row[4] ) txo = txs[row[0]].outputs[row[5]] - row_accounts = {k: v for k, v in (a.split('|') for a in row[8].split(','))} + row_accounts = dict(a.split('|') for a in row[8].split(',')) account_match = set(row_accounts) & my_accounts if account_match: txo.is_my_account = True diff --git a/torba/torba/client/basetransaction.py b/torba/torba/client/basetransaction.py index d6c7eb76b..724ee3f2a 100644 --- a/torba/torba/client/basetransaction.py +++ b/torba/torba/client/basetransaction.py @@ -507,18 +507,17 @@ class BaseTransaction: if tx._outputs: break - else: - # this condition and the outer range(5) loop cover an edge case - # whereby a single input is just enough to cover the fee and - # has some change left over, but the change left over is less - # than the cost_of_change: thus the input is completely - # consumed and no output is added, which is an invalid tx. - # to be able to spend this input we must increase the cost - # of the TX and run through the balance algorithm a second time - # adding an extra input and change output, making tx valid. - # we do this 5 times in case the other UTXOs added are also - # less than the fee, after 5 attempts we give up and go home - cost += cost_of_change + 1 + # this condition and the outer range(5) loop cover an edge case + # whereby a single input is just enough to cover the fee and + # has some change left over, but the change left over is less + # than the cost_of_change: thus the input is completely + # consumed and no output is added, which is an invalid tx. + # to be able to spend this input we must increase the cost + # of the TX and run through the balance algorithm a second time + # adding an extra input and change output, making tx valid. + # we do this 5 times in case the other UTXOs added are also + # less than the fee, after 5 attempts we give up and go home + cost += cost_of_change + 1 if sign: await tx.sign(funding_accounts) diff --git a/torba/torba/coin/bitcoinsegwit.py b/torba/torba/coin/bitcoinsegwit.py index 22b451147..b9856cf58 100644 --- a/torba/torba/coin/bitcoinsegwit.py +++ b/torba/torba/coin/bitcoinsegwit.py @@ -14,11 +14,11 @@ from torba.client.baseheader import BaseHeaders, ArithUint256 class MainHeaders(BaseHeaders): - header_size = 80 - chunk_size = 2016 - max_target = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff + header_size: int = 80 + chunk_size: int = 2016 + max_target: int = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff genesis_hash: Optional[bytes] = b'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' - target_timespan = 14 * 24 * 60 * 60 + target_timespan: int = 14 * 24 * 60 * 60 @staticmethod def serialize(header: dict) -> bytes: