Improve code style by removing duplicated code in the pallas-validate crate
#679
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses code duplication in the
pallas-validatecrate by introducing generic traits and functions to unify similar operations across different Cardano eras.Problem
The
pallas-validate/src/utils.rsfile contained significant code duplication, with separate implementations for similar operations across different eras (Alonzo, Babbage, Conway). Examples included:aux_data_from_alonzo_tx,aux_data_from_babbage_tx,aux_data_from_conway_txget_babbage_tx_size,get_conway_tx_sizeadd_valuesvsconway_add_valuesfind_policyvsconway_find_policySolution
New Generic Traits
Introduced trait-based abstractions to unify operations across eras:
ValueOps: Abstracts value operations (getting lovelace, checking coin-only values, etc.)MultiassetOps: Abstracts multiasset operations (finding policies/assets, iteration)AuxDataAccess: Abstracts auxiliary data extraction from transactionsTxSizeCalculator: Abstracts transaction size calculationGeneric Functions
Created reusable generic implementations:
Improvements Made
Backward Compatibility
All existing public APIs are preserved through compatibility wrapper functions, ensuring no breaking changes. All 119 existing tests continue to pass without modification.
Benefits
The refactoring maintains full backward compatibility while significantly improving code organization and reducing maintenance burden for future development.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.