Add Ethereum transaction ID handling utility#8
Conversation
Agent-Logs-Url: https://github.com/Darliewithrow/master/sessions/46dc35b4-63a2-4f6b-b608-02ed19a9dc46 Co-authored-by: Darliewithrow <216807437+Darliewithrow@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Darliewithrow/master/sessions/46dc35b4-63a2-4f6b-b608-02ed19a9dc46 Co-authored-by: Darliewithrow <216807437+Darliewithrow@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a small Python utility module for working with Ethereum transaction IDs (tx hashes), plus tests and documentation.
Changes:
- Introduces
transaction_id.pywith validation, normalization, formatting, and extraction helpers (plus a CLI demo entrypoint). - Adds
test_transaction_id.pyunit tests for core behaviors (validation/normalization/formatting/parsing). - Documents usage in
README.mdand adds a Python-focused.gitignore.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| transaction_id.py | Implements tx hash validate/normalize/format/parse helpers and a CLI demo. |
| test_transaction_id.py | Adds unittest coverage for the helper functions. |
| README.md | Documents the new utility and provides usage examples. |
| .gitignore | Adds standard Python/venv/IDE/OS ignore patterns. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| format_transaction_id(tx, short=True) # "0xabc123...56abc1" | ||
|
|
||
| # Extract all valid IDs from a block of text | ||
| parse_transaction_ids("tx1=0x... tx2=0x...") |
There was a problem hiding this comment.
The parsing example uses placeholders like "tx1=0x... tx2=0x...", but parse_transaction_ids only extracts full 32-byte transaction hashes (no ellipses/short forms). Update the example to include full-length IDs or clarify the supported input formats.
| parse_transaction_ids("tx1=0x... tx2=0x...") | |
| parse_transaction_ids( | |
| "tx1=0xabc123def456abc123def456abc123def456abc123def456abc123def456abc1 " | |
| "tx2=0xdef456abc123def456abc123def456abc123def456abc123def456abc123def4" | |
| ) |
| def test_case_normalization(self): | ||
| tx_upper = "0x" + "A" * 64 | ||
| tx_lower = "0x" + "a" * 64 | ||
| # Both forms refer to the same ID; only one should appear | ||
| result = parse_transaction_ids(f"{tx_upper} {tx_lower}") |
There was a problem hiding this comment.
Consider adding a test that parse_transaction_ids extracts IDs with an uppercase 0X prefix (and normalizes them), plus a boundary case where a valid 66-char ID is immediately followed by another hex character (to avoid greedy-match failures). This will lock in the intended extraction behavior.
| if len(sys.argv) > 1: | ||
| file_path = sys.argv[1] | ||
| try: | ||
| with open(file_path, 'r') as f: |
There was a problem hiding this comment.
open(file_path, 'r') relies on the platform default encoding. Specify an explicit encoding (e.g., UTF-8) for consistent behavior across environments.
| with open(file_path, 'r') as f: | |
| with open(file_path, 'r', encoding='utf-8') as f: |
|
Cloned Darliewithrow/documentation and checked out branch copilot/check-previous-step-changes |
…ck-previous-step-changes Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Darliewithrow
left a comment
There was a problem hiding this comment.
from transaction_id import is_valid_transaction_id, format_transaction_id, parse_transaction_ids
tx = "0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"
is_valid_transaction_id(tx) # True
format_transaction_id(tx, short=True) # "0xdeadbe...adbeef"
text = "sent via 0xabc123...def456 and 0xfeed00...cafe11"
parse_transaction_ids(text) # [normalized list of unique IDs found]
Implements a Python module for validating, normalizing, formatting, and extracting Ethereum transaction IDs (32-byte hex hashes).
Changes
transaction_id.py— Core logic:is_valid_transaction_id— validates0x+ 64 hex chars formatnormalize_transaction_id— adds missing0xprefix, lowercasesformat_transaction_id— full or shortened (0xabcdef...123456) displayparse_transaction_ids— extracts all unique valid IDs from arbitrary texttest_transaction_id.py— 26 unit tests covering validation, normalization, deduplication, case folding, and edge casesREADME.md— Documents the utility with usage examples.gitignore— Standard Python exclusions (__pycache__,*.pyc, etc.)Example