-
Notifications
You must be signed in to change notification settings - Fork 1
/
bt_bank account.txt
47 lines (46 loc) · 2.13 KB
/
bt_bank account.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
42
43
44
45
46
47
pragma solidity ^0.8;
contract bank{
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] = 0;
user_exists[msg.sender] = true;
return "Account created";
}
function deposit(uint amount) public payable returns(string memory){
require(user_exists[msg.sender]==true,"Account not created");
require(amount >0,"amount should be more then zero");
user_account[msg.sender] = user_account[msg.sender]+amount;
return "deposited succefully";
}
function withdraw(uint amount) public payable returns(string memory){
require(user_account[msg.sender]>amount,"Insufficient amount");
require(user_exists[msg.sender]==true,"Account not created");
require(amount>0,"Amount should be greater than zero");
user_account[msg.sender] = user_account[msg.sender]-amount;
return "withdraw successfully";
}
function transfer(address payable userAddress , uint amount) public returns (string memory)
{
require( user_account[msg.sender]>amount , "Insufficient Balance");
require( user_exists[msg.sender]==true , "Account not created");
require( user_exists[userAddress]==true , "Transfer account not created");
require( amount>0 , "Amount should be greater than zero");
user_account[msg.sender] = user_account[msg.sender] - amount;
user_account[userAddress] = user_account[userAddress] + amount;
return "Transfer Successfully";
}
function user_balance()public view returns(uint){
return user_account[msg.sender];
}
function account_exist()public view returns(bool){
return user_exists[msg.sender];
}
}