10 Solidity 中获得数组切片

struct Position {
    uint name,
    uint age
}
Position[] public positions; // 结构数组

//通过call()的方式,获取postion数组,但实际不发出交易
function getAllarray() external returns(Positon memory){
    //从其他合约获取数据
    for(){
        postion.push(postion(12,12));
    }
    return postion;
}

现在想利用calldata的数组切片功能https://learnblockchain.cn/docs/solidity/types.html#array-slices,对最终得到的数组进行切片,不知道该怎么做。比如

//return(Position[] memory)会报错
function(positon[] calldata postions, uint start, uint end) external returns(){
    return postions[start:end];
}
请先 登录 后评论

3 个回答

Tiny熊 - 布道者
  擅长:智能合约,以太坊
请先 登录 后评论
Ethereal - Solidity智能合约开发工程师
请先 登录 后评论
Ethereal - Solidity智能合约开发工程师
请先 登录 后评论