refactor: introduce SettlementError contracterror enum#385
Merged
greatest0fallt1me merged 1 commit intoMay 28, 2026
Merged
Conversation
- Add #[contracterror] SettlementError with 8 stable u32 codes (NotInitialized=1 through DeveloperOverflow=8) - Replace all targeted panic!/unwrap_or_else(||panic!()) paths with env.panic_with_error(SettlementError::*) — no raw error strings in production paths - Add MAX_BATCH_SIZE = 50 constant (was missing, caused compile error) - Fix storage key consistency: init and set_vault now use StorageKey::Admin / StorageKey::Vault enum keys, matching get_admin / get_vault reads (previously used Symbol string keys causing a key mismatch that broke all reads after init) - Fix batch_receive_payment to use persistent StorageKey::DeveloperBalance storage, consistent with receive_payment and get_developer_balance (previously used a separate instance-storage map so balances from the two functions were invisible to each other) - Remove unused string constants (VAULT_KEY, ADMIN_KEY, PENDING_ADMIN_KEY, GLOBAL_POOL_KEY, DEVELOPER_BALANCES_KEY) that would fail clippy -D warnings - Update tests: replace catch_unwind/panic_message with try_* client methods and typed InvokeError::Contract(code) assertions - Fix test_settlement_initialization: remove assertion on StorageKey::DeveloperIndex (written lazily, not at init) - Update docs/interfaces/settlement.json: add errors table, replace panics arrays with typed error code entries
|
@Vvictor-commits 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! 🚀 |
Contributor
|
Merged via direct push to main (admin) |
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 #330
Summary
Replaces raw panic strings in
CalloraSettlementwith a typed#[contracterror]enum so callers and indexers can handle errors deterministically, and removes embedded string literals to shrink WASM.Changes
contracts/settlement/src/lib.rsSettlementErrorenum with 8 stableu32codes (1–8)panic!()/unwrap_or_else(|| panic!())error paths withenv.panic_with_error(SettlementError::*)MAX_BATCH_SIZE = 50constant (was missing — compile error)initandset_vaultnow write viaStorageKey::Admin/StorageKey::Vaultenum keys, matching whatget_admin/get_vaultreadbatch_receive_paymentto useStorageKey::DeveloperBalancepersistent storage, consistent withreceive_paymentandget_developer_balanceclippy -D warningscontracts/settlement/src/test.rs+test_views.rscatch_unwind/panic_messagewithtry_*client methods andInvokeError::Contract(code)assertionstest_settlement_initialization: remove assertion onStorageKey::DeveloperIndex(written lazily, not at init)docs/interfaces/settlement.jsonerrorstable with all 8 codespanicsstring arrays with typederrorsarrays per functionError codes
initinitcalled twiceamount <= 0to_pool=falsewith no developerto_pool=truewith a developeri128overflow on pool balancei128overflow on developer balance