feat(precompiles): add move_precompiles method#270
Merged
Conversation
Add a method to move precompiles from source addresses to destination addresses, with a dedicated MovePrecompileError type. The method: - Takes an iterator of (source, dest) address pairs - Validates all source addresses are precompiles before making changes - Skips no-op moves where source == dest - Removes precompiles from source and installs at destination Also adds: - MovePrecompileError enum with NotAPrecompile variant - with_moved_precompiles builder-style variant - Comprehensive tests for the new functionality Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019bfaa4-f4da-731b-be5d-4278ddd726b8
623868d to
04bc994
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a method to move precompiles from source addresses to destination addresses, supporting the
movePrecompileTofield ineth_simulateV1state overrides.Changes
New Error Type
MovePrecompileErrorenum withNotAPrecompile(Address)variantDisplay,Debug,PartialEq,Eq,Clone, andErrorNew Methods on
PrecompilesMapmove_precompiles<I>(&mut self, moves: I) -> Result<(), MovePrecompileError>- takes an iterator of(source, dest)pairswith_moved_precompiles<I>(self, moves: I) -> Result<Self, MovePrecompileError>- builder-style variantBehavior
source == dest(no-op)NotAPrecompileerror if any source is not a precompileExample Usage
Tests
test_move_precompiles- basic move with verificationtest_move_precompiles_not_a_precompile- error casetest_move_precompiles_same_address_noop- no-op casetest_move_precompiles_multiple- moving multiple precompiles