From 37269c4fc4374f7b394bc063cd52181e7aee4ef6 Mon Sep 17 00:00:00 2001 From: kozuelam <47081678+kozuelam@users.noreply.github.com> Date: Wed, 12 Aug 2020 09:16:21 -0400 Subject: [PATCH] add minibank solidity contract --- minibank.sol | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 minibank.sol diff --git a/minibank.sol b/minibank.sol new file mode 100644 index 00000000..197c375d --- /dev/null +++ b/minibank.sol @@ -0,0 +1,53 @@ +pragma solidity ^0.5.12; + +contract MiniBank { + + // the contract owner + address public owner; + // the bank accounts mapper + mapping (address => uint) private accounts; + // event for deposit log + event LogDeposit(address indexed accountAddress, uint amount); + // event for withdraw log + event LogWithdraw(address indexed withdrawAddress, uint amount); + + constructor() public { + // 1. set the owner to your current account + // add the code here + } + + /// Deposit amount into MiniBank + /// @return User balance after the deposit is made + function deposit() public payable returns (uint) { + + require((accounts[msg.sender] + msg.value) >= accounts[msg.sender]); + + // 2. add msg.value to the user account + // add the code here + + + emit LogDeposit(msg.sender, msg.value); + return accounts[msg.sender]; + } + + /// Withdraw amount from MiniBank + /// @param withdraw amount + /// @return The ramaining balance + function withdraw(uint withdrawAmount) public returns (uint) { + require(withdrawAmount <= accounts[msg.sender]); + // 3. decrease user balance + // add the code here + + msg.sender.transfer(withdrawAmount); + + // 4. emit LogWithdraw event + // add the code here + + return accounts[msg.sender]; + } + + /// @return The user balance + function balance() view public returns (uint) { + return accounts[msg.sender]; + } +}