Skip to content

Commit

Permalink
Create PI-Wallet.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jun 15, 2024
1 parent 26a085b commit caad4e0
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit caad4e0

Please sign in to comment.