@ocap/state 1.23.1 → 1.24.1
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/token.js +16 -6
- package/package.json +9 -9
package/lib/states/token.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const pick = require('lodash/pick');
|
|
2
2
|
const { toChecksumAddress } = require('@arcblock/did/lib/type');
|
|
3
|
-
const { toAddress } = require('@ocap/util');
|
|
3
|
+
const { toAddress, BN } = require('@ocap/util');
|
|
4
4
|
|
|
5
5
|
const { create: createStateContext } = require('../contexts/state');
|
|
6
6
|
|
|
@@ -16,6 +16,7 @@ const create = (attrs, context) => {
|
|
|
16
16
|
'icon',
|
|
17
17
|
'totalSupply',
|
|
18
18
|
'initialSupply',
|
|
19
|
+
'maxTotalSupply',
|
|
19
20
|
'address',
|
|
20
21
|
'foreignToken',
|
|
21
22
|
'data',
|
|
@@ -35,12 +36,21 @@ const create = (attrs, context) => {
|
|
|
35
36
|
|
|
36
37
|
token.address = toAddress(token.address);
|
|
37
38
|
|
|
38
|
-
return token;
|
|
39
|
+
return validate(token);
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
const update = (state, attrs) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const update = (state, attrs) =>
|
|
43
|
+
validate({
|
|
44
|
+
...state,
|
|
45
|
+
...pick(attrs, ['totalSupply']),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const validate = (state) => {
|
|
49
|
+
if (state.maxTotalSupply && new BN(state.maxTotalSupply).lt(new BN(state.totalSupply))) {
|
|
50
|
+
throw new Error('INVALID_TOKEN', 'maxTotalSupply must be greater than or equal to totalSupply');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return state;
|
|
54
|
+
};
|
|
45
55
|
|
|
46
56
|
module.exports = { create, update };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.24.1",
|
|
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/
|
|
20
|
-
"@ocap/
|
|
21
|
-
"@ocap/
|
|
15
|
+
"@arcblock/did": "1.24.1",
|
|
16
|
+
"@arcblock/validator": "1.24.1",
|
|
17
|
+
"@ocap/contract": "1.24.1",
|
|
18
|
+
"@ocap/mcrypto": "1.24.1",
|
|
19
|
+
"@ocap/message": "1.24.1",
|
|
20
|
+
"@ocap/util": "1.24.1",
|
|
21
|
+
"@ocap/wallet": "1.24.1"
|
|
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.24.1"
|
|
27
27
|
},
|
|
28
28
|
"keywords": [],
|
|
29
29
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|