sui icon indicating copy to clipboard operation
sui copied to clipboard

move: extracting visitor

Open amnn opened this issue 4 months ago • 1 comments

Description

Introduce a visitor that can extract a value from some sub-structure, by using a path of Elements to find the sub-structure and then delegating to another visitor to deserialize it.

This can be used as a building block in other visitors. It will be used to replace existing logic to create GraphQL representations of Move Values, and also to expose functionality to extract sub-values in the GraphQL schema.

Paths work by either selecting some sub-structure (by field name, or offset), or filtering on that sub-structure's type (or variant name, if it is an enum variant). Offsets work for selecting elements of vectors, but also fields in structs and variants, this is to simplify the process of describing the location of a field in a positional struct/variant without leaking how its field names are generated.

There is no affordance for selecting multiple values, to avoid introducing a complicated return value representation: The extractor either produces Ok(Some(v)) if the path exists and the inner visitor succeeds, None if the path is not found or some error if the path is found but the inner visitor failed.

Test plan

New unit tests for this functionality

move-core-types$ cargo nextest run -- extractor_test

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • [ ] Protocol:
  • [ ] Nodes (Validators and Full nodes):
  • [ ] Indexer:
  • [ ] JSON-RPC:
  • [ ] GraphQL:
  • [ ] CLI:
  • [ ] Rust SDK:
  • [ ] REST API:

amnn avatar Oct 07 '24 18:10 amnn