Event & Risk Data
Using the Chainlink Node for Event and Risk Data
The Event Data can be accessed via the same process as the Biomass and Tree Validation Data. An Example can be see below.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import '@chainlink/contracts/src/v0.8/ChainlinkClient.sol';
import '@chainlink/contracts/src/v0.8/ConfirmedOwner.sol';
contract ATestnetConsumerMulti is ChainlinkClient {
using Chainlink for Chainlink.Request;
uint256 private constant ORACLE_PAYMENT = 1 * LINK_DIVISIBILITY / 10; // 1 * 10**18, costs .1 link
uint256 public currentPrice;
uint256 public hasEvent;
uint256 public year;
uint256 public month;
uint256 public prevMintFlag;
constructor() {
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
// 0x67CB6fc6C1Fd1C2D01698f074F50E2DE5F4E2970 oracle
// 0x102D769e8e5e8ED11eC2b8e91c35A9Ef7E3C5DA9 ne operator.sol
setChainlinkOracle(0x102D769e8e5e8ED11eC2b8e91c35A9Ef7E3C5DA9);
}
function requestEventYNFullReponse(string memory _jobId, int256 _month) public {
// _jobId: e733290b2d9d4eb99057d6b0da83d686
// month: 6
// will return 1 (uint256) in varuable mintFlag when called
// TODO: Further parameterize and test.
Chainlink.Request memory req = buildChainlinkRequest(
stringToBytes32(_jobId),
address(this),
this.fulfillEventYNFullResponse.selector
);
req.add('siteId', '0001');
req.addInt('year', 2022);
req.addInt('month', _month);
sendOperatorRequest(req, ORACLE_PAYMENT);
}
event RequestEventYNMultipleFulfilled(
bytes32 indexed requestId,
uint256 _hasEvent,
uint256 _year,
uint256 _month
);
function fulfillEventYNFullResponse(
bytes32 _requestId,
uint256 _hasEvent,
uint256 _year,
uint256 _month
) public recordChainlinkFulfillment(_requestId) {
emit RequestEventYNMultipleFulfilled(_requestId, _hasEvent, _year, _month);
hasEvent = _hasEvent;
year = _year;
month = _month;
}
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))
}
}
}
Last updated