基于Chainlink v2规范实现直接请求的配置问题咨询
核心问题解答
1. 事件与sendChainlinkRequest调用规则
你不需要自定义事件,也不需要自行生成requestId,正常调用sendChainlinkRequest即可。
你之前感知到的ChainlinkRequested是ChainlinkClient合约的内部轻量事件,仅携带requestId参数,实际Chainlink节点作业监听的是Oracle合约层面触发的标准事件,无需你在业务合约中额外定义。
2. 标准监听事件的ABI参数
底层默认触发的事件名称为OracleRequest,你直接将以下事件定义填入ethabidecodelog任务的abi参数即可:
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
其中末尾的data字段就是buildChainlinkRequest自动编码生成的CBOR payload,后续cborparse任务直接读取$(decode_log.data)即可正常解析参数。
另外你提供的合约示例中doRequest方法遗漏了sendChainlinkRequest(req, 支付额度)的调用,补充后即可正常触发上述标准事件,无需修改其他合约逻辑。
encode_mwr变量说明
encode_mwr是Chainlink Direct Request作业的常规自定义中间变量,全称是encode multi word response,文档示例省略了该变量的定义步骤,标准写法是在你拿到外部适配器返回结果后,增加ethabiencode任务生成该变量:
encode_mwr [type="ethabiencode" abi="fulfill(bytes32 requestId, uint256 value)" data={ "requestId": $(decode_log.requestId), "value": $(你的适配器返回结果字段) }]
后续encode_tx的data字段直接引用$(encode_mwr)即可生成符合fulfill方法入参要求的调用数据。
内容的提问来源于stack exchange,提问作者Jamie Pickett
相关产品推荐
相关产品推荐

