Skip to content

Workshop submission with GitHub Box Storage and Testnet Deployment #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -4,23 +4,39 @@
// smart_contracts.personal_bank.contract.PersonalBank.__algopy_entrypoint_with_init() -> uint64:
main:
intcblock 1 0
bytecblock 0x151f7c75
bytecblock 0x151f7c75 0x676974687562
// smart_contracts/personal_bank/contract.py:5
// class PersonalBank(ARC4Contract):
txn NumAppArgs
bz main_bare_routing@7
pushbytess 0x3298e7c0 0x3a395f2b // method "deposit(pay)uint64", method "withdraw()uint64"
bz main_bare_routing@8
pushbytess 0xd822ffef 0x3a395f2b 0x62b8318d // method "deposit(pay,string)uint64", method "withdraw()uint64", method "get_box()string"
txna ApplicationArgs 0
match main_deposit_route@5 main_withdraw_route@6
match main_deposit_route@5 main_withdraw_route@6 main_get_box_route@7

main_after_if_else@9:
main_after_if_else@10:
// smart_contracts/personal_bank/contract.py:5
// class PersonalBank(ARC4Contract):
intc_1 // 0
return

main_get_box_route@7:
// smart_contracts/personal_bank/contract.py:72
// @abimethod()
txn OnCompletion
!
assert // OnCompletion is not NoOp
txn ApplicationID
assert // can only call when not creating
callsub get_box
bytec_0 // 0x151f7c75
swap
concat
log
intc_0 // 1
return

main_withdraw_route@6:
// smart_contracts/personal_bank/contract.py:42
// smart_contracts/personal_bank/contract.py:49
// @abimethod()
txn OnCompletion
!
@@ -37,7 +53,7 @@ main_withdraw_route@6:
return

main_deposit_route@5:
// smart_contracts/personal_bank/contract.py:15
// smart_contracts/personal_bank/contract.py:20
// @abimethod()
txn OnCompletion
!
@@ -54,7 +70,8 @@ main_deposit_route@5:
intc_0 // pay
==
assert // transaction type is pay
// smart_contracts/personal_bank/contract.py:15
txna ApplicationArgs 1
// smart_contracts/personal_bank/contract.py:20
// @abimethod()
callsub deposit
itob
@@ -65,52 +82,52 @@ main_deposit_route@5:
intc_0 // 1
return

main_bare_routing@7:
main_bare_routing@8:
// smart_contracts/personal_bank/contract.py:5
// class PersonalBank(ARC4Contract):
txn OnCompletion
bnz main_after_if_else@9
bnz main_after_if_else@10
txn ApplicationID
!
assert // can only call when creating
intc_0 // 1
return


// smart_contracts.personal_bank.contract.PersonalBank.deposit(pay_txn: uint64) -> uint64:
// smart_contracts.personal_bank.contract.PersonalBank.deposit(pay_txn: uint64, github_handle: bytes) -> uint64:
deposit:
// smart_contracts/personal_bank/contract.py:15-16
// smart_contracts/personal_bank/contract.py:20-21
// @abimethod()
// def deposit(self, pay_txn: gtxn.PaymentTransaction) -> UInt64:
proto 1 1
// smart_contracts/personal_bank/contract.py:29
// def deposit(self, pay_txn: gtxn.PaymentTransaction, github_handle: arc4.String) -> UInt64:
proto 2 1
// smart_contracts/personal_bank/contract.py:34
// pay_txn.receiver == Global.current_application_address
frame_dig -1
frame_dig -2
gtxns Receiver
global CurrentApplicationAddress
==
// smart_contracts/personal_bank/contract.py:28-30
// smart_contracts/personal_bank/contract.py:33-35
// assert (
// pay_txn.receiver == Global.current_application_address
// ), "Receiver must be the contract address"
assert // Receiver must be the contract address
// smart_contracts/personal_bank/contract.py:31
// smart_contracts/personal_bank/contract.py:36
// assert pay_txn.amount > 0, "Deposit amount must be greater than zero"
frame_dig -1
frame_dig -2
gtxns Amount
dup
assert // Deposit amount must be greater than zero
// smart_contracts/personal_bank/contract.py:33
// smart_contracts/personal_bank/contract.py:38
// deposit_amt, deposited = self.depositors.maybe(pay_txn.sender)
frame_dig -1
frame_dig -2
gtxns Sender
dup
box_get
bury 1
// smart_contracts/personal_bank/contract.py:35
// smart_contracts/personal_bank/contract.py:40
// if deposited:
bz deposit_else_body@2
// smart_contracts/personal_bank/contract.py:36
// smart_contracts/personal_bank/contract.py:41
// self.depositors[pay_txn.sender] += pay_txn.amount
frame_dig 1
dup
@@ -125,7 +142,15 @@ deposit:
box_put

