1

我正在通过创建一个简单的存储合约来练习,但我无法从数组“数字”中存储或检索值。uint "structID" 不会增加,函数 "testRetrieve" 只为正确的索引返回 0。

“StructID”没有递增的事实让我相信问题出在“store”函数上。但是,在 SO 和在线教程/文档中阅读了多个问题后,我仍然感到困惑。

有谁知道为什么这个合约不会存储数据?

contract testStruct {

   uint public structID;

    struct SomeStruct {
        uint[] numbers;
    }

    SomeStruct[] someStructs;

    function store(uint _numbers, uint entryID) public {

        SomeStruct memory someStruct;
        someStructs.push(someStruct);

        someStructs[entryID].numbers.push(_numbers);

        structID++;

    }

    function testRetrieve(uint entryID, uint test) public view returns (uint) {

        return someStructs[entryID].numbers[test];

    }
}

编辑:对于上述功能,我从私有区块链上的 geth 控制台调用所有功能。对于“testRetrieve”,我正在使用为“entryID”和“test”提供的“0”来测试函数,以指定数组中的第一个条目。

函数“store”在调用时发送交易。

编辑:

问题是气体。尽管我的私网 gas 价格很低,但在我的网络默认值 90000 的基础上,给交易 200000 gas(存储功能成本约为 104000)使其成功。

4

0 回答 0