Adding one new field to struct makes Contract stop working

rroschinrroschin Member Posts: 5
edited February 2016 in Smart Contracts and Dapps
Hi,

I do have very simple contract (ver1):
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) external constant returns (uint _balance) { return balance[_user]; } function get42(address _user) external constant returns (uint _fourtytwo) { return mystructmap[_user].amount; } }
I do deploy contract and then call it like this:
  1. contract.getLog()
  2. contract.setBalance(valid_address, 55)
  3. contract.getLog()
  4. contract.getBalance(address)
  5. contract.get42(address)
And I get:
  1. [call end]: T()
  2. [call end]: setBalance()
  3. 55
  4. 42
Now I just add new field to TData structure:
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:
  1. contract.getLog()
  2. contract.setBalance(valid_address, 55)
  3. contract.getLog()
  4. contract.getBalance(address)
  5. contract.get42(address)
But now I get:
  1. [call end]: T()
  2. [call end]: T()
  3. 0
  4. 0
Seems like 'setBalance()' function is not executed (or exited somewhere) and state in storage is not changed.

Please help!

Thanks.
Post edited by rroschin on
Sign In or Register to comment.