V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
rimutuyuan
V2EX  ›  Solidity

Solidity 中如何返回部分 struct 数组元素

  •  
  •   rimutuyuan · 2022-04-11 11:22:28 +08:00 · 1385 次点击
    这是一个创建于 717 天前的主题,其中的信息可能已经有所发展或是发生改变。
    function getLogisticsInfo(address goods) public returns(LogisticsData[] memory _goodsLogisticsData) {
        LogisticsData[] memory _goodsLogisticsData = new LogisticsData[](2);
        
        for (uint i=0; i < 2; i++) {
            if (_logisticsData[i].goods == goods) {
                // _logisticsData[i].queryCount = _logisticsData[i].queryCount + 1;
                _goodsLogisticsData[i] = _logisticsData[i];
            }
        }
        return _goodsLogisticsData;
    }
    

    solidity 版本 0.6.10 。以上代码可以编译通过,但是运行时报错 Bad Instruction

    其中_logisticsData 为全局 storage struct 数组

    第 1 条附言  ·  2022-04-11 13:18:15 +08:00
    已解决,是超出数组长度了
    2 条回复    2022-04-11 13:18:41 +08:00
    passon
        1
    passon  
       2022-04-11 12:53:14 +08:00
    写合约好找工作吗
    samohyes
        2
    samohyes  
       2022-04-11 13:18:41 +08:00
    _logisticsData 看下是咋定义的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3157 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:35 · PVG 20:35 · LAX 05:35 · JFK 08:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.