-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(store): emit event after calling beforeSetRecord hook [L-02] #2017
Conversation
🦋 Changeset detectedLatest commit: ea87f34 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, let's just remove the unrelated docs changes, add a changeset, and update the gas report
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized we also need to apply this change to the deleteRecord
function
// Emit event to notify indexers | ||
emit Store_DeleteRecord(tableId, keyTuple); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also need to move the early return for offchain tables below the event emission, otherwise there is no event emitted for offchain tables (and the onBefore hook is not triggered)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a test for this to make sure we don't regress?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a couple tests
Rearranges
setRecord
,spliceStaticData
, and_spliceDynamicData
inStoreCore
to emit the storage event after calling thebeforeSetRecord
hook, ensuring that storage events are emitted in the same order that values are stored on-chain.An important side-effect is that off-chain tables also early return after the hook, which means they can now use theEDIT: registering before hooks for offchain tables is explicitly not allowed so this is a no-opbeforeSetRecord
hook. I think this is okay because hooks do not necessarily need to read the current storage; they can just react to the new value.