-
Notifications
You must be signed in to change notification settings - Fork 1
/
NetworkManagerContract.sol
72 lines (58 loc) · 2.06 KB
/
NetworkManagerContract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
pragma solidity^0.6.1;
contract NetworkManagerContract {
uint nodeCounter;
struct NodeDetails {
string nodeName;
string role;
string publickey;
string enode;
string ip;
string id;
}
mapping (string => NodeDetails)nodes;
string[] enodeList;
event print(string nodeName, string role,string publickey, string enode, string ip, string id);
function registerNode(string memory n, string memory r, string memory p, string memory e, string memory ip, string memory id) public {
nodes[e].publickey = p;
nodes[e].nodeName = n;
nodes[e].role = r;
nodes[e].ip = ip;
nodes[e].id = id;
enodeList.push(e);
emit print(n, r, p, e, ip, id);
}
function getNodeDetails(uint16 _index) public view returns (string memory n, string memory r, string memory p, string memory ip, string memory e, string memory id, uint i) {
NodeDetails memory nodeInfo = nodes[enodeList[_index]];
return (
nodeInfo.nodeName,
nodeInfo.role,
nodeInfo.publickey,
nodeInfo.ip,
enodeList[_index],
nodeInfo.id,
_index
);
}
function getNodesCounter() public view returns (uint) {
return enodeList.length;
}
function updateNode(string memory n, string memory r, string memory p, string memory e, string memory ip, string memory id) public {
nodes[e].publickey = p;
nodes[e].nodeName = n;
nodes[e].role = r;
nodes[e].ip = ip;
nodes[e].id = id;
emit print(n, r, p, e, ip, id);
}
function getNodeList(uint16 i) public view returns (string memory n, string memory r,string memory p,string memory ip,string memory e, string memory id) {
NodeDetails memory nodeInfo = nodes[enodeList[i]];
return (
nodeInfo.nodeName,
nodeInfo.role,
nodeInfo.publickey,
nodeInfo.ip,
enodeList[i],
nodeInfo.id
);
}
}