@ocap/resolver 1.13.68 → 1.13.72

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.
Files changed (2) hide show
  1. package/lib/hooks.js +24 -2
  2. package/package.json +12 -12
package/lib/hooks.js CHANGED
@@ -2,6 +2,8 @@
2
2
  // Purpose of these hooks: update indexdb to speed up subsequent queries
3
3
  // RULE: do not try to update statedb in these hooks
4
4
 
5
+ const merge = require('lodash/merge');
6
+ const pick = require('lodash/pick');
5
7
  const { BN } = require('@ocap/util');
6
8
  const { toStakeAddress } = require('@arcblock/did-util');
7
9
 
@@ -105,7 +107,8 @@ const ensureRollupValidator = async (address, rollupAddress, ctx, indexdb, upser
105
107
 
106
108
  const onCreateRollupBlock = async (block, ctx, indexdb) => {
107
109
  const { validators, proposer } = block;
108
- const { rollupState } = ctx;
110
+ const { rollupState, txStates } = ctx;
111
+
109
112
  validators.forEach(async (address) => {
110
113
  try {
111
114
  const doc = await ensureRollupValidator(address, rollupState.address, ctx, indexdb);
@@ -125,6 +128,22 @@ const onCreateRollupBlock = async (block, ctx, indexdb) => {
125
128
  console.error('update rollup validator error', err);
126
129
  }
127
130
  });
131
+
132
+ // Withdraw tx.actualFee needs to be reindexed
133
+ if (Array.isArray(txStates)) {
134
+ txStates
135
+ .filter((x) => x.type === 'withdraw_token_v2')
136
+ .forEach(async (x) => {
137
+ try {
138
+ const doc = await indexdb.tx.get(x.hash);
139
+ const updates = merge(doc, pick(x, ['tx.itxJson.actualFee']));
140
+ await indexdb.tx.update(x.hash, updates);
141
+ debug('update tx on new block', x.hash);
142
+ } catch (err) {
143
+ console.error('update tx on new block error', err);
144
+ }
145
+ });
146
+ }
128
147
  };
129
148
 
130
149
  const updateRollupStats = async (address, value, key, indexdb) => {
@@ -153,7 +172,9 @@ const onDepositTokenV2 = async (tx, ctx, indexdb) => {
153
172
  }
154
173
  });
155
174
 
156
- await updateRollupStats(ctx.rollupState.address, tx.tx.itxJson.token.value, 'totalDepositAmount', indexdb);
175
+ // totalDepositAmount should include txFee
176
+ const amount = new BN(tx.tx.itxJson.token.value).add(new BN(tx.tx.itxJson.actualFee));
177
+ await updateRollupStats(ctx.rollupState.address, amount.toString(), 'totalDepositAmount', indexdb);
157
178
  };
158
179
 
159
180
  const onClaimBlockReward = async (tx, ctx, indexdb) => {
@@ -277,6 +298,7 @@ const onCreateTx = async (tx, ctx, indexdb) => {
277
298
  case 'fg:t:claim_block_reward':
278
299
  return onClaimBlockReward(tx, ctx, indexdb);
279
300
  case 'fg:t:withdraw_token_v2':
301
+ // totalWithdrawAmount does not include txFee
280
302
  return updateRollupStats(ctx.rollupState.address, tx.tx.itxJson.token.value, 'totalWithdrawAmount', indexdb);
281
303
  default:
282
304
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.13.68",
6
+ "version": "1.13.72",
7
7
  "description": "GraphQL resolver built upon ocap statedb and GQL layer",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -22,18 +22,18 @@
22
22
  "jest": "^27.3.1"
23
23
  },
24
24
  "dependencies": {
25
- "@arcblock/did": "1.13.68",
26
- "@arcblock/did-util": "1.13.68",
27
- "@ocap/config": "1.13.68",
28
- "@ocap/indexdb": "1.13.68",
29
- "@ocap/mcrypto": "1.13.68",
30
- "@ocap/message": "1.13.68",
31
- "@ocap/state": "1.13.68",
32
- "@ocap/tx-protocols": "1.13.68",
33
- "@ocap/util": "1.13.68",
34
- "@ocap/validator": "1.13.68",
25
+ "@arcblock/did": "1.13.72",
26
+ "@arcblock/did-util": "1.13.72",
27
+ "@ocap/config": "1.13.72",
28
+ "@ocap/indexdb": "1.13.72",
29
+ "@ocap/mcrypto": "1.13.72",
30
+ "@ocap/message": "1.13.72",
31
+ "@ocap/state": "1.13.72",
32
+ "@ocap/tx-protocols": "1.13.72",
33
+ "@ocap/util": "1.13.72",
34
+ "@ocap/validator": "1.13.72",
35
35
  "debug": "^4.3.2",
36
36
  "lodash": "^4.17.21"
37
37
  },
38
- "gitHead": "d84324870fe9dca3619df362ba09219dd420f274"
38
+ "gitHead": "c9fcd79d6e1ea7ac45831d79ea202a983304f69b"
39
39
  }