-
Notifications
You must be signed in to change notification settings - Fork 1
/
transparentCharity.sol
176 lines (135 loc) · 4.71 KB
/
transparentCharity.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
pragma solidity ^0.5.3;
contract charity_contract{
/*
bytes32 public hash_byt;
string public name1;
string public bankAccount;
string public bankName;
*/
struct charity_structure {
string name_of_charity;
string bankAccount;
string bankName;
bytes32 hash;
uint amount_balance;
address payable addres;
}
charity_structure[10] public cs ;
uint index_charity = 0;
struct personOrOrganisation_structure {
string name_of_organisation;
string bankAccount;
string bankName;
bytes32 hash;
uint amount_balance;
address payable addres;
}
personOrOrganisation_structure[10] public ps;
uint index_organisation = 0;
function generate_address_charity(string memory name, string memory bankacc , string memory bankname) private returns(bytes32) {
bytes memory _name = bytes(name);
bytes memory _bankacc = bytes(bankacc);
bytes memory _bankname = bytes(bankname);
//bytes memory _amount_balance = bytes(amount_balance);
//string memory _amount_balance = string(amount_balance);
string memory length_abc = new string(_name.length + _bankacc.length + _bankname.length );
bytes memory hash_address = bytes(length_abc);
uint k = 0;
for(uint i = 0;i < _name.length; i++){
hash_address[k++] = _name[i];
}
for(uint i = 0; i < _bankacc.length; i++){
hash_address[k++] = _bankacc[i];
}
for(uint i = 0; i < _bankname.length; i++){
hash_address[k++] = _bankname[i];
}
// hash_address[k] = bytes(amount_balance);
bytes32 hash = keccak256(hash_address);
return hash;
}
function generate_address_organisation(string memory name, string memory bankacc , string memory bankname) private returns(bytes32) {
bytes memory _name = bytes(name);
bytes memory _bankacc = bytes(bankacc);
bytes memory _bankname = bytes(bankname);
string memory length_abc = new string(_name.length + _bankacc.length + _bankname.length);
bytes memory hash_address = bytes(length_abc);
uint k = 0;
for(uint i = 0;i < _name.length; i++){
hash_address[k++] = _name[i];
}
for(uint i = 0; i < _bankacc.length; i++){
hash_address[k++] = _bankacc[i];
}
for(uint i = 0; i < _bankname.length; i++){
hash_address[k++] = _bankname[i];
}
bytes32 hash = keccak256(hash_address);
return hash;
}
function add_charity(string memory name, string memory bankacc , string memory bankname , address payable address_) public returns(string memory status){
bytes32 hash = generate_address_charity(name,bankacc,bankname);
cs[index_charity].hash = hash;
cs[index_charity].name_of_charity = name;
cs[index_charity].bankAccount = bankacc;
cs[index_charity].bankName = bankname;
cs[index_charity].addres = address_;
cs[index_charity].amount_balance = address_.balance;
/*
hash_byt = hash;
bankName = bankname;
name1 = name;
bankAccount = bankacc;
*/
index_charity++;
return("succesfully added the charity!!");
}
function add_organisation(string memory name, string memory bankacc , string memory bankname , address payable address_) public returns(string memory status){
bytes32 hash = generate_address_organisation(name,bankacc,bankname);
ps[index_organisation].hash = hash;
ps[index_organisation].name_of_organisation = name;
ps[index_organisation].bankAccount = bankacc;
ps[index_organisation].bankName = bankname;
ps[index_organisation].addres = address_;
ps[index_organisation].amount_balance = address_.balance;
/*
hash_byt = hash;
bankName = bankname;
name1 = name;
bankAccount = bankacc;
*/
index_organisation++;
return("succesfully added the organisation!!");
}
function transact_organisation_to_charity(address payable address_of_charity, address payable address_of_oranisation ) public payable returns(string memory status){
address _address_of_charity ;
address _address_of_oranisation;
uint index_organisation_ = 0;
uint index_charity_ = 0;
uint flag1 = 0;
uint flag2 = 0;
for(uint i = 0; i < index_charity;i++){
if(cs[i].addres == address_of_charity ){
index_charity_ = i;
flag1 = 1;
break;
}
}
for(uint i = 0; i < index_organisation; i++){
if(ps[i].addres == address_of_oranisation){
index_organisation_ = i;
flag2 = 1;
break;
}
}
if(flag1 == 1 && flag2 ==1){
cs[index_charity_].amount_balance += msg.value;
ps[index_organisation_].amount_balance -= msg.value;
address_of_charity.transfer(msg.value);
return("transaction has been done succesfully!!!");
}
else{
return("transaction not done!!");
}
}
}