-
Notifications
You must be signed in to change notification settings - Fork 0
/
finAid.sol
executable file
·121 lines (100 loc) · 3.43 KB
/
finAid.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
pragma solidity ^0.4.15;
/**
* http://solidity.readthedocs.io/en/develop/units-and-global-variables.html?highlight=block%20and%20transaction
* https://vomtom.at/solidity-send-vs-transfer/
- Variables for [school, government, studentID, aidAmount
Functions needed:
-() SEND( school, recipient) transcripts
-(modifiers) Check if authorizedViewer
-(modifiers) Check if authorizedEditor
-() Apply aid to balance
-() Send left over amount to student
-() Add new authorized viewer
*/
//Defining a financial aid contract
contract finAid {
struct User{
uint _govtSender;
}
struct School{
address _school;
}
struct Student{
address _studentID;
mapping(address => bool) correctStudent; // Is this necessary?
}
struct FinAid{
uint _awardedAmount;
}
/**Global Variables */
uint _balance = _studentID.balance;
Schools[] schoolListA; // Type[] variableName;
User[] authorizedReadersA;
mapping(address => bool) userCanRead; //Short function check that returns if userCanRead
User[] authorizedEditorA;
mapping(address => bool) userCanEdit; //Short function check that returns if userCanEdit
User[] authorizedPatronsA;
mapping(address => bool) userCanDonate;
/**Modifiers */
modifier onlyAuthorizedReaders(){
if (userCanRead[msg.sender] == false){
revert(); // AKA Like throw exception --> was getting bug earlier
}
_; // AKA Go back to the original function
}
modifier onlyAuthorizedEditor(){
if (userCanEdit[msg.sender] == false){
revert();
}
_;
}
modifier onlyAuthorizedPatron(){
if(userCanDonate[msg.sender] == false){
revert;
}
_;
}
/**Events */
/*Authorize school or student or those with clearnace to read docu's; event()
will create a log of */
event NewReaderAuth(address whoAddedThem, address whoWasAdded);
event Deposit(address _from, address _id, uint _awardedAmount);
/**Functions */
function sendAid(uint _awardedAmount, address _school) onlyAuthorizedEditor() public {
_inStudentID.send(_awardedAmount);
/*address.send or address.tranfser? Also how does it know who it's coming from*/
// returns (bool); ...solidity.readdocs
}
/* Could ClientReceipt code work for sending cash monz?
http://solidity.readthedocs.io/en/develop/contracts.html*/
function newAuthReader(address _newUser) onlyAuthReader() public {
authorizedReadersA.push(User({
_school: _newUser
}));
isAuthUser[_newUser];
// NewUserAdded(msg.sender, _newUser);
}
// This should add authorizedPatrons who can donate as well, which may need further authorization restrictions in their own class
function newAuthPatron(address _newPatron) onlyAuthPatron() public{
authorizedPatronsA.push(User({
_school: _newUser
}));
isAuthUser[_newPatron];
}
function extraAid(uint _awardedAmount, address _inStudentID) onlyAuthorizedEditor() public {
//or would you do onlu
_inStudentID.send(_awardedAmount);
// returns (bool); @...solidity.readdocs
}
function applyAid(address _studentID, address currentSchool, uint _awardedAmount) onlyAuthUser() public{
if(_awardedAmount <= 0 ) { //maybe just = 0
revert();
}
else {
balance = balance - _awardedAmount;
if (balance > 0 ) {
extraAid(balance, studentID);
}
}
}
}