Skip to content

Instantly share code, notes, and snippets.

@jpswelch
Created May 21, 2022 23:07
Show Gist options
  • Save jpswelch/5bbfac3da28b786826769ecfaa9a1c26 to your computer and use it in GitHub Desktop.
Save jpswelch/5bbfac3da28b786826769ecfaa9a1c26 to your computer and use it in GitHub Desktop.
TheRunDown Event Request
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
// Contract Address: 0xD0f66Ca18E1E21f4A05fEA0AB684CAEb52716a84
// import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/contracts/src/v0.8/ChainlinkClient.sol";
// import "@chainlink/contracts/src/v0.8/ConfirmedOwner.sol";
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/contracts/src/v0.8/ConfirmedOwner.sol";
contract TheRunDownEventRequest is ChainlinkClient, ConfirmedOwner {
using Chainlink for Chainlink.Request;
uint256 constant private ORACLE_PAYMENT = 0 * LINK_DIVISIBILITY / 100 * 5;
uint256 public Away;
uint256 public Home;
constructor() ConfirmedOwner(msg.sender){
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
setChainlinkOracle(0xedaa6962Cf1368a92e244DdC11aaC49c0A0acC37);
}
function requestHomeAndAway(
string memory eventId
)
public
onlyOwner
{
bytes32 _jobId = "10ba46001cd14678923e1ec8af026774";
Chainlink.Request memory req = buildChainlinkRequest(_jobId, address(this), this.fulfillHomeAndAway.selector);
req.add("matchId", eventId);
sendOperatorRequest(req, ORACLE_PAYMENT);
}
event RequestFulfilledHomeAndAway(
bytes32 indexed requestId,
uint256 indexed Away,
uint256 indexed Home
);
function fulfillHomeAndAway(
bytes32 requestId,
uint256 _Away,
uint256 _Home
)
public
recordChainlinkFulfillment(requestId)
{
emit RequestFulfilledHomeAndAway(requestId, _Away, _Home);
Home = _Home;
Away = _Away;
}
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