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 – Tjaden Hess Oct 12 '16 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. – etang Oct 12 '16 at 20:33
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? – etang Oct 12 '16 at 19:05
  • The browser compiler uses testrpc, yes – Tjaden Hess Oct 12 '16 at 20:17
  • Ok. Yeah - the contract works fine in testrpc. But it doesn't work in geth. – etang Oct 13 '16 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.