Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christoph2806/9016d629efbbf5eeef0522077bdfb7ed to your computer and use it in GitHub Desktop.
Save christoph2806/9016d629efbbf5eeef0522077bdfb7ed 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=
// 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('e67eb5a4072b48ba881863f1b9b57fab'),
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