From caad4e00a953f3dc7afa519eb334b97056c1d852 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 15 Jun 2024 18:41:21 +0700 Subject: [PATCH] Create PI-Wallet.sol --- .../contracts/PI-bank/contracts/PI-Wallet.sol | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 blockchain_integration/pi_network/contracts/PI-bank/contracts/PI-Wallet.sol diff --git a/blockchain_integration/pi_network/contracts/PI-bank/contracts/PI-Wallet.sol b/blockchain_integration/pi_network/contracts/PI-bank/contracts/PI-Wallet.sol new file mode 100644 index 000000000..1192c7dcf --- /dev/null +++ b/blockchain_integration/pi_network/contracts/PI-bank/contracts/PI-Wallet.sol @@ -0,0 +1,37 @@ +pragma solidity ^0.8.0; + +import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/access/Ownable.sol"; +import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol"; + +contract PIWallet { + using SafeMath for uint256; + + address public owner; + mapping (address => uint256) public balances; + + event Deposit(address indexed user, uint256 amount); + event Withdrawal(address indexed user, uint256 amount); + + constructor() public { + owner = msg.sender; + } + + function deposit() public payable { + balances[msg.sender] = balances[msg.sender].add(msg.value); + emit Deposit(msg.sender, msg.value); + } + + function withdraw(uint256 _amount) public { + require(_amount <= balances[msg.sender], "Insufficient balance"); + msg.sender.transfer(_amount); + balances[msg.sender] = balances[msg.sender].sub(_amount); + emit Withdrawal(msg.sender, _amount); + } + + function transfer(address _to, uint256 _amount) public { + require(_amount <= balances[msg.sender], "Insufficient balance"); + balances[msg.sender] = balances[msg.sender].sub(_amount); + balances[_to] = balances[_to].add(_amount); + emit Transfer(msg.sender, _to, _amount); + } +}