@ocap/resolver 1.18.166 → 1.19.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.
Files changed (3) hide show
  1. package/lib/hooks.js +22 -20
  2. package/lib/index.js +8 -5
  3. package/package.json +12 -12
package/lib/hooks.js CHANGED
@@ -9,7 +9,7 @@ const { toStakeAddress } = require('@arcblock/did-util');
9
9
 
10
10
  const debug = require('debug')(require('../package.json').name);
11
11
 
12
- const onCreateRollup = async (rollup, ctx, indexdb) => {
12
+ const onCreateRollup = (rollup, ctx, indexdb) => {
13
13
  rollup.seedValidators.forEach(async (x) => {
14
14
  const { pk, address, endpoint } = x;
15
15
  try {
@@ -106,7 +106,7 @@ const ensureRollupValidator = async (address, rollupAddress, ctx, indexdb, upser
106
106
  });
107
107
  };
108
108
 
109
- const onCreateRollupBlock = async (block, ctx, indexdb) => {
109
+ const onCreateRollupBlock = (block, ctx, indexdb) => {
110
110
  const { validators, proposer } = block;
111
111
  const { rollupState, txStates } = ctx;
112
112
 
@@ -178,27 +178,29 @@ const onDepositTokenV2 = async (tx, ctx, indexdb) => {
178
178
  await updateRollupStats(ctx.rollupState.address, amount.toString(), 'totalDepositAmount', indexdb);
179
179
  };
180
180
 
181
- const onClaimBlockReward = async (tx, ctx, indexdb) => {
181
+ const onClaimBlockReward = (tx, ctx, indexdb) => {
182
182
  const { rollupState, blockState } = ctx;
183
183
  const { signatures } = blockState;
184
184
  // TODO: delegation is not supported here
185
- signatures.forEach(async ({ signer }) => {
186
- try {
187
- const doc = await ensureRollupValidator(signer, rollupState.address, ctx, indexdb);
188
-
189
- const receipt = tx.receipts.find((x) => x.address === signer);
190
- if (receipt) {
191
- const change = receipt.changes.find(
192
- (x) => x.target === rollupState.tokenAddress && new BN(x.value).isNeg() === false
193
- );
194
- doc.totalGain = new BN(doc.totalGain).add(new BN(change.value).abs()).toString(10);
195
- await indexdb.rollupValidator.update(signer, doc);
196
- debug('update rollup validator on claim reward', signer);
185
+ return Promise.all(
186
+ signatures.map(async ({ signer }) => {
187
+ try {
188
+ const doc = await ensureRollupValidator(signer, rollupState.address, ctx, indexdb);
189
+
190
+ const receipt = tx.receipts.find((x) => x.address === signer);
191
+ if (receipt) {
192
+ const change = receipt.changes.find(
193
+ (x) => x.target === rollupState.tokenAddress && new BN(x.value).isNeg() === false
194
+ );
195
+ doc.totalGain = new BN(doc.totalGain).add(new BN(change.value).abs()).toString(10);
196
+ await indexdb.rollupValidator.update(signer, doc);
197
+ debug('update rollup validator on claim reward', signer);
198
+ }
199
+ } catch (err) {
200
+ console.error('update rollup validator on claim reward error', err);
197
201
  }
198
- } catch (err) {
199
- console.error('update rollup validator on claim reward error', err);
200
- }
201
- });
202
+ })
203
+ );
202
204
  };
203
205
 
204
206
  const onJoinRollup = async (tx, ctx, indexdb) => {
@@ -293,7 +295,7 @@ const onAccountMigrate = async (tx, resolver) => {
293
295
  }
294
296
  };
295
297
 
296
- const onCreateTx = async (tx, ctx, resolver) => {
298
+ const onCreateTx = (tx, ctx, resolver) => {
297
299
  if (tx.code !== 'OK') {
298
300
  return;
299
301
  }
package/lib/index.js CHANGED
@@ -209,7 +209,7 @@ module.exports = class OCAPResolver {
209
209
  });
210
210
  }
211
211
 
212
- async sendTx({ tx: txBase64 }, ctx = {}) {
212
+ async sendTx({ tx: txBase64, extra }, ctx = {}) {
213
213
  debug('sendTx', { txBase64, request: ctx.request });
214
214
 
215
215
  if (process.env.CHAIN_MODE === 'readonly') {
@@ -225,7 +225,10 @@ module.exports = class OCAPResolver {
225
225
  config: this.config,
226
226
  filter: this.filter,
227
227
  logger: this.logger,
228
- extra: ctx,
228
+ extra: {
229
+ ...ctx,
230
+ txExtra: extra,
231
+ },
229
232
  };
230
233
 
231
234
  // 1. execute and persist the transaction
@@ -684,7 +687,7 @@ module.exports = class OCAPResolver {
684
687
  return this._doPaginatedSearch('listDelegations', args, 'delegations', 'data', ctx);
685
688
  }
686
689
 
687
- async verifyAccountRisk(args, ctx) {
690
+ verifyAccountRisk(args, ctx) {
688
691
  return tokenFlow.verifyAccountRisk(
689
692
  {
690
693
  ...args,
@@ -699,7 +702,7 @@ module.exports = class OCAPResolver {
699
702
  );
700
703
  }
701
704
 
702
- async listTokenFlows(args, ctx) {
705
+ listTokenFlows(args, ctx) {
703
706
  return tokenFlow.listTokenFlows(args, this, ctx);
704
707
  }
705
708
 
@@ -731,7 +734,7 @@ module.exports = class OCAPResolver {
731
734
  return { results: [] };
732
735
  }
733
736
 
734
- async estimateGas(args = {}) {
737
+ estimateGas(args = {}) {
735
738
  const { typeUrl = '' } = args;
736
739
  if (!typeUrl || !maxGasOps[typeUrl]) {
737
740
  throw new CustomError('INVALID_REQUEST', 'Unknown tx typeUrl');
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.166",
6
+ "version": "1.19.1",
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": "^29.7.0"
23
23
  },
24
24
  "dependencies": {
25
- "@arcblock/did": "1.18.166",
26
- "@arcblock/did-util": "1.18.166",
27
- "@arcblock/validator": "1.18.166",
28
- "@ocap/config": "1.18.166",
29
- "@ocap/indexdb": "1.18.166",
30
- "@ocap/mcrypto": "1.18.166",
31
- "@ocap/message": "1.18.166",
32
- "@ocap/state": "1.18.166",
33
- "@ocap/tx-protocols": "1.18.166",
34
- "@ocap/util": "1.18.166",
25
+ "@arcblock/did": "1.19.1",
26
+ "@arcblock/did-util": "1.19.1",
27
+ "@arcblock/validator": "1.19.1",
28
+ "@ocap/config": "1.19.1",
29
+ "@ocap/indexdb": "1.19.1",
30
+ "@ocap/mcrypto": "1.19.1",
31
+ "@ocap/message": "1.19.1",
32
+ "@ocap/state": "1.19.1",
33
+ "@ocap/tx-protocols": "1.19.1",
34
+ "@ocap/util": "1.19.1",
35
35
  "debug": "^4.3.6",
36
36
  "lodash": "^4.17.21"
37
37
  },
38
- "gitHead": "58c8356b3b8c238728560e4c3fef6ed1704d3ac4"
38
+ "gitHead": "21184488172c6c824ebd1714f728ff2aee4a3ac0"
39
39
  }