@ocap/tx-protocols 1.13.66 → 1.13.67

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/execute.js CHANGED
@@ -29,7 +29,7 @@ module.exports = ({ filter, runAsLambda }) => {
29
29
  // Since bloom-filters may give false positive, we need to check for statedb if replay detected
30
30
  const exist = await context.statedb.tx.get(context.txHash, context);
31
31
  if (exist) {
32
- return next(new Error('FORBIDDEN', 'Can not execute duplicate transaction'));
32
+ return next(new Error('DUPLICATE_TX', 'Can not execute duplicate transaction'));
33
33
  }
34
34
  }
35
35
 
@@ -77,7 +77,7 @@ runner.use(
77
77
  // For security consideration, user can not create fake assets from a factory
78
78
  // https://github.com/ArcBlock/asset-chain/issues/97
79
79
  {
80
- error: 'FORBIDDEN',
80
+ error: 'CREATE_FROM_FACTORY',
81
81
  message: 'You can only get asset from factory from acquire or mint',
82
82
  fn: ({ itx, factoryState }) => !(itx.parent && factoryState),
83
83
  persist: true,
@@ -31,7 +31,7 @@ runner.use(pipes.ExtractState({ from: 'itx.owner', to: 'ownerState', status: 'OK
31
31
  runner.use(
32
32
  pipes.VerifyInfo([
33
33
  {
34
- error: 'FORBIDDEN',
34
+ error: 'OWNER_ONLY_OPERATION',
35
35
  message: 'Only factory owner is allowed to mint',
36
36
  fn: ({ factoryState, senderState }) => factoryState.owner === senderState.address,
37
37
  persist: true,
@@ -9,5 +9,5 @@ module.exports = ({ factoryState }, next) => {
9
9
  return next();
10
10
  }
11
11
 
12
- return next(new Error('FORBIDDEN', 'This request will exceed factory mint limit'));
12
+ return next(new Error('EXCEED_MINT_LIMIT', 'This request will exceed factory mint limit'));
13
13
  };
@@ -72,7 +72,7 @@ runner.use(pipes.ExtractState({ from: 'itx.address', to: 'factoryState', status:
72
72
  runner.use(
73
73
  pipes.VerifyInfo([
74
74
  {
75
- error: 'FORBIDDEN',
75
+ error: 'DUPLICATE_FACTORY',
76
76
  message: 'This asset factory already exist on chain',
77
77
  fn: (context) => isEmpty(context.factoryState),
78
78
  },
@@ -31,7 +31,7 @@ runner.use(pipes.ExtractState({ from: 'itx.address', to: 'stakeState', status: '
31
31
  runner.use(
32
32
  pipes.VerifyInfo([
33
33
  {
34
- error: 'FORBIDDEN',
34
+ error: 'SENDER_NOT_MATCH',
35
35
  message: 'You are not allowed to claim stake from this address',
36
36
  fn: ({ tx, stakeState }) => tx.from === stakeState.sender,
37
37
  },
@@ -43,7 +43,7 @@ runner.use(pipes.ExtractState({ from: 'itx.evidence.hash', to: 'evidenceState',
43
43
  runner.use(
44
44
  pipes.VerifyInfo([
45
45
  {
46
- error: 'FORBIDDEN',
46
+ error: 'ALREADY_CLAIMED',
47
47
  message: 'Revoke evidence already seen on this chain',
48
48
  fn: ({ evidenceState }) => !evidenceState,
49
49
  },
@@ -70,7 +70,7 @@ runner.use(
70
70
  fn: ({ txState, itx }) => txState.tx.itxJson.address === itx.address,
71
71
  },
72
72
  {
73
- error: 'FORBIDDEN',
73
+ error: 'WITHIN_WAITING_PERIOD',
74
74
  message: 'You can not claim stake before waiting period ends',
75
75
  fn: ({ txState, stakeState, txTime }) => {
76
76
  const end = +new Date(txState.time) + (stakeState.revokeWaitingPeriod || 0) * 1000;
@@ -49,12 +49,12 @@ runner.use(
49
49
  runner.use(
50
50
  pipes.VerifyInfo([
51
51
  {
52
- error: 'FORBIDDEN',
52
+ error: 'SENDER_NOT_MATCH',
53
53
  message: 'You are not allowed to revoke stake from this address',
54
54
  fn: ({ tx, stakeState }) => tx.from === stakeState.sender,
55
55
  },
56
56
  {
57
- error: 'FORBIDDEN',
57
+ error: 'STAKE_NOT_REVOCABLE',
58
58
  message: 'This stake address is not revocable',
59
59
  fn: ({ stakeState }) => stakeState.revocable,
60
60
  },
@@ -88,7 +88,7 @@ runner.use(async (context, next) => {
88
88
  const { statedb, itx } = context;
89
89
  const exist = await statedb.rollup.existByToken(itx.tokenAddress, context);
90
90
  if (exist) {
91
- return next(new Error('FORBIDDEN', 'Only 1 rollup can be created for the token'));
91
+ return next(new Error('DUPLICATE_ROLLUP', 'Only 1 rollup can be created for the token'));
92
92
  }
93
93
 
94
94
  return next();
@@ -99,7 +99,7 @@ runner.use(pipes.ExtractState({ from: 'itx.address', to: 'rollupState', status:
99
99
  runner.use(
100
100
  pipes.VerifyInfo([
101
101
  {
102
- error: 'FORBIDDEN',
102
+ error: 'DUPLICATE_ROLLUP',
103
103
  message: 'This rollup already exist on chain',
104
104
  fn: (context) => isEmpty(context.rollupState),
105
105
  },
@@ -10,8 +10,8 @@ module.exports = async (context, next) => {
10
10
  const vaultState = await statedb.account.get(config.vaults.txFee, context);
11
11
 
12
12
  if (!txFee) {
13
- context.senderUpdates = { tokens: {} };
14
- context.vaultUpdates = { tokens: {} };
13
+ context.senderUpdates = {};
14
+ context.vaultUpdates = {};
15
15
  context.vaultState = vaultState;
16
16
  context.updatedAccounts = [];
17
17
  return next();
@@ -66,7 +66,7 @@ runner.use(pipes.ExtractState({ from: 'itx.address', to: 'tokenState', table: 't
66
66
  runner.use(
67
67
  pipes.VerifyInfo([
68
68
  {
69
- error: 'FORBIDDEN',
69
+ error: 'DUPLICATE_TOKEN',
70
70
  message: 'Token address already exists on chain',
71
71
  fn: (context) => isEmpty(context.tokenState),
72
72
  },
@@ -77,12 +77,12 @@ runner.use(
77
77
  runner.use(async (context, next) => {
78
78
  const { symbol } = context.config.token;
79
79
  if (symbol.toLowerCase() === context.itx.symbol.toLowerCase()) {
80
- return next(new Error('FORBIDDEN', `Token symbol can not be ${symbol}`));
80
+ return next(new Error('DUPLICATE_SYMBOL', `Token symbol can not be ${symbol}`));
81
81
  }
82
82
 
83
83
  const exist = await context.statedb.token.existBySymbol(context.itx.symbol, context);
84
84
  if (exist) {
85
- return next(new Error('FORBIDDEN', 'Token symbol already exists'));
85
+ return next(new Error('DUPLICATE_SYMBOL', 'Token symbol already exists'));
86
86
  }
87
87
 
88
88
  return next();
@@ -97,6 +97,7 @@ runner.use(
97
97
  const data = decodeAnySafe(itx.data);
98
98
 
99
99
  // We are definitely creating a different token, so it is safe to set tokens to initial supply
100
+ senderUpdates.tokens = senderUpdates.tokens || {};
100
101
  senderUpdates.tokens[itx.address] = itx.initialSupply;
101
102
 
102
103
  const [newSenderState, tokenState, newVaultState] = await Promise.all([
package/lib/util.js CHANGED
@@ -54,7 +54,7 @@ const decodeAnySafe = (encoded) => {
54
54
 
55
55
  const applyTokenUpdates = (tokens, state, operator) => {
56
56
  if (['add', 'sub'].includes(operator) === false) {
57
- throw new Error('FORBIDDEN', `Invalid operator when applyTokenUpdates: ${operator}`);
57
+ throw new Error('UNEXPECTED_OPERATOR', `Invalid operator when applyTokenUpdates: ${operator}`);
58
58
  }
59
59
 
60
60
  if (!state) {
@@ -69,7 +69,7 @@ const applyTokenUpdates = (tokens, state, operator) => {
69
69
  const balance = new BN(oldTokens[address] || 0);
70
70
  const newBalance = balance[operator](requirement);
71
71
  if (newBalance.lt(ZERO)) {
72
- throw new Error('FORBIDDEN', `Negative token balance when applyTokenUpdates for ${address}`);
72
+ throw new Error('NEGATIVE_TOKEN_BALANCE', `Negative token balance when applyTokenUpdates for ${address}`);
73
73
  }
74
74
  newTokens[address] = newBalance.toString(10);
75
75
  }
@@ -102,16 +102,16 @@ const getTxFee = ({ amount, feeRate, maxFee, minFee, stringify = true }) => {
102
102
  const minFeeAmount = new BN(minFee);
103
103
 
104
104
  if (feeRate < 0) {
105
- throw new Error('FORBIDDEN', 'Unexpected negative feeRate when getTxFee, abort!');
105
+ throw new Error('NEGATIVE_FEE_RATE', 'Unexpected negative feeRate when getTxFee, abort!');
106
106
  }
107
107
  if (userAmount.lt(ZERO)) {
108
- throw new Error('FORBIDDEN', 'Unexpected negative amount when getTxFee, abort!');
108
+ throw new Error('NEGATIVE_AMOUNT', 'Unexpected negative amount when getTxFee, abort!');
109
109
  }
110
110
  if (maxFeeAmount.lt(ZERO)) {
111
- throw new Error('FORBIDDEN', 'Unexpected negative maxFee when getTxFee, abort!');
111
+ throw new Error('NEGATIVE_MAX_FEE', 'Unexpected negative maxFee when getTxFee, abort!');
112
112
  }
113
113
  if (minFeeAmount.lt(ZERO)) {
114
- throw new Error('FORBIDDEN', 'Unexpected negative minFee when getTxFee, abort!');
114
+ throw new Error('NEGATIVE_MIN_FEE', 'Unexpected negative minFee when getTxFee, abort!');
115
115
  }
116
116
 
117
117
  // total fee
@@ -144,11 +144,11 @@ const getTxFee = ({ amount, feeRate, maxFee, minFee, stringify = true }) => {
144
144
  const splitTxFee = ({ total, shares = {}, stringify = true }) => {
145
145
  const totalAmount = new BN(total);
146
146
  if (totalAmount.lt(ZERO)) {
147
- throw new Error('FORBIDDEN', 'Unexpected negative total when splitTxFee, abort!');
147
+ throw new Error('NEGATIVE_TOTAL_AMOUNT', 'Unexpected negative total when splitTxFee, abort!');
148
148
  }
149
149
  Object.keys(shares).forEach((key) => {
150
150
  if (shares[key] < 0) {
151
- throw new Error('FORBIDDEN', `Unexpected negative shares[${key}] when splitTxFee, abort!`);
151
+ throw new Error('NEGATIVE_FEE_SHARE', `Unexpected negative shares[${key}] when splitTxFee, abort!`);
152
152
  }
153
153
  });
154
154
 
@@ -217,7 +217,7 @@ const ensureBlockReward = (rollupState, minReward, txStates) => {
217
217
  }
218
218
 
219
219
  if (actualFee.lt(ZERO)) {
220
- throw new Error('FORBIDDEN', 'Got negative actualFee for tx, abort!');
220
+ throw new Error('NEGATIVE_ACTUAL_FEE', 'Got negative actualFee for tx, abort!');
221
221
  }
222
222
 
223
223
  // If the actualFee is less than the maxFee, user will have a refund
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.13.66",
6
+ "version": "1.13.67",
7
7
  "description": "Predefined tx pipeline sets to execute certain type of transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,17 +19,17 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@arcblock/did": "1.13.66",
23
- "@arcblock/did-util": "1.13.66",
24
- "@ocap/asset": "1.13.66",
25
- "@ocap/mcrypto": "1.13.66",
26
- "@ocap/merkle-tree": "1.13.66",
27
- "@ocap/message": "1.13.66",
28
- "@ocap/state": "1.13.66",
29
- "@ocap/tx-pipeline": "1.13.66",
30
- "@ocap/util": "1.13.66",
31
- "@ocap/validator": "1.13.66",
32
- "@ocap/wallet": "1.13.66",
22
+ "@arcblock/did": "1.13.67",
23
+ "@arcblock/did-util": "1.13.67",
24
+ "@ocap/asset": "1.13.67",
25
+ "@ocap/mcrypto": "1.13.67",
26
+ "@ocap/merkle-tree": "1.13.67",
27
+ "@ocap/message": "1.13.67",
28
+ "@ocap/state": "1.13.67",
29
+ "@ocap/tx-pipeline": "1.13.67",
30
+ "@ocap/util": "1.13.67",
31
+ "@ocap/validator": "1.13.67",
32
+ "@ocap/wallet": "1.13.67",
33
33
  "debug": "^4.3.2",
34
34
  "empty-value": "^1.0.1",
35
35
  "lodash": "^4.17.21",
@@ -42,5 +42,5 @@
42
42
  "devDependencies": {
43
43
  "jest": "^27.3.1"
44
44
  },
45
- "gitHead": "1395a8dccee398dd0aed47c2b54a2c6e350d8621"
45
+ "gitHead": "866f6a0dbf4fc22425b8583d84610880472a3109"
46
46
  }