@ocap/config 1.17.23 → 1.18.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/default.js CHANGED
@@ -41,6 +41,12 @@ module.exports = {
41
41
  'fg:t:create_token': 1000,
42
42
  'fg:t:create_rollup': 10000,
43
43
  },
44
+ txGas: {
45
+ price: 100000000, // in ARC
46
+ createState: 1000000, // per op
47
+ updateState: 10000, // per op
48
+ dataStorage: 100, // per bytes
49
+ },
44
50
  delegate: {
45
51
  deltaInterval: 18000,
46
52
  // list transaction protocols that can work with delegation
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const merge = require('lodash/merge');
2
2
  const pick = require('lodash/pick');
3
+ const flatten = require('lodash/flatten');
3
4
  const { fromTokenToUnit } = require('@ocap/util');
4
5
  const { isValid, toTypeInfoStr } = require('@arcblock/did');
5
6
  const { toTokenAddress } = require('@arcblock/did-util');
@@ -15,15 +16,23 @@ const validate = (config) => {
15
16
  }
16
17
 
17
18
  const { vaults, transaction, accounts } = value;
18
- if (Object.keys(vaults).some((v) => !accounts.find((x) => x.address === vaults[v]))) {
19
+ if (flatten(Object.values(vaults)).some((a) => !accounts.find((x) => x.address === a))) {
19
20
  throw new Error('Invalid config: vault address does not exist in accounts');
20
21
  }
21
22
 
23
+ if (transaction.txGas.price > 0 && (!vaults.txGas || !vaults.txGas.length)) {
24
+ throw new Error('Invalid config: vaults.txGas can not be empty when gas enabled');
25
+ }
26
+
22
27
  const hasPaidTx = Object.keys(transaction.txFee).some((x) => transaction.txFee[x] > 0);
23
28
  if (hasPaidTx && !vaults.txFee) {
24
29
  throw new Error('Invalid config: vaults.txFee can not be empty when there are paid transactions');
25
30
  }
26
31
 
32
+ if (vaults.txFee && vaults.txGas && vaults.txGas.includes(vaults.txFee)) {
33
+ throw new Error('Invalid config: vaults.txFee can not contain same address with vaults.txGas');
34
+ }
35
+
27
36
  return value;
28
37
  };
29
38
 
package/lib/schema.js CHANGED
@@ -6,6 +6,7 @@ const accountSchema = {
6
6
  address: Joi.DID().required(),
7
7
  pk: Joi.string().allow('').required(),
8
8
  balance: Joi.number().optional().default(0),
9
+ moniker: Joi.string().optional().allow(''),
9
10
  };
10
11
 
11
12
  const configSchema = Joi.object({
@@ -27,12 +28,22 @@ const configSchema = Joi.object({
27
28
  txFee: Joi.object()
28
29
  .pattern(Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), Joi.number().precision(6).min(0))
29
30
  .required(),
31
+ txGas: Joi.object({
32
+ price: Joi.number().integer().min(0).required(),
33
+ createState: Joi.number().integer().min(1).required(),
34
+ updateState: Joi.number().integer().min(1).required(),
35
+ dataStorage: Joi.number().integer().min(1).required(),
36
+ }).optional(),
30
37
  })
31
38
  .optional()
32
39
  .default(defaultConfig.transaction),
33
40
  moderator: Joi.object(accountSchema).required(),
34
41
  accounts: Joi.array().items(accountSchema).required(),
35
- vaults: Joi.object().pattern(Joi.string().allow('quotaSlash', 'txFee'), Joi.DID()).default({}),
42
+ vaults: Joi.object({
43
+ quotaSlash: Joi.DID(),
44
+ txFee: Joi.DID(),
45
+ txGas: Joi.array().items(Joi.DID()),
46
+ }).default({}),
36
47
  token: Joi.object({
37
48
  name: Joi.string().required(),
38
49
  description: Joi.string().required(),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.17.23",
6
+ "version": "1.18.0",
7
7
  "description": "OCAP config parsing/validation and default",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -25,11 +25,11 @@
25
25
  "jest": "^27.5.1"
26
26
  },
27
27
  "dependencies": {
28
- "@arcblock/did": "1.17.23",
29
- "@arcblock/did-util": "1.17.23",
30
- "@arcblock/validator": "1.17.23",
31
- "@ocap/util": "1.17.23",
28
+ "@arcblock/did": "1.18.0",
29
+ "@arcblock/did-util": "1.18.0",
30
+ "@arcblock/validator": "1.18.0",
31
+ "@ocap/util": "1.18.0",
32
32
  "lodash": "^4.17.21"
33
33
  },
34
- "gitHead": "aecdce3fc6aaee32ea60db191d61962963f5e0bf"
34
+ "gitHead": "c48f928ee4f0deddf0f5e4bcb82fd6ffd7f2bc99"
35
35
  }