I am trying to get from truffle develop console an array of identifiers using a custom get function but the return array is []
.
Here is my contract:
pragma solidity ^0.4.18;
contract MyInfo {
struct Info {
bytes32 id;
bytes32 name;
}
bytes32[] infoIDs;
mapping(bytes32 => Info) infos;
function addInfo(bytes32 _name) public
returns(bool success) {
bytes32 ID = keccak256(_name);
infoIDs.push(ID);
infos[ID].id = ID;
infos[ID].name =_name;
return true;
}
function getInfoIDs() public view returns(bytes32[] ids) {
return infoIDs;
}
}
And from the truffle console I run:
MyInfo.deployed().then(inst => { return inst.addInfo("testname", {from: web3.eth.accounts[0]}) })
which returns true.
To get the ids I run:
MyInfo.deployed().then(inst => { return inst.getInfoIDs.call() })
but I get []
.
Any ideas what it might be the problem?
I'm using
Truffle v4.1.0 (core: 4.1.0)
and
Solidity v0.4.19 (solc-js)
EDIT: If I put the code in Remix I get the ids correct.
EDIT2: I noticed that the values assigned to other variables inside the addInfo function don't exist afterwards...