AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题 / 77619710
Accepted
János Barna
János Barna
Asked: 2023-12-07 19:41:33 +0800 CST2023-12-07 19:41:33 +0800 CST 2023-12-07 19:41:33 +0800 CST

在我的智能合约中看不到(Chainlink)请求的数据

  • 772

我正在尝试从 Chainlink 外部适配器获取智能合约中的数据:

获取桥 "{"data":{"result":{"id":"UCAl9Ld79qaZxp9JzEOwd3aA","statistics":{"subscriberCount":"209000"}}},"jobRunId":"0x84aae6f7b7144fbc8196230158918797","statusCode": 200}”

姓名:玉兔

requestData: {"id": $(jobSpec.externalJobID), "data": { "chid": $(decode_cbor.chid)},"key": $(decode_cbor.key)}

解析 jsonparse "209000"

路径:数据、结果、统计、订阅者计数

数据:$(获取)

编码数据ethabiencode“0x0000000000000000000000000000000000000000000000000000000000033068”

abi:(uint256 值)

数据:{“值”:$(解析)}

编码_tx ethabiencode“0x4ab0d1902a02a37be17119894c2d9400f9bcf563bd4be47496af9a493a96eb412676916c000000000000000000000000000000000000000000000 00000de0b6b3a76400000000000000000000000000002e495ea15b191aff2dea171abba537dc597d6f117642d3750000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000006571ad1800000000000000000000000000000000000000000000 000000000000000033068"

abi:fullOracleRequest(bytes32 requestId,uint256付款,地址callbackAddress,bytes4callbackFunctionId,uint256到期,bytes32数据)

数据:{“requestId”:$(decode_log.requestId),“付款”:$(decode_log. payment),“callbackAddress”:$(decode_log.callbackAddr),“callbackFunctionId”:$(decode_log.callbackFunctionId),“到期” :$(decode_log.cancelExpiration),“数据”:$(encode_data)}

将 tx ethtx 提交至:0x34b33d85A6a642A6Eaa1fE554f576c6122FF64b6

数据:$(encode_tx)

我正在尝试获取以下智能合约中的订阅者数量: // SPDX-License-Identifier: MIT pragma Solidity ^0.8.7;

导入“@chainlink/contracts/src/v0.8/ChainlinkClient.sol”;导入“@chainlink/contracts/src/v0.8/ConfirmedOwner.sol”;

/**

  • 这是使用未经审核代码的示例合同。
  • 请勿在生产中使用此代码。*/

合约 ConsumerContract 是 ChainlinkClient,ConfirmedOwner { 使用 Chainlink for Chainlink.Request;

uint256 private constant ORACLE_PAYMENT = 1 * LINK_DIVISIBILITY; // 1 * 10**18
uint256 public lastRetrievedSubscriberCount;

event RequestForSubscriberCountFulfilled(
    bytes32 indexed requestId,
    uint256 indexed subscriberCount
);

/**
 *  Goerli
 * @dev LINK address in Sepholia network: 0x779877A7B0D9E8603169DdbD7836e478b4624789
 * @dev Check https://docs.chain.link/docs/link-token-contracts/ for LINK address for the right network
 */
constructor() ConfirmedOwner(msg.sender) {
    setChainlinkToken(0x779877A7B0D9E8603169DdbD7836e478b4624789);
}

function requestSubscriberCount(
    address _oracle,
    string memory _jobId,
    string memory channelId,
    string memory apiKey
) public onlyOwner {
    Chainlink.Request memory req = buildOperatorRequest(
        stringToBytes32(_jobId),
        this.fulfillRequestInfo.selector
    );

    req.add("chid", channelId);
    req.add("key", apiKey);
    sendOperatorRequestTo(_oracle, req, ORACLE_PAYMENT);
}

function fulfillRequestInfo(bytes32 _requestId, string memory _info)
    public
    recordChainlinkFulfillment(_requestId)
{
    // Parse the JSON data to extract the subscriberCount
    (uint256 subscriberCount, ) = abi.decode(bytes(_info), (uint256, uint256));

    emit RequestForSubscriberCountFulfilled(_requestId, subscriberCount);
    lastRetrievedSubscriberCount = subscriberCount;
}

function getSubscriberCount() public view returns (uint256) {
    return lastRetrievedSubscriberCount;
}

/*
========= UTILITY FUNCTIONS ==========
*/

function contractBalances()
    public
    view
    returns (uint256 eth, uint256 link)
{
    eth = address(this).balance;

    LinkTokenInterface linkContract = LinkTokenInterface(
        chainlinkTokenAddress()
    );
    link = linkContract.balanceOf(address(this));
}

function getChainlinkToken() public view returns (address) {
    return chainlinkTokenAddress();
}

function withdrawLink() public onlyOwner {
    LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
    require(
        link.transfer(msg.sender, link.balanceOf(address(this))),
        "Unable to transfer Link"
    );
}

function withdrawBalance() public onlyOwner {
    payable(msg.sender).transfer(address(this).balance);
}

function cancelRequest(
    bytes32 _requestId,
    uint256 _payment,
    bytes4 _callbackFunctionId,
    uint256 _expiration
) public onlyOwner {
    cancelChainlinkRequest(
        _requestId,
        _payment,
        _callbackFunctionId,
        _expiration
    );
}

function stringToBytes32(string memory source)
    private
    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))
    }
}

}

