@ocap/contract 1.30.24 → 1.30.25

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/esm/index.mjs CHANGED
@@ -99,7 +99,7 @@ const validateAmount = (amount) => {
99
99
  */
100
100
  const validate = (compiled, quota, ensureZeroSum = false) => {
101
101
  if (!Array.isArray(compiled) || compiled.length === 0) throw new Error("no contract calls to validate");
102
- if (compiled.length > 30) throw new Error("too much contract calls found, max is 15");
102
+ if (compiled.length > 30) throw new Error("too much contract calls found, max is 30");
103
103
  let remaining = new BN(quota ? quota.value : "0");
104
104
  const tokens = quota?.tokens ?? {};
105
105
  const tokenRemaining = Object.keys(tokens).reduce((acc, x) => {
@@ -107,7 +107,7 @@ const validate = (compiled, quota, ensureZeroSum = false) => {
107
107
  return acc;
108
108
  }, {});
109
109
  for (const item of compiled) {
110
- const { call, args } = item;
110
+ const { call, args } = item || {};
111
111
  if (call === "transfer") {
112
112
  validateDid(args.to, TOKEN_RECEIVER_ROLE_TYPES);
113
113
  const consumption = validateAmount(args.amount);
@@ -126,7 +126,7 @@ const validate = (compiled, quota, ensureZeroSum = false) => {
126
126
  if (!tokenRemaining[token] || tokenRemaining[token].sub(consumption).isNeg()) throw new Error(`transferToken for ${args.tokenAddress} exceeded quota`);
127
127
  tokenRemaining[token] = tokenRemaining[token].sub(consumption);
128
128
  }
129
- }
129
+ } else throw new Error(`unrecognized call ${call}`);
130
130
  }
131
131
  if (ensureZeroSum) {
132
132
  if (remaining.isZero() === false) throw new Error("transfer violates zero sum");
package/lib/index.cjs CHANGED
@@ -102,7 +102,7 @@ const validateAmount = (amount) => {
102
102
  */
103
103
  const validate = (compiled, quota, ensureZeroSum = false) => {
104
104
  if (!Array.isArray(compiled) || compiled.length === 0) throw new Error("no contract calls to validate");
105
- if (compiled.length > 30) throw new Error("too much contract calls found, max is 15");
105
+ if (compiled.length > 30) throw new Error("too much contract calls found, max is 30");
106
106
  let remaining = new _ocap_util.BN(quota ? quota.value : "0");
107
107
  const tokens = quota?.tokens ?? {};
108
108
  const tokenRemaining = Object.keys(tokens).reduce((acc, x) => {
@@ -110,7 +110,7 @@ const validate = (compiled, quota, ensureZeroSum = false) => {
110
110
  return acc;
111
111
  }, {});
112
112
  for (const item of compiled) {
113
- const { call, args } = item;
113
+ const { call, args } = item || {};
114
114
  if (call === "transfer") {
115
115
  validateDid(args.to, TOKEN_RECEIVER_ROLE_TYPES);
116
116
  const consumption = validateAmount(args.amount);
@@ -129,7 +129,7 @@ const validate = (compiled, quota, ensureZeroSum = false) => {
129
129
  if (!tokenRemaining[token] || tokenRemaining[token].sub(consumption).isNeg()) throw new Error(`transferToken for ${args.tokenAddress} exceeded quota`);
130
130
  tokenRemaining[token] = tokenRemaining[token].sub(consumption);
131
131
  }
132
- }
132
+ } else throw new Error(`unrecognized call ${call}`);
133
133
  }
134
134
  if (ensureZeroSum) {
135
135
  if (remaining.isZero() === false) throw new Error("transfer violates zero sum");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocap/contract",
3
3
  "description": "Utility to compile/validate and run ocap contract",
4
- "version": "1.30.24",
4
+ "version": "1.30.25",
5
5
  "author": {
6
6
  "name": "wangshijun",
7
7
  "email": "shijun@arcblock.io",
@@ -39,9 +39,9 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@arcblock/did": "1.30.24",
43
- "@ocap/mcrypto": "1.30.24",
44
- "@ocap/util": "1.30.24",
42
+ "@arcblock/did": "1.30.25",
43
+ "@ocap/mcrypto": "1.30.25",
44
+ "@ocap/util": "1.30.25",
45
45
  "lodash": "^4.17.23"
46
46
  },
47
47
  "devDependencies": {