-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment1.sol
89 lines (61 loc) · 1.7 KB
/
assignment1.sol
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
pragma solidity ^0.5.0;
contract assigment2{
address addr;
struct Member{
string name;
uint8 balance;
bool isValid;
}
mapping(address =>Member) accounts ;
address owner;
constructor() public
{
owner=msg.sender;
}
modifier onlyOwner{
require( msg.sender==owner,"you are not permitted to deposit amount");
_;
}
modifier onlyMembers{
require(accounts[msg.sender].isValid,"you are not permitted to withdraw amount");
_;
}
event log(address add,string text);
event logTxn(string name,string text,uint8 amount);
// set members ,with initial balance=0
function addMembers(address _accAddress,string memory _name) public onlyOwner{
accounts[_accAddress]=Member(_name,0,true);
emit log(_accAddress ," member added !");
}
//deposit in member's account
function deposit(address _addr,uint8 _amount) public onlyOwner returns (bool)
{
if( accounts[_addr].isValid )
{
accounts[_addr].balance=accounts[_addr].balance+_amount;
return true;
}
else
emit log(_addr," not a valid member!!");
}
function viewBalance(address _addr) public view returns (uint8)
{
if( accounts[_addr].isValid )
{
return accounts[_addr].balance;
}
}
function withdrawAmount(address _addr,uint8 _amount) public onlyMembers returns (string memory)
{
if (accounts[_addr].balance >= _amount)
{
accounts[_addr].balance = accounts[_addr].balance - _amount;
return "withdrawal success !!";
}
else
{
emit log(_addr,"has insufficient balance ");
return "insufficient balance !!" ;
}
}
}