-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloanSystem.sol
More file actions
42 lines (33 loc) · 1.26 KB
/
loanSystem.sol
File metadata and controls
42 lines (33 loc) · 1.26 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./userWallet.sol";
contract LoanSystem is userWallet {
enum LoanStatus { Pending, Approved, Rejected }
struct LoanRequest {
uint amount;
LoanStatus status;
}
mapping(address => LoanRequest) public loanRequests;
address[] public loanApplicants;
uint public totalLoans;
function applyForLoan(uint _amount) public {
require(accounts[msg.sender].balance >= 1 ether, "You need at least 1 ether in your account to apply for a loan.");
loanRequests[msg.sender] = LoanRequest(_amount, LoanStatus.Pending);
loanApplicants.push(msg.sender);
}
function processLoans() public {
for (uint i = 0; i < loanApplicants.length; i++) {
address applicant = loanApplicants[i];
LoanRequest storage request = loanRequests[applicant];
if (accounts[applicant].balance >= request.amount / 2) {
request.status = LoanStatus.Approved;
totalLoans++;
} else {
request.status = LoanStatus.Rejected;
}
}
}
function getLoanStatus(address _applicant) public view returns (LoanStatus) {
return loanRequests[_applicant].status;
}
}