Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Clarity Tweaks to Python sample
Browse files Browse the repository at this point in the history
  • Loading branch information
rfustino committed Sep 15, 2022
1 parent 8bbc6c7 commit 0bbfbb8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions contracts/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def transfer(self, axfer: abi.AssetTransferTransaction, asset: abi.Asset):
# Change the method signature to specify that it wants an asset reference instead
# of the Uint64 and get its id using `.asset_id` instead of `.get`.
# See above for examples.

# Create group transaction to send asset and call method
# If you need to modify the contract logic, make sure the virtualenv is active and run:
# ```
# (.venv)$ cd contracts
# (.venv)$ python application.py
# ```
# This will overwrite the teal programs and contract json file.

@external
def withdraw(self, asset: abi.Uint64):
"""withdraw allows 1 unit of the asset passed to be sent to the caller
Expand All @@ -59,6 +68,14 @@ def withdraw(self, asset: abi.Uint64):
"""
return self.send_asset(asset.get(), Int(1), Txn.sender())

# @external
# def withdraw(self, asset: abi.Asset):
# """withdraw allows 1 unit of the asset passed to be sent to the caller
# Args:
# asset: The asset we're set up to handle
# """
# return self.send_asset(asset.asset_id(), Int(1), Txn.sender())

@internal(TealType.none)
def send_asset(self, id, amt, rcv):
"""send asset handles executing the inner transaction to send an asset"""
Expand Down
7 changes: 4 additions & 3 deletions py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def main():
except Exception as e:
le = LogicException(e, approval_program, approval_map)
print(
f"A Logic Exception was encountered: '{le.msg[:15]}...'\n\t{le.trace()}\n"
f"A Logic Exception was encountered: '{le.msg[:40]}...'\n\t{le.trace()}\n"
)
perform_dryrun(atc, algod_client)
return
Expand Down Expand Up @@ -92,12 +92,13 @@ def main():
except Exception as e:
le = LogicException(e, approval_program, approval_map)
print(
f"A Logic Exception was encountered: '{le.msg[:15]}...'\n\t{le.trace()}\n"
f"A Logic Exception was encountered: '{le.msg[:55]}...'\n\t{le.trace()}\n"
)
perform_dryrun(atc, algod_client)
return

# Create group transaction to send asset and call method
# See TODO in contracts/application.py
atc = AtomicTransactionComposer()
atc.add_method_call(
app_id,
Expand All @@ -112,7 +113,7 @@ def main():
except Exception as e:
le = LogicException(e, approval_program, approval_map)
print(
f"A Logic Exception was encountered: '{le.msg[:15]}...'\n\t{le.trace()}\n"
f"A Logic Exception was encountered: '{le.msg[:50]}...'\n\t{le.trace()}\n"
)
perform_dryrun(atc, algod_client)
return
Expand Down

0 comments on commit 0bbfbb8

Please sign in to comment.