-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNodeMetaInfo.js
71 lines (58 loc) · 1.62 KB
/
NodeMetaInfo.js
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
/**
iZ³ | Izzzio blockchain - https://izzz.io
*/
/**
* Blockchain validators object
* Provide list of validators and modules for checking blocks
*/
'use strict';
class NodeMetaInfo {
constructor(config) {
this.validators = config ? config.validators : [];
this.modules = [];
this.versions = {};
this.messageBusAddress = config ? config.recieverAddress : '';
}
/**
* Parse input meta message
* @param {NodeMetaInfo} nodeMetaInfo
* @return {NodeMetaInfo}
*/
parse(nodeMetaInfo){
if(typeof nodeMetaInfo==='string'){
try {
nodeMetaInfo = JSON.parse(nodeMetaInfo);
}catch (e) {
return this;
}
}
this.validators = nodeMetaInfo.validators;
this.modules = nodeMetaInfo.modules;
this.versions = nodeMetaInfo.versions;
this.messageBusAddress = nodeMetaInfo.messageBusAddress;
return this;
}
/**
* add new module description
* @param {object} moduleName
* @param {string} version = '0.0'
*/
addModule(moduleName, version = '0.0') {
this.modules.push(moduleName);
this.versions[moduleName] = version;
}
/**
* delete information about module
* @param {string} moduleName
*/
deleteModule(moduleName) {
if(this.modules.indexOf(moduleName) !== -1) {
this.modules.splice(this.modules.indexOf(moduleName), 1);
delete this.versions[moduleName];
}
}
}
//unify browser and node
if (this.window === undefined){
module.exports = NodeMetaInfo;
}