-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvcsContract.js
More file actions
89 lines (67 loc) · 2.1 KB
/
Copy pathvcsContract.js
File metadata and controls
89 lines (67 loc) · 2.1 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
*
* iZ³ | IZZZIO blockchain - https://izzz.io
*
* Contract version control system
* Version control contract
*/
class vcsContract extends Contract {
get contract() {
return {
name: 'VCSContract',
owner: this._getContractOwner(),
type: 'service',
};
}
/**
* Initialization
*/
init() {
//Storage
this._contractsData = new BlockchainMap('contractsData');
//VersionChanged Event contractAddress newVersion
this._VersionChanged = new Event('VersionChanged', 'number', 'number');
//Initialize other params
super.init();
}
/**
* First call
*/
deploy() {
super.deploy();
//Change contract owner to caller
this._changeOwner();
}
/**
* Returns contract source
* @param {Number} contractAddress
* @returns {string}
*/
getContractSource(contractAddress) {
contractAddress = Number(contractAddress);
if(!this._contractsData[contractAddress]) {
return JSON.stringify({source: '', version: 0, prevSrc: ''});
}
return JSON.stringify(this._contractsData[contractAddress]);
}
/**
* Deploy new contract version
* @param {Number} contractAddress
* @param {string} newSource
*/
deployContract(contractAddress, newSource) {
this.assertOwnership('This contract can be called only from owner');
contractAddress = Number(contractAddress);
newSource = String(newSource);
if(!this._contractsData[contractAddress]) {
this._contractsData[contractAddress] = {source: '', version: 0, prevSrc: ''};
}
this._contractsData[contractAddress] = {
prevSrc: this._contractsData[contractAddress].source,
source: newSource,
version: this._contractsData[contractAddress].version + 1
};
this._VersionChanged.emit(contractAddress, this._contractsData[contractAddress].version);
}
}
global.registerContract(vcsContract);