@ocap/state 1.18.34 → 1.18.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/states/rollup-block.js +3 -0
- package/lib/states/rollup.js +62 -6
- package/package.json +8 -8
|
@@ -27,6 +27,8 @@ const schema = Joi.object({
|
|
|
27
27
|
|
|
28
28
|
minReward: Joi.BN().min(0).required(),
|
|
29
29
|
|
|
30
|
+
governance: Joi.boolean().default(false),
|
|
31
|
+
|
|
30
32
|
context: schemas.context,
|
|
31
33
|
data: Joi.any().optional(),
|
|
32
34
|
}).options({ stripUnknown: true, noDefaults: false });
|
|
@@ -48,6 +50,7 @@ const create = (attrs, context) => {
|
|
|
48
50
|
'burnedAmount',
|
|
49
51
|
'rewardAmount',
|
|
50
52
|
'minReward',
|
|
53
|
+
'governance',
|
|
51
54
|
'data',
|
|
52
55
|
]),
|
|
53
56
|
};
|
package/lib/states/rollup.js
CHANGED
|
@@ -14,14 +14,18 @@ const validator = Joi.object({
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
const schema = Joi.object({
|
|
17
|
+
// a closed rollup must be paused
|
|
17
18
|
address: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
|
|
18
19
|
tokenAddress: Joi.DID().prefix().role('ROLE_TOKEN').required(),
|
|
19
20
|
contractAddress: Joi.DID().prefix().wallet('ethereum').required(),
|
|
21
|
+
vaultAddress: Joi.DID().wallet('ethereum').optional().allow(''), // FIXME: this should be enforced
|
|
20
22
|
migrateHistory: Joi.array().items(Joi.DID().prefix().wallet('ethereum')).default([]),
|
|
23
|
+
vaultHistory: Joi.array().items(Joi.DID().prefix().wallet('ethereum')).default([]),
|
|
21
24
|
paused: Joi.boolean().default(false),
|
|
25
|
+
closed: Joi.boolean().default(false),
|
|
22
26
|
|
|
23
27
|
seedValidators: Joi.array().items(validator).min(1).required(),
|
|
24
|
-
validators: Joi.array().items(validator).default([]),
|
|
28
|
+
validators: Joi.array().items(validator).max(24).default([]),
|
|
25
29
|
|
|
26
30
|
minStakeAmount: Joi.BN().positive().required(),
|
|
27
31
|
maxStakeAmount: Joi.BN().min(Joi.ref('minStakeAmount')).required(),
|
|
@@ -72,13 +76,15 @@ const create = (attrs, context) => {
|
|
|
72
76
|
const rollup = {
|
|
73
77
|
context: createStateContext(context),
|
|
74
78
|
paused: false,
|
|
79
|
+
closed: false,
|
|
75
80
|
migrateHistory: [],
|
|
81
|
+
vaultHistory: [],
|
|
76
82
|
blockHeight: 0,
|
|
77
83
|
blockHash: '',
|
|
78
84
|
...pick(attrs, [
|
|
79
85
|
'address',
|
|
80
|
-
'paused',
|
|
81
86
|
'tokenAddress',
|
|
87
|
+
'vaultAddress',
|
|
82
88
|
'contractAddress',
|
|
83
89
|
'seedValidators',
|
|
84
90
|
'validators',
|
|
@@ -177,6 +183,9 @@ const update = (state, updates, context) => {
|
|
|
177
183
|
};
|
|
178
184
|
|
|
179
185
|
const pause = (state, context) => {
|
|
186
|
+
if (state.closed) {
|
|
187
|
+
throw new Error('INVALID_PAUSE_ATTEMPT', 'rollup already closed');
|
|
188
|
+
}
|
|
180
189
|
if (state.paused) {
|
|
181
190
|
throw new Error('INVALID_PAUSE_ATTEMPT', 'rollup already paused');
|
|
182
191
|
}
|
|
@@ -190,7 +199,27 @@ const pause = (state, context) => {
|
|
|
190
199
|
return validate(rollup);
|
|
191
200
|
};
|
|
192
201
|
|
|
202
|
+
const close = (state, context) => {
|
|
203
|
+
if (state.closed) {
|
|
204
|
+
throw new Error('INVALID_CLOSE_ATTEMPT', 'rollup already closed');
|
|
205
|
+
}
|
|
206
|
+
if (!state.paused) {
|
|
207
|
+
throw new Error('INVALID_CLOSE_ATTEMPT', 'rollup must be paused');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const rollup = {
|
|
211
|
+
...state,
|
|
212
|
+
closed: true,
|
|
213
|
+
context: updateStateContext(state.context, context),
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
return validate(rollup);
|
|
217
|
+
};
|
|
218
|
+
|
|
193
219
|
const resume = (state, context) => {
|
|
220
|
+
if (state.closed) {
|
|
221
|
+
throw new Error('INVALID_RESUME_ATTEMPT', 'rollup is closed');
|
|
222
|
+
}
|
|
194
223
|
if (state.paused === false) {
|
|
195
224
|
throw new Error('INVALID_RESUME_ATTEMPT', 'rollup not paused');
|
|
196
225
|
}
|
|
@@ -204,15 +233,18 @@ const resume = (state, context) => {
|
|
|
204
233
|
return validate(rollup);
|
|
205
234
|
};
|
|
206
235
|
|
|
207
|
-
const
|
|
236
|
+
const migrateContract = (state, to, context) => {
|
|
237
|
+
if (state.closed) {
|
|
238
|
+
throw new Error('INVALID_MIGRATE_ATTEMPT', 'rollup is closed');
|
|
239
|
+
}
|
|
208
240
|
if (state.paused === false) {
|
|
209
241
|
throw new Error('INVALID_MIGRATE_ATTEMPT', 'rollup not paused');
|
|
210
242
|
}
|
|
211
243
|
if (state.contractAddress === to) {
|
|
212
|
-
throw new Error('INVALID_MIGRATE_ATTEMPT', 'can not migrate to self');
|
|
244
|
+
throw new Error('INVALID_MIGRATE_ATTEMPT', 'can not migrate contract to self');
|
|
213
245
|
}
|
|
214
246
|
if (state.migrateHistory.includes(to)) {
|
|
215
|
-
throw new Error('INVALID_MIGRATE_ATTEMPT', 'can not migrate to history contracts');
|
|
247
|
+
throw new Error('INVALID_MIGRATE_ATTEMPT', 'can not migrate contract to history contracts');
|
|
216
248
|
}
|
|
217
249
|
|
|
218
250
|
const rollup = {
|
|
@@ -225,6 +257,30 @@ const migrate = (state, to, context) => {
|
|
|
225
257
|
return validate(rollup);
|
|
226
258
|
};
|
|
227
259
|
|
|
260
|
+
const migrateVault = (state, to, context) => {
|
|
261
|
+
if (state.closed) {
|
|
262
|
+
throw new Error('INVALID_MIGRATE_ATTEMPT', 'rollup is closed');
|
|
263
|
+
}
|
|
264
|
+
if (state.paused === false) {
|
|
265
|
+
throw new Error('INVALID_MIGRATE_ATTEMPT', 'rollup not paused');
|
|
266
|
+
}
|
|
267
|
+
if (state.vaultAddress === to) {
|
|
268
|
+
throw new Error('INVALID_MIGRATE_ATTEMPT', 'can not migrate vault to self');
|
|
269
|
+
}
|
|
270
|
+
if (state.vaultHistory.includes(to)) {
|
|
271
|
+
throw new Error('INVALID_MIGRATE_ATTEMPT', 'can not migrate vault to history vaults');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const rollup = {
|
|
275
|
+
...state,
|
|
276
|
+
vaultAddress: to,
|
|
277
|
+
vaultHistory: [...state.vaultHistory, state.vaultAddress],
|
|
278
|
+
context: updateStateContext(state.context, context),
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
return validate(rollup);
|
|
282
|
+
};
|
|
283
|
+
|
|
228
284
|
const validate = (state) => {
|
|
229
285
|
const { value, error } = schema.validate(state);
|
|
230
286
|
if (error) {
|
|
@@ -238,4 +294,4 @@ const validate = (state) => {
|
|
|
238
294
|
return value;
|
|
239
295
|
};
|
|
240
296
|
|
|
241
|
-
module.exports = { create, update, pause, resume,
|
|
297
|
+
module.exports = { create, update, pause, close, resume, migrateContract, migrateVault, validate, schema };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.18.
|
|
6
|
+
"version": "1.18.36",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"coverage": "npm run test -- --coverage"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@arcblock/did": "1.18.
|
|
20
|
-
"@arcblock/validator": "1.18.
|
|
21
|
-
"@ocap/contract": "1.18.
|
|
22
|
-
"@ocap/mcrypto": "1.18.
|
|
23
|
-
"@ocap/message": "1.18.
|
|
24
|
-
"@ocap/util": "1.18.
|
|
19
|
+
"@arcblock/did": "1.18.36",
|
|
20
|
+
"@arcblock/validator": "1.18.36",
|
|
21
|
+
"@ocap/contract": "1.18.36",
|
|
22
|
+
"@ocap/mcrypto": "1.18.36",
|
|
23
|
+
"@ocap/message": "1.18.36",
|
|
24
|
+
"@ocap/util": "1.18.36",
|
|
25
25
|
"bloom-filters": "^1.3.9",
|
|
26
26
|
"lodash": "^4.17.21"
|
|
27
27
|
},
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"keywords": [],
|
|
32
32
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
33
33
|
"license": "MIT",
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "507eaab0fc94d92a88c49c2e3441c5f6b0e3788f"
|
|
35
35
|
}
|