essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
14 stars 0 forks source link

Change `pint-abi-gen` to construct keys for storage/pub-vars programmatically #762

Closed mitchmindtree closed 1 month ago

mitchmindtree commented 2 months ago

Opening a dedicated issue for the approach originally described here: https://github.com/essential-contributions/pint/issues/752#issuecomment-2212460367.

we could potentially remove the key from the ABI output altogether if we standardise and document how storage type nesting maps to key construction. E.g.

  • Top-level storage "fields" are prefixed by a single word field index.
  • Array elements are prefixed by a single word array index.
  • Tuple elements are prefixed by a single word tuple index.
  • Map entries are prefixed by the map key encoded as words.

This might also make it a bit easier to support dynamically sized keys (e.g. strings or byte arrays) in the future, as the current key representation in the ABI output (Vec<Option<Key>> with Nones for map keys) can't support unknown sized keys.

@mohammadfawaz pointed out that we will likely want to continue flattening tuples and arrays. While these complicate the rules slighlty, it should still be doable as long as the necessary context required for flattening is provided during traversal.

Steps

These changes will also help to separate the concept of keys (which can sometimes be flattened) from the concept of type nesting which is required for human-readable API generation that matches the user's storage/pub var declarations.