Skip to content
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

Add snap_getState, snap_setState, snap_clearState methods #2916

Merged
merged 31 commits into from
Dec 18, 2024

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Nov 29, 2024

snap_manageState is currently the only way to manage state in a Snap. We added it as a single method initially, because it was complicated to add separate methods with a single permission. In addition, snap_manageState only supports operations on the entire state, it's not possible to get or set partial state.

Instead, I've added new methods, which will eventually replace snap_manageState. The snap_getState and snap_setState methods accept an optional key, which can be an object property-style key (e.g., some.nested.value), and returns or updates the value at that location in the state. This makes it possible to do partial updates, or receive a small part of the state easily.

Currently these methods require the snap_manageState permission. In the future (when we remove snap_manageState) this could be replaced by an endowment.

@Mrtenz Mrtenz force-pushed the mrtenz/state-methods branch 2 times, most recently from b620e54 to 0e32390 Compare December 10, 2024 13:08
@Mrtenz Mrtenz marked this pull request as ready for review December 18, 2024 15:04
@Mrtenz Mrtenz requested a review from a team as a code owner December 18, 2024 15:04
@Mrtenz Mrtenz merged commit 1e16931 into main Dec 18, 2024
166 checks passed
@Mrtenz Mrtenz deleted the mrtenz/state-methods branch December 18, 2024 18:25
Mrtenz added a commit that referenced this pull request Dec 19, 2024
)

This adds support for the state methods introduced in #2916 to
`snaps-simulation` (and `snaps-jest`), and updates the example to test
these methods as well.

## Breaking changes

- The middleware hooks in `snaps-simulation` were separated into two
separate types, `PermittedMiddlewareHooks` and
`RestrictedMiddlewareHooks`.
- The `MiddlewareHooks` type was removed.
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.

2 participants