Skip to content

feat(campaign-escrow): emit SubmissionApproved from approve_submission - #77

Open
Ogstevyn wants to merge 1 commit into
Ads-Bazaar:mainfrom
Ogstevyn:feat/submission-approved-event
Open

feat(campaign-escrow): emit SubmissionApproved from approve_submission#77
Ogstevyn wants to merge 1 commit into
Ads-Bazaar:mainfrom
Ogstevyn:feat/submission-approved-event

Conversation

@Ogstevyn

Copy link
Copy Markdown

closes #62

Problem

approve_submission was the only meaningful state transition in campaign-escrow that mutated an application and returned without publishing a typed event. Its sibling reject_submission publishes events::SubmissionRejected on the equivalent transition, and events.rs defines an event for every other transition in the contract.

The consequence is that an indexer or frontend subscribed to contract events cannot observe "the business approved this proof". It can only see the eventual PaymentReleased once the creator happens to claim, or it has to poll get_application for every pending submission on every campaign to notice the proof_approved flip. That breaks any UI that wants to prompt a creator to come claim their payment as soon as the approval lands.

Change

  • contracts/campaign-escrow/src/events.rs: add SubmissionApproved { campaign_id, creator }, placed next to SubmissionRejected and mirroring its shape, derives, and #[topic] annotations, so both topics are indexable the same way.
  • contracts/campaign-escrow/src/lib.rs: publish it from approve_submission, after storage::set_application, so the event is emitted only on the success path and never on an early error return.

Nothing else changes: no storage layout, no validation order, no public function signatures. Existing consumers are unaffected; the contract spec gains one additional event.

Tests

Added a test_events module in contracts/campaign-escrow/src/test.rs:

  • approve_submission_emits_submission_approved drives a creator to ProofSubmitted, calls approve_submission, and asserts the last event published by the contract equals SubmissionApproved { campaign_id, creator }.to_xdr(...) — which compares topics and data, not just the event name.
  • submission_approved_identifies_the_approved_creator puts two creators on one campaign in ProofSubmitted, approves the second, and asserts the published event names that creator and not the other one — guarding against the topic being wired to the wrong address.

Full suite: 100 unit tests and 18 integration tests pass. cargo clippy --workspace --all-targets is clean, and cargo fmt --check reports no diffs in the touched regions (the four pre-existing diffs elsewhere in the tree are unchanged by this branch).

approve_submission was the only state transition in campaign-escrow that
mutated an application without publishing a typed event. Off-chain
consumers had no way to observe a business accepting a proof: they either
waited for the eventual PaymentReleased once the creator happened to claim,
or polled get_application for every pending submission to notice the
proof_approved flip.

Add a SubmissionApproved { campaign_id, creator } event mirroring the shape
and derives of its sibling SubmissionRejected, and publish it from
approve_submission after the application is persisted, so the event is only
emitted on the success path.

Tests cover that the event is published with the correct campaign_id and
creator, and that approving one creator's submission does not emit an event
naming another creator on the same campaign.
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.

feat: approve_submission emits no event, breaking off-chain indexing of proof approvals

1 participant