在以太坊私人网络(geth)中我确实有非常简单的合同(在Solidity中)。
版本1:
contract T {
string log;
function getLastLog() constant returns (string lastLog) { return log; }
function T() { log = "[call end]: T()\n"; }
struct TData {
uint amount;
}
mapping (address => uint) balance;
mapping (address => TData) mystructmap;
function setBalance(address _user, uint _balance) {
log = "[call start]: setBalance()\n";
balance[_user] = _balance;
mystructmap[_user] = TData({amount: 42});
log = "[call end]: setBalance()\n";
}
function getBalance(address _user) constant returns (uint _balance) {
return balance[_user];
}
function get42(address _user) constant returns (uint _fourtytwo) {
return mystructmap[_user].amount;
}
}
我会部署合同,然后像这样调用它(来自 web3.js ):
我得到输出结果:
现在我只为TData结构添加一个新字段:
第2版:
contract T {
string log;
function getLastLog() constant returns (string lastLog) { return log; }
function T() { log = "[call end]: T()\n"; }
struct TData {
uint somedata;
uint amount;
}
mapping (address => uint) balance;
mapping (address => TData) mystructmap;
function setBalance(address _user, uint _balance) {
log = "[call start]: setBalance()\n";
balance[_user] = _balance;
mystructmap[_user] = TData({somedata: 11, amount: 42});
log = "[call end]: setBalance()\n";
}
function getBalance(address _user) external constant returns (uint _balance) {
return balance[_user];
}
function get42(address _user) external constant returns (uint _fourtytwo) {
return mystructmap[_user].amount;
}
}
我做同样的呼叫:
但现在我明白了:
似乎' setBalance()'函数未执行(或退出某处),存储状态不会改变。
请帮忙!
感谢。
答案 0 :(得分:2)
我之前遇到过同样的问题。我非常确定它与你发送的气体量有关。 Web3会猜测,但此前我失败了。尝试手动发送不同数量的气体以及您的请求。
这是我正在做的事情:
store
.changeProduct(d.id, d.name, d.price, d.description, d.quantity,d.enabled, {from: account, gas:1000000})
答案 1 :(得分:0)
miner.setGasPrice(gasPrice);
希望有所帮助!