2

Contract code:

contract RecordStore{ struct Record { string value; address owner; } mapping(string => Record) records; Record lastRecord; function addRecord(string _recordId, string _value, address _owner) returns (bool) { Record r = records[_recordId]; r.value = _value; r.owner = _owner; lastRecord = r; return true; } function getLastRecordOwner() returns (addr) { return lastRecord.owner; } } 

Client code:

 var rs = RecordStore.deployed(); var account = web3.eth.getAccounts()[0]; var recordName = "test_name"; rs.addRecord(recordName, account, recordName, account, {from:account}).then(function(res) { rs.getLastRecordOwner.call().then(function(lastRecord) { console.log("last record owner: " + lastRecord); }); }); 

When I run the test on testrpc everything works as expected. But when I run it on geth lastRecord is null. Does anyone know why?

2
  • When you say it works on geth, do you mean on the live network or with the --dev flag? Also, it's likely an issue with your deployment/interaction, not with the contract, so you should post your process for testing Commented Oct 12, 2016 at 20:15
  • @TjadenHess I'm not running with --dev. I'm running geth locally with a local chain (using my own genesis json). I've been using truffle and do truffle migrate --reset for deploy. Commented Oct 12, 2016 at 20:33

1 Answer 1

2

it works for me this is the code with minor changes

contract test{ struct Record { string value; address owner; } mapping(string => Record) records; Record lastRecord; function addRecord(string _recordId, string _value, address _owner) returns (bool) { Record r = records[_recordId]; r.value = _value; r.owner = _owner; lastRecord = r; return true; } function getLastRecordOwner() returns (address) { return lastRecord.owner; } } 

enter image description here

3
  • Do you know if this is ran on testrpc? Commented Oct 12, 2016 at 19:05
  • The browser compiler uses testrpc, yes Commented Oct 12, 2016 at 20:17
  • Ok. Yeah - the contract works fine in testrpc. But it doesn't work in geth. Commented Oct 13, 2016 at 0:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.