entropyxyz / programs

Source, toolchain, and examples for using programs on Entropy
https://docs.entropy.xyz/concepts/programs/
GNU Affero General Public License v3.0
19 stars 3 forks source link

Add `generate-types` crate #63

Closed JesseAbram closed 5 months ago

JesseAbram commented 5 months ago

Adds a generate type crate that can help generate config and aux types

vercel[bot] commented 5 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
programs ❌ Failed (Inspect) Mar 26, 2024 3:09pm
JesseAbram commented 5 months ago

Okay so I see the intention in this PR, but I think we can improve this. My high level suggestions here:

Let's get rid of the generate-types crate. Instead if we want to show people in this repo how to get the type definitions we can: add an example Rust code snippted to the README, add a doc-test to the examples, or a normal test in the examples.

Let's add the actual generation to the test-cli in the Core repo (schemar annotations are fine here). There we can add CLI options for outputing the JSON schema formatted data, or hex-bytes depending on what the user prefers.

This should give us a more robust and usable solution that can be used across all programs, not just one specific example program.

but the test cli does only feeds in the compiled wasm (which requires the serialized types at chain upload time) you can't get the needed types from the bytecode. As well I agree this is not perfect, the whole flow kinda sucks. We should have a package you can pull down to write a program and autogenerate the template code, that should also have a generate types functions, that I think is doable but takes a lot of steps. IMO this is a good incremental step before that, which tests out the thesis and moves us along

ameba23 commented 5 months ago

I haven't got around to looking at this in detail but it looks good.

One thing we could do to encourage people to use this is add schemars to the Cargo.toml of the cargo-generate template: https://github.com/entropyxyz/programs/tree/master/templates/basic-template

Possibly we could also include the function there from generate-types/src/main.rs so that people can build the schemas right out of the box with their own program. But im not sure if we could have a main fn there without it meddling with building the program itself.

It would be cool if there was some way to make the generic-types crate more generic - as in have a way of specifying what program you want it to build from without manually changing the code. But i can't think of a way to do that.

JesseAbram commented 5 months ago

I haven't got around to looking at this in detail but it looks good.

One thing we could do to encourage people to use this is add schemars to the Cargo.toml of the cargo-generate template: https://github.com/entropyxyz/programs/tree/master/templates/basic-template

Possibly we could also include the function there from generate-types/src/main.rs so that people can build the schemas right out of the box with their own program. But im not sure if we could have a main fn there without it meddling with building the program itself.

It would be cool if there was some way to make the generic-types crate more generic - as in have a way of specifying what program you want it to build from without manually changing the code. But i can't think of a way to do that.

totally agreed, I know this is only a half step, maybe a macro to do it automatically or something, but either way dev ex here is way lacking, in fact this repo should not be used at all to make programs, there should be a cargo init and it have a template with this, not exactly sure, for me this is a half measure until we figure out a full devex plan

JesseAbram commented 5 months ago

Looks great - assuming generating schemas for a template works - i haven't tried it.

I have lol, super unfun to test

As i said in other comment, i would keep the program itself top-level, and have just one readme, which can include the instructions for generating types. I guess we can put more details about what you should actually do with these schemas when you want to publish a program in a separate PR once its possible to do that from the SDK or some other programs build tool. I guess eventually we'll have something which compiles the program, generates the schemas and bundles it all into a set_program extrinsic.

Pretty much what I was thinking, the generate can be its whole own tool that can take someone from cargo generate to deploy