-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCredits.sol
149 lines (118 loc) · 4.78 KB
/
Credits.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
pragma solidity ^ 0.4.21;
import "./SafeMath.sol";
pragma experimental ABIEncoderV2;
contract credit {
// lender variable starts
address[] public lenders;
struct profile {
address lenderAddress; // address of lender
string institutionName; // institutionName of the lender;
string idDocumentHash; //idDocument which will contains addrss and name like details about institution
bool verificationStatus;
}
mapping(address => profile) public lendersProfile;
address public manager;
// lender variable ends here
//creditSeeker variable starts here
uint public transactionId = 0;
mapping(address => uint) public scores; // credit scores assigned to customers;
mapping(address => uint[]) public transactionRecords;
struct creditRequest {
address creditSeekerAddress;
address civicId;
address lenderAddress;
uint amount;
uint duration;
string status;
uint256 timeStamp;
uint256 interest;
uint256 penalty;
bool lenderVerified;
bool creditSeekerVerified;
bool checked;
}
mapping(uint => creditRequest) public creditRequests;
function credit(){
manager = msg.sender;
}
modifier onlyOwner(){
require(msg.sender == manager);
_;
}
modifier verifiedLender(address lender){
require(lendersProfile[lender].verificationStatus == true);
_;
}
function registerAsLender(address _lenderAddress,string _institutionName,string _idDocumentHash) public {
profile pf = lendersProfile[_lenderAddress];
pf.lenderAddress = _lenderAddress;
pf.institutionName = _institutionName;
pf.idDocumentHash = _idDocumentHash;
pf.verificationStatus = false;
lenders.push(_lenderAddress);
}
function verifyLender(address _lender) public onlyOwner {
profile pf = lendersProfile[_lender];
pf.verificationStatus = true;
}
function getLender() public view returns (address[]){
return lenders;
}
function applyForCredit(address civicAddress,address _lenderAddress,uint _amount,uint _duration,uint _interest,uint _penalty) public verifiedLender(_lenderAddress){
transactionId = transactionId + 1;
transactionRecords[civicAddress].push(transactionId);
creditRequest cr= creditRequests[transactionId];
cr.lenderAddress = _lenderAddress;
cr.creditSeekerAddress = msg.sender;
cr.civicId = civicAddress;
cr.amount = _amount;
cr.duration = _duration;
cr.status = 'pending';
cr.timeStamp = now;
cr.interest = _interest;
cr.penalty = _penalty;
}
function verifyRequest(uint _transactionID) public {
require(creditRequests[_transactionID].lenderAddress == msg.sender);
scores[creditRequests[_transactionID].lenderAddress] = scores[creditRequests[_transactionID].lenderAddress] + 10;
creditRequests[_transactionID].status = 'Verified ,Your credit money will be send to you shortly';
}
function declineRequest(uint _transactionID) public {
require(creditRequests[_transactionID].lenderAddress == msg.sender);
creditRequests[_transactionID].status = 'Rejected';
}
function paymentAmount(uint _transactionID) public view returns(uint){
creditRequest cr = creditRequests[_transactionID];
uint256 AmountToBePaid ;
require(creditRequests[_transactionID].lenderAddress == msg.sender || creditRequests[_transactionID].creditSeekerAddress == msg.sender);
if(now - creditRequests[_transactionID].timeStamp > 2 * creditRequests[_transactionID].duration){
AmountToBePaid = creditRequests[_transactionID].amount + cr.amount * cr.interest/100 + cr.penalty;
if(cr.checked == false){
scores[cr.civicId] = scores[cr.civicId] - 5;
}
cr.checked = true;
return AmountToBePaid;
}
else {
AmountToBePaid = creditRequests[_transactionID].amount + cr.amount * cr.interest/100;
return AmountToBePaid;
}
}
function paymentVerify(uint transactionId,uint hashOfProof) public {
creditRequest cr = creditRequests[transactionId];
require(cr.lenderVerified != true);
if(msg.sender == cr.creditSeekerAddress){
cr.creditSeekerVerified = true;
}
else if(msg.sender == cr.lenderAddress){
cr.lenderVerified = true;
cr.status = "Transaction settled";
if(now - cr.timeStamp > 2 * cr.duration){
scores[cr.civicId] = scores[cr.civicId] + 5;
}
}
}
function getTransactionRecords(address civicAddress) public view returns (uint[]){
return transactionRecords[civicAddress];
}
}