Created
April 18, 2021 19:35
-
-
Save christoph2806/81f262153eb4df23a9d98d39dd13b8fc to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.11+commit.5ef660b1.js&optimize=true&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: Apache-2.0 | |
pragma solidity ^0.6.0; | |
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol"; | |
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/vendor/Ownable.sol"; | |
/* | |
* This is a demo of the Chainlink FlightRatings Oracle. | |
* To demonstrate, follow these steps: | |
* | |
* 1) Compile the contract | |
* 2) Deploy the contract to xDai Chain | |
* 3) Call the requestRatingsOracle function | |
* 4) A short time later, the oracle will call back the fullfillRatingsOracle function with the result. | |
* | |
*/ | |
contract ChainlinkFlightRatingsOracleDemo is ChainlinkClient, Ownable { | |
uint256 constant private ORACLE_PAYMENT = 0 * LINK; | |
address oracle = 0xa68bC2d344f69F34f5A7cbb5233f9bF1a270B2f6; | |
// string jobId = "d62ca345ab9443ddbe9087560f7e833b"; | |
bytes32 public ratings; | |
event RequestRatingsOracleFulfilled( | |
bytes32 indexed requestId, | |
bytes32 ratings | |
); | |
constructor() public Ownable() { | |
setChainlinkToken(0xE2e73A1c69ecF83F464EFCE6A5be353a37cA09b2); | |
} | |
function requestRatingsOracle() | |
public | |
onlyOwner | |
{ | |
Chainlink.Request memory req = buildChainlinkRequest( | |
stringToBytes32('d62ca345ab9443ddbe9087560f7e833b'), | |
address(this), | |
this.fulfillRatingsOracle.selector | |
); | |
req.add("extPath", "LH/117"); // replace this with Carrier/FlightNumber combination of your choice | |
sendChainlinkRequestTo(oracle, req, ORACLE_PAYMENT); | |
} | |
function fulfillRatingsOracle(bytes32 _requestId, bytes32 _ratings) | |
public | |
recordChainlinkFulfillment(_requestId) | |
{ | |
ratings = _ratings; | |
emit RequestRatingsOracleFulfilled(_requestId, _ratings); | |
} | |
function stringToBytes32(string memory source) private pure returns (bytes32 result) { | |
bytes memory tempEmptyStringTest = bytes(source); | |
if (tempEmptyStringTest.length == 0) { | |
return 0x0; | |
} | |
assembly { // solhint-disable-line no-inline-assembly | |
result := mload(add(source, 32)) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment