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

2022-04-11 11:22:28 +08:00
 rimutuyuan
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 数组

1423 次点击
所在节点    Solidity
2 条回复
passon
2022-04-11 12:53:14 +08:00
写合约好找工作吗
samohyes
2022-04-11 13:18:41 +08:00
_logisticsData 看下是咋定义的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/846234

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX