链链接:合同无法从外部适配器检索大响应数据类型
我尝试使用大响应
类型来满足请求,但是以某种方式没有在合同中显示我试图实现status status
值,而作业完全起作用如我的链条节点所示,但它不会更改status
值,它将保持0x
。所以,我想知道我的合同或工作规格是错误的吗?
这是我的合同,
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
using Chainlink for Chainlink.Request;
bytes public status;
string public statusString;
address private oracle;
bytes32 private jobId;
uint256 private fee;
event RequestFulfilled(bytes32 indexed requestId,bytes indexed data);
/**
* Network: Kovan
* Oracle: 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8 (Chainlink Devrel
* Node)
* Job ID: d5270d1c311941d0b08bead21fea7747
* Fee: 0.1 LINK
*/
constructor() {
setPublicChainlinkToken();
oracle = 0xDFE5e6C5C624724384b55719b7da79d3EbB60057;
fee = 1 * 10 ** 18; // (Varies by network and job)
}
function requesData(string memory _jobId) public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(stringToBytes32(_jobId), address(this), this.fulfill.selector);
// Set the URL to perform the GET request on
request.add("trackingNo", "HF123456789DL");
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, bytes memory bytesData) public recordChainlinkFulfillment(_requestId)
{
emit RequestFulfilled(_requestId, bytesData);
status = bytesData;
statusString = string(status);
}
// function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract
// function getStatus() public view returns (string memory) {
// return bytes32ToString(status);
// }
function bytes32ToString(bytes32 _bytes32)
public
pure
returns (string memory)
{
uint8 i = 0;
while (i < 32 && _bytes32[i] != 0) {
i++;
}
bytes memory bytesArray = new bytes(i);
for (i = 0; i < 32 && _bytes32[i] != 0; i++) {
bytesArray[i] = _bytes32[i];
}
return string(bytesArray);
}
function stringToBytes32(string memory source)
public
pure
returns (bytes32 result)
{
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}
assembly {
// solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}
这是我的工作规格。
type = "directrequest"
schemaVersion = 1
name = "Halffin-Data-EA-Create-Tracking8"
externalJobID = "3f706a6b-efdd-44ac-8167-f880a6ca63ac"
maxTaskDuration = "0s"
contractAddress = "0xDFE5e6C5C624724384b55719b7da79d3EbB60057"
minIncomingConfirmations = 0
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="halffin-data" requestData="{\\"id\\": $(jobSpec.externalJobID), \\"data\\": { \\"trackingNo\\": $(decode_cbor.trackingNo)}}"]
parse [type=jsonparse path="data,tracking,slug" data="$(fetch)"]
encode_data [type=ethabiencode abi="(bytes value)" data="{ \\"value\\": $(parse) }"]
encode_tx [type=ethabiencode
abi="fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes 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="0xDFE5e6C5C624724384b55719b7da79d3EbB60057" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> encode_data -> encode_tx -> submit_tx
"""
- 中的日志
这些是已完成的作业Fetch
"{\"jobRunID\":\"3f706a6b-efdd-44ac-8167-f880a6ca63ac\",\"data\":{\"tracking\":{\"id\":2,\"slug\":\"halffin-logistics\",\"tracking_number\":\"HF123456789DL\"},\"result\":null},\"result\":null}"
name: halffin-data
requestData: {"id": $(jobSpec.externalJobID), "data": { "trackingNo": $(decode_cbor.trackingNo)}}
parse
"halffin-logistics"
path: data,tracking,slug
data: $(fetch)
encode_data
"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001168616c6666696e2d6c6f67697374696373000000000000000000000000000000"
abi: (bytes value)
data: { "value": $(parse) }
encode_tx
"0x728853aa63b008d8b908b2d431b9ea703268ba10e60ab40603941ec91a2955278f219c1e0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000136e61cdeae727926aa768574e2f979c724d6cad7c1de7e1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062586d6800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001168616c6666696e2d6c6f67697374696373000000000000000000000000000000"
abi: fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes 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)}
crises_tx
"{\"logs\": [], \"root\": \"0x\", \"status\": \"0x0\", \"gasUsed\": \"0x5c49\", \"blockHash\": \"0x5b55db677b2776bb637fdb9ba2077e7db21de8e8beba60fb79e1384ae51f39a8\", \"logsBloom\": \"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", \"blockNumber\": \"0x1d94cd5\", \"contractAddress\": \"0x0000000000000000000000000000000000000000\", \"transactionHash\": \"0xc5371c5ce1692b39835e44fb61c47d2deeeb509f71e32fccb0c5d42eec3be443\", \"transactionIndex\": \"0x1\", \"cumulativeGasUsed\": \"0x39418\"}"
to: 0xDFE5e6C5C624724384b55719b7da79d3EbB60057
data: $(encode_tx)
,如果您可能想知道为什么我使用大响应
data类型。我遵循此 link
I tried to use the large-response
type to fulfil the request but somehow it does not show up in my contract I tried to fulfil the status
value, and the job works completely as shown in my chainlink node but it does not change the status
value, it stays 0x
as it is. So, I wonder that is my contract or job spec wrong?
This is my contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
using Chainlink for Chainlink.Request;
bytes public status;
string public statusString;
address private oracle;
bytes32 private jobId;
uint256 private fee;
event RequestFulfilled(bytes32 indexed requestId,bytes indexed data);
/**
* Network: Kovan
* Oracle: 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8 (Chainlink Devrel
* Node)
* Job ID: d5270d1c311941d0b08bead21fea7747
* Fee: 0.1 LINK
*/
constructor() {
setPublicChainlinkToken();
oracle = 0xDFE5e6C5C624724384b55719b7da79d3EbB60057;
fee = 1 * 10 ** 18; // (Varies by network and job)
}
function requesData(string memory _jobId) public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(stringToBytes32(_jobId), address(this), this.fulfill.selector);
// Set the URL to perform the GET request on
request.add("trackingNo", "HF123456789DL");
return sendChainlinkRequestTo(oracle, request, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, bytes memory bytesData) public recordChainlinkFulfillment(_requestId)
{
emit RequestFulfilled(_requestId, bytesData);
status = bytesData;
statusString = string(status);
}
// function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract
// function getStatus() public view returns (string memory) {
// return bytes32ToString(status);
// }
function bytes32ToString(bytes32 _bytes32)
public
pure
returns (string memory)
{
uint8 i = 0;
while (i < 32 && _bytes32[i] != 0) {
i++;
}
bytes memory bytesArray = new bytes(i);
for (i = 0; i < 32 && _bytes32[i] != 0; i++) {
bytesArray[i] = _bytes32[i];
}
return string(bytesArray);
}
function stringToBytes32(string memory source)
public
pure
returns (bytes32 result)
{
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}
assembly {
// solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}
This is my job spec.
type = "directrequest"
schemaVersion = 1
name = "Halffin-Data-EA-Create-Tracking8"
externalJobID = "3f706a6b-efdd-44ac-8167-f880a6ca63ac"
maxTaskDuration = "0s"
contractAddress = "0xDFE5e6C5C624724384b55719b7da79d3EbB60057"
minIncomingConfirmations = 0
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="halffin-data" requestData="{\\"id\\": $(jobSpec.externalJobID), \\"data\\": { \\"trackingNo\\": $(decode_cbor.trackingNo)}}"]
parse [type=jsonparse path="data,tracking,slug" data="$(fetch)"]
encode_data [type=ethabiencode abi="(bytes value)" data="{ \\"value\\": $(parse) }"]
encode_tx [type=ethabiencode
abi="fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes 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="0xDFE5e6C5C624724384b55719b7da79d3EbB60057" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> encode_data -> encode_tx -> submit_tx
"""
- These are logs from completed job
fetch
"{\"jobRunID\":\"3f706a6b-efdd-44ac-8167-f880a6ca63ac\",\"data\":{\"tracking\":{\"id\":2,\"slug\":\"halffin-logistics\",\"tracking_number\":\"HF123456789DL\"},\"result\":null},\"result\":null}"
name: halffin-data
requestData: {"id": $(jobSpec.externalJobID), "data": { "trackingNo": $(decode_cbor.trackingNo)}}
parse
"halffin-logistics"
path: data,tracking,slug
data: $(fetch)
encode_data
"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001168616c6666696e2d6c6f67697374696373000000000000000000000000000000"
abi: (bytes value)
data: { "value": $(parse) }
encode_tx
"0x728853aa63b008d8b908b2d431b9ea703268ba10e60ab40603941ec91a2955278f219c1e0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000136e61cdeae727926aa768574e2f979c724d6cad7c1de7e1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062586d6800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001168616c6666696e2d6c6f67697374696373000000000000000000000000000000"
abi: fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes 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
"{\"logs\": [], \"root\": \"0x\", \"status\": \"0x0\", \"gasUsed\": \"0x5c49\", \"blockHash\": \"0x5b55db677b2776bb637fdb9ba2077e7db21de8e8beba60fb79e1384ae51f39a8\", \"logsBloom\": \"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", \"blockNumber\": \"0x1d94cd5\", \"contractAddress\": \"0x0000000000000000000000000000000000000000\", \"transactionHash\": \"0xc5371c5ce1692b39835e44fb61c47d2deeeb509f71e32fccb0c5d42eec3be443\", \"transactionIndex\": \"0x1\", \"cumulativeGasUsed\": \"0x39418\"}"
to: 0xDFE5e6C5C624724384b55719b7da79d3EbB60057
data: $(encode_tx)
In case, you might wonder why I use the large-response
data type. I followed this link
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
contractAddress
在(get&gt;大字节)中指定的
必须指向operator.sol.sol.sol
notoracle.sol.sol.sol.sol.sol
。(get&gt; uint256)
指向oracle.sol
。oracle.sol
并不是要处理大字节,也不是多变量的UINT256输出。这是在混音上部署
operator.sol.sol.sol.sol的当前版本的代码,然后将正确的
ConsectAddress
在链链节点GUI中获取相关的Job-Spec。The
contractAddress
specified in the(Get > Large bytes)
must be pointed atoperator.sol
notoracle.sol
.(Get > Uint256)
is pointed atoracle.sol
.Oracle.sol
is not meant to handle Large bytes, nor multi-variable Uint256 output.Here is the code to deploy the current version of
operator.sol
on remix to then obtain the correctcontractAddress
to the associated job-spec within the chainlink node GUI.