Skip to content

Commit

Permalink
Merge pull request #15 from certikfoundation/minibank.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
kozuelam authored Aug 13, 2020
2 parents 23c0fe0 + 73caf23 commit 9595d2e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions minibank.sol
Original file line number Diff line number Diff line change
@@ -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 withdrawAmount amount for withdrawing
/// @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];
}
}

0 comments on commit 9595d2e

Please sign in to comment.