Skip to content

refactor(storage): extract repeated TTL boilerplate into helpers (#236) - #450

Open
ZacLou wants to merge 3 commits into
crackedstudio:mainfrom
ZacLou:refactor/storage-helpers-1788622213
Open

ZacLou wants to merge 3 commits into
crackedstudio:mainfrom
ZacLou:refactor/storage-helpers-1788622213

Conversation

@ZacLou

@ZacLou ZacLou commented Sep 5, 2026

Copy link
Copy Markdown

Closes #236

What

Extracts the repeated five-line TTL-extension boilerplate into a new storage module, eliminating four copy-paste sites and fixing the missing instance-TTL bump in cancel_circle.

New contracts/sharibo/src/storage.rs

  • load_circle(env, id) — load a Circle from persistent storage, panic with CircleNotFound if absent.
  • save_circle(env, id, circle) — persist a Circle, extend its persistent TTL, and bump the instance TTL.
  • bump_instance(env) — extend instance TTL (used internally by save_circle).
  • LEDGER_THRESHOLD and LEDGER_EXTEND_TO constants moved here with their full doc comments.

Changes to lib.rs

  • Replaced all env.storage().persistent().get(...).unwrap_or_else(...) calls with load_circle.
  • Replaced all set / extend_ttl / extend_ttl triplets with save_circle.
  • Bugfix: cancel_circle now also bumps the instance TTL (it was missing the env.storage().instance().extend_ttl(...) call).
  • LEDGER_THRESHOLD and LEDGER_EXTEND_TO are no longer duplicated in lib.rs.

Verification

  • cargo test should still pass (21 tests).
  • cargo build --target wasm32-unknown-unknown --release should succeed.
  • No error variants were added, renamed, or removed.
  • No discriminants were changed.

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.

Extract the repeated TTL-extension boilerplate in the contract into storage helpers

2 participants