deposit_after_if_else@3:
// smart_contracts/personal_bank/contract.py:40
// smart_contracts/personal_bank/contract.py:45
// self.github.value = github_handle
bytec_1 // 0x676974687562
box_del
pop
bytec_1 // 0x676974687562
frame_dig -1
box_put
// smart_contracts/personal_bank/contract.py:47
// return self.depositors[pay_txn.sender]
frame_dig 1
box_get
@@ -137,7 +162,7 @@ deposit_after_if_else@3:
retsub

deposit_else_body@2:
// smart_contracts/personal_bank/contract.py:38
// smart_contracts/personal_bank/contract.py:43
// self.depositors[pay_txn.sender] = pay_txn.amount
frame_dig 0
itob
@@ -149,50 +174,60 @@ deposit_else_body@2:

// smart_contracts.personal_bank.contract.PersonalBank.withdraw() -> uint64:
withdraw:
// smart_contracts/personal_bank/contract.py:52
// smart_contracts/personal_bank/contract.py:59
// deposit_amt, deposited = self.depositors.maybe(Txn.sender)
txn Sender
box_get
swap
btoi
// smart_contracts/personal_bank/contract.py:53
// smart_contracts/personal_bank/contract.py:60
// assert deposited, "No deposits found for this account"
swap
assert // No deposits found for this account
// smart_contracts/personal_bank/contract.py:55-59
// smart_contracts/personal_bank/contract.py:62-66
// result = itxn.Payment(
// receiver=Txn.sender,
// amount=deposit_amt,
// fee=0,
// ).submit()
itxn_begin
// smart_contracts/personal_bank/contract.py:56
// smart_contracts/personal_bank/contract.py:63
// receiver=Txn.sender,
txn Sender
itxn_field Receiver
itxn_field Amount
// smart_contracts/personal_bank/contract.py:55
// smart_contracts/personal_bank/contract.py:62
// result = itxn.Payment(
intc_0 // pay
itxn_field TypeEnum
// smart_contracts/personal_bank/contract.py:58
// smart_contracts/personal_bank/contract.py:65
// fee=0,
intc_1 // 0
itxn_field Fee
// smart_contracts/personal_bank/contract.py:55-59
// smart_contracts/personal_bank/contract.py:62-66
// result = itxn.Payment(
// receiver=Txn.sender,
// amount=deposit_amt,
// fee=0,
// ).submit()
itxn_submit
itxn Amount
// smart_contracts/personal_bank/contract.py:61
// smart_contracts/personal_bank/contract.py:68
// self.depositors[Txn.sender] = UInt64(0)
txn Sender
intc_1 // 0
itob
box_put
// smart_contracts/personal_bank/contract.py:63
// smart_contracts/personal_bank/contract.py:70
// return result.amount
retsub


// smart_contracts.personal_bank.contract.PersonalBank.get_box() -> bytes:
get_box:
// smart_contracts/personal_bank/contract.py:74
// return self.github.value
bytec_1 // 0x676974687562
box_get
assert // check self.github exists
retsub

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from algopy import Account, ARC4Contract, BoxMap, Global, Txn, UInt64, gtxn, itxn
from algopy import Account, ARC4Contract, BoxMap, Global, Txn, UInt64, gtxn, itxn, Box, arc4, String
from algopy.arc4 import abimethod


@@ -11,9 +11,14 @@ def __init__(self) -> None:
The BoxMap uses Account addresses as keys and UInt64 values to track deposited amounts.
"""
self.depositors = BoxMap(Account, UInt64, key_prefix="")

"""Create box
"""

self.github = Box(arc4.String, key=b"github")

@abimethod()
def deposit(self, pay_txn: gtxn.PaymentTransaction) -> UInt64:
def deposit(self, pay_txn: gtxn.PaymentTransaction, github_handle: arc4.String) -> UInt64:
"""Deposits funds into the personal bank
This method accepts a payment transaction and records the deposit amount in the sender's BoxMap.
@@ -36,6 +41,8 @@ def deposit(self, pay_txn: gtxn.PaymentTransaction) -> UInt64:
self.depositors[pay_txn.sender] += pay_txn.amount
else:
self.depositors[pay_txn.sender] = pay_txn.amount

self.github.value = github_handle

return self.depositors[pay_txn.sender]

@@ -61,3 +68,7 @@ def withdraw(self) -> UInt64:
self.depositors[Txn.sender] = UInt64(0)

return result.amount

@abimethod()
def get_box(self) -> arc4.String:
return self.github.value
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
738167630