Skip to content

Commit 64a0825

Browse files
committed
chore: refomatted with black due to precommit failures
1 parent c623cf3 commit 64a0825

File tree

12 files changed

+822
-213
lines changed

12 files changed

+822
-213
lines changed

examples/payments/payments.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def print_payment(transaction: SubscribedTransaction, filter_name: str) -> None:
5959
Here we are only using this EventListener callback for one filter, but if we had multiple filters we could use the filter name to determine which filter the transaction matched.
6060
"""
6161
pay = transaction["payment-transaction"]
62-
print(f"{filter_name}: {transaction['sender']} sent {pay['receiver']} {pay['amount'] * 1e-6} ALGO")
62+
print(
63+
f"{filter_name}: {transaction['sender']} sent {pay['receiver']} {pay['amount'] * 1e-6} ALGO"
64+
)
6365

6466

6567
# Attach our callback to the 'pay txns' filter

examples/usdc/usdc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def print_usdc(transaction: SubscribedTransaction, filter_name: str) -> None:
5555
Here we are only using this EventListener callback for one filter, but if we had multiple filters we could use the filter name to determine which filter the transaction matched.
5656
"""
5757
axfer = transaction["asset-transfer-transaction"]
58-
print(f"{filter_name}: {transaction['sender']} sent {axfer['receiver']} {axfer['amount'] * 1e-6} USDC")
58+
print(
59+
f"{filter_name}: {transaction['sender']} sent {axfer['receiver']} {axfer['amount'] * 1e-6} USDC"
60+
)
5961

6062

6163
subscriber.on("usdc", print_usdc)

src/algokit_subscriber/block.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
def block_response_to_block_data(response: bytes) -> BlockData:
1212
return cast(
1313
"BlockData",
14-
msgpack.unpackb(response, strict_map_key=False, unicode_errors="surrogateescape"),
14+
msgpack.unpackb(
15+
response, strict_map_key=False, unicode_errors="surrogateescape"
16+
),
1517
)
1618

1719

