Browse Source

Update 'SimpleBank/SimpleBank.sol'

main
Anindya Maiti 7 months ago
parent
commit
a7da128179
  1. 64
      SimpleBank/SimpleBank.sol

64
SimpleBank/SimpleBank.so → SimpleBank/SimpleBank.sol

@ -1,32 +1,32 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
// SimpleBank contract definition // SimpleBank contract definition
contract SimpleBank { contract SimpleBank {
// Mapping from addresses to balances // Mapping from addresses to balances
mapping(address => uint) private balances; mapping(address => uint) private balances;
// Event declarations // Event declarations
event DepositMade(address indexed accountAddress, uint amount); event DepositMade(address indexed accountAddress, uint amount);
event WithdrawalMade(address indexed accountAddress, uint withdrawAmount, uint newBalance); event WithdrawalMade(address indexed accountAddress, uint withdrawAmount, uint newBalance);
// Deposit function allows users to deposit Ether into the bank // Deposit function allows users to deposit Ether into the bank
function deposit() public payable { function deposit() public payable {
require(msg.value > 0, "Deposit amount must be greater than zero."); require(msg.value > 0, "Deposit amount must be greater than zero.");
balances[msg.sender] += msg.value; balances[msg.sender] += msg.value;
emit DepositMade(msg.sender, msg.value); emit DepositMade(msg.sender, msg.value);
} }
// Withdraw function allows users to withdraw Ether from the bank // Withdraw function allows users to withdraw Ether from the bank
function withdraw(uint withdrawAmount) public { function withdraw(uint withdrawAmount) public {
require(withdrawAmount <= balances[msg.sender], "Insufficient balance."); require(withdrawAmount <= balances[msg.sender], "Insufficient balance.");
payable(msg.sender).transfer(withdrawAmount); payable(msg.sender).transfer(withdrawAmount);
balances[msg.sender] -= withdrawAmount; balances[msg.sender] -= withdrawAmount;
emit WithdrawalMade(msg.sender, withdrawAmount, balances[msg.sender]); emit WithdrawalMade(msg.sender, withdrawAmount, balances[msg.sender]);
} }
// Get balance function returns the Ether balance of the user // Get balance function returns the Ether balance of the user
function getBalance() public view returns (uint) { function getBalance() public view returns (uint) {
return balances[msg.sender]; return balances[msg.sender];
} }
} }
Loading…
Cancel
Save