Fix/implement contract upgrade service methods#206
Merged
Conversation
- Import callReadOnlyFunction for querying contract state - Import cvToValue for parsing Clarity values - Support read-only operations on migration contract
- Support optional network configuration for contract operations - Enable flexibility in test and production environments - Store network for use in read-only function calls
- Extract base address from contract name format (address.contract-name) - Handle both qualified and unqualified contract addresses - Support flexibility in contract address specification
- Query get-current-version read-only function from migration contract - Parse returned Clarity value and convert to number - Fallback to version 1 on error or invalid response - Add comprehensive error handling and logging
- Call get-migration read-only function with migration ID parameter - Parse response and map contract fields to Migration interface - Handle optional fields (executedAt, executedBy) - Support snake_case contract field names - Return null if migration not found or on error
- Query get-migration-data read-only function with migration ID - Extract data hash and size from contract response - Map contract response fields to MigrationData interface - Return empty Uint8Array and 0 for missing values - Return null if data not found or on error
- Query is-migration-executed read-only function - Check migration execution status on contract - Return boolean indicating if migration has been executed - Fallback to false on error or invalid response - Add error handling and logging for execution status checks
- Query get-migration-count read-only function - Return total number of migrations registered in contract - Parse Clarity integer response and convert to JavaScript number - Fallback to 0 on error or invalid response - Add error handling and logging
- Import callReadOnlyFunction for querying contract state - Import cvToValue for parsing Clarity values - Support read-only operations on proxy upgrade contract
- Support optional network configuration for contract operations - Enable flexibility in test and production environments - Store network for use in read-only function calls
- Extract base address from contract name format (address.contract-name) - Handle both qualified and unqualified contract addresses - Support flexibility in contract address specification
- Call get-implementation read-only function from proxy contract - Retrieve current contract implementation address - Parse and validate response from Clarity - Return null on error or invalid response
- Call get-pending-implementation read-only function - Retrieve pending upgrade proposal if exists - Map response to UpgradeProposal interface - Return null if no pending upgrade or on error
- Query get-upgrade-history read-only function with upgrade ID - Map contract response fields to UpgradeHistory interface - Handle snake_case contract field names - Return null if upgrade record not found or on error
- Query get-upgrade-count read-only function - Return total number of contract upgrades executed - Parse Clarity integer response and convert to JavaScript number - Fallback to 0 on error or invalid response
- Query get-upgrade-timelock read-only function - Return configured timelock block duration for upgrades - Parse and validate Clarity integer response - Return null on error or invalid response
- Check if an upgrade is currently pending execution - Query pending upgrade status - Return boolean indicating pending state - Simplify upgrade state management
- Verify pending upgrade exists - Check timelock requirement is configured - Return boolean indicating readiness for execution - Provide pre-execution validation
- Query multiple upgrade history records in sequence - Accept start ID and count parameters - Return array of UpgradeHistory or null values - Enable efficient history pagination
- Validate principal address format (ST/SM prefix) - Check address string type and non-empty - Return boolean indicating validity - Prevent invalid implementation address proposals
- Retrieve current and pending implementations - Compare addresses for equality - Return object with current, pending, and same flag - Enable upgrade preview before execution
- Retrieve all upgrade-related metadata in parallel - Include owner, implementations, timelock, and count - Efficient parallel Promise.all execution - Single API for complete upgrade state
- Validate implementation address format and uniqueness - Check address differs from current implementation - Verify format before equality comparison - Prevent invalid or unchanged upgrades
- Retrieve the most recent upgrade execution record - Calculate last upgrade ID from total count - Return null if no upgrades executed - Enable upgrade history analysis
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.
Key Features:
Contract Integration: Uses Stacks SDK callReadOnlyFunction for all read operations
Error Handling: Comprehensive try-catch blocks with appropriate fallbacks
Field Mapping: Converts snake_case contract fields to camelCase JavaScript interfaces
Network Support: Optional network parameter for test/production flexibility
Address Parsing: Helper method for qualified and unqualified contract addresses
Closes #156