-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOffChainBorrow.sol
47 lines (39 loc) · 1.27 KB
/
OffChainBorrow.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
pragma solidity ^0.4.19;
contract EthereumCourse {
mapping (address => bool) private borrows;
mapping (address => uint256) private borrowAmount;
address private owner = msg.sender;
string private message = "The amount of the loan is";
string private error = "He has already borrow";
event Result(string message, uint256 borrow);
event DebtorValue(uint256 credit);
event Error(string message);
function getCredit(uint256 _borrowAmount) public returns(bool){
if(!borrows[msg.sender]){
borrows[msg.sender] = true;
borrowAmount[msg.sender] = _borrowAmount;
Result(message, _borrowAmount);
return true;
}
Error(error);
return false;
}
function returnCredit(uint256 _returnAmount, address _address) public returns(bool){
if(msg.sender == owner && borrowAmount[_address] > 0){
borrowAmount[_address] = borrowAmount[_address] - _returnAmount;
Result("Rest of the borrow is", borrowAmount[_address]);
return true;
} else {
Error("This address don't have any credit");
return false;
}
}
function isDebtor(address _address) public returns(bool){
if(borrows[_address]){
DebtorValue(borrowAmount[_address]);
return true;
} else{
return false;
}
}
}