@ocap/state 1.24.8 → 1.25.0
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/asset.js +8 -0
- package/lib/states/factory.js +10 -3
- package/lib/states/token.js +29 -3
- package/lib/states/tx.js +2 -2
- package/package.json +9 -9
package/lib/states/asset.js
CHANGED
|
@@ -41,6 +41,10 @@ const create = (attrs, context) => {
|
|
|
41
41
|
]),
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
if (asset.tags === null) {
|
|
45
|
+
asset.tags = [];
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
asset.address = toAddress(asset.address);
|
|
45
49
|
|
|
46
50
|
return validate(asset);
|
|
@@ -53,6 +57,10 @@ const update = (state, attrs, context) => {
|
|
|
53
57
|
context: updateStateContext(state.context, context),
|
|
54
58
|
};
|
|
55
59
|
|
|
60
|
+
if (asset.tags === null) {
|
|
61
|
+
asset.tags = [];
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
if (!asset.consumedTime) {
|
|
57
65
|
asset.consumedTime = '';
|
|
58
66
|
}
|
package/lib/states/factory.js
CHANGED
|
@@ -60,12 +60,19 @@ const create = (attrs, context) => {
|
|
|
60
60
|
return validate(factory);
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
const update = (state, attrs, context) =>
|
|
64
|
-
|
|
63
|
+
const update = (state, attrs, context) => {
|
|
64
|
+
const factory = {
|
|
65
65
|
...state,
|
|
66
66
|
...pick(attrs, ['numMinted', 'tokens']),
|
|
67
67
|
context: updateStateContext(state.context, context),
|
|
68
|
-
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (factory.output?.tags === null) {
|
|
71
|
+
factory.output.tags = [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return validate(factory);
|
|
75
|
+
};
|
|
69
76
|
|
|
70
77
|
const validate = (state) => {
|
|
71
78
|
const { value, error } = stateSchema.validate(state);
|
package/lib/states/token.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
const pick = require('lodash/pick');
|
|
2
|
+
const cloneDeep = require('lodash/cloneDeep');
|
|
2
3
|
const { toChecksumAddress } = require('@arcblock/did/lib/type');
|
|
3
4
|
const { toAddress, BN } = require('@ocap/util');
|
|
5
|
+
const { Joi } = require('@arcblock/validator');
|
|
4
6
|
|
|
5
7
|
const { create: createStateContext } = require('../contexts/state');
|
|
6
8
|
|
|
9
|
+
const metadataSchema = Joi.object({
|
|
10
|
+
communityUrl: Joi.string()
|
|
11
|
+
.uri({ scheme: ['https'], allowRelative: false })
|
|
12
|
+
.max(256)
|
|
13
|
+
.optional()
|
|
14
|
+
.allow(null, ''),
|
|
15
|
+
issuer: Joi.string().max(64).required(),
|
|
16
|
+
}).options({ stripUnknown: true, noDefaults: false });
|
|
17
|
+
|
|
7
18
|
const create = (attrs, context) => {
|
|
8
19
|
const token = {
|
|
9
20
|
context: createStateContext(context),
|
|
@@ -21,6 +32,8 @@ const create = (attrs, context) => {
|
|
|
21
32
|
'foreignToken',
|
|
22
33
|
'data',
|
|
23
34
|
'issuer',
|
|
35
|
+
'website',
|
|
36
|
+
'metadata',
|
|
24
37
|
'tokenFactoryAddress',
|
|
25
38
|
]),
|
|
26
39
|
};
|
|
@@ -28,6 +41,9 @@ const create = (attrs, context) => {
|
|
|
28
41
|
if (!token.data) {
|
|
29
42
|
token.data = null;
|
|
30
43
|
}
|
|
44
|
+
if (!token.metadata) {
|
|
45
|
+
token.metadata = null;
|
|
46
|
+
}
|
|
31
47
|
if (!token.foreignToken) {
|
|
32
48
|
token.foreignToken = null;
|
|
33
49
|
} else {
|
|
@@ -42,7 +58,7 @@ const create = (attrs, context) => {
|
|
|
42
58
|
const update = (state, attrs) =>
|
|
43
59
|
validate({
|
|
44
60
|
...state,
|
|
45
|
-
...pick(attrs, ['totalSupply']),
|
|
61
|
+
...pick(attrs, ['totalSupply', 'metadata', 'icon', 'website']),
|
|
46
62
|
});
|
|
47
63
|
|
|
48
64
|
const validate = (state) => {
|
|
@@ -50,7 +66,17 @@ const validate = (state) => {
|
|
|
50
66
|
throw new Error('INVALID_TOKEN', 'maxTotalSupply must be greater than or equal to totalSupply');
|
|
51
67
|
}
|
|
52
68
|
|
|
53
|
-
|
|
69
|
+
const data = cloneDeep(state);
|
|
70
|
+
|
|
71
|
+
if (data.metadata?.value) {
|
|
72
|
+
const { value, error } = metadataSchema.validate(data.metadata.value, { stripUnknown: true });
|
|
73
|
+
if (error) {
|
|
74
|
+
throw new Error('INVALID_TOKEN', 'Invalid token metadata');
|
|
75
|
+
}
|
|
76
|
+
data.metadata.value = value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return data;
|
|
54
80
|
};
|
|
55
81
|
|
|
56
|
-
module.exports = { create, update };
|
|
82
|
+
module.exports = { create, update, metadataSchema };
|
package/lib/states/tx.js
CHANGED
|
@@ -648,8 +648,8 @@ const verifyTxReceipts = (receipts, typeUrl, ctx = {}) => {
|
|
|
648
648
|
SetupSwapTx: ['swap'],
|
|
649
649
|
RevokeSwapTx: ['swap'],
|
|
650
650
|
RetrieveSwapTx: ['swap'],
|
|
651
|
-
MintTokenTx: ['swap', 'mint'],
|
|
652
|
-
BurnTokenTx: ['burn', 'swap'],
|
|
651
|
+
MintTokenTx: ['swap', 'mint', 'fee'],
|
|
652
|
+
BurnTokenTx: ['burn', 'swap', 'fee'],
|
|
653
653
|
}[typeUrl] || [];
|
|
654
654
|
|
|
655
655
|
for (const [target, changes] of Object.entries(targets)) {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.25.0",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"bloom-filters": "^1.3.9",
|
|
14
14
|
"lodash": "^4.17.21",
|
|
15
|
-
"@arcblock/did": "1.
|
|
16
|
-
"@arcblock/validator": "1.
|
|
17
|
-
"@ocap/contract": "1.
|
|
18
|
-
"@ocap/mcrypto": "1.
|
|
19
|
-
"@ocap/message": "1.
|
|
20
|
-
"@ocap/util": "1.
|
|
21
|
-
"@ocap/wallet": "1.
|
|
15
|
+
"@arcblock/did": "1.25.0",
|
|
16
|
+
"@arcblock/validator": "1.25.0",
|
|
17
|
+
"@ocap/contract": "1.25.0",
|
|
18
|
+
"@ocap/mcrypto": "1.25.0",
|
|
19
|
+
"@ocap/message": "1.25.0",
|
|
20
|
+
"@ocap/util": "1.25.0",
|
|
21
|
+
"@ocap/wallet": "1.25.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"jest": "^29.7.0",
|
|
25
25
|
"start-server-and-test": "^1.14.0",
|
|
26
|
-
"@ocap/e2e-test": "1.
|
|
26
|
+
"@ocap/e2e-test": "1.25.0"
|
|
27
27
|
},
|
|
28
28
|
"keywords": [],
|
|
29
29
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|