0

Can I define a smart contract including a dynamic array that I can update its content later?

precisely,I have some IoT(Internet of things) nodes sharing the received data from sensors with each others. I partitioned them to 2 permissioned networks: Network 1 includes: X,Y,Z nodes trusting each other. Network 2 includes: M,N,O nodes trusting each other.

Can I define a smart contract to each network containing the list of nodes (their PK) in order to create permissioned networks that enables nodes to accept the data of only its own peers in own network?

For instance, smart contract 1 includes the PK of X,Y,Z and enable them share data with each other. smart contract 2 includes the PK of M,N,O.

Due to some conditions, for changing these partitions, for example, moving node Z from network 1 to network 2.

Can I update arrays including the list of members in smart contracts 1 and 2.

That is, the list of new smart contract 1 is updated to X,Y,

and new smart contract 2 is M,N,O and plus new node Z can share data with network 2 members. Regards

0

I believe in your particular case it is better to take advantage of nested mappings.
You mentioned sensors, so I’m assuming you will not be iterating through ever-evolving dynamic arrays (this could have serious consequences in regards to security, e.g. exploiting cost > block gas limit).

To get your started you could do something as shown below (I’m sure you can take it from there, in regards to following proper C-E-I design pattern etc).

 contract PermissionedNetworks {
        //Track nodes and their particular network state (their network permission).  
        mapping(uint8 => mapping(bytes32 => bool)) public networkNodes;

        //Add a node to a particular network partition/zone.
        function addNodeToPermissionedNetwork(bytes32 _nodeID, uint8 _networkID, bool _nodeState) public {
            networkNodes[_networkID][_nodeID] = networkNodes[_networkID][_nodeID] = _nodeState;
        }
    }

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.