Refactor/issue 89 error discriminants - #720
Merged
EDOHWARES merged 6 commits intoAug 1, 2026
Merged
Conversation
added 5 commits
July 24, 2026 15:52
…nd export JSON schema spec
|
@Chrisbankz0 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Collaborator
|
Nice implementation, LGTM! |
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.
#closes
#647
Pull Request: [Contract] Implement Custom Error Enums with Explicit Numerical Discriminants
🎯 Overview
This PR addresses **Issue by annotating all contract error enums with explicit
#[repr(u32)]numerical discriminants (e.g.AlreadyInitialized = 1) and exporting a standardized JSON schema specification.Previously, implicit error discriminant mappings caused cross-language mapping between Rust contracts, the SoroScope web dashboard (Next.js/TypeScript), and external clients to be fragile and prone to decoding mismatches when enums were extended. Explicit numerical discriminants guarantee a stable on-chain ABI and deterministic cross-language error decoding.
✨ Features Implemented
#[repr(u32)]Discriminants:ContractErrorincontracts/error_codes/src/lib.rswith explicit numerical discriminants (1to17).as_u32(&self)andfrom_u32(code: u32) -> Option<Self>.ERROR_SCHEMA_JSONconstant incontracts/error_codes.contracts/error_codes/schema.jsonmapping variant names, integer codes, and descriptions.contracts/liquidity_pool/src/lib.rs.CrossChainErrorincontracts/cross_chain_payload/src/errors.rswith#[contracterror],#[repr(u32)], and explicit variant discriminants matchingas_u32().contracts/and nestedsoroscope/contracts/structures.🔧 Technical Implementation
ContractErrorenum definition:contracts/error_codes/schema.json):{ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "ContractError", "type": "object", "description": "Explicit numerical discriminant mappings for SoroScope smart contract error codes.", "error_codes": [ { "name": "AlreadyInitialized", "code": 1, "description": "Contract has already been initialized." }, ... ] }🧪 Step-by-Step Testing & Verification Process
Follow these steps to verify that the assignment was successfully completed:
Verify Contract Error Code Discriminant Tests:
Run cargo test on the error codes crate:
cargo test -p soroscope-error-codes(If testing on Windows without MSVC linker installed, use the GNU toolchain):
cargo +stable-x86_64-pc-windows-gnu test -p soroscope-error-codesExpected Result: All 3 tests (
test_explicit_numerical_discriminants,test_from_u32_conversion,test_schema_json_contains_all_variants) pass cleanly.Verify JSON Schema Specification:
Inspect the generated schema file:
Expected Result: Valid JSON structure mapping error variants (
AlreadyInitializedthroughInvalidInput) to their corresponding integer codes (1through17).Verify Contract Workspace Checks:
Check contract compilation across the workspace:
Verify Web Frontend Diagnostics:
Ensure web application lints pass:
cd web npm run lint📁 Files Changed
contracts/error_codes/src/lib.rs- Added explicit numerical discriminants, conversion helpers, JSON schema export, and tests.contracts/error_codes/schema.json- Added exported JSON schema specification.contracts/liquidity_pool/src/lib.rs- Removed duplicate enum variants.contracts/cross_chain_payload/src/errors.rs- Added#[contracterror],#[repr(u32)], and explicit discriminants.soroscope/contracts/error_codes/src/lib.rs- Synchronized nested crate file.soroscope/contracts/error_codes/schema.json- Synchronized nested schema file.soroscope/contracts/cross_chain_payload/src/errors.rs- Synchronized nested cross-chain errors.docs/PR_DESCRIPTION_ISSUE_647.md- Added PR documentation.✅ Acceptance Criteria Checklist
🔗 Related Issues
Closes #647