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:

{ [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?

Your Answer

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

Browse other questions tagged or ask your own question.