Created
September 30, 2021 01:43
-
-
Save onahprosper/2317454faa8c92c31ce1d7659968a7d7 to your computer and use it in GitHub Desktop.
chain link cancel trx failing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.12; | |
import "./ChainlinkClient.sol"; | |
interface IERC20 { | |
function balanceOf(address owner) external view returns (uint); | |
function approve(address spender, uint value) external returns (bool); | |
function transfer(address to, uint value) external returns (bool); | |
function transferFrom(address from, address to, uint value) external returns (bool); | |
} | |
abstract contract Context { | |
function _msgSender() internal view virtual returns (address) { | |
return msg.sender; | |
} | |
} | |
contract ABCAlarm is ChainlinkClient, Context { | |
IERC20 internal swapToken; | |
IERC20 public link = IERC20(0x84b9B910527Ad5C03A9Ca831909E21e236EA7b06); | |
address public contractAddress = address(this); | |
address public callee; | |
address private oracle = 0x46cC5EbBe7DA04b45C0e40c061eD2beD20ca7755; | |
bytes32 private jobId = "842e5f3cbcd34f76bf416d92b47ed416"; | |
bytes32 public queries; | |
uint256 public myQuerie; | |
struct userData { | |
uint256 amountIn; | |
uint256 amountOut; | |
address[] path; | |
uint expectedTime; | |
address to; | |
} | |
mapping(address => userData) public Data; | |
mapping(uint => mapping(address => userData)) getUserData; | |
event callUserDetails(address indexed user, uint256 amountToSwap, uint256 outputAmount, uint time, address alarm); | |
event re(uint256); | |
constructor() public { | |
setChainlinkToken(0x84b9B910527Ad5C03A9Ca831909E21e236EA7b06); | |
} | |
receive() external payable {} | |
modifier onlyOwner() { | |
require(callee == _msgSender(), "Ownable: caller is not the owner"); | |
_; | |
} | |
function setPeriodToswapETHForTokens(IERC20 _swapToken, uint _timeOf) external returns (bytes32 requestId){ | |
userData storage _userData = Data[msg.sender]; | |
swapToken = _swapToken; | |
callee = msg.sender; | |
_userData.expectedTime = block.timestamp + (_timeOf); | |
_userData.to = msg.sender; | |
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfillAlarm.selector); | |
// This will return in 90 seconds | |
queries = sendChainlinkRequestTo(oracle, request, 0.1e18); | |
return queries; | |
} | |
function cancelRequest( bytes32 _requestId) public returns(bytes32 requestId) { | |
cancelChainlinkRequest(_requestId, 0.1e18, this.requested.selector,block.timestamp); | |
} | |
function requested(bytes32 _requestId) public recordChainlinkFulfillment(_requestId){ | |
myQuerie = 100; | |
} | |
function fulfillAlarm(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) { | |
userData storage userCall = Data[callee]; | |
swapToken.transferFrom(address(callee), address(this), 0.1e18); | |
emit callUserDetails(callee, userCall.amountIn, userCall.amountOut, block.timestamp, address(this)); | |
} | |
function withdrawETH() public onlyOwner{ | |
require((address(this)).balance > 0, "cannot withdraw 0 balance"); | |
userData storage userCall = Data[callee]; | |
userCall.amountIn = (address(this)).balance ; | |
payable(_msgSender()).transfer(address(this).balance); | |
} | |
function withdrawLink() public onlyOwner{ | |
link.transfer(msg.sender, link.balanceOf(address(this))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment