Skip to content

Instantly share code, notes, and snippets.

View EtDu's full-sized avatar

ET EtDu

  • Canada
View GitHub Profile

Keybase proof

I hereby claim:

  • I am etdu on github.
  • I am etdu (https://keybase.io/etdu) on keybase.
  • I have a public key ASBB65KMRKVbUlqyni0wbnkD1T7ftVoLVobik8NiUI8piwo

To claim this, I am signing this object:

const { utils } = require("ethers")
const {
formatUnits
} = utils
const calldata = "0x128acb08000000000000000000000000eef86c2e49e11345f1a693675df9a38f7d880c8f0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000002ea20ceeb6f00000000000000000000000000000000000000000000000000000001000276a400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a7030100000bb800000000000000aa19700d222ca3107a010204358ad599c3a0ff1de082011efddc58f1908eb6e6d8000000000000008a159794279997eacd0000660301000001f400000000000000000000026d8137b3e003000c000b000000000000001b9deb1da1851e622901040b8ad599c3a0ff1de082011efddc58f1908eb6e6d800000000000000000000007c9f97378f000c0035000000000000008a159794279997eacd00000000000000000000000000000000000000000000000000"
const decoded = utils.defaultAbiCoder.decode(
['address', 'bool', 'int256', 'uint160' , 'bytes'],
utils.hexDataSlice(calldata, 4)
const { utils } = require("ethers")
const {
formatUnits
} = utils
const calldata = ""
const decoded = utils.defaultAbiCoder.decode(
[],
utils.hexDataSlice(calldata, 4)
pragma solidity ^0.5.17;
import "./SafeMath.sol";
import "./provableAPI.sol";
contract LeaseGenerator is usingProvable {
using SafeMath for uint;
address payable landlordAddress;
address payable tenantAddress;
function withdrawFunds() public onlyLandlord {
require(leaseBalanceWei > 0, "Lease balance must be greater than 0");
uint transferAmount = leaseBalanceWei;
leaseBalanceWei = 0;
landlordAddress.transfer(transferAmount);
emit fundsWithdrawn(
transferAmount,
leaseBalanceWei
);
function reclaimLeaseDeposit() public {
Lease storage lease = tenantLease[msg.sender];
require(lease.leaseFullyPaid, "Lease must be fully paid to take back lease deposit");
require(lease.leaseDepositUsd > 0, "Lease deposit has already been removed");
tenantAddress = msg.sender;
workingState = State.reclaimingLeaseDeposit;
fetchUsdRate();
}
function collectLeaseDeposit(address payable tenantAddr) public onlyLandlord {
Lease storage lease = tenantLease[tenantAddr];
require(!lease.leaseFullyPaid, "Cannot collect lease deposit if lease is already paid");
require(lease.leasePaymentWindowEnd <= now, "Lease payment must be overdue past payment window to collect lease deposit");
require(lease.leaseDepositUsd > 0, "Lease deposit has already been removed");
tenantAddress = tenantAddr;
workingState = State.collectingLeaseDeposit;
fetchUsdRate();
}
function payLease() public payable {
Lease storage lease = tenantLease[msg.sender];
require(lease.leaseDepositPaid, "Lease deposit must be paid before making lease payments");
require(!lease.leaseFullyPaid, "Lease has already been fully paid");
require(lease.leasePaymentWindowEnd >= now, "Lease payment must fit into payment window");
tenantAddress = msg.sender;
tenantPayment = msg.value;
workingState = State.payingLease;
fetchUsdRate();
function createNewLease(
uint8 numberOfMonths,
uint16 monthlyAmountUsd,
uint16 leaseDepositUsd,
uint32 leasePaymentWindowSeconds,
uint32 depositPaymentWindowSeconds,
address payable tenantAddr
) public onlyLandlord {
uint64 depositPaymentWindowEnd = uint64(now.add(depositPaymentWindowSeconds));
constructor () public payable {
landlordAddress = msg.sender;
provable_setCustomGasPrice(100000000000);
OAR = OracleAddrResolverI(0xB7D2d92e74447535088A32AD65d459E97f692222);
}
function fetchUsdRate() internal {
require(provable_getPrice("URL") < address(this).balance, "Not enough Ether in contract, please add more");
bytes32 queryId = provable_query("URL", "json(https://api.pro.coinbase.com/products/ETH-USD/ticker).price");
validIds[queryId] = true;