-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpoba_consumer.sol
83 lines (69 loc) · 2.28 KB
/
poba_consumer.sol
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
74
75
76
77
78
79
80
81
82
83
pragma solidity 0.4.24;
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.4/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.4/vendor/Ownable.sol";
import './pobaerc721.sol';
contract POBA is ChainlinkClient, Ownable, POBAasset {
uint256 constant PAYMENT = 1 * LINK;
bytes32 constant jobId = bytes32("c21ce5725bbd4f4a8aaf1aff31a1ad65");
uint256 public orderID;
event RequestOrderIdFulfilled(
bytes32 indexed requestId,
uint256 indexed orderId
);
constructor() public Ownable() {
setPublicChainlinkToken();
setChainlinkOracle(0xa42fdfd2e1a7239b76d753803cbb7611004fe068);
}
function RequestorderId(string memory _licenseKey)
public
onlyOwner
{
orderID =0;
Chainlink.Request memory req = buildChainlinkRequest(jobId, this, this.fulfillorderId.selector);
req.add("endpoint", _licenseKey);
req.add("copyPath", "data.orderId");
sendChainlinkRequest( req, PAYMENT);
}
function fulfillorderId(bytes32 _requestId, uint256 _orderId)
public
recordChainlinkFulfillment(_requestId)
{
emit RequestOrderIdFulfilled(_requestId, _orderId);
orderID = _orderId;
}
function mintPOBA() public {
require (orderID>0);
mintPobaAsset(msg.sender, orderID);
orderID =0;
}
function getOrderID() public view returns (uint256) {
return orderID;
}
function getChainlinkToken() public view returns (address) {
return chainlinkTokenAddress();
}
function withdrawLink() public onlyOwner {
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
}
function cancelRequest(
bytes32 _requestId,
uint256 _payment,
bytes4 _callbackFunctionId,
uint256 _expiration
)
public
onlyOwner
{
cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
}
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))
}
}
}