Skip to content

Instantly share code, notes, and snippets.

@EtDu EtDu/leaseGenerator.sol
Last active Mar 22, 2020

Embed
What would you like to do?
function createNewLease(
uint8 numberOfMonths,
uint16 monthlyAmountUsd,
uint16 leaseDepositUsd,
uint32 leasePaymentWindowSeconds,
uint32 depositPaymentWindowSeconds,
address payable tenantAddr
) public onlyLandlord {
uint64 depositPaymentWindowEnd = uint64(now.add(depositPaymentWindowSeconds));
tenantLease[tenantAddr] = Lease(
numberOfMonths,
0,
monthlyAmountUsd,
leaseDepositUsd,
leasePaymentWindowSeconds,
0,
depositPaymentWindowEnd,
false,
false
);
emit leaseCreated(
numberOfMonths,
0,
monthlyAmountUsd,
leaseDepositUsd,
leasePaymentWindowSeconds,
false,
false
);
}
function payLeaseDeposit() public payable {
Lease storage lease = tenantLease[msg.sender];
require(!lease.leaseDepositPaid, "Lease deposit is already paid.");
require(lease.depositPaymentWindowEnd >= now, "Lease deposit payment must fit into payment window");
tenantAddress = msg.sender;
tenantPayment = msg.value;
workingState = State.payingLeaseDeposit;
fetchUsdRate();
}
function _payLeaseDeposit() internal {
workingState = State.idle;
Lease storage lease = tenantLease[tenantAddress];
uint amountSentUsd = tenantPayment.mul(ETHUSD).div(1e18);
require(
amountSentUsd >= lease.leaseDepositUsd - 5 &&
amountSentUsd <= lease.leaseDepositUsd + 5,
"Deposit payment must equal to the deposit amount with a maximum offset of $5");
lease.leaseDepositPaid = true;
lease.depositPaymentWindowEnd = 0;
lease.leasePaymentWindowEnd = uint64(now + lease.leasePaymentWindowSeconds);
emit leaseDepositPaid(
tenantAddress,
amountSentUsd
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.