@ocap/state 1.24.9 → 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.
@@ -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
- return state;
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.24.9",
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/validator": "1.24.9",
16
- "@ocap/contract": "1.24.9",
17
- "@ocap/mcrypto": "1.24.9",
18
- "@arcblock/did": "1.24.9",
19
- "@ocap/message": "1.24.9",
20
- "@ocap/util": "1.24.9",
21
- "@ocap/wallet": "1.24.9"
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.24.9"
26
+ "@ocap/e2e-test": "1.25.0"
27
27
  },
28
28
  "keywords": [],
29
29
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",