@ocap/resolver 1.21.2 → 1.22.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.
Files changed (2) hide show
  1. package/lib/index.js +41 -3
  2. package/package.json +15 -15
package/lib/index.js CHANGED
@@ -35,6 +35,7 @@ const {
35
35
  createIndexedRollup,
36
36
  createIndexedRollupBlock,
37
37
  isDefaultTokenChanged,
38
+ createIndexedTokenFactory,
38
39
  } = require('@ocap/indexdb/lib/util');
39
40
  const { formatTxType } = require('@ocap/util');
40
41
 
@@ -85,6 +86,11 @@ const maxGasOps = {
85
86
  'fg:t:transfer_v3': { create: 9, update: 16 },
86
87
  'fg:t:exchange_v2': { create: 1, update: 18 },
87
88
 
89
+ 'fg:t:create_token_factory': { create: 2, update: 1 },
90
+ 'fg:t:mint_token': { create: 1, update: 5 },
91
+ 'fg:t:burn_token': { create: 1, update: 5 },
92
+ 'fg:t:update_token_factory': { create: 0, update: 2 },
93
+
88
94
  'fg:t:create_rollup': { create: 2, update: 2 },
89
95
  'fg:t:update_rollup': { create: 1, update: 2 },
90
96
  'fg:t:pause_rollup': { create: 1, update: 2 },
@@ -508,6 +514,27 @@ module.exports = class OCAPResolver {
508
514
  return state;
509
515
  }
510
516
 
517
+ getTokenFactoryState(args, ctx) {
518
+ return this._getState({
519
+ table: 'tokenFactory',
520
+ id: args.address,
521
+ dataKey: 'data',
522
+ ctx,
523
+ onRead: async (state) => {
524
+ if (state) {
525
+ const [token, reserveToken] = await Promise.all([
526
+ this.tokenCache.get(state.tokenAddress),
527
+ this.tokenCache.get(state.reserveAddress),
528
+ ]);
529
+ state.token = token;
530
+ state.reserveToken = reserveToken;
531
+ }
532
+
533
+ return state;
534
+ },
535
+ });
536
+ }
537
+
511
538
  getDelegateState({ address }, ctx) {
512
539
  return this._getState({
513
540
  table: 'delegation',
@@ -624,8 +651,9 @@ module.exports = class OCAPResolver {
624
651
  };
625
652
  }
626
653
 
627
- listTransactions(args, ctx) {
628
- return this._doPaginatedSearch('listTransactions', args, 'transactions', 'tx.itxJson.data', ctx);
654
+ async listTransactions(args, ctx) {
655
+ const data = await this._doPaginatedSearch('listTransactions', args, 'transactions', 'tx.itxJson.data', ctx);
656
+ return data;
629
657
  }
630
658
 
631
659
  listAssets(args, ctx) {
@@ -668,6 +696,10 @@ module.exports = class OCAPResolver {
668
696
  return this._doPaginatedSearch('listTokens', args, 'tokens', 'data', ctx);
669
697
  }
670
698
 
699
+ listTokenFactories(args, ctx) {
700
+ return this._doPaginatedSearch('listTokenFactories', args, 'tokenFactories', 'data', ctx);
701
+ }
702
+
671
703
  listStakes(args, ctx) {
672
704
  return this._doPaginatedSearch('listStakes', args, 'stakes', 'data', ctx);
673
705
  }
@@ -755,7 +787,7 @@ module.exports = class OCAPResolver {
755
787
  return { results: results.filter(Boolean) };
756
788
  }
757
789
 
758
- const entitiesByDid = ['account', 'asset', 'delegation', 'factory', 'token', 'stake', 'rollup'];
790
+ const entitiesByDid = ['account', 'asset', 'delegation', 'factory', 'token', 'stake', 'rollup', 'tokenFactory'];
759
791
  if (isValidDid(args.keyword)) {
760
792
  const keyword = toAddress(args.keyword);
761
793
  const results = await Promise.all(entitiesByDid.map((type) => doSearch(type, keyword)));
@@ -916,6 +948,7 @@ module.exports = class OCAPResolver {
916
948
  stake: [createIndexedStake, 'address'],
917
949
  rollup: [createIndexedRollup, 'address', hooks.onCreateRollup],
918
950
  rollupBlock: [createIndexedRollupBlock, 'hash', hooks.onCreateRollupBlock],
951
+ tokenFactory: [createIndexedTokenFactory, 'address'],
919
952
  };
920
953
  Object.keys(mapping).forEach((table) => {
921
954
  const [fn, key, onCreate, onUpdate] = mapping[table];
@@ -1177,6 +1210,11 @@ module.exports = class OCAPResolver {
1177
1210
  tokens.push({ address: rollup.tokenAddress, value: '0' });
1178
1211
  } else if (typeUrl === 'CreateTokenTx') {
1179
1212
  return [extractTokenMeta(tx.tx.itxJson.address, [tx.tx.itxJson])];
1213
+ } else if (typeUrl === 'MintTokenTx' || typeUrl === 'BurnTokenTx') {
1214
+ const token = await this.indexdb.tokenFactory.get(tx.tx.itxJson.tokenFactory);
1215
+ tokens.push({ address: token.tokenAddress });
1216
+ } else if (typeUrl === 'CreateTokenFactoryTx') {
1217
+ tokens.push({ address: tx.tx.itxJson.token.address });
1180
1218
  }
1181
1219
 
1182
1220
  if (tokens.length > 0) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.21.2",
6
+ "version": "1.22.0",
7
7
  "description": "GraphQL resolver built upon ocap statedb and GQL layer",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -14,25 +14,25 @@
14
14
  "license": "MIT",
15
15
  "devDependencies": {
16
16
  "jest": "^29.7.0",
17
- "@ocap/statedb-memory": "1.21.2",
18
- "@ocap/indexdb-memory": "1.21.2"
17
+ "@ocap/indexdb-memory": "1.22.0",
18
+ "@ocap/statedb-memory": "1.22.0"
19
19
  },
20
20
  "dependencies": {
21
21
  "debug": "^4.3.6",
22
22
  "lodash": "^4.17.21",
23
23
  "queue": "^6",
24
- "@arcblock/did": "1.21.2",
25
- "@arcblock/did-util": "1.21.2",
26
- "@arcblock/validator": "1.21.2",
27
- "@ocap/config": "1.21.2",
28
- "@ocap/indexdb": "1.21.2",
29
- "@ocap/mcrypto": "1.21.2",
30
- "@ocap/message": "1.21.2",
31
- "@ocap/state": "1.21.2",
32
- "@ocap/tx-protocols": "1.21.2",
33
- "@ocap/util": "1.21.2",
34
- "@ocap/wallet": "1.21.2",
35
- "@arcblock/did-ext": "1.21.2"
24
+ "@arcblock/did-ext": "1.22.0",
25
+ "@arcblock/did-util": "1.22.0",
26
+ "@arcblock/validator": "1.22.0",
27
+ "@ocap/config": "1.22.0",
28
+ "@ocap/indexdb": "1.22.0",
29
+ "@ocap/mcrypto": "1.22.0",
30
+ "@ocap/message": "1.22.0",
31
+ "@ocap/state": "1.22.0",
32
+ "@ocap/tx-protocols": "1.22.0",
33
+ "@ocap/util": "1.22.0",
34
+ "@ocap/wallet": "1.22.0",
35
+ "@arcblock/did": "1.22.0"
36
36
  },
37
37
  "scripts": {
38
38
  "lint": "eslint tests lib",