Giter Site home page Giter Site logo

Comments (2)

fergalwalsh avatar fergalwalsh commented on August 21, 2024

I think there are 3 levels where template substitution can be used:

  1. Tealish
  2. Teal
  3. Bytecode

So far I have been doing it at the bytecode level. For example in Tinyman we have logicsigs per pool. These are generated from a template and the asset ids are inserted by replacing specific bytes of the bytecode. It works this way so that the frontend can generate the final logicsig without needing to compile Teal.

I understand in your case you currently have a single PyTeal file which compiles to a single Teal file but then at assembly time you generate specific Teal files with the values before assembling.

In theory you could also replace the values in the PyTeal/Tealish before compiling to Teal but I assume there is a reason you prefer to do the replacement at the Teal level?

Supporting this would require accepting TMPL_ prefixed names in places that expect int or byes. I'd be tempted to restrict this to const declarations. E.g. const int APP_ID = TMPL_APP_ID. Would that work for you? With #49 that would result in the following Teal #define APP_ID TMPL_APP_ID.

from tealish.

pbennett avatar pbennett commented on August 21, 2024

For me at least, constants would be fine as my templates are explicitly for network-specific asset and application IDs.
I also do bytecode manipulation for LSIGs in the backend, but deployed Smart-Contracts doing the same thing would also do it using the template technique as the deployed smart-contract would need to vary from network to network.
Generically, because the templates are like constants in their use - I don't see how your constant eg wouldn't work fine for pretty much all cases.

I do it at the teal level because the pyteal/beaker/tealish/.. -> TEAL compilation step is part of a 'contract build'. The output should be stable (recreating them should always compile to the same teal) and doesn't vary from environment to environment.

The output of that feeds into another repo which has those teal files as part of their build process - with the TEAL being directly compiled into the backend infra - whether for system tests (substituting just created IDs in a sandbox environment for eg) or for production with values pulled from bootstrapped data specific to each deployment.

from tealish.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.