From df251def26671e469d61baf4133a5d76906987a5 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Thu, 16 Aug 2018 00:56:46 -0400 Subject: [PATCH] pylint and mypy fixes --- setup.cfg | 3 ++- torba/baseheader.py | 7 ++++--- torba/baseledger.py | 2 +- torba/coin/bitcoincash.py | 7 ++----- torba/coin/bitcoinsegwit.py | 3 ++- torba/util.py | 10 +++++----- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/setup.cfg b/setup.cfg index 66c7c22cf..1cb422611 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,4 +27,5 @@ disable= too-many-arguments, too-many-public-methods, too-many-instance-attributes, - protected-access + protected-access, + unused-argument diff --git a/torba/baseheader.py b/torba/baseheader.py index 04ca677df..442407c84 100644 --- a/torba/baseheader.py +++ b/torba/baseheader.py @@ -27,7 +27,7 @@ class BaseHeaders: chunk_size: int max_target: int - genesis_hash: bytes + genesis_hash: Optional[bytes] target_timespan: int validate_difficulty: bool = True @@ -36,7 +36,7 @@ class BaseHeaders: if path == ':memory:': self.io = BytesIO() self.path = path - self._size = None + self._size: Optional[int] = None self._on_change_controller = StreamController() self.on_changed = self._on_change_controller.stream self._header_connect_lock = defer.DeferredLock() @@ -61,7 +61,8 @@ class BaseHeaders: def get_next_chunk_target(self, chunk: int) -> ArithUint256: return ArithUint256(self.max_target) - def get_next_block_target(self, chunk_target: ArithUint256, previous: Optional[dict], + @staticmethod + def get_next_block_target(chunk_target: ArithUint256, previous: Optional[dict], current: Optional[dict]) -> ArithUint256: return chunk_target diff --git a/torba/baseledger.py b/torba/baseledger.py index 24c7ad295..bde70f59c 100644 --- a/torba/baseledger.py +++ b/torba/baseledger.py @@ -11,7 +11,7 @@ from torba import baseaccount from torba import basenetwork from torba import basetransaction from torba.basedatabase import BaseDatabase -from torba.baseheader import BaseHeaders, InvalidHeader +from torba.baseheader import BaseHeaders from torba.coinselection import CoinSelector from torba.constants import COIN, NULL_HASH32 from torba.stream import StreamController diff --git a/torba/coin/bitcoincash.py b/torba/coin/bitcoincash.py index 6678af616..77e991217 100644 --- a/torba/coin/bitcoincash.py +++ b/torba/coin/bitcoincash.py @@ -8,8 +8,8 @@ __electrumx__ = 'electrumx.lib.coins.BitcoinCashRegtest' from binascii import unhexlify from torba.baseledger import BaseLedger -from torba.baseheader import BaseHeaders from torba.basetransaction import BaseTransaction +from .bitcoinsegwit import MainHeaders, UnverifiedHeaders class Transaction(BaseTransaction): @@ -23,6 +23,7 @@ class MainNetLedger(BaseLedger): symbol = 'BCH' network_name = 'mainnet' + headers_class = MainHeaders transaction_class = Transaction pubkey_address_prefix = bytes((0,)) @@ -33,10 +34,6 @@ class MainNetLedger(BaseLedger): default_fee_per_byte = 50 -class UnverifiedHeaders(BaseHeaders): - verify_bits_to_target = False - - class RegTestLedger(MainNetLedger): headers_class = UnverifiedHeaders network_name = 'regtest' diff --git a/torba/coin/bitcoinsegwit.py b/torba/coin/bitcoinsegwit.py index 89109de99..bae056eb3 100644 --- a/torba/coin/bitcoinsegwit.py +++ b/torba/coin/bitcoinsegwit.py @@ -7,6 +7,7 @@ __node_url__ = ( __electrumx__ = 'electrumx.lib.coins.BitcoinSegwitRegtest' import struct +from typing import Optional from binascii import hexlify, unhexlify from torba.baseledger import BaseLedger from torba.baseheader import BaseHeaders, ArithUint256 @@ -16,7 +17,7 @@ class MainHeaders(BaseHeaders): header_size = 80 chunk_size = 2016 max_target = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff - genesis_hash = b'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' + genesis_hash: Optional[bytes] = b'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' target_timespan = 14 * 24 * 60 * 60 @staticmethod diff --git a/torba/util.py b/torba/util.py index 5a61d550f..8ae838027 100644 --- a/torba/util.py +++ b/torba/util.py @@ -1,5 +1,5 @@ from binascii import unhexlify, hexlify -from typing import TypeVar, Sequence +from typing import TypeVar, Sequence, Optional T = TypeVar('T') @@ -52,7 +52,7 @@ class ArithUint256: def __init__(self, value: int) -> None: self._value = value - self._compact = None + self._compact: Optional[int] = None @classmethod def from_compact(cls, compact) -> 'ArithUint256': @@ -80,10 +80,10 @@ class ArithUint256: @property def bits(self) -> int: """ Returns the position of the highest bit set plus one. """ - bn = bin(self._value)[2:] - for i, d in enumerate(bn): + bits = bin(self._value)[2:] + for i, d in enumerate(bits): if d: - return (len(bn) - i) + 1 + return (len(bits) - i) + 1 return 0 @property