Comments (17)
We already have a functionality for that (it's there for few months). See this documentation, or on our new website.
Few weeks ago we integrated that mechanism into the generated project (algob init
).
Let me know if you have a suggestion how to make it better.
from algo-builder.
I am not quite sure that is what I am looking for although I may not fully understand.
Can you provide the PyTEAL code for an example? I am looking at https://github.com/scale-it/algo-builder/blob/master/examples/htlc-pyteal-ts/assets/htlc.py but that does not use the Tmpl
expression so it does not compile if no params are passed
from algo-builder.
This is what I am looking to use https://pyteal.readthedocs.io/en/latest/api.html?highlight=Tmpl#pyteal.Tmpl
from algo-builder.
I didn't know about TMPL
type and never used it. Could you share an example? Why do you need to use TMPL, and why our htlc.py example doesn't solve your need?
from algo-builder.
What is nice about Tmpl
is that you can compile PyTEAL code without knowing certain values. Eg Tmpl.Int('TMPL_UNKNOWN)
will compile to TEAL int TMPL_UNKNOWN
. This is very useful when you want to compile PyTEAL when you don't know certain values.
For my use case I don't know certain values until I receive a client side request to my server with the values. At that point I can replace TMPL_UNKNOWN
with the value provided.
Everytime I want to copy my smart contracts that I have written in algo-builder
over to my server I need to either:
- in PyTEAL manually replace all the params with
Tmpl
- compile to TEAL and replace the default values with
TMPL_<NAME>
.
I need to do this for over 100 variables which is very tedious.
from algo-builder.
hmm, we can have a special rules in parseTemp
:
- if a parameter name starts with
templ_int
then the parseTemp will useInt
wrapper - if a parameter name starts with
templ_addr
then the parseTemp will useAdd
wrapper
from algo-builder.
I am not quite sure that is what I am looking for although I may not fully understand.
Can you provide the PyTEAL code for an example? I am looking at https://github.com/scale-it/algo-builder/blob/master/examples/htlc-pyteal-ts/assets/htlc.py but that does not use the
Tmpl
expression so it does not compile if no params are passed
Hi @gidonkatten Suppose
params values are unknown and we can use them only when client gives us,
so in our program we can set these values as some mock values,
params = {
"bob": "2ILRL5YU3FZ4JDQZQVXEZUYKEWF7IEIGRRCPCMI36VKSGDMAS6FHSBXZDQ",
"alice": "EDXG4GGBEHFLNX6A7FGT3F6Z3TQGIU6WVVJNOXGYLVNTLWDOCEJJ35LWJY",
"hash_image": "QzYhq9JlYbn2QdOMrhyxVlNtNjeyvyJc/I8d8VAGfGc=",
"timeout": 3001
}
-
- Once client enters these values
- From the script:
/// client inputs some values
const scTmplParams = { bob: client_values0, alice: client_values1, hash_image: client_values2 };
await deployer.fundLsig('htlc.py',
{ funder: bob, fundingMicroAlgo: 2e6 }, {fee: 1000}, scTmplParams);
When we pass these values to fundLsig
, this will automatically replace placeHolder values with the client_values when compiling to TEAL.
Note: For exact key match the code replaces its value while compiling to TEAL. so bob
key-value in params
is replaced with bob
key-value in scTmplParams
from algo-builder.
does this solve your problem ?
from algo-builder.
At the moment my server and my algo builder projects are in seperate repositories. My server is using NodeJSm
I would have to try to see if it would work. Would I be able to compile the PyTeal to TEAL and then submit to MainNet?
from algo-builder.
To me it would make match more sense to support the Tmpl
expression in algo-builder and be able to replace them when testing, as that is already used by PyTeal.
from algo-builder.
To me it would make match more sense to support the
Tmpl
expression in algo-builder and be able to replace them when testing, as that is already used by PyTeal.
yes, i am looking into Tmpl how it exactly works,
I think it only places values suppose TMPL_UNKNOWN
and then we have to do search and replace manually
from algo-builder.
At the moment my server and my algo builder projects are in seperate repositories. My server is using NodeJSm
I would have to try to see if it would work. Would I be able to compile the PyTeal to TEAL and then submit to MainNet?
yes, TEAL code you will get will have replaced values.
from algo-builder.
To me it would make match more sense to support the
Tmpl
expression in algo-builder and be able to replace them when testing, as that is already used by PyTeal.yes, i am looking into Tmpl how it exactly works,
I think it only places values supposeTMPL_UNKNOWN
and then we have to do search and replace manually
Yes I do one pass through the TEAL code and use the replace
function to substitute the values.
from algo-builder.
This is what we want to implement in the next sprint:
PyTEAL has TMPL
expression which creates a placeholder in the generate TEAL. That placeholders have to be substituted later on.
Let's extend our smart contract loader to find and substitute that generates code:
- if a
scTmplParams?: SCParams
parameter starts withtmpl_
then it won't be passed to PyTEAL. Instead the code loader will use it to search for smart contract template variables and substitute it using string replace function.
@gidonkatten - what do you think?
from algo-builder.
@robert-zaremba I don't really understand the proposed solution.
What would the PyTEAL code look like when you have a parameter that starts with tmpl_
?
from algo-builder.
@gidonkatten we won't change the PyTEAL code. It will be a feature between TEAL and the compiled code.
- (only when using PyTEAL) compile PyTEAL to TEAL.
- In TEAL substitute all
TMPL_<NAME>
totmpl_<name>
from parameters. - compile the updated TEAL.
from algo-builder.
Okay that makes sense, I think that would be a good solution.
from algo-builder.
Related Issues (20)
- Add support `loadLogic` for *.teal program and SCParams HOT 3
- Contract to contract call HOT 2
- Unable to compile contracts on Windows machine HOT 11
- Mocha printing "ASA file not defined" HOT 2
- Rename optIntoASA to optInToASA HOT 2
- Getting warning for opt out of asset transaction in Mocha
- Allow `getProgram` to compile files outside of assets directory HOT 4
- Txn.asset_sender() gives different values in runtime and TestNet HOT 4
- RUNTIME_ERR1003: Type of data is incorrect. Expected unsigned integer (upto 64 bit) but got 0 HOT 7
- ABI support HOT 3
- TEAL 7 makes runtime fail HOT 4
- Improve runtime debug output for contract-to-contract calls
- Minimal interactive debugger for runtime HOT 1
- Overwritting parameter from algobuilder script to Pyteal programe with deployer.mkDelegatedLsig HOT 3
- [Yarn workspaces config] Cannot find module '@algo-builder/web' or its corresponding type declarations. HOT 4
- Error: RUNTIME_ERR1500: Invalid ASA definition: Total must be a positive number and smaller than 2^64-1 HOT 2
- Algob deploy not working HOT 7
- InnerTxn does not have 'foreignAssets' field HOT 1
- Invalid value "" for config.networks.testnet.token - Expected a value of type string (with length > 10). HOT 2
- Cannot find module 'findup-sync' in runtime package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algo-builder.