I created a struct as follows:
struct Node{ // each node models each device on the network
address nodeAdress; // adress of the node
uint trustValue; // trust value assigned to the node
uint perCentMalware;// percent probability calculated at the node
}
Then I declared an array Node[] allNodes;.
I have a function addNewNode() in my contract.
function addNewNode(address newNodeAdress) public returns(uint)
{
addressToIndex[newNodeAdress] = allNodes.length; // newNodeAdress added to map
return allNodes.push(Node(newNodeAdress,50,200)); // nodes with default values
}
This is the result obtained while testing the code:
contractInstance.addNewNode.call(0x21f2118a4c7c5fda33d22faa1e2497211e69e935)
{ [String: '1'] s: 1, e: 0, c: [ 1 ] } contractInstance.addNewNode.call(0xfb075f799ba2b86599f93a73a34626ade8c237a6)
{ [String: '1'] s: 1, e: 0, c: [ 1 ] }
As it can be observed clearly, I called the addNewNode() function two times, but the return value,i.e., the allNodes.length value remains the same 1. Why is it so? Is there any conceptual misunderstanding here?
.calldoesn't persist state changes: try removing it. See https://ethereum.stackexchange.com/questions/765/what-is-the-difference-between-a-transaction-and-a-call – eth Jun 21 '17 at 07:22