Skip to content

Commit dce2238

Browse files
created bank app methods
1 parent c36fe7b commit dce2238

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Bank_App/contracts/BankApp.sol

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,45 @@ pragma solidity ^0.8.0;
33

44
contract BankApp
55
{
6+
// owner
7+
address public owner;
8+
9+
constructor()
10+
{
11+
owner = msg.sender;
12+
}
13+
14+
// user balance
15+
mapping(address => uint) private userBalance;
16+
617
// deposit
18+
function deposit() public payable
19+
{
20+
require(msg.value > 0, "Deposit amount must be greater than 0");
21+
userBalance[msg.sender] += msg.value;
22+
}
23+
724
// withdraw
25+
function withdrawl(uint amount) public
26+
{
27+
require(amount <= userBalance[msg.sender], "You do not have sufficient balance");
28+
(bool success, ) = payable(msg.sender).call{value: amount}("");
29+
require(success, "Amount Transfer failed");
30+
userBalance[msg.sender] -= amount;
31+
}
32+
833
// balance
34+
function viewBalance() public view returns(uint)
35+
{
36+
return userBalance[msg.sender];
37+
}
38+
39+
// change account balance
40+
function creditOwner(address account, uint amount) public
41+
{
42+
require(msg.sender == owner, "You do not have the permissions. Only te owner can change the balance");
43+
require(amount > 0, "Deposit amount must be greater than 0");
44+
userBalance[account] += amount;
45+
}
946
}
47+

0 commit comments

Comments
 (0)