{"id":22994297,"url":"https://github.com/jccdex/jcc_moac_alarm","last_synced_at":"2026-04-24T16:35:52.923Z","repository":{"id":44058334,"uuid":"215090268","full_name":"JCCDex/jcc_moac_alarm","owner":"JCCDex","description":"Timer oracle on MOAC","archived":false,"fork":false,"pushed_at":"2023-01-24T00:43:44.000Z","size":479,"stargazers_count":0,"open_issues_count":15,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T12:48:49.909Z","etag":null,"topics":["contract","moac","oracle","solidity","timer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JCCDex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-14T16:17:06.000Z","updated_at":"2020-03-26T05:46:02.000Z","dependencies_parsed_at":"2023-01-26T20:46:28.863Z","dependency_job_id":null,"html_url":"https://github.com/JCCDex/jcc_moac_alarm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JCCDex/jcc_moac_alarm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCCDex%2Fjcc_moac_alarm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCCDex%2Fjcc_moac_alarm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCCDex%2Fjcc_moac_alarm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCCDex%2Fjcc_moac_alarm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JCCDex","download_url":"https://codeload.github.com/JCCDex/jcc_moac_alarm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCCDex%2Fjcc_moac_alarm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32231127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contract","moac","oracle","solidity","timer"],"created_at":"2024-12-15T05:17:43.702Z","updated_at":"2026-04-24T16:35:52.908Z","avatar_url":"https://github.com/JCCDex.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jcc_moac_alarm\n\njcc moac alarm 是一个朴素的预言机，就是一个定时执行驱动的合约，用来辅助业务合约的定时任务唤醒操作，任何人都能注册该服务，并充值方便自动驱动调用。\n\n主网合约地址: 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8\n\n测试网合约地址: 0xc87f0b41e26da5919837427e46eb8b2e683380e7\n\n## 如何使用\n\njcc moac alarm 服务的是需要定时执行的合约，也就是说你的合约需要一个定时触发的调用，而合约本身是不能自动执行的，需要一个外部的输入来驱动，jcc moac alarm 通过标准接口方式可以提供这种服务。\n\n使用这个服务，简单四步即可：\n\n1. 加入 IJccMoacAlarmCallback 接口定义，给自己合约扩展一个驱动接口\n2. 在 jcc_moac_alarm 合约中注册需要驱动的合约地址\n3. 充值，为驱动者消耗燃料\n4. 创建定时回调任务\n\n### 合约接口定义\n\n安装 jcc_solidity_utils\n\n```bash\nnpm install jcc_solidity_utils\n```\n\n在合约代码中引用\n\n```javascript\nimport \"jcc-solidity-utils/contracts/interface/IJccMoacAlarmCallback.sol\";\n...\n// 回调接口实现\nfunction jccMoacAlarmCallback() public {\n  // 定时业务逻辑\n}\n...\n```\n\n示例代码请参见我们的测试代码[MockAlarmClient.sol](https://github.com/JCCDex/jcc_moac_alarm/blob/master/contract/contracts/mock/MockAlarmClient.sol)\n\n### 注册服务\n\n用户只需要在 jcc moac alarm 中注册自己的合约（已经实现 jccMoacAlarmCallback）,给出定时要求。有两种方式，一种直接在命令行上调用注册，一种在 DAPP 中，通过人机交互方式注册。\n\n命令行方式使用[jcc_moac_tool](https://github.com/JCCDex/jcc-moac-tool)\n\n```bash\n# 添加服务的合约:只有注册的合约地址才能调用预言机创建定时任务\njcc_moac_tool --abi JccMoacAlarm.json --contractAddr 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8 --method \"addClient\" --parameters '\"客户合约地址\"' --gas_limit 80000\n\n# 删除服务的合约\njcc_moac_tool --abi JccMoacAlarm.json --contractAddr 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8 --method \"removeClient\" --parameters '\"客户合约地址\"' --gas_limit 100000\n```\n\n### 充值\n\njcc moac alarm 是一个公益性的服务，通过合约方式计算每次的燃料消耗，从用户充值的资产中扣除，因此需要客户进行充值。\n\n```bash\n# 充值：朴素预言机发起定时调用前，一般和该合约关联的余额少于0.1MOAC则放弃调用\njcc_moac_tool --abi JccMoacAlarm.json --contractAddr 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8 --method \"deposit\" --parameters '\"待充值的合约\"' --amount 10 --gas_limit 150000\n\n# 查询指定合约的充值余额\njcc_moac_tool --abi JccMoacAlarm.json --contractAddr 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8 --method \"balance\" --parameters '\"待服务的合约地址\"'\n```\n\n### 创建定时任务\n\n创建定时任务可以从命令行发起，也可以在 DAPP 中操作。\n\n```bash\n# 创建定时任务\njcc_moac_tool --abi JccMoacAlarm.json --contractAddr 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8 --method \"createAlarm\" --parameters '\"待服务的合约地址\",类型(0:一次性, 1:周期性), 开始时间(单位秒), 周期(秒)'\n\n# 查询定时任务数量\njcc_moac_tool --abi JccMoacAlarm.json --contractAddr 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8 --method \"getAlarmCount\"\n\n# 查询定时任务清单\njcc_moac_tool --abi JccMoacAlarm.json --contractAddr 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8 --method \"getAlarmList\" --parameters '起始索引, 数量'\n\n# 删除定时任务\njcc_moac_tool --abi JccMoacAlarm.json --contractAddr 0xf28f3c6c6bd4911d9947c5dfea1c3b4cb09ea7d8 --method \"removeAlarm\" --parameters '\"待服务的合约地址\"'\n```\n\n除了在 DAPP 中可以操作定时任务的管理之外，也可以在合约中动态创建定时任务，做到这一点，客户合约还需要实现 IJccMoacAlarm 接口。\n\n```javascript\n// 客户合约注册定时任务通过createAlarm，取消定时任务通过removeAlarm\n// createAlarm建立新定时任务的调用者地址，必须是管理员添加的地址，防止恶意攻击\ninterface IJccMoacAlarm {\n  event CreateAlarm(address indexed contractAddr, uint256 indexed _type, uint256 indexed _begin, uint256 _peroid);\n  event RemoveAlarm(address indexed contractAddr);\n  event Alarm(address indexed contractAddr, uint256 indexed time);\n\n  function createAlarm(address _addr, uint256 _type, uint256 _begin, uint256 _peroid) external returns (bool);\n  function removeAlarm(address _addr) external returns (bool);\n}\n```\n\n客户合约的例子，请参考[MockAlarmClient.sol](https://github.com/JCCDex/jcc_moac_alarm/blob/master/contract/contracts/mock/MockAlarmClient.sol)\n\n### DAPP 模式\n\n在[TokenPocket](https://www.tokenpocket.pro/)钱包 APP 中的发现模块，查找 JCC 墨客朴素预言机，进行合约注册和充值。\n\n## 多签名钱包执行任务的注册（示例）\n\n```bash\njcc_moac_tool --abi JccMoacMultiSig.json --contractAddr \"多签名钱包地址\" --method \"setAlarm\" --parameters '\"预言机合约地址\",1,600' --gas_limit 200000\n\n```\n\n**_注意事项_**\n区块链的出块是否稳定受到很多因素影响，本合约发起执行的时间窗口为 2 分钟，如果合约和高精度时间相关，不建议使用这种方式。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjccdex%2Fjcc_moac_alarm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjccdex%2Fjcc_moac_alarm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjccdex%2Fjcc_moac_alarm/lists"}