Ethereum solidity无法从私有链上的另一个契约访问成员变量,在remix javascript vm上运行良好
我有下面的坚固代码Ethereum solidity无法从私有链上的另一个契约访问成员变量,在remix javascript vm上运行良好,ethereum,solidity,smartcontracts,web3,geth,Ethereum,Solidity,Smartcontracts,Web3,Geth,我有下面的坚固代码 pragma solidity ^0.4.21; contract Parent { uint public childCount; Child[] public children; function makeChild(string name) external { children.push(new Child(address(this), childCount, name)); childCount++;
pragma solidity ^0.4.21;
contract Parent {
uint public childCount;
Child[] public children;
function makeChild(string name) external {
children.push(new Child(address(this), childCount, name));
childCount++;
}
function renameChild(uint index, string newName) external {
require(address(children[index]) != 0);
Child thisChild = Child(address(children[index]));
if (thisChild.isUpdated()) {
thisChild.rename(newName);
}
}
}
contract Child {
address parentAddress;
uint index;
string public name;
bool public isUpdated;
constructor(address parent, uint _index, string _name) public {
parentAddress = parent;
index = _index;
name = _name;
isUpdated = false;
}
function rename(string newName) external {
name = newName;
}
function renameViaParent(string updateName) external {
isUpdated = true;
Parent(parentAddress).renameChild(index, updateName);
}
}
我一直在通过测试这个代码。当我在JavaScriptVM中运行时,我可以从parentInstance.makeChild(“childName”)创建一个子项,并使用childInstance.renameViaParent(“newName”)重命名它
但是,当我切换到以太坊专用链(即注入式Web3)时,我仍然可以创建子级,但无法使用childInstance.renameViaParent(“newName”)重命名。它传达了这样一个信息:
气体估算错误,显示以下信息(见下文)。事务执行可能会失败。您想强制发送吗?
无效的JSON RPC响应:{“id”:1830,“jsonrpc”:“2.0”,“错误”:{“代码”:-32603}
我试图删除thisChild.isUpdated()
条件签入renameChild(index,newName)
,代码在JS VM和private Web3中都运行良好。这就是为什么我认为从Parent
访问Child
的成员变量isUpdated
是导致问题的原因
这里怎么了?可能是我的私人连锁店建立的?它与Javascript VM Remix使用的有什么不同
我正在使用geth-linux-amd64-1.8.6-12683来运行我的私有链