/** 2018-07-30 initial cut... Combining ChainLink's example with our Salary contract. OpenLaw call [[Payroll call:EthereumCall( contract:"0xc91cb6603421d96b3aee9ca3f9c0945e369d80c6"; interface:[{"constant":false,"inputs":[{"name":"target","type":"address"},{"name":"amountInWei","type":"uint256"}],"name":"makePayment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"}]; function:"makePayment"; arguments:Recipient Address,Monthly Salary in Wei; startDate:Payment Start Date; endDate: Payment End Date; repeatEvery:"1 minute")]] */ pragma solidity ^0.4.24; //1) add this import "github.com/smartcontractkit/chainlink/solidity/contracts/Chainlinked.sol"; //2) add these parents contract salary is Chainlinked, Ownable { uint256 public currentEthUsdConvRate; //3) add these constants //TODO - genericize these so they aren't tied to Ropsten address constant ROPSTEN_LINK_ADDRESS = 0x20fE562d797A42Dcb3399062AE9546cd06f63280; address constant ROPSTEN_ORACLE_ADDRESS = 0x1b4b6b38926f8edf03e734e0c96e1f2e9caacc03; bytes32 constant ETH_CURRENT_PRICE_SPEC_ID = bytes32("0bdf244a39234ea6a416c9d37d66c701"); //4) changes the constructor to match ownable //TODO - we'll need to make this more flexible than the constructor constructor() Ownable() public { setLinkToken(ROPSTEN_LINK_ADDRESS); setOracle(ROPSTEN_ORACLE_ADDRESS); } // 5) adds this function updateCurrentEthConversionRate() public onlyOwner { ChainlinkLib.Run memory run = newRun(PRICE_SPEC_ID, this, "ethConversionChainlinkFullfillment(bytes32,uint256)"); run.add("url", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY"); string[] memory path = new string[](1); path[0] = "USD"; run.addStringArray("path", path); run.addInt("times", 100); chainlinkRequest(run, LINK(1)); } // 5) adds this function ethConversionChainlinkFullfillment(bytes32 _requestId, uint256 _ethPrice) public checkChainlinkFulfillment(_requestId) { currentEthUsdConvRate = _ethPrice; } //left over from prior salary.sol function makePayment(address target, uint amountInWei) public { target.transfer(amountInWei); } //left over from prior salary.sol function() public payable {} //#) needed to get the LINK tokens back out when necessary function withdrawLink() public onlyOwner { require(link.transfer(owner, link.balanceOf(address(this))), "Unable to transfer"); } }
0.4.24