-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRealEstate.sol
62 lines (50 loc) · 1.66 KB
/
RealEstate.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
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Apartment is ERC20 {
uint256 public balance;
uint256 public totalIncome;
mapping(address => uint256) withdrawRegister;
constructor() ERC20("RealEstateContract", "RLSC") {
super._mint(_msgSender(), 100);
console.log("Deploying a Greeter with greeting:");
}
function withdraw() public {
withdraw(msg.sender);
}
function withdraw(address recipient) private {
require(this.balanceOf(recipient) > 0, "unauthorized");
require(getFundsToWithdraw(recipient) > 0,
"0 funds to withdraw"
);
uint fundsToWithdraw = getFundsToWithdraw(recipient);
balance = balance - fundsToWithdraw;
withdrawRegister[recipient] = totalIncome;
payable(recipient).transfer(fundsToWithdraw);
}
function transfer(address recipient, uint amount)
public
virtual
override
returns (bool)
{
if(getFundsToWithdraw(recipient) > 0){
console.log(getFundsToWithdraw(recipient));
withdraw(recipient);
}
if(getFundsToWithdraw(msg.sender) > 0){
withdraw(msg.sender);
}
super.transfer(recipient, amount);
return true;
}
function getFundsToWithdraw(address recipient) public view returns(uint){
return (totalIncome -
withdrawRegister[recipient]) * this.balanceOf(recipient) / 100;
}
receive() external payable {
balance += msg.value;
totalIncome += msg.value;
}
}