@@ -23,7 +25,9 @@ def get_blocks_bulk(context: dict[str, int], client: AlgodClient) -> list[BlockD
2325
:return: The blocks
2426
"""
2527
# Grab 30 at a time to not overload the node
26-
block_chunks = chunk_array(range_inclusive(context["start_round"], context["max_round"]), 30)
28+
block_chunks = chunk_array(
29+
range_inclusive(context["start_round"], context["max_round"]), 30
30+
)
2731
blocks = []
2832

2933
for chunk in block_chunks:
@@ -41,6 +45,8 @@ def get_blocks_bulk(context: dict[str, int], client: AlgodClient) -> list[BlockD
4145
blocks.append(decoded)
4246

4347
elapsed_time = time.time() - start_time
44-
logger.debug(f"Retrieved {len(chunk)} blocks from round {chunk[0]} via algod in {elapsed_time:.2f}s")
48+
logger.debug(
49+
f"Retrieved {len(chunk)} blocks from round {chunk[0]} via algod in {elapsed_time:.2f}s"
50+
)
4551

4652
return blocks

src/algokit_subscriber/indexer_lookup.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def transaction(transaction_id: str, indexer: IndexerClient) -> TransactionLooku
2626
return indexer.transaction(txid=transaction_id) # type: ignore[no-untyped-call, no-any-return]
2727

2828

29-
def lookup_account_by_address(account_address: str, indexer: IndexerClient) -> AccountLookupResult:
29+
def lookup_account_by_address(
30+
account_address: str, indexer: IndexerClient
31+
) -> AccountLookupResult:
3032
"""
3133
Looks up an account by address using Indexer.
3234
"""
@@ -62,7 +64,9 @@ def build_request(next_token: str | None = None) -> dict[str, Any]:
6264

6365
return args
6466

65-
return execute_paginated_request(indexer.lookup_account_application_by_creator, extract_items, build_request)
67+
return execute_paginated_request(
68+
indexer.lookup_account_application_by_creator, extract_items, build_request
69+
)
6670

6771

6872
def lookup_asset_holdings(
@@ -84,17 +88,29 @@ def build_request(next_token: str | None = None) -> dict[str, Any]:
8488
args: dict[str, Any] = {
8589
"asset-id": asset_id,
8690
"limit": pagination_limit or DEFAULT_INDEXER_MAX_API_RESOURCES_PER_ACCOUNT,
87-
"include-all": (options["include-all"] if options and "include-all" in options else None),
88-
"currency-greater-than": (options["currency-greater-than"] if options and "currency-greater-than" in options else None),
89-
"currency-less-than": (options["currency-less-than"] if options and "currency-less-than" in options else None),
91+
"include-all": (
92+
options["include-all"] if options and "include-all" in options else None
93+
),
94+
"currency-greater-than": (
95+
options["currency-greater-than"]
96+
if options and "currency-greater-than" in options
97+
else None
98+
),
99+
"currency-less-than": (
100+
options["currency-less-than"]
101+
if options and "currency-less-than" in options
102+
else None
103+
),
90104
}
91105

92106
if next_token:
93107
args["next-token"] = next_token
94108

95109
return args
96110

97-
return execute_paginated_request(indexer.lookup_account_assets, extract_items, build_request)
111+
return execute_paginated_request(
112+
indexer.lookup_account_assets, extract_items, build_request
113+
)
98114

99115

100116
def search_transactions(
@@ -116,13 +132,17 @@ def extract_items(response: TransactionSearchResults) -> list[TransactionResult]
116132

117133
def build_request(next_token: str | None = None) -> dict[str, Any]:
118134
args: dict[str, Any] = search_criteria
119-
args["limit"] = pagination_limit or DEFAULT_INDEXER_MAX_API_RESOURCES_PER_ACCOUNT
135+
args["limit"] = (
136+
pagination_limit or DEFAULT_INDEXER_MAX_API_RESOURCES_PER_ACCOUNT
137+
)
120138
if next_token:
121139
args["next_page"] = next_token
122140

123141
return args
124142

125-
transactions = execute_paginated_request(indexer.search_transactions, extract_items, build_request)
143+
transactions = execute_paginated_request(
144+
indexer.search_transactions, extract_items, build_request
145+
)
126146

127147
return {
128148
"current-round": current_round,

src/algokit_subscriber/subscriber.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def __init__(
4242
self.filter_names = [f["name"] for f in self.config["filters"]]
4343

4444
if config["sync_behaviour"] == "catchup-with-indexer" and not indexer_client:
45-
raise ValueError("Received sync behaviour of catchup-with-indexer, but didn't receive an indexer instance.")
45+
raise ValueError(
46+
"Received sync behaviour of catchup-with-indexer, but didn't receive an indexer instance."
47+
)
4648

4749
def default_error_handler(
4850
self,
@@ -58,7 +60,9 @@ def poll_once(self) -> TransactionSubscriptionResult:
5860
watermark = self.config["watermark_persistence"]["get"]() or 0
5961
current_round = cast("dict", self.algod.status())["last-round"]
6062

61-
self.event_emitter.emit("before:poll", {"watermark": watermark, "current_round": current_round})
63+
self.event_emitter.emit(
64+
"before:poll", {"watermark": watermark, "current_round": current_round}
65+
)
6266

6367
poll_result = get_subscribed_transactions(
6468
subscription=cast(
@@ -72,11 +76,21 @@ def poll_once(self) -> TransactionSubscriptionResult:
7276
try:
7377
for filter_name in self.filter_names:
7478
mapper = next(
75-
(f.get("mapper") for f in self.config["filters"] if f["name"] == filter_name),
79+
(
80+
f.get("mapper")
81+
for f in self.config["filters"]
82+
if f["name"] == filter_name
83+
),
7684
None,
7785
)
78-
matched_transactions = [t for t in poll_result["subscribed_transactions"] if filter_name in (t.get("filters_matched") or [])]
79-
mapped_transactions = mapper(matched_transactions) if mapper else matched_transactions
86+
matched_transactions = [
87+
t
88+
for t in poll_result["subscribed_transactions"]
89+
if filter_name in (t.get("filters_matched") or [])
90+
]
91+
mapped_transactions = (
92+
mapper(matched_transactions) if mapper else matched_transactions
93+
)
8094

8195
self.event_emitter.emit(f"batch:{filter_name}", mapped_transactions)
8296
for transaction in mapped_transactions:
@@ -112,12 +126,16 @@ def start( # noqa: C901
112126
duration_in_seconds = time.time() - start_time
113127

114128
if not suppress_log:
115-
logger.info(f"Subscription poll completed in {duration_in_seconds:.2f}s")
129+
logger.info(
130+
f"Subscription poll completed in {duration_in_seconds:.2f}s"
131+
)
116132
logger.info(f"Current round: {result['current_round']}")
117133
logger.info(f"Starting watermark: {result['starting_watermark']}")
118134
logger.info(f"New watermark: {result['new_watermark']}")
119135
logger.info(f"Synced round range: {result['synced_round_range']}")
120-
logger.info(f"Subscribed transactions: {len(result['subscribed_transactions'])}")
136+
logger.info(
137+
f"Subscribed transactions: {len(result['subscribed_transactions'])}"
138+
)
121139

122140
if inspect:
123141
inspect(result)
@@ -126,7 +144,9 @@ def start( # noqa: C901
126144
if self.stop_requested:
127145
break # type: ignore[unreachable]
128146

129-
if result["current_round"] > result["new_watermark"] or not self.config.get("wait_for_block_when_at_tip", False):
147+
if result["current_round"] > result[
148+
"new_watermark"
149+
] or not self.config.get("wait_for_block_when_at_tip", False):
130150
sleep_time = self.config.get("frequency_in_seconds", 1)
131151
if not suppress_log:
132152
logger.info(f"Sleeping for {sleep_time}s")
@@ -138,7 +158,9 @@ def start( # noqa: C901
138158
wait_start = time.time()
139159
self.algod.status_after_block(result["current_round"])
140160
if not suppress_log:
141-
logger.info(f"Waited for {time.time() - wait_start:.2f}s until next block")
161+
logger.info(
162+
f"Waited for {time.time() - wait_start:.2f}s until next block"
163+
)
142164
except Exception as e:
143165
self.event_emitter.emit("error", e)
144166
self.started = False
@@ -154,11 +176,15 @@ def on(self, filter_name: str, listener: EventListener) -> "AlgorandSubscriber":
154176
Register an event handler to run on every subscribed transaction matching the given filter name.
155177
"""
156178
if filter_name == "error":
157-
raise ValueError("'error' is reserved, please supply a different filter_name.")
179+
raise ValueError(
180+
"'error' is reserved, please supply a different filter_name."
181+
)
158182
self.event_emitter.on(filter_name, listener)
159183
return self
160184

161-
def on_batch(self, filter_name: str, listener: EventListener) -> "AlgorandSubscriber":
185+
def on_batch(
186+
self, filter_name: str, listener: EventListener
187+
) -> "AlgorandSubscriber":
162188
"""
163189
Register an event handler to run on all subscribed transactions matching the given filter name
164190
for each subscription poll.

0 commit comments

Comments
 (0)