Replies: 2 comments
-
I think there are 3 levels where template substitution can be used:
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 |
Beta Was this translation helpful? Give feedback.
-
For me at least, constants would be fine as my templates are explicitly for network-specific asset and application IDs. 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. |
Beta Was this translation helpful? Give feedback.
-
My infra works with raw teal, so I use beaker, pyteal, etc. to generate TEAL that's checked-in and built directly into binaries or part of a bootstrapping process.
That raw teal includes 'template' substitutions that are replaced with values specific to each environment (testnet / mainnet contract IDs, or parameter values for eg).
In PyTeal, a reference to a templated int (same w/ Bytes) might be like:
xxx.store( Itob(Tmpl.Int("TMPL_XXX")) )
which might become:
in TEAL. My code converts that prior to compilation, replacing the templates in descending length order.
This is one of the showstoppers for me in using Tealish.
Beta Was this translation helpful? Give feedback.
All reactions