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

feat(cli): add prototypes to tablegen #459

Closed
wants to merge 23 commits into from
Closed

feat(cli): add prototypes to tablegen #459

wants to merge 23 commits into from

Conversation

dk1a
Copy link
Contributor

@dk1a dk1a commented Mar 4, 2023

A prototype is a collection of tables with the same primaryKeys
You can use it to set/delete all tables with one method.
Default values are a bit clunky and don't work well with dynamic fields. I'm not yet sure how useful they will be.
Also a helper to get all tableIds, which can be used by a Prototype table and LibPrototype to dynamically copy prototypes (but these aren't a part of this PR)

also adds minor improvements, in particular storeArgument for all relevant methods and a new shorthand schema: SchemaType....

@dk1a dk1a mentioned this pull request Mar 4, 2023
47 tasks
@dk1a dk1a marked this pull request as ready for review March 9, 2023 01:15
@dk1a dk1a requested review from alvrs and holic as code owners March 9, 2023 01:15
Copy link
Member

@alvrs alvrs left a comment

Choose a reason for hiding this comment

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

Didn't review in-depth yet, but looks good on first sight! Could you add an integration/example branch to v2sandbox to illustrate this change?

Copy link
Member

@holic holic left a comment

Choose a reason for hiding this comment

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

(oops, forgot to submit this review)

*
* The string is rendered in solidity as-is, unescaped and without adding quotes
*/
default?: string | Record<z.input<typeof ColumnName>, string>;
Copy link
Member

Choose a reason for hiding this comment

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

Not blocking but I wonder if we could refine this based on what field/types were defined in the TableConfig corresponding to the table name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'd prefer it to be typed, but that's complicated and would kinda use a lot of v2 networking/schema-type stuff, which I'd rather take/generalize later than reimplement now. It's also not a very important feature and I have some doubts about its usefulness

packages/cli/src/render-solidity/common.ts Outdated Show resolved Hide resolved
@dk1a
Copy link
Contributor Author

dk1a commented Mar 15, 2023

ready for review

see https://github.com/latticexyz/v2sandbox/tree/dk1a/prototypes for some examples (they're real prototypes from 3 mud games)

v2sandbox doesn't have tests, I just tested that it all compiles (prototypes there are too complicated. It would be useful to add complex tests later though, when prototypes are more stable).
cli itself has some create/destroy tests for simple prototypes.

@@ -188,9 +173,9 @@ library SchemaLib {
return Schema.unwrap(schema) == bytes32(0);
}

function validate(Schema schema) internal pure {
function validate(Schema schema, bool allowEmpty) internal pure {
Copy link
Contributor Author

@dk1a dk1a Mar 15, 2023

Choose a reason for hiding this comment

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

this is needed to allow empty keys for singletons (I add a test for a prototype of singletons in this PR)

@dk1a
Copy link
Contributor Author

dk1a commented Mar 16, 2023

closing in favor of #500

@dk1a dk1a closed this Mar 16, 2023
@dk1a dk1a deleted the dk1a/tablegen-4 branch May 9, 2023 16:25
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.

3 participants