Solidity 智能合约未使用 Operator.sol 合约调用 Chainlink 作业
当使用使用 oracle.sol.sol.sol.sol.sol.sol.sol
合同的固体性智能合约时,已成功触发并完成了在链条节点上部署和运行的作业规格。
但是,由于要求是返回大响应( https://docs.chain.link /docs/ligal-respons/),所以我必须使用 operator.sol.sol
合同,而不是 oracle.sol.sol.sol.sol
。然后,这项工作没有被称为。
部署的操作员合同看起来为:
/I.sstatic.net/e77nz.png“ rel =” nofollow noreferrer“>
链接令牌地址基本上取自官方的链条文档( https:///docs.chain。 link/docs/yearling-requests/)提及kovan testnet链接令牌:
,所有者地址是从运行链链接节点的帐户地址获取的:
坚固的智能合同代码是:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
contract GenericLargeResponse is ChainlinkClient {
using Chainlink for Chainlink.Request;
bytes public data;
constructor(
) {
setChainlinkToken(0xa36085F69e2889c224210F603D836748e7dC0088);
setChainlinkOracle(0x8114f13FaF377FFc7A5AD32fb8a1e448667b871D);
}
function requestBytes(
)
public
{
bytes32 specId = "a3d1b2c945244e44bdb412c5b5287df3";
uint256 payment = 100000000000000000;
Chainlink.Request memory req = buildChainlinkRequest(specId, address(this), this.fulfillBytes.selector);
req.add("data", "{\"agg_x\": \"agg_mean\", \"dataset_code\":\"MODIS/006/MOD14A1\", \"selected_band\":\"MaxFRP\", \"image_scale\":1000, \"start_date\":\"2021-09-01\", \"end_date\":\"2021-09-10\", \"geometry\":{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"id\":1},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[29.53125,19.642587534013032],[29.53125,27.059125784374068],[39.90234375,27.059125784374068],[39.90234375,19.642587534013032],[29.53125,19.642587534013032]]]}},{\"type\":\"Feature\",\"properties\":{\"id\":2},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[46.40625,13.752724664396988],[46.40625,20.138470312451155],[56.25,20.138470312451155],[56.25,13.752724664396988],[46.40625,13.752724664396988]]]}}]}}");
sendOperatorRequest(req, payment);
}
function fulfillBytes(
bytes32 requestId,
bytes memory bytesData
)
public
recordChainlinkFulfillment(requestId)
{
data = bytesData;
}
}
合同已成功编译和部署。但是 requestBytes
函数无法触发链条节点上运行的作业规格。
PS:使用 oracle.sol.sol
的类似智能合约的功能成功地触发了作业规格。
在链链接节点上运行的TOML作业规格是:
type = "directrequest"
schemaVersion = 1
name = "shamba-fire-data"
contractAddress = "0x8114f13FaF377FFc7A5AD32fb8a1e448667b871D"
maxTaskDuration = "0s"
observationSource = """
decode_log [type="ethabidecodelog"
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
decode_cbor [type="cborparse" data="$(decode_log.data)"]
fetch [type="bridge" name="shamba-fire-bridge" requestData="{\\"id\\": $(jobSpec.externalJobID), \\"data\\":$(decode_cbor.data)}"]
parse [type="jsonparse" path="result,1,0" data="$(fetch)"]
encode_data [type="ethabiencode" abi="(uint256 value)" data="{ \\"value\\": $(parse) }"]
encode_tx [type="ethabiencode"
abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}"
]
submit_tx [type="ethtx" to="0x8114f13FaF377FFc7A5AD32fb8a1e448667b871D" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> encode_data -> encode_tx -> submit_tx
"""
externalJobID = "a3d1b2c9-4524-4e44-bdb4-12c5b5287df3"
任何人都可以向我指出正确的方向,就像我在这些步骤中做错了什么,智能合约无法触发工作规格?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,
operator.sol.sol
的所有者地址应为MetAmask Wallet kovan testnet地址(而不是运行链链节点的帐户地址)。然后,在成功部署
operator.sol.sol
之后,通过传递运行的帐户地址中的帐户地址,调用setAuthorizedSenders
函数发件人地址[]
字段中的链条节点如:然后,Job-Spec的
encode_data
应具有request> request> reaction> parameter同样:
整个工作规格应该是:
同样,坚固的智能合约代码应该是:
First of all, the owner address of the
Operator.sol
should be the Metamask wallet Kovan testnet address (instead of the account address of the running Chainlink node) from which the transactions are being done.Then, after the
Operator.sol
being deployed successfully, call thesetAuthorizedSenders
function of theOperator.sol
by passing in the account address of the running Chainlink node in the sendersaddress[]
field like:Then, the job-spec's
encode_data
should be havingrequestId
parameter as well:The entire job-spec should be:
Similarly, the solidity smart contract code should be: