@ocap/state 1.14.2 → 1.14.6
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/account.js +3 -2
- package/lib/states/asset.js +73 -11
- package/lib/states/blacklist.js +2 -1
- package/lib/states/chain.js +2 -1
- package/lib/states/evidence.js +3 -2
- package/lib/states/rollup-block.js +3 -2
- package/lib/states/stake.js +3 -2
- package/package.json +8 -8
package/lib/states/account.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const pick = require('lodash/pick');
|
|
2
2
|
const uniq = require('lodash/uniq');
|
|
3
3
|
const flatten = require('lodash/flatten');
|
|
4
|
+
const Error = require('@ocap/util/lib/error');
|
|
4
5
|
const { isFromPublicKey } = require('@arcblock/did');
|
|
5
6
|
const { toBase58, BN } = require('@ocap/util');
|
|
6
7
|
|
|
@@ -39,7 +40,7 @@ const create = (attrs, context) => {
|
|
|
39
40
|
|
|
40
41
|
const update = (state, attrs, context) => {
|
|
41
42
|
if (attrs.nonce && new BN(attrs.nonce).eq(new BN(state.nonce))) {
|
|
42
|
-
throw new Error('nonce must be greater in newer transactions');
|
|
43
|
+
throw new Error('INVALID_NONCE', 'nonce must be greater in newer transactions');
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
// ensure we are updating the correct pk
|
|
@@ -73,7 +74,7 @@ const validate = (state) => {
|
|
|
73
74
|
|
|
74
75
|
const { value, error } = schema.validate(state);
|
|
75
76
|
if (error) {
|
|
76
|
-
throw new Error(`Invalid account: ${error.details.map((x) => x.message).join(', ')}`);
|
|
77
|
+
throw new Error('INVALID_ACCOUNT', `Invalid account: ${error.details.map((x) => x.message).join(', ')}`);
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
if (!value.data) {
|
package/lib/states/asset.js
CHANGED
|
@@ -1,7 +1,41 @@
|
|
|
1
1
|
const pick = require('lodash/pick');
|
|
2
|
+
const Joi = require('@ocap/validator');
|
|
3
|
+
const Error = require('@ocap/util/lib/error');
|
|
2
4
|
|
|
3
5
|
const { create: createStateContext, update: updateStateContext } = require('../contexts/state');
|
|
4
6
|
|
|
7
|
+
const props = {
|
|
8
|
+
address: Joi.DID().role('ROLE_ASSET').required(),
|
|
9
|
+
moniker: Joi.string().min(2).max(255).required(),
|
|
10
|
+
data: Joi.any().required(),
|
|
11
|
+
readonly: Joi.boolean().default(false),
|
|
12
|
+
transferrable: Joi.boolean().default(false),
|
|
13
|
+
ttl: Joi.number().min(0).default(0),
|
|
14
|
+
parent: Joi.DID().optional().allow(''),
|
|
15
|
+
issuer: Joi.DID().optional().allow(''),
|
|
16
|
+
endpoint: Joi.object({
|
|
17
|
+
id: Joi.string().uri({ scheme: ['http', 'https'] }).required(), // prettier-ignore
|
|
18
|
+
scope: Joi.string().valid('public', 'private').default('public'),
|
|
19
|
+
}).optional(),
|
|
20
|
+
display: Joi.object({
|
|
21
|
+
type: Joi.string().valid('svg', 'url', 'uri').required(),
|
|
22
|
+
content: Joi.string()
|
|
23
|
+
.when('type', { is: 'uri', then: Joi.string().dataUri().required() })
|
|
24
|
+
.when('type', { is: 'url', then: Joi.string().uri({ scheme: ['http', 'https'] }).required() }), // prettier-ignore
|
|
25
|
+
}).optional(),
|
|
26
|
+
tags: Joi.array().items(Joi.string().min(1)).optional(),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const schema = Joi.object({
|
|
30
|
+
...props,
|
|
31
|
+
owner: Joi.DID().required(),
|
|
32
|
+
consumedTime: Joi.date().iso().raw().allow(''),
|
|
33
|
+
context: Joi.schemas.context,
|
|
34
|
+
}).options({
|
|
35
|
+
stripUnknown: true,
|
|
36
|
+
noDefaults: false,
|
|
37
|
+
});
|
|
38
|
+
|
|
5
39
|
const create = (attrs, context) => {
|
|
6
40
|
const asset = {
|
|
7
41
|
consumedTime: '',
|
|
@@ -10,16 +44,25 @@ const create = (attrs, context) => {
|
|
|
10
44
|
readonly: false,
|
|
11
45
|
transferrable: true,
|
|
12
46
|
ttl: 0, // means unlimited
|
|
13
|
-
|
|
47
|
+
tags: [],
|
|
14
48
|
context: createStateContext(context),
|
|
15
|
-
...pick(attrs, [
|
|
49
|
+
...pick(attrs, [
|
|
50
|
+
'address',
|
|
51
|
+
'owner',
|
|
52
|
+
'issuer',
|
|
53
|
+
'moniker',
|
|
54
|
+
'parent',
|
|
55
|
+
'data',
|
|
56
|
+
'readonly',
|
|
57
|
+
'transferrable',
|
|
58
|
+
'ttl',
|
|
59
|
+
'endpoint',
|
|
60
|
+
'display',
|
|
61
|
+
'tags',
|
|
62
|
+
]),
|
|
16
63
|
};
|
|
17
64
|
|
|
18
|
-
|
|
19
|
-
asset.data = null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return asset;
|
|
65
|
+
return validate(asset);
|
|
23
66
|
};
|
|
24
67
|
|
|
25
68
|
const update = (state, attrs, context) => {
|
|
@@ -29,11 +72,30 @@ const update = (state, attrs, context) => {
|
|
|
29
72
|
context: updateStateContext(state.context, context),
|
|
30
73
|
};
|
|
31
74
|
|
|
32
|
-
|
|
33
|
-
|
|
75
|
+
return validate(asset);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const validate = (state) => {
|
|
79
|
+
const { value, error } = schema.validate(state);
|
|
80
|
+
if (error) {
|
|
81
|
+
throw new Error('INVALID_ASSET', `Invalid asset: ${error.details.map((x) => x.message).join(', ')}`);
|
|
34
82
|
}
|
|
35
83
|
|
|
36
|
-
|
|
84
|
+
['endpoint', 'display'].forEach((key) => {
|
|
85
|
+
if (!value[key]) {
|
|
86
|
+
delete value[key];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return value;
|
|
37
91
|
};
|
|
38
92
|
|
|
39
|
-
module.exports = {
|
|
93
|
+
module.exports = {
|
|
94
|
+
create,
|
|
95
|
+
update,
|
|
96
|
+
validate,
|
|
97
|
+
schema: Joi.object(props).options({
|
|
98
|
+
stripUnknown: true,
|
|
99
|
+
noDefaults: false,
|
|
100
|
+
}),
|
|
101
|
+
};
|
package/lib/states/blacklist.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const Error = require('@ocap/util/lib/error');
|
|
2
3
|
const { BloomFilter } = require('bloom-filters');
|
|
3
4
|
|
|
4
5
|
class Blacklist {
|
|
@@ -10,7 +11,7 @@ class Blacklist {
|
|
|
10
11
|
const json = JSON.parse(fs.readFileSync(dumpPath));
|
|
11
12
|
filter = BloomFilter.fromJSON(json);
|
|
12
13
|
} catch (err) {
|
|
13
|
-
throw new Error(`Cat not read serialized blacklist from json${dumpPath}`);
|
|
14
|
+
throw new Error('INTERNAL', `Cat not read serialized blacklist from json${dumpPath}`);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
package/lib/states/chain.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const pick = require('lodash/pick');
|
|
2
2
|
const isEqual = require('lodash/isEqual');
|
|
3
|
+
const Error = require('@ocap/util/lib/error');
|
|
3
4
|
|
|
4
5
|
const { create: createStateContext, update: updateStateContext } = require('../contexts/state');
|
|
5
6
|
|
|
@@ -18,7 +19,7 @@ const update = (state, updates) => {
|
|
|
18
19
|
// eslint-disable-next-line no-restricted-syntax
|
|
19
20
|
for (const attr of immutableAttrs) {
|
|
20
21
|
if (updates[attr] && isEqual(updates[attr], state[attr]) === false) {
|
|
21
|
-
throw new Error(`Cannot update ${attr} field on chain state`);
|
|
22
|
+
throw new Error('FORBIDDEN', `Cannot update ${attr} field on chain state`);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
package/lib/states/evidence.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const pick = require('lodash/pick');
|
|
2
|
-
|
|
2
|
+
const Error = require('@ocap/util/lib/error');
|
|
3
3
|
const Joi = require('@ocap/validator');
|
|
4
|
+
|
|
4
5
|
const { create: createStateContext } = require('../contexts/state');
|
|
5
6
|
|
|
6
7
|
const schema = Joi.object({
|
|
@@ -21,7 +22,7 @@ const create = (attrs, context) => {
|
|
|
21
22
|
const validate = (state) => {
|
|
22
23
|
const { value, error } = schema.validate(state);
|
|
23
24
|
if (error) {
|
|
24
|
-
throw new Error(`Invalid evidence state: ${error.details.map((x) => x.message).join(', ')}`);
|
|
25
|
+
throw new Error('INVALID_EVIDENCE', `Invalid evidence state: ${error.details.map((x) => x.message).join(', ')}`);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
if (!value.data) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const pick = require('lodash/pick');
|
|
2
|
-
|
|
2
|
+
const Error = require('@ocap/util/lib/error');
|
|
3
3
|
const Joi = require('@ocap/validator');
|
|
4
|
+
|
|
4
5
|
const { create: createStateContext, update: updateStateContext } = require('../contexts/state');
|
|
5
6
|
|
|
6
7
|
const schema = Joi.object({
|
|
@@ -67,7 +68,7 @@ const update = (state, context) => {
|
|
|
67
68
|
const validate = (state) => {
|
|
68
69
|
const { value, error } = schema.validate(state);
|
|
69
70
|
if (error) {
|
|
70
|
-
throw new Error(`Invalid rollup block: ${error.details.map((x) => x.message).join(', ')}`);
|
|
71
|
+
throw new Error('INVALID_ROLLUP_BLOCK', `Invalid rollup block: ${error.details.map((x) => x.message).join(', ')}`);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
if (!value.data) {
|
package/lib/states/stake.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const pick = require('lodash/pick');
|
|
2
|
-
|
|
2
|
+
const Error = require('@ocap/util/lib/error');
|
|
3
3
|
const Joi = require('@ocap/validator');
|
|
4
|
+
|
|
4
5
|
const { create: createStateContext, update: updateStateContext } = require('../contexts/state');
|
|
5
6
|
|
|
6
7
|
const schema = Joi.object({
|
|
@@ -60,7 +61,7 @@ const update = (state, attrs, context) => {
|
|
|
60
61
|
const validate = (state) => {
|
|
61
62
|
const { value, error } = schema.validate(state);
|
|
62
63
|
if (error) {
|
|
63
|
-
throw new Error(`Invalid stake state: ${error.details.map((x) => x.message).join(', ')}`);
|
|
64
|
+
throw new Error('INVALID_STAKE', `Invalid stake state: ${error.details.map((x) => x.message).join(', ')}`);
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
if (!value.data) {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.14.
|
|
6
|
+
"version": "1.14.6",
|
|
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.14.
|
|
20
|
-
"@ocap/contract": "1.14.
|
|
21
|
-
"@ocap/mcrypto": "1.14.
|
|
22
|
-
"@ocap/message": "1.14.
|
|
23
|
-
"@ocap/util": "1.14.
|
|
24
|
-
"@ocap/validator": "1.14.
|
|
19
|
+
"@arcblock/did": "1.14.6",
|
|
20
|
+
"@ocap/contract": "1.14.6",
|
|
21
|
+
"@ocap/mcrypto": "1.14.6",
|
|
22
|
+
"@ocap/message": "1.14.6",
|
|
23
|
+
"@ocap/util": "1.14.6",
|
|
24
|
+
"@ocap/validator": "1.14.6",
|
|
25
25
|
"bloom-filters": "^1.3.1",
|
|
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": "dd379a7d1bd2a46be27a29e6f0c65fa161ec0b0c"
|
|
35
35
|
}
|