-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIGTokenizerConsumer.sol
More file actions
73 lines (60 loc) · 2.8 KB
/
IGTokenizerConsumer.sol
File metadata and controls
73 lines (60 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import {Chainlink, ChainlinkClient} from "@chainlink/contracts@0.8.0/src/v0.8/ChainlinkClient.sol";
import {ConfirmedOwner} from "@chainlink/contracts@0.8.0/src/v0.8/shared/access/ConfirmedOwner.sol";
import {LinkTokenInterface} from "@chainlink/contracts@0.8.0/src/v0.8/shared/interfaces/LinkTokenInterface.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract IGTokenizerConsumer is ChainlinkClient {
using Chainlink for Chainlink.Request;
using Strings for uint96;
uint256 public volume;
bytes32 private jobId;
uint256 private fee;
struct IGTokenization {
string postId;
address requester;
string postTokenId;
bool isPending;
bool isVerified;
}
mapping(bytes32 => IGTokenization) public requests;
bytes32[] public requestKeys;
event TokenizationRequest(bytes32 indexed requestId, string postId, string hashId);
event InstagramPostVerification(bytes32 indexed requestId, string postId, bool isVerified);
constructor() {
setChainlinkToken(0x779877A7B0D9E8603169DdbD7836e478b4624789);
setChainlinkOracle(0xDE6fe1bC4Dda932e0a5b557DdB10bbe5878ee752);
jobId = "969b68fc36ab4cdfb2626c42d82842eb";
fee = 0.1 * 10**18;
}
function verifyAuthority(string memory postIg, string memory hashVerify) public returns (bytes32 requestId) {
Chainlink.Request memory req = buildChainlinkRequest(
jobId,
address(this),
this.processVerification.selector
);
req.add("postId", postIg);
req.add("hashToVerify", hashVerify);
requestId = sendChainlinkRequest(req, fee);
requestKeys.push(requestId);
requests[requestId] = IGTokenization(postIg, msg.sender, hashVerify, true, false);
emit TokenizationRequest(requestId, postIg, hashVerify);
return requestId;
}
function processVerification(bytes32 requestId, bool valid) virtual public recordChainlinkFulfillment(requestId) {
require(requests[requestId].isPending, "Oracle request already resolved");
requests[requestId].isPending = false;
requests[requestId].isVerified = valid;
emit InstagramPostVerification(requestId, requests[requestId].postId, valid);
}
function getAllTokenizationRequests() external view returns (bytes32[] memory, IGTokenization[] memory) {
bytes32[] memory keys = new bytes32[](requestKeys.length);
IGTokenization[] memory tokenizationContracts = new IGTokenization[](requestKeys.length);
for (uint256 i = 0; i < requestKeys.length; i++) {
bytes32 key = requestKeys[i];
keys[i] = key;
tokenizationContracts[i] = requests[key];
}
return (keys, tokenizationContracts);
}
}