Skip to content

Commit 8534bf8

Browse files
MoonBoi9001claude
andauthored
feat: Add clickable transaction links and Python style guidelines (#15)
* feat: Add clickable transaction links to Slack notifications - Enhanced Slack notifications to show clickable transaction hashes - Modified blockchain_client to return full block explorer URLs instead of raw hashes - Updated both success and failure notifications with defensive error handling - Added production-ready error handling for transaction link formatting 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * docs: Add Python style guidelines and integrate with Claude - Created comprehensive Python style guidelines document (STYLE_GUIDELINES.md) - Defined 9 core style principles for consistent code formatting - Integrated style guidelines into CLAUDE.md for AI coding consistency - Added guidance for comment placement, spacing, and function separation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * style: Fix linting issues and apply code formatting - Fix line length violations in slack_notifier.py comments - Apply automated formatting via ruff and custom formatter - Ensure all code passes CI linting requirements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * test: Update Slack notification test for clickable link format - Fix test expectation to match new clickable link format: <url|hash> - Add style guideline for compressing long comments vs truncating 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent daaa778 commit 8534bf8

File tree

5 files changed

+93
-6
lines changed

5 files changed

+93
-6
lines changed

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,6 @@ The system follows a clear data pipeline with daily scheduled execution:
173173

174174
# Session Context Import
175175
@./SESSION_CONTEXT.md
176+
177+
# Style Guidelines Import
178+
@./STYLE_GUIDELINES.md

STYLE_GUIDELINES.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Python Style Guidelines
2+
3+
This document defines the coding style guidelines for Python code in this repository. These guidelines should be followed to maintain consistency and readability across the codebase.
4+
5+
## Core Style Guidelines
6+
7+
### 1. Comments Before Logical Blocks
8+
Add descriptive comments above logical blocks when the purpose needs clarification or when explaining complex operations and error handling.
9+
10+
### 2. Blank Lines Before Comments (Except After Docstrings)
11+
Include a blank line before each comment that is before a logical block, except when the comment directly follows a function's docstring.
12+
13+
### 3. Blank Lines After Logical Sections Complete
14+
After a logical block completes (end of loops, after appending to lists, etc.), include a blank line before the next comment/section. This helps improve readability of the code.
15+
16+
### 4. Comments Describe "What" Not "How"
17+
Comments should describe what the code accomplishes rather than implementation details.
18+
19+
### 5. Spacing Within Control Structures
20+
Inside try/except blocks and if/else statements, include a blank line after each branch's code block completes.
21+
22+
### 6. Comments for Primary and Fallback Logic
23+
Both the main execution path and fallback/error handling should have descriptive comments when their purpose isn't immediately self-evident.
24+
25+
### 7. Comments for Final Actions
26+
Simple operations at the end of functions should have descriptive comments when the purpose needs clarification.
27+
28+
### 8. Two Blank Lines Between Functions/Methods/Classes
29+
Two blank lines before all function/method/class definitions, whether top-level or nested.
30+
31+
### 9. Compress long comments, don't truncate
32+
When comments exceed the 115-character line limit, compress them by removing unnecessary articles and prepositions while preserving full meaning, rather than truncating important information.
33+
34+
### 10. Code clarity not guideline following perfection
35+
The code is more important than the style guidelines
36+
37+
## Integration with Code Formatting Tools
38+
39+
These style guidelines work in conjunction with automated formatting tools:
40+
41+
- **Ruff**: Handles basic formatting, import sorting, and linting
42+
- **Custom formatter**: Applies additional spacing rules via `scripts/ruff_check_format_assets.sh`
43+
44+
Always run the formatting script before committing:
45+
```bash
46+
./scripts/ruff_check_format_assets.sh
47+
```

src/models/blockchain_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,8 @@ def batch_allow_indexers_issuance_eligibility(
632632
data_bytes,
633633
)
634634
tx_hash = "0x" + tx_hash
635-
transaction_hashes.append(tx_hash)
635+
tx_url = f"{self.block_explorer_url}/tx/{tx_hash}"
636+
transaction_hashes.append(tx_url)
636637
logger.info(f"Successfully sent batch {i // batch_size + 1}, tx_hash: {tx_hash}")
637638

638639
except Exception as e:

src/utils/slack_notifier.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,26 @@ def send_success_notification(
130130

131131
# Add transaction links if provided
132132
if transaction_links:
133-
tx_links = "\n".join([f"Batch {i + 1}: {link}" for i, link in enumerate(transaction_links)])
134-
fields.append({"title": "Transactions", "value": tx_links, "short": False})
133+
tx_links = []
134+
135+
# For each transaction link, extract the transaction hash from the URL
136+
for i, link in enumerate(transaction_links):
137+
try:
138+
if "/tx/" in link:
139+
tx_hash = link.split("/tx/")[-1]
140+
tx_links.append(f"Batch {i + 1}: <{link}|{tx_hash}>")
141+
142+
# Fallback: show the full link if format is unexpected
143+
else:
144+
tx_links.append(f"Batch {i + 1}: {link}")
145+
146+
# If transaction link not in expected format, add full link to list
147+
except Exception as e:
148+
logger.warning(f"Failed to format transaction link: {link}, error: {e}")
149+
tx_links.append(f"Batch {i + 1}: {link}")
150+
151+
# Add the list of transaction links to the fields
152+
fields.append({"title": "Transactions", "value": "\n".join(tx_links), "short": False})
135153

136154
# Create message payload
137155
payload = self._create_payload("Service Quality Oracle - Success", fields, "good")
@@ -180,8 +198,26 @@ def send_failure_notification(
180198

181199
# Add partial transaction links if any succeeded before failure
182200
if partial_transaction_links:
183-
tx_links = "\n".join([f"Batch {i + 1}: {link}" for i, link in enumerate(partial_transaction_links)])
184-
fields.append({"title": "Partial Transactions", "value": tx_links, "short": False})
201+
tx_links = []
202+
203+
# For each partial transaction link, extract the transaction hash from the URL
204+
for i, link in enumerate(partial_transaction_links):
205+
try:
206+
if "/tx/" in link:
207+
tx_hash = link.split("/tx/")[-1]
208+
tx_links.append(f"Batch {i + 1}: <{link}|{tx_hash}>")
209+
210+
# Fallback: show the full link if format is unexpected
211+
else:
212+
tx_links.append(f"Batch {i + 1}: {link}")
213+
214+
# If transaction link not in expected format, add full link to list
215+
except Exception as e:
216+
logger.warning(f"Failed to format transaction link: {link}, error: {e}")
217+
tx_links.append(f"Batch {i + 1}: {link}")
218+
219+
# Add the list of partial transaction links to the fields
220+
fields.append({"title": "Partial Transactions", "value": "\n".join(tx_links), "short": False})
185221

186222
# Truncate error message if too long
187223
error_text = error_message[:1000] + "..." if len(error_message) > 1000 else error_message

tests/test_slack_notifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_send_success_notification_builds_correct_payload(mock_requests: MagicMo
103103
assert fields["Status"] == "Successfully completed"
104104
assert fields["Eligible Indexers"] == "1"
105105
assert "123.4" in fields["Execution Time"]
106-
assert "Batch 1: http://etherscan.io/tx/1" in fields["Transactions"]
106+
assert "Batch 1: <http://etherscan.io/tx/1|1>" in fields["Transactions"]
107107

108108

109109
def test_send_failure_notification_builds_correct_payload(mock_requests: MagicMock):

0 commit comments

Comments
 (0)