feat(icrc1): add ICRC-123 Rosetta support for freeze/unfreeze operations#9556
feat(icrc1): add ICRC-123 Rosetta support for freeze/unfreeze operations#9556bogwar wants to merge 2 commits intoicrc-123-2-index-ngfrom
Conversation
- Add 4 IcrcOperation variants: FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal - Add TryFrom parsing for 4 new block types from generic blocks - Add From<IcrcOperation> serialization to BTreeMap for storage - Add OperationType variants and metadata structs for freeze operations - Add IcrcOperationBuilder fields and conversion logic for freeze ops - Update storage_operations balance tracking (no balance impact) - Update construction_api and data_api match arms - Add proptest strategy functions for freeze operations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive ICRC-123 Rosetta support for freeze/unfreeze operations, building on the foundation established in PR #9533. The implementation includes full block-to-operation conversion, storage operations, metadata handling, and balance tracking for four new operation types: FreezeAccount, UnfreezeAccount, FreezePrincipal, and UnfreezePrincipal. All freeze operations are correctly treated as non-balance-affecting, and the code includes extensive test coverage with property-based testing.
Changes:
- Added four new operation variants to IcrcOperation enum with full CBOR encoding/decoding support
- Implemented bidirectional conversion between Rosetta operations and ICRC-1 operations for freeze operations
- Added FreezeAccountMetadata and FreezePrincipalMetadata types for serialization
- Updated balance tracking logic to handle freeze operations as no-ops
- Added comprehensive test coverage including property-based tests
- Updated all exhaustive match arms across the codebase
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| rs/rosetta-api/icrc1/src/common/types.rs | Added OperationType variants and metadata types for freeze operations |
| rs/rosetta-api/icrc1/src/common/storage/types.rs | Added IcrcOperation variants, CBOR encoding/decoding, test infrastructure |
| rs/rosetta-api/icrc1/src/common/utils/utils.rs | Implemented builder pattern and bidirectional Rosetta-ICRC1 conversion |
| rs/rosetta-api/icrc1/src/common/storage/storage_operations/mod.rs | Updated balance tracking and block storage for freeze operations |
| rs/rosetta-api/icrc1/src/construction_api/utils.rs | Updated match arms to handle freeze operations as unsupported |
| rs/rosetta-api/icrc1/src/construction_api/services.rs | Updated error message for freeze operations |
| rs/rosetta-api/icrc1/src/data_api/services.rs | Updated test match arms for freeze operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| | crate::common::storage::types::IcrcOperation::UnfreezeAccount { .. } | ||
| | crate::common::storage::types::IcrcOperation::FreezePrincipal { .. } | ||
| | crate::common::storage::types::IcrcOperation::UnfreezePrincipal { .. } => { | ||
| bail!("ICRC-124 operations not supported") |
There was a problem hiding this comment.
Error message refers only to "ICRC-124 operations" but the match arm also includes ICRC-123 freeze/unfreeze operations (FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal). The error message should be updated to reflect both ICRC-123 and ICRC-124 operations, or more generally "Management and freeze operations not supported".
| bail!("ICRC-124 operations not supported") | |
| bail!("Management and freeze operations not supported") |
| | crate::common::storage::types::IcrcOperation::UnfreezeAccount { .. } | ||
| | crate::common::storage::types::IcrcOperation::FreezePrincipal { .. } | ||
| | crate::common::storage::types::IcrcOperation::UnfreezePrincipal { .. } => { | ||
| bail!("ICRC-124 operations not supported") |
There was a problem hiding this comment.
Error message refers only to "ICRC-124 operations" but the match arm also includes ICRC-123 freeze/unfreeze operations (FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal). The error message should be updated to reflect both ICRC-123 and ICRC-124 operations, or more generally "Management and freeze operations not supported".
| bail!("ICRC-124 operations not supported") | |
| bail!("Management and freeze operations not supported") |
| | ic_icrc1::Operation::FreezePrincipal { .. } | ||
| | ic_icrc1::Operation::UnfreezePrincipal { .. } => { | ||
| panic!("Management operations not implemented") | ||
| panic!("ICRC-124 operations not implemented") |
There was a problem hiding this comment.
Error message refers only to "ICRC-124 operations" but the match arm also includes ICRC-123 freeze/unfreeze operations (FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal). The error message should be updated to reflect both ICRC-123 and ICRC-124 operations, or more generally "Management and freeze operations not implemented".
| panic!("ICRC-124 operations not implemented") | |
| panic!("Management and freeze operations not implemented") |
| } | ||
|
|
||
| pub fn build(self) -> anyhow::Result<crate::common::storage::types::IcrcOperation> { | ||
| Ok(match self.icrc_operation.context("Icrc Operation type must be one of Mint, Burn, Transfer, Approve, FeeCollector, Pause, Unpause, or Deactivate")? { |
There was a problem hiding this comment.
The context message for the build function lists the allowed operation types but is outdated. It should also include the new freeze operation types (FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal) that are now handled.
| Ok(match self.icrc_operation.context("Icrc Operation type must be one of Mint, Burn, Transfer, Approve, FeeCollector, Pause, Unpause, or Deactivate")? { | |
| Ok(match self.icrc_operation.context("Icrc Operation type must be one of Mint, Burn, Transfer, Approve, FeeCollector, FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal, Pause, Unpause, or Deactivate")? { |
…ations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
FreezeAccount,UnfreezeAccount,FreezePrincipal, andUnfreezePrincipalvariants toIcrcOperationin the Rosetta data APIStacked on #9533.
Test plan
ic-icrc-rosetta-unit-tests)icrc_rosetta_integration_tests)icrc_rosetta_system_tests,icrc_multitoken_rosetta_system_tests)🤖 Generated with Claude Code