-
Notifications
You must be signed in to change notification settings - Fork 1
/
BT Ass3 (medium).txt
41 lines (41 loc) · 1.53 KB
/
BT Ass3 (medium).txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//SPDX-License-Identifier: MIT
pragma solidity ^0.6;
contract banking
{
mapping(address=>uint) public user_account;
mapping(address=>bool) public user_exists;
function create_account() public payable returns(string memory)
{
require(user_exists[msg.sender]==false,'Account already created');
if(msg.value==0)
{
user_account[msg.sender]=0;
user_exists[msg.sender]=true;
return "Account created";
}
require(user_exists[msg.sender]==false,"Account already created");
user_account[msg.sender]=msg.value;
user_exists[msg.sender]=true;
return "Account created";
}
function deposit() public payable returns(string memory)
{
require(user_exists[msg.sender]==true,"Account not created");
require(msg.value>0,"Value for deposit is Zero");
user_account[msg.sender]=user_account[msg.sender]+msg.value;
return "Deposited Successfully";
}
function withdraw(uint amount) public payable returns(string memory)
{
require(user_account[msg.sender]>amount,"Insufficient Balance");
require(user_exists[msg.sender]==true,"Account not created");
require(amount>0,"Amount should be more than zero");
user_account[msg.sender]=user_account[msg.sender]-amount;
msg.sender.transfer(amount);
return "Withdrawl Successful";
}
function user_balance() public view returns(uint)
{
return user_account[msg.sender];
}
}