solidity
  • 1 1 个回答
  • 21 Views

1 个回答

  • Voted
  1. Best Answer
    Derek
    2023-12-07T23:27:12+08:002023-12-07T23:27:12+08:00

    您能否向我们指出您的请求交易以及您要发送到的预言机地址?

    根据上下文,我假设您正在向 Chainlink 的 ETH Sepolia 测试网预言机 0x34b33d85a6a642a6eaa1fe554f576c6122ff64b6 发出请求。

    根据您提出问题的时间,我假设这些失败的 Oracle 履行交易之一是您的:

    1. https://sepolia.etherscan.io/tx/0x7a440e81964e7552ba7784d7246fdd6b35b310f910c3639a8f88372e007640a4
    2. https://sepolia.etherscan.io/tx/0x45862741e98669d733f6645f53b2078ab9359d9f0a46798ccab26d87ce6ba29a
    3. https://sepolia.etherscan.io/tx/0xac2ce4aca4fbe7fff50234c3de568a4dbdaeea249a7e881d9f46152f4e93a7f5
    4. https://sepolia.etherscan.io/tx/0xa50050fb9c77b40ebcb22dad25f095c4c9bdbd7ee22f52ffd2aa7f1e87c9d2ed

    如果您查看上述任何履行交易,您都会看到合约执行错误Data versions must match。

    查看 Operator.sol(oracle)合约,这是失败的情况: https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.7/Operator.sol#L480

    您将哪个版本ChainlinkClient.sol导入您的智能合约?我建议您使用最新版本,看看这是否会有所不同。

    • 0

相关问题

  • 安全帽安装正在下降安装

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    使用 <font color="#xxx"> 突出显示 html 中的代码

    • 2 个回答
  • Marko Smith

    为什么在传递 {} 时重载解析更喜欢 std::nullptr_t 而不是类?

    • 1 个回答
  • Marko Smith

    您可以使用花括号初始化列表作为(默认)模板参数吗?

    • 2 个回答
  • Marko Smith

    为什么列表推导式在内部创建一个函数?

    • 1 个回答
  • Marko Smith

    我正在尝试仅使用海龟随机和数学模块来制作吃豆人游戏

    • 1 个回答
  • Marko Smith

    java.lang.NoSuchMethodError: 'void org.openqa.selenium.remote.http.ClientConfig.<init>(java.net.URI, java.time.Duration, java.time.Duratio

    • 3 个回答
  • Marko Smith

    为什么 'char -> int' 是提升,而 'char -> Short' 是转换(但不是提升)?

    • 4 个回答
  • Marko Smith

    为什么库中不调用全局变量的构造函数?

    • 1 个回答
  • Marko Smith

    std::common_reference_with 在元组上的行为不一致。哪个是对的?

    • 1 个回答
  • Marko Smith

    C++17 中 std::byte 只能按位运算?

    • 1 个回答
  • Martin Hope
    fbrereto 为什么在传递 {} 时重载解析更喜欢 std::nullptr_t 而不是类? 2023-12-21 00:31:04 +0800 CST
  • Martin Hope
    比尔盖子 您可以使用花括号初始化列表作为(默认)模板参数吗? 2023-12-17 10:02:06 +0800 CST
  • Martin Hope
    Amir reza Riahi 为什么列表推导式在内部创建一个函数? 2023-11-16 20:53:19 +0800 CST
  • Martin Hope
    Michael A fmt 格式 %H:%M:%S 不带小数 2023-11-11 01:13:05 +0800 CST
  • Martin Hope
    God I Hate Python C++20 的 std::views::filter 未正确过滤视图 2023-08-27 18:40:35 +0800 CST
  • Martin Hope
    LiDa Cute 为什么 'char -> int' 是提升,而 'char -> Short' 是转换(但不是提升)? 2023-08-24 20:46:59 +0800 CST
  • Martin Hope
    jabaa 为什么库中不调用全局变量的构造函数? 2023-08-18 07:15:20 +0800 CST
  • Martin Hope
    Panagiotis Syskakis std::common_reference_with 在元组上的行为不一致。哪个是对的? 2023-08-17 21:24:06 +0800 CST
  • Martin Hope
    Alex Guteniev 为什么编译器在这里错过矢量化? 2023-08-17 18:58:07 +0800 CST
  • Martin Hope
    wimalopaan C++17 中 std::byte 只能按位运算? 2023-08-17 17:13:58 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve