Coder Social home page Coder Social logo

Support PyTEAL Tmpl about algo-builder HOT 17 CLOSED

scale-it avatar scale-it commented on June 9, 2024
Support PyTEAL Tmpl

from algo-builder.

Comments (17)

robert-zaremba avatar robert-zaremba commented on June 9, 2024

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.

gidonkatten avatar gidonkatten commented on June 9, 2024

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.

gidonkatten avatar gidonkatten commented on June 9, 2024

This is what I am looking to use https://pyteal.readthedocs.io/en/latest/api.html?highlight=Tmpl#pyteal.Tmpl

from algo-builder.

robert-zaremba avatar robert-zaremba commented on June 9, 2024

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.

gidonkatten avatar gidonkatten commented on June 9, 2024

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.

robert-zaremba avatar robert-zaremba commented on June 9, 2024

hmm, we can have a special rules in parseTemp:

  • if a parameter name starts with templ_int then the parseTemp will use Int wrapper
  • if a parameter name starts with templ_addr then the parseTemp will use Add wrapper

from algo-builder.

amityadav0 avatar amityadav0 commented on June 9, 2024

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.

amityadav0 avatar amityadav0 commented on June 9, 2024

does this solve your problem ?

from algo-builder.

gidonkatten avatar gidonkatten commented on June 9, 2024

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.

gidonkatten avatar gidonkatten commented on June 9, 2024

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.

amityadav0 avatar amityadav0 commented on June 9, 2024

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.

amityadav0 avatar amityadav0 commented on June 9, 2024

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.

gidonkatten avatar gidonkatten commented on June 9, 2024

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

Yes I do one pass through the TEAL code and use the replace function to substitute the values.

from algo-builder.

robert-zaremba avatar robert-zaremba commented on June 9, 2024

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 ascTmplParams?: SCParams parameter starts with tmpl_ 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.

gidonkatten avatar gidonkatten commented on June 9, 2024

@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.

robert-zaremba avatar robert-zaremba commented on June 9, 2024

@gidonkatten we won't change the PyTEAL code. It will be a feature between TEAL and the compiled code.

  1. (only when using PyTEAL) compile PyTEAL to TEAL.
  2. In TEAL substitute all TMPL_<NAME> to tmpl_<name> from parameters.
  3. compile the updated TEAL.

from algo-builder.

gidonkatten avatar gidonkatten commented on June 9, 2024

Okay that makes sense, I think that would be a good solution.

from algo-builder.

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.