-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.sol
288 lines (232 loc) · 10.9 KB
/
main.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
pragma solidity ^0.4.19;
pragma experimental ABIEncoderV2;
contract Anticorruption{
address Goverment = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c;
struct BasicInfoOfEntity{
// Basic info of every entity
string Name;
uint BankAccountNo;
bool Validity;
}
struct StaticEntitiy{
// Basic info of entities like state , District etc.
string Name;
uint BankAccountNo;
bool Validity;
}
struct SchemesInfo{
// Schemes basic Info
string Name;
string Description;
uint TotalAmount;
uint BankAccountNo;
address SuperUser;
mapping(uint => bool) AuthorizedEntity;
mapping(uint => uint) MoneyAllocatedForEntityForPerticularEntity;
mapping(uint => uint) MoneyReceived;
mapping(uint => uint) MoneyAtPresent;
mapping(uint => bool) MoneyGiven;
mapping(uint => bool) BenifitsGiven;
uint [] Authorized;
uint [] AddedAfterLock;
uint [] BenifitReached;
bool Validity;
bool Lock;
}
mapping(uint => bool) StaticORNOt;
mapping(address => uint) AddressOfStaticEntity;
mapping(uint => StaticEntitiy) StaticEntities;
mapping(uint => BasicInfoOfEntity) EntityInfo;
mapping(uint => SchemesInfo) Schemes;
mapping(uint => uint) TotalMoney;
mapping(uint => bool) BankAccount;
function AddStaticEntity(uint UniqueCode, string _name, uint _BankAccountNo) returns (string Status ) {
// Add new Entity
uint UID = UniqueCode;
if (StaticEntities[UID].Validity==false && BankAccount[_BankAccountNo] == false){
AddressOfStaticEntity[msg.sender] = UniqueCode;
StaticEntities[UID].Name = _name;
StaticEntities[UID].BankAccountNo = _BankAccountNo;
StaticEntities[UID].Validity = true;
StaticORNOt[UID] = true;
return(" Entity Added Successfully.");
}
else{
return(" Entity Already present.");
}
}
function GetStaticEntity(uint UniqueCode) view returns (string Name ,uint BankAccountNo ) {
// Get info About Entity
uint UID = UniqueCode;
require(StaticORNOt[UID] == true);
return(StaticEntities[UID].Name,StaticEntities[UID].BankAccountNo);
}
function AddEntity(uint AdharcardNo, string _name, uint _BankAccountNo) returns (string Status ) {
// Add new Entity
if (EntityInfo[AdharcardNo].Validity==false && BankAccount[_BankAccountNo] == false){
EntityInfo[AdharcardNo].Name = _name;
EntityInfo[AdharcardNo].BankAccountNo = _BankAccountNo;
EntityInfo[AdharcardNo].Validity = true;
return(" Entity Added Successfully.");
}
else{
return(" Entity Already present.");
}
}
function GetEntity(uint AdharcardNo) view returns (string Name ,uint BankAccountNo ) {
// Get info About Entity
require(EntityInfo[AdharcardNo].Validity==true);
return(EntityInfo[AdharcardNo].Name,EntityInfo[AdharcardNo].BankAccountNo);
}
function AddScheme(string SID,string _name,string _Description,uint _amount,uint _BankAccountNo,address _Superuser) returns (string Status) {
// Add new Schemes
require(msg.sender == Goverment); // Only Goverment can create Schemes
uint sid = uint(keccak256(SID));
if (Schemes[sid].Validity==false && BankAccount[_BankAccountNo] == false ){
Schemes[sid].Name = _name;
Schemes[sid].Description = _Description;
Schemes[sid].TotalAmount = _amount;
Schemes[sid].BankAccountNo = _BankAccountNo;
Schemes[sid].SuperUser = _Superuser;
Schemes[sid].Validity = true;
return(" Scheme Created Successfully.");
}
else{
return(" Scheme ID Already Present.");
}
}
function GetScheme(string SID) view returns (string Description ,uint TotalAmount , uint BankAccountNo, uint [] Authorized) {
// Get Schemes
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true);
return(Schemes[sid].Description,Schemes[sid].TotalAmount,Schemes[sid].BankAccountNo,Schemes[sid].Authorized);
}
function AddAuthorizedPerson(string SID,uint AdharcardNo, uint _money) returns (string Status) {
// AddAuthorizedPerson
uint sid = uint(keccak256(SID));
uint UniqueCode = AddressOfStaticEntity[msg.sender];
require(Schemes[sid].Validity==true && (Schemes[sid].SuperUser == msg.sender || StaticORNOt[UniqueCode] == true) && Schemes[sid].AuthorizedEntity[AdharcardNo] == false); //Only SuperUser can add Authorized persons
if(Schemes[sid].Lock == false)
{
Schemes[sid].AuthorizedEntity[AdharcardNo] = true;
Schemes[sid].MoneyAllocatedForEntityForPerticularEntity[AdharcardNo] = _money;
Schemes[sid].Authorized.push(AdharcardNo);
return("Person Added Successfully");
}
else {
Schemes[sid].AuthorizedEntity[AdharcardNo] = true;
Schemes[sid].MoneyAllocatedForEntityForPerticularEntity[AdharcardNo] = _money;
Schemes[sid].Authorized.push(AdharcardNo);
Schemes[sid].AddedAfterLock.push(AdharcardNo);
return("Person Added Successfully");
}
}
function AddAuthorizedCompany(string SID, uint CIN, uint _money) returns (string Status) {
// AddAuthorizedCompany
uint sid = uint(keccak256(SID));
uint UniqueCode = AddressOfStaticEntity[msg.sender];
require(Schemes[sid].Validity==true && (Schemes[sid].SuperUser == msg.sender || StaticORNOt[UniqueCode] == true) && Schemes[sid].AuthorizedEntity[CIN] == false);
if(Schemes[sid].Lock == false){
Schemes[sid].AuthorizedEntity[CIN] = true;
Schemes[sid].MoneyAllocatedForEntityForPerticularEntity[CIN] = _money;
Schemes[sid].Authorized.push(CIN);
return("Company Added Successfully");
}
else {
Schemes[sid].AuthorizedEntity[CIN] = true;
Schemes[sid].MoneyAllocatedForEntityForPerticularEntity[CIN] = _money;
Schemes[sid].Authorized.push(CIN);
Schemes[sid].AddedAfterLock.push(CIN);
return("Company Added Successfully");
}
}
function LockScheme(string SID) returns (string Status) {
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true && (Schemes[sid].SuperUser==msg.sender || Goverment==msg.sender ));
Schemes[sid].Lock = true;
return("Locked Successfully");
}
function UnlockockScheme(string SID) returns (string Status) {
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true && Schemes[sid].SuperUser==msg.sender);
Schemes[sid].Lock = false;
return("Locked Successfully");
}
function EntitiesAddedAfterLock(string SID) view returns (uint []) {
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true);
return(Schemes[sid].AddedAfterLock);
}
function MoneyAPersonGetting(string SID,uint AdharcardNo) view returns (uint Money) {
// GetMoneyForEntityForPerticularSchemes
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true);
return(Schemes[sid].MoneyAllocatedForEntityForPerticularEntity[AdharcardNo]);
}
function TotalMoneyForEntity(uint UID) view returns (uint Money) {
// TotalMoneyForEntity
return(TotalMoney[UID]);
}
function MoneyReceivedInScheme(string SID,uint UID) view returns (uint Money){
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true);
return(Schemes[sid].MoneyReceived[UID]);
}
function MoneyATPresent(string SID, uint UID) view returns (uint Money) {
// MoneyAPersonGetting
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true);
return(Schemes[sid].MoneyAtPresent[UID]);
}
function TransferMoney(string SID,uint From, uint To,uint money) returns (string Status) {
// TransferMoney Dont ristrict ststic entities
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true && (StaticORNOt[To] == true || (Schemes[sid].MoneyAllocatedForEntityForPerticularEntity[To] == money && Schemes[sid].AuthorizedEntity[To] == true)));
if (StaticORNOt[To] == true){
Schemes[sid].MoneyAtPresent[To] = Schemes[sid].MoneyAtPresent[To] + money;
Schemes[sid].MoneyAtPresent[From] = Schemes[sid].MoneyAtPresent[From] - money;
Schemes[sid].MoneyReceived[To] = money;
TotalMoney[From] = TotalMoney[From] - money;
TotalMoney[To] = TotalMoney[To] + money;
Schemes[sid].BenifitReached.push(To);
}
else if (Schemes[sid].MoneyAllocatedForEntityForPerticularEntity[To] == money && Schemes[sid].AuthorizedEntity[To] == true){
Schemes[sid].MoneyAtPresent[To] = Schemes[sid].MoneyAtPresent[To] + money;
Schemes[sid].MoneyAtPresent[From] = Schemes[sid].MoneyAtPresent[From] - money;
Schemes[sid].MoneyReceived[To] = money;
TotalMoney[From] = TotalMoney[From] - money;
TotalMoney[To] = TotalMoney[To] + money;
Schemes[sid].BenifitsGiven[To] = true;
Schemes[sid].BenifitReached.push(To);
}
}
function BenifitsReached(string SID) returns (uint []) {
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true);
return Schemes[sid].BenifitReached;
}
function AddMoney(string SID,uint UID,uint Money) {
uint sid = uint(keccak256(SID));
require(Schemes[sid].Validity==true);
if(StaticEntities[UID].Validity == true || EntityInfo[UID].Validity == true){
TotalMoney[UID] = TotalMoney[UID] + Money;
Schemes[sid].MoneyAtPresent[UID] = Schemes[sid].MoneyAtPresent[UID] + Money;
}
}
function DriverFunction(){
AddStaticEntity(1046,"Maharastra",4);
AddStaticEntity(1001,"Mumbai",5);
AddStaticEntity(1010,"NaviMumbai",6);
AddEntity(1,"Swapnil",1);
AddEntity(2,"Pradnya",2);
AddEntity(3,"Shweta",3);
AddScheme("PMJDY","Pradhan Mantri Jan Dhan Yogana","Pradhan Mantri Jan-Dhan Yojana (PMJDY) is National Mission for Financial Inclusion to ensure access to financial services, namely, Banking/ Savings & Deposit Accounts, Remittance, Credit, Insurance, Pension in an affordable manner.",1000,222222,0x14723a09acff6d2a60dcdf7aa4aff308fddc160c);
AddAuthorizedPerson("PMJDY",1,10);
AddAuthorizedPerson("PMJDY",2,20);
AddAuthorizedPerson("PMJDY",3,30);
AddMoney("PMJDY",1046,1000);
AddMoney("PMJDY",1001,500);
AddMoney("PMJDY",1010,100);
TransferMoney("PMJDY",1046,2,20);
}
}