Skip to content

Commit

Permalink
contract assignment finished
Browse files Browse the repository at this point in the history
  • Loading branch information
iskysun96 committed May 27, 2024
1 parent b80de11 commit 798572b
Showing 1 changed file with 17 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# pyright: reportMissingModuleSource=false
from algopy import (
Asset,
Global,
Txn,
UInt64,
arc4,
gtxn,
itxn,
)
from algopy import *

"""
NftMarketplace 앱 설명
Expand Down Expand Up @@ -52,9 +44,9 @@ class NftMarketplace(arc4.ARC4Contract):

def __init__(self) -> None:
"문제 1 시작"
self.asset_id = UInt64(0)
self.unitary_price = UInt64(0)
self.bootstrapped = False
self.asset_id = "여기에 코드 작성"
self.unitary_price = "여기에 코드 작성"
self.bootstrapped = "여기에 코드 작성"
"문제 1 끝"

"""
Expand Down Expand Up @@ -93,24 +85,15 @@ def __init__(self) -> None:
힌트 4 itxn asset transfer 코드 예시: https://github.com/algorandfoundation/puya/blob/2acea25a96c0acd818e9410007d473b2a82e754d/examples/amm/contract.py#L357
"""

"문제 2 시작"

@arc4.abimethod
def bootstrap(
self, asset: Asset, unitary_price: UInt64, mbr_pay: gtxn.PaymentTransaction
) -> None:
assert Txn.sender == Global.creator_address
assert not self.bootstrapped
assert mbr_pay.receiver == Global.current_application_address
assert mbr_pay.amount == Global.min_balance + Global.asset_opt_in_min_balance

self.asset_id = asset.id
self.unitary_price = unitary_price
self.bootstrapped = True
"여기에 코드 작성"

itxn.AssetTransfer(
xfer_asset=asset,
asset_receiver=Global.current_application_address,
asset_amount=0,
).submit()
"문제 2 끝"

"""
문제 3
Expand Down Expand Up @@ -140,23 +123,18 @@ def bootstrap(
힌트 2 - Asset Transfer Inner Txn: https://algorandfoundation.github.io/puya/api-algopy.itxn.html#algopy.itxn.AssetTransfer
힌트 3 itxn asset transfer 코드 예시: https://github.com/algorandfoundation/puya/blob/2acea25a96c0acd818e9410007d473b2a82e754d/examples/amm/contract.py#L357
"""
"문제 3 시작"

@arc4.abimethod
def buy(
self,
buyer_txn: gtxn.PaymentTransaction,
quantity: UInt64,
) -> None:
assert self.bootstrapped == True
assert buyer_txn.sender == Txn.sender
assert buyer_txn.receiver == Global.current_application_address
assert buyer_txn.amount == self.unitary_price * quantity

itxn.AssetTransfer(
xfer_asset=self.asset_id,
asset_receiver=Txn.sender,
asset_amount=quantity,
).submit()
"여기에 코드 작성"

"문제 3 끝"

"""
문제 4
Expand Down Expand Up @@ -196,17 +174,10 @@ def buy(
이때 두 트랜잭션 다 앱 계정이 보내는 트랜잭션이기 때문에 Inner Transaction을 사용하세요!
"""

"문제 4 시작"

@arc4.abimethod(allow_actions=["DeleteApplication"])
def withdraw_and_delete(self) -> None:
assert Txn.sender == Global.creator_address

itxn.AssetTransfer(
xfer_asset=self.asset_id,
asset_receiver=Global.creator_address,
asset_close_to=Global.creator_address,
).submit()

itxn.Payment(
receiver=Global.creator_address,
close_remainder_to=Global.creator_address,
).submit()
"여기에 코드 작성"

"문제 4 끝"

0 comments on commit 798572b

Please sign in to comment.