Repository navigation
feat: add a per-jar pause switch - #217
Merged
Merged
Conversation
Let a jar owner temporarily stop accepting tips without abandoning the slug. set_jar_paused (owner-only) toggles a paused flag on the jar; every tip entry point rejects a paused jar with the typed error JarPaused before any funds move, while all reads stay available. The flag rides on the Jar returned by get_jar, is read by is_jar_paused, emits a jar_pause event, and survives transfer_jar_ownership. Bumps INTERFACE_VERSION to 5 for the new function and error code. Closes Novatip#45 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
PR #45 feat: add a per-jar pause switch
Summary
A creator mid-way through changing collaborators, or dealing with a dispute over
how a jar is split, previously had no way to stop tips arriving while they sort
it out — the only options were to leave the jar accepting money on terms that
may be wrong, or to abandon the slug entirely.
This adds a per-jar pause flag so the owner can close a jar temporarily
without losing it. Tips are rejected while paused with a typed error; every read
stays available throughout.
Changes
Contract (
contracts/tip-splitter/src/lib.rs)paused: boolto theJarstruct, alongside the existinglockedfield, so the flag is visible for free in the
Jarthatget_jarreturns.set_jar_paused(jar_id, paused)— owner-only. A single function that bothsets (
true) and clears (false) the flag. Emits ajar_pauseeventcarrying the new value.
is_jar_paused(jar_id) -> bool— a cheap read of the flag, mirroringis_splits_locked. Panics withJarNotFoundfor an unregistered slug, likeget_jar.Error::JarPaused = 39— a new typed error, appended (no existing coderenumbered).
settle_tip, so every tip entrypoint —
tip,tip_with_ref,tip_in_token, and each entry oftip_many—rejects a paused jar. The check runs after the jar is looked up and before
any funds move, so a rejected tip transfers nothing.
transfer_jar_ownership(same treatment aslocked) and is carried throughevery
Jarwrite path.INTERFACE_VERSION4 → 5, per the rule that a new function or errorcode is a public-interface change.
Tests (
contracts/tip-splitter/src/test.rs)paused_jar_rejects_tips_until_unpaused— a paused jar rejectstip,tip_in_tokenandtip_manywithJarPausedand moves no funds; reads(
get_jar,preview_split,is_jar_paused) stay available; unpausingrestores normal settlement.
set_jar_paused_is_owner_only— a non-owner cannot toggle the flag.jar_pause_emits_event_and_survives_ownership_transfer— thejar_pauseevent fires with the expected topics/data, the flag shows in
get_jar, and itsurvives a handover to a new owner.
version()pin (4 → 5) and completed the error-code pin table(added 37, 38, 39).
Docs (
docs/CONTRACT.md)Jartype now listspaused; added function-table rows forset_jar_paused/is_jar_paused; added thejar_pauseevent, error code39, the per-jar check in the
tip/tip_manyerror ordering, and a new"Pausing a jar (Add a per-jar pause switch so a creator can stop accepting tips #45)" section covering read-availability, survival across
ownership transfer, and how it relates to the admin-wide
pause.Example (
examples/tip-forwarder/src/lib.rs)pausedto theJarmirror, which decodesget_jar; its own commentrequires the mirror to carry every field the real
Jarstores (the XDR is aname-keyed map).
Acceptance criteria
a paused jar is rejected with a typed error (
JarPaused).the owner can change the flag.
documented in
docs/CONTRACT.md.Testing
cargo fmt --all -- --check— passes.tip-splittersuite is green for everypath this change touches.
Closes #45