Skip to content

Commit 07b6021

Browse files
committed
lint progress
1 parent 9f7afb1 commit 07b6021

File tree

12 files changed

+48
-43
lines changed

12 files changed

+48
-43
lines changed

counterparty-core/counterpartycore/lib/api/queries.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2771,12 +2771,12 @@ def get_asset_balances(
27712771
def prepare_where_status(status, arg_type, other_conditions=None):
27722772
where = []
27732773
statuses = status.split(",")
2774-
for status in statuses:
2775-
if status == "all":
2774+
for status_item in statuses:
2775+
if status_item == "all":
27762776
where = [other_conditions] if other_conditions else []
27772777
break
2778-
if status in typing.get_args(arg_type):
2779-
where_status = {"status": status}
2778+
if status_item in typing.get_args(arg_type):
2779+
where_status = {"status": status_item}
27802780
if other_conditions:
27812781
where_status.update(other_conditions)
27822782
where.append(where_status)

counterparty-core/counterpartycore/lib/backend/bitcoind.py

-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ def satoshis_per_vbyte(
355355

356356

357357
def get_btc_supply(normalize=False):
358-
f"""returns the total supply of {config.BTC} (based on what Bitcoin Core says the current block height is)""" # noqa: B021
359358
block_count = getblockcount()
360359
blocks_remaining = block_count
361360
total_supply = 0

counterparty-core/counterpartycore/lib/backend/rsfetcher.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ def prefetch_blocks(self):
176176
time.sleep(0.1)
177177
elif not self.stopped_event.is_set():
178178
retry += 1
179-
logger.debug(f"Waiting to prefetch block {expected_height}...({retry / 10}s)")
179+
logger.debug(
180+
"Waiting to prefetch block %s...(%.1fs)", expected_height, retry / 10
181+
)
180182
# Use Event's wait method instead of time.sleep for better responsiveness
181183
self.stopped_event.wait(retry / 10) # noqa: S311
182184
except Exception as e: # pylint: disable=broad-except
@@ -205,7 +207,7 @@ def stop(self):
205207
self.fetcher.stop()
206208
logger.debug("Fetcher stopped.")
207209
except Exception as e: # pylint: disable=broad-except
208-
logger.error(f"Error during stop: {e}")
210+
logger.error("Error during stop: %s", e)
209211
if str(e) != "Stopped error":
210212
raise e
211213
finally:
@@ -221,5 +223,5 @@ def restart(self):
221223

222224

223225
def stop():
224-
if RSFetcher in RSFetcher._instances and RSFetcher._instances[RSFetcher] is not None:
226+
if RSFetcher in RSFetcher._instances and RSFetcher._instances[RSFetcher] is not None: # pylint: disable=protected-access
225227
RSFetcher().stop()

counterparty-core/counterpartycore/lib/config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import os
22

3-
"""Variables prefixed with `DEFAULT` should be able to be overridden by
4-
configuration file and command‐line arguments."""
3+
# Variables prefixed with `DEFAULT` should be able to be overridden by
4+
# configuration file and command‐line arguments.
55

66
UNIT = 100000000 # The same across assets.
77

88

99
# Semantic Version
1010
__version__ = "10.10.0" # for hatch
1111
VERSION_STRING = __version__
12-
version = VERSION_STRING.split("-")[0].split(".")
12+
version = VERSION_STRING.split("-", maxsplit=1)[0].split(".")
1313
VERSION_MAJOR = int(version[0])
1414
VERSION_MINOR = int(version[1])
1515
VERSION_REVISION = int(version[2])

counterparty-core/counterpartycore/lib/messages/bet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def validate(
128128

129129
# For SQLite3
130130
if (
131-
wager_quantity > config.MAX_INT
131+
wager_quantity > config.MAX_INT # pylint: disable=too-many-boolean-expressions
132132
or counterwager_quantity > config.MAX_INT
133133
or bet_type > config.MAX_INT
134134
or deadline > config.MAX_INT

counterparty-core/counterpartycore/lib/messages/burn.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def compose(db, source: str, quantity: int, overburn: bool = False, skip_validat
5454

5555
# Check that a maximum of 1 BTC total is burned per address.
5656
burns = ledger.other.get_burns(db, source)
57-
already_burned = sum([burn["burned"] for burn in burns])
57+
already_burned = sum(burn["burned"] for burn in burns)
5858

5959
if quantity > (1 * config.UNIT - already_burned) and not overburn:
6060
raise exceptions.ComposeError(f"1 {config.BTC} may be burned per address")
@@ -87,7 +87,7 @@ def parse(db, tx):
8787
if status == "valid":
8888
# Calculate quantity of XCP earned. (Maximum 1 BTC in total, ever.)
8989
burns = ledger.other.get_burns(db, tx["source"])
90-
already_burned = sum([burn["burned"] for burn in burns])
90+
already_burned = sum(burn["burned"] for burn in burns)
9191
one = 1 * config.UNIT
9292
max_burn = one - already_burned
9393
if sent > max_burn:

counterparty-core/counterpartycore/lib/messages/dispenser.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def validate(
6060
oracle_address,
6161
):
6262
problems = []
63-
order_match = None # noqa: F841
6463
asset_id = None
6564

6665
if asset == config.BTC:
@@ -70,14 +69,14 @@ def validate(
7069
# resolve subassets
7170
asset = ledger.issuances.resolve_subasset_longname(db, asset)
7271

73-
if status == STATUS_OPEN or status == STATUS_OPEN_EMPTY_ADDRESS:
72+
if status in [STATUS_OPEN, STATUS_OPEN_EMPTY_ADDRESS]:
7473
if give_quantity <= 0:
7574
problems.append("give_quantity must be positive")
7675
if mainchainrate <= 0:
7776
problems.append("mainchainrate must be positive")
7877
if escrow_quantity < give_quantity:
7978
problems.append("escrow_quantity must be greater or equal than give_quantity")
80-
elif not (status == STATUS_CLOSED):
79+
elif status != STATUS_CLOSED:
8180
problems.append(f"invalid status {status}")
8281

8382
cursor = db.cursor()
@@ -149,7 +148,7 @@ def validate(
149148
open_dispensers[0]["satoshirate"] == mainchainrate
150149
and open_dispensers[0]["give_quantity"] == give_quantity
151150
):
152-
if (max_refills > 0) and (refilling_count >= max_refills):
151+
if refilling_count >= max_refills > 0:
153152
problems.append("the dispenser reached its maximum refilling")
154153
else:
155154
if open_dispensers[0]["satoshirate"] != mainchainrate:

counterparty-core/counterpartycore/lib/messages/issuance.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def compose(
315315
asset_id
316316
) # This will remove leading zeros in the numeric assets
317317

318-
(
318+
( # pylint: disable=unbalanced-tuple-unpacking
319319
call_date,
320320
call_price,
321321
problems,
@@ -748,7 +748,7 @@ def parse(db, tx, message, message_type_id):
748748
reissuance = None
749749
fee = 0
750750
if status == "valid":
751-
(
751+
( # pylint: disable=unbalanced-tuple-unpacking
752752
call_date,
753753
call_price,
754754
problems,

counterparty-core/counterpartycore/lib/messages/order.py

+23-18
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ def cancel_order_match(db, order_match, status, block_index, tx_index):
203203

204204
if status == "expired":
205205
# Record order match expiration.
206-
cursor = db.cursor() # noqa: F841
207206
bindings = {
208207
"order_match_id": order_match["id"],
209208
"tx0_address": order_match["tx0_address"],
@@ -545,7 +544,7 @@ def match(db, tx, block_index=None):
545544
tx0_fee_provided_remaining = tx0["fee_provided_remaining"]
546545

547546
# Make sure that that both orders still have funds remaining (if order involves BTC, and so cannot be ‘filled’).
548-
if tx0["give_asset"] == config.BTC or tx0["get_asset"] == config.BTC: # Gratuitous
547+
if config.BTC in [tx0["give_asset"], tx0["get_asset"]]: # Gratuitous
549548
if tx0_give_remaining <= 0 or tx1_give_remaining <= 0:
550549
logger.trace("Skipping: negative give quantity remaining")
551550
continue
@@ -637,17 +636,19 @@ def match(db, tx, block_index=None):
637636
)
638637

639638
logger.trace(
640-
f"Tx0 fee provided remaining: {tx0_fee_provided_remaining / config.UNIT}; required fee: {fee / config.UNIT}"
639+
"Tx0 fee provided remaining: %s; required fee: %s",
640+
tx0_fee_provided_remaining / config.UNIT,
641+
fee / config.UNIT,
641642
)
642643
if tx0_fee_provided_remaining < fee:
643644
logger.trace("Skipping: tx0 fee provided remaining is too low.")
644645
continue
645-
else:
646-
tx0_fee_provided_remaining -= fee
647-
if protocol.after_block_or_test_network(
648-
block_index, 287800
649-
): # Protocol change.
650-
tx1_fee_required_remaining -= fee
646+
647+
tx0_fee_provided_remaining -= fee
648+
if protocol.after_block_or_test_network(
649+
block_index, 287800
650+
): # Protocol change.
651+
tx1_fee_required_remaining -= fee
651652

652653
elif tx1["give_asset"] == config.BTC:
653654
if protocol.after_block_or_test_network(
@@ -664,17 +665,21 @@ def match(db, tx, block_index=None):
664665
)
665666

666667
logger.trace(
667-
f"Tx1 fee provided remaining: {tx1_fee_provided_remaining / config.UNIT}; required fee: {fee / config.UNIT}"
668+
"Tx1 fee provided remaining: %(fee_provided)s; required fee: %(required_fee)s",
669+
{
670+
"fee_provided": tx1_fee_provided_remaining / config.UNIT,
671+
"required_fee": fee / config.UNIT,
672+
},
668673
)
669674
if tx1_fee_provided_remaining < fee:
670675
logger.trace("Skipping: tx1 fee provided remaining is too low.")
671676
continue
672-
else:
673-
tx1_fee_provided_remaining -= fee
674-
if protocol.after_block_or_test_network(
675-
block_index, 287800
676-
): # Protocol change.
677-
tx0_fee_required_remaining -= fee
677+
678+
tx1_fee_provided_remaining -= fee
679+
if protocol.after_block_or_test_network(
680+
block_index, 287800
681+
): # Protocol change.
682+
tx0_fee_required_remaining -= fee
678683

679684
else: # Don’t deduct.
680685
if tx1["get_asset"] == config.BTC:
@@ -722,7 +727,7 @@ def match(db, tx, block_index=None):
722727
if tx0_give_remaining <= 0 or (
723728
tx0_get_remaining <= 0 and protocol.after_block_or_test_network(block_index, 292000)
724729
): # Protocol change
725-
if tx0["give_asset"] != config.BTC and tx0["get_asset"] != config.BTC:
730+
if config.BTC not in [tx0["give_asset"], tx0["get_asset"]]:
726731
# Fill order, and recredit give_remaining.
727732
tx0_status = "filled"
728733
ledger.events.credit(
@@ -747,7 +752,7 @@ def match(db, tx, block_index=None):
747752
if tx1_give_remaining <= 0 or (
748753
tx1_get_remaining <= 0 and protocol.after_block_or_test_network(block_index, 292000)
749754
): # Protocol change
750-
if tx1["give_asset"] != config.BTC and tx1["get_asset"] != config.BTC:
755+
if config.BTC not in [tx1["give_asset"], tx1["get_asset"]]:
751756
# Fill order, and recredit give_remaining.
752757
tx1_status = "filled"
753758
ledger.events.credit(

counterparty-core/counterpartycore/lib/messages/sweep.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def validate(db, source, destination, flags, memo, block_index):
5757

5858
if flags > FLAGS_ALL:
5959
problems.append(f"invalid flags {flags}")
60-
elif not (flags & (FLAG_BALANCES | FLAG_OWNERSHIP)):
60+
elif not flags & (FLAG_BALANCES | FLAG_OWNERSHIP):
6161
problems.append("must specify which kind of transfer in flags")
6262

6363
if memo and len(memo) > MAX_MEMO_LENGTH:
@@ -103,7 +103,7 @@ def unpack(message):
103103
short_address_bytes, flags, memo_bytes = struct.unpack(struct_format, message)
104104
if len(memo_bytes) == 0:
105105
memo_bytes = None
106-
elif not (flags & FLAG_BINARY_MEMO):
106+
elif not flags & FLAG_BINARY_MEMO:
107107
memo_bytes = memo_bytes.decode("utf-8")
108108

109109
# unpack address

counterparty-core/counterpartycore/lib/messages/versions/send1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def parse(db, tx, message):
128128
asset_id, quantity = struct.unpack(FORMAT, message)
129129
asset = ledger.issuances.get_asset_name(db, asset_id)
130130
status = "valid"
131-
except (exceptions.UnpackError, exceptions.AssetNameError, struct.error) as e: # noqa: F841
131+
except (exceptions.UnpackError, exceptions.AssetNameError, struct.error):
132132
asset, quantity = None, None
133133
status = "invalid: could not unpack"
134134

counterparty-core/counterpartycore/lib/parser/blocks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ def parse_tx(db, tx):
150150
or len(tx["source"].split("-")) > 1
151151
or (tx["destination"] and len(tx["destination"].split("-")) > 1)
152152
):
153-
return
153+
return False
154154

155155
# Burns.
156156
if tx["destination"] == config.UNSPENDABLE:
157157
burn.parse(db, tx)
158-
return
158+
return supported
159159

160160
# Protocol change.
161161
rps_enabled = protocol.after_block_or_test_network(tx["block_index"], 308500)

0 commit comments

Comments
 (0)