In Ethereum private network (geth) I do have very simple contract (in Solidity).
version 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;
}
}
I do deploy contract and then call it like this (from web3.js):
- contract.getLog()
- contract.setBalance(valid_address, 55)
- contract.getLog()
- contract.getBalance(address)
- contract.get42(address)
And I get as output result:
- [call end]: T()
- [call end]: setBalance()
- 55
- 42
Now I just add one new field to TData structure:
version 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;
}
}
I do the same calls as above:
- contract.getLog()
- contract.setBalance(valid_address, 55)
- contract.getLog()
- contract.getBalance(address)
- contract.get42(address)
But now I get:
- [call end]: T()
- [call end]: T()
- 0
- 0
Seems like 'setBalance()' function is not executed (or exited somewhere) and state in storage is not changed.
Please help!
Thanks.