hirosystems / stacks-subnets

Stacks Subnets: a layer-2 scaling solution for Stacks, intended for high-throughput, low-latency workloads
http://docs.hiro.so
GNU General Public License v3.0
52 stars 13 forks source link

Generate Clarity contracts from templates #301

Closed jbencin closed 1 year ago

jbencin commented 1 year ago

The Clarity contracts in this repository require slight changes depending on where they are deployed (mainnet/testnet/devnet/etc.). Currently this requires manual file edits, which is time consuming and error prone. I plan on using a Mustache templating engine (the Ruby implementation) to achieve this.

obycode commented 1 year ago

Why Ruby? I'd prefer if we stuck with Rust and put it inside our existing tools, e.g. it could be in the stacks-inspect binary. This should be renamed to subnet-inspect and could have other useful subnet features added to it.

jbencin commented 1 year ago

Why Ruby?

Because doing it in Rust requires writing code, whereas the Ruby implementation provides a standalone binary. There is a Rust library for Mustache here, but it's not a complete binary, so would require writing some code to read the template files, read in data files, and then output the results. I suppose we should do that eventually if this works out, but I'd like to skip that for now to get a proof of concept working

diwakergupta commented 1 year ago

FWIW this seems like a more generic problem that something like Clarinet might solve (vs. a subnets specific solution). And if we're going with templating, I agree we should avoid introducing new languages / tools if we can. How about handlebars?

cc/ @lgalabru @hugocaillard

hugocaillard commented 1 year ago

Sounds like something we could re-use in the no code project as well

jbencin commented 1 year ago

FWIW this seems like a more generic problem that something like Clarinet might solve

I was thinking I'd share this with the rest of the team after I got a proof of concept working. Subnets is a good test case because we have a few contracts we have to keep in sync. It would also be nice to get some sort of IDE or syntax highlighting support for this

How about handlebars?

This looks similar to and largely compatible with Mustache. One thing I don't like about Handlebars though is that it does HTML escaping by default. If this catches on, we'd want to integrate it into Clarinet instead of using a separate tool, and Rust has libraries for both.

jbencin commented 1 year ago

@obycode @kantai Do you think there is any need for the runtime version checks (in multi-miner.clar and in the node) once all the version references are derived from a single canonical source using templates? That would let us remove some code and simplify the templating as well

kantai commented 1 year ago

Yes -- I think we still want runtime version checks. Redundancy there makes sense because version mismatches can be pretty hard to diagnose.

On the topic of templating-- I'd favor handlebars over mustache, because handlebars seems more active (last release in handlebars was 2022, last release in mustache was 2015). But ultimately, I'd defer to clarinet folks on this: whether it's easier to integrate a rust library or invoke a binary probably makes a big difference in terms of choice. If invoking a binary is easy, I'd favor using the jinja CLI -- it's overkill for a lot of clarity use cases, but it's very well supported (whereas handlebars and mustache appear less so).

jbencin commented 1 year ago

One thing I don't like about Handlebars though is that it does HTML escaping by default

I just found out that Mustache does this also, so I'll prefer Handlebars over it now

blockstack-devops commented 1 year ago

:tada: This issue has been resolved in version 0.8.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: