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

Map struct encoding #129

Closed
wants to merge 4 commits into from
Closed

Conversation

rjharmon
Copy link
Contributor

STILL a WIP (see add'l comment below). Merge after #127, which comes after #128.

Helios up until v0.17.0.93 allowed definition of a string-mapped struct (aka mStruct) in this form

struct MyStructDef {
  name: String
  description: String
  otherField: Int
}

This was encoded as a ConstrData(0, MapData), and it worked fine when a script's Datum was itself defined as an mStruct such as this myStructDef, and not an enum with a variant having field1: mStruct. Using that definition inside an enum variant would produce a second layer of ConstrData.

This change establishes:

  • Datum enum variants with field1 as an mStruct will match the CIP-68 requirements (the Enum's ConstrData element provides that aspect of the requirement)
  • Use of an mStruct in any position does no longer have a ConstrData wrapper, because it would be redundant

This represents a behavioral change versus version 0.16 (which expects a ConstrData in all cases when decoding an mStruct). Developers using such a struct as their Datum can continue getting CIP-68-compliant encoding by changing to an enum:

enum Datum {
  ForCip68 {
    data: MyStructDef
    version: String
    extraData: <any type>
}

@rjharmon
Copy link
Contributor Author

As mentioned, this is still a work in progress; I had difficulty identifying the right changes to make in the IR for the mStruct to pass the on-chain is_valid_data check, given removal of the ConstrData wrapper.

It could use a couple more tests as well.

.pre-push-hook Outdated Show resolved Hide resolved
jsconfig.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Contributor Author

@rjharmon rjharmon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes to clarify things for you (and reminders to me)

prepush.excalidraw.svg Outdated Show resolved Hide resolved
src/expressions/Expr.js Outdated Show resolved Hide resolved
src/parse/parseTypeExpr.js Outdated Show resolved Hide resolved
src/parse/parseDataFields.js Outdated Show resolved Hide resolved
src/scopes/Scope.js Outdated Show resolved Hide resolved
test/struct.test.js Outdated Show resolved Hide resolved
test/utils.js Outdated Show resolved Hide resolved
src/parse/parseStructStatement.js Outdated Show resolved Hide resolved
test/utils.js Outdated Show resolved Hide resolved
 - moves Cip68 support to developer side (use enum::Variant{data: mStruct})
 - combines earlier commits into one
Randall added 3 commits October 1, 2024 16:03
 - undo attempt to export test/utils.js
 - moved pre-push-hook install out of "post-install"
   (was happening at downstream client-install time)
   ... added to before-tests to make it more likely to happen magically
 - removed .only modifiers on test cases
@christianschmitz
Copy link
Contributor

Closing this particular PR because this work has been merged as part of #130 instead

@rjharmon
Copy link
Contributor Author

rjharmon commented Oct 6, 2024

just as hoped, thanks!

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