feat(campaign-escrow): emit SubmissionApproved from approve_submission - #77
Open
Ogstevyn wants to merge 1 commit into
Open
feat(campaign-escrow): emit SubmissionApproved from approve_submission#77Ogstevyn wants to merge 1 commit into
Ogstevyn wants to merge 1 commit into
Conversation
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.
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 #62
Problem
approve_submissionwas the only meaningful state transition incampaign-escrowthat mutated an application and returned without publishing a typed event. Its siblingreject_submissionpublishesevents::SubmissionRejectedon the equivalent transition, andevents.rsdefines 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
PaymentReleasedonce the creator happens to claim, or it has to pollget_applicationfor every pending submission on every campaign to notice theproof_approvedflip. 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: addSubmissionApproved { campaign_id, creator }, placed next toSubmissionRejectedand mirroring its shape, derives, and#[topic]annotations, so both topics are indexable the same way.contracts/campaign-escrow/src/lib.rs: publish it fromapprove_submission, afterstorage::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_eventsmodule incontracts/campaign-escrow/src/test.rs:approve_submission_emits_submission_approveddrives a creator toProofSubmitted, callsapprove_submission, and asserts the last event published by the contract equalsSubmissionApproved { campaign_id, creator }.to_xdr(...)— which compares topics and data, not just the event name.submission_approved_identifies_the_approved_creatorputs two creators on one campaign inProofSubmitted, 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-targetsis clean, andcargo fmt --checkreports no diffs in the touched regions (the four pre-existing diffs elsewhere in the tree are unchanged by this branch).