Skip to content

refactor: introduce SettlementError contracterror enum#385

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
Vvictor-commits:task/settlement-contracterror-enum
May 28, 2026
Merged

refactor: introduce SettlementError contracterror enum#385
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
Vvictor-commits:task/settlement-contracterror-enum

Conversation

@Vvictor-commits
Copy link
Copy Markdown
Contributor

@Vvictor-commits Vvictor-commits commented May 28, 2026

Closes #330


Summary

Replaces raw panic strings in CalloraSettlement with 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.rs

  • Add SettlementError enum with 8 stable u32 codes (1–8)
  • Replace all panic!() / unwrap_or_else(|| panic!()) error paths with env.panic_with_error(SettlementError::*)
  • Add MAX_BATCH_SIZE = 50 constant (was missing — compile error)
  • Fix storage key consistency: init and set_vault now write via StorageKey::Admin / StorageKey::Vault enum keys, matching what get_admin / get_vault read
  • Fix batch_receive_payment to use StorageKey::DeveloperBalance persistent storage, consistent with receive_payment and get_developer_balance
  • Remove unused string constants that would fail clippy -D warnings

contracts/settlement/src/test.rs + test_views.rs

  • Replace catch_unwind / panic_message with try_* client methods and InvokeError::Contract(code) assertions
  • Fix test_settlement_initialization: remove assertion on StorageKey::DeveloperIndex (written lazily, not at init)

docs/interfaces/settlement.json

  • Add top-level errors table with all 8 codes
  • Replace panics string arrays with typed errors arrays per function

Error codes

Code Variant When
1 NotInitialized Called before init
2 AlreadyInitialized init called twice
3 Unauthorized Caller is not vault or admin
4 AmountNotPositive amount <= 0
5 DeveloperRequired to_pool=false with no developer
6 DeveloperMustBeNone to_pool=true with a developer
7 PoolOverflow i128 overflow on pool balance
8 DeveloperOverflow i128 overflow on developer balance

- 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
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@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! 🚀

Learn more about application limits

@greatest0fallt1me
Copy link
Copy Markdown
Contributor

Merged via direct push to main (admin)

@greatest0fallt1me greatest0fallt1me merged commit f6d730f into CalloraOrg:main May 28, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Settlement: add contracterror enum and replace panic strings

3 participants