algorand / pyteal

Algorand Smart Contracts in Python
https://pyteal.readthedocs.io
MIT License
285 stars 131 forks source link

Update signature deploy examples #30

Open jasonpaulos opened 4 years ago

jasonpaulos commented 4 years ago

Summary

Currently the examples for deploying signature mode smart contracts call goal directly. They would be more helpful if they used the Python SDK, since it can now support calling the compile endpoint.

Scope

Need to update examples/signature/periodic_payment_deploy.py and examples/siguature/recurring_swap_deploy.py and test that they still work correctly.

Urgency

These are the only examples of how to deploy stateless PyTeal smart contracts, so it would help developers if they used the current best practices. That being said, more of a nice-to-have. Not much of a blocker currently

waltergaldamez commented 3 years ago

I am interested in contributing to this. I see that these files under "Scope" contain the string "goal" within a list, passed as a parameter into an execute() function. From my understanding, this needs to be changed. Do you have a proposed solution or a pointer to how I can know how to solve this?

jasonpaulos commented 3 years ago

The execute function no longer exists, but it used to be here: https://github.com/algorand/pyteal/blob/5c22a45de9a4ae4886db3ab0f355d51ec5a159f7/pyteal/util.py#L115

Instead of using the CLI tool goal, the examples should use the v2 algod client from the Python SDK (from algosdk.v2client import algod). examples/application/vote_deploy.py has already been updated to do this. For example, this function is equivalent to invoking goal clerk compile: https://github.com/algorand/pyteal/blob/8ad44a4fa1f1984a6cd3d6ea9710106319120104/examples/application/vote_deploy.py#L21

You may find the Algorand Python SDK documentation useful: https://py-algorand-sdk.readthedocs.io/en/latest/

waltergaldamez commented 3 years ago

So, currently execute is assigned to stdout, stderr which invoke print statements. Looking at the example you linked, it looks like there is no stdout, stderr variables and no print statements. Is this logic taken care of in the Algod.compile() function? Furthermore, the file examples/signature/recurring_swap_deploy.py is executing more than just the goal command. There is algokey generate and algokey export as well being executed using the no longer existing execute() function. Does this need to be changed as well?

jasonpaulos commented 3 years ago

The Algod.compile() function sends the program to an algod node to be compiled, in comparison to directly invoking the command line program goal clerk compile. See this link for more information: https://developer.algorand.org/docs/features/asc1/stateless/sdks/#compiling-teal-program-from-sdks

algokey generate and algokey export can be replaced by the function generate_account, see https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/account.html#algosdk.account.generate_account

Also, either of the functions teal_sign or teal_sign_from_program should be used in favor of goal clerk tealsign, see https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/logic.html#algosdk.logic.teal_sign

uday7981 commented 1 year ago

Is this issue still open?