Created
June 21, 2022 16:48
-
-
Save donoso-eth/517e2dca691980de506229cbe27eee62 to your computer and use it in GitHub Desktop.
This file contains 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
// ============= ============= Create Task and Cancel after one execution Use Case Business Logic ============= ============= // | |
// #region Create Task and Cancel after one executio | |
/************************************************************************** | |
* Stop Create Task and Cancel | |
* Similar case as the first create imple task, the difference is that | |
* we are cancelling the task (it will only run once) after first execution | |
* | |
* Step 1 : ccreateTaskAndCancel() | |
* - will create a gelato task | |
* - will store the taskId | |
* | |
* Step 2 : checkerCancel() Function. | |
* - Check If the task can be executed , in rhis case if we don't have headache | |
* - returns the execPayload of startPartyandCancel | |
* | |
* Step 3 : Executable Function: startPartyandCancel | |
* - will Start the party setting lastPartyStrt to block.timestamo | |
* - will cause a headache | |
*************************************************************************/ | |
function createTaskAndCancel() public { | |
bytes32 taskId = IOps(ops).createTask( | |
address(this), /// Contract executing the task | |
this.startPartyandCancel.selector, /// Executable function's selector | |
address(this), /// Resolver contract, in our case will be the same | |
abi.encodeWithSelector(this.checkerCancel.selector, msg.sender) /// Checker Condition | |
); | |
taskIdByUser[msg.sender] = taskId; | |
} | |
function checkerCancel(address user) | |
external | |
view | |
returns (bool canExec, bytes memory execPayload) | |
{ | |
canExec = headachePresent == false; | |
execPayload = abi.encodeWithSelector( | |
this.startPartyandCancel.selector, | |
user | |
); | |
} | |
function startPartyandCancel(address user) external onlyOps { | |
require(headachePresent == false, "NOT_READY"); | |
cancelTaskById(taskIdByUser[user]); | |
lastPartyStart = block.timestamp; | |
headachePresent = true; | |
} | |
// #endregion Create Task and Cancel after one execution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment