From f862f2b21d4e6168c94e4f85ca917924b4c0b3e5 Mon Sep 17 00:00:00 2001 From: Sohail Ahmed Laghari <82243670+12SohailBlockchain@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:14:30 +0500 Subject: [PATCH] solved smart contract errors 'Expression has type "Any"', "Unsupported operand types", 'Argument 2 to "app_opted_in"' --- .../smart_contracts/personal_vault/contract.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/projects/challenge/smart_contracts/personal_vault/contract.py b/projects/challenge/smart_contracts/personal_vault/contract.py index d1e6cf8..5d3ebfe 100644 --- a/projects/challenge/smart_contracts/personal_vault/contract.py +++ b/projects/challenge/smart_contracts/personal_vault/contract.py @@ -10,7 +10,6 @@ op, ) - class PersonalVault(ARC4Contract): def __init__(self) -> None: self.balance = LocalState(UInt64) @@ -22,12 +21,17 @@ def opt_in_to_app(self) -> None: @arc4.abimethod() def deposit(self, ptxn: gtxn.PaymentTransaction) -> UInt64: assert ptxn.amount > 0, "Deposit amount must be greater than 0" + + # Corrected the receiver check assert ( - ptxn.receiver == Global.current_application_id + ptxn.receiver == Global.current_application_address ), "Deposit receiver must be the contract address" + assert ptxn.sender == Txn.sender, "Deposit sender must be the caller" + + # Corrected the argument type for app_opted_in assert op.app_opted_in( - Txn.sender, Global.current_application_address + Txn.sender, Global.current_application_id ), "Deposit sender must opt-in to the app first." self.balance[Txn.sender] += ptxn.amount @@ -37,13 +41,13 @@ def deposit(self, ptxn: gtxn.PaymentTransaction) -> UInt64: @arc4.abimethod(allow_actions=["CloseOut"]) def withdraw(self) -> UInt64: - userBalance = self.balance[Txn.sender] + user_balance = self.balance[Txn.sender] itxn.Payment( receiver=Txn.sender, sender=Global.current_application_address, - amount=userBalance, + amount=user_balance, fee=0, ).submit() - return userBalance + return user_balance