Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve Code Readability and Performance for Contract Hash Gener… #1275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0xwitty
Copy link

@0xwitty 0xwitty commented Dec 28, 2024

Description

Hey team,

I’ve made some improvements to the contract hash generation script to enhance readability, maintainability, and performance while keeping the functionality intact. Below is a summary of the changes:

What I’ve Changed

  1. Reduced Redundancy:

    • Combined remove_prefix_from_names and remove_prefix into a single operation using Python’s built-in str.removeprefix. This simplifies the logic and reduces the number of helper functions.
  2. Optimized Sorting:

    • Improved the sorting of contracts by leveraging pre-defined indexes from the KNOWN_ORDER list. This avoids the use of a lambda function in sorting.
  3. Improved String Handling:

    • Replaced += string concatenations in loops with list-building and a single '\n'.join call. This makes the script more efficient and Pythonic.
  4. Simplified Normalization Logic:

    • Refactored normalize_len to use zfill for zero-padding, simplifying the function while keeping the behavior unchanged.
  5. Enhanced Readability:

    • Restructured the script for cleaner and more compact logic, making it easier to follow and modify in the future.

Why This Matters

These changes don’t just clean up the code—they make it easier for others (and future us!) to understand and extend. The performance improvements, while not dramatic, ensure the script runs efficiently, even with a large number of contracts.

Testing

  • I’ve tested the updated script with various sets of contract data, ensuring that the output matches the current implementation exactly.
  • It successfully skips contracts with "Mock" in their names and maintains the specified order for known contracts.

Feel free to tweak this to include any specific context or examples you think the team would appreciate!

PR Checklist

  • Tests
  • [] Documentation
  • [] Added entry to CHANGELOG.md
  • [] Tried the feature on a public network

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant