@ocap/resolver 1.13.32 → 1.13.36
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/hooks.js +11 -2
- package/lib/index.js +15 -13
- package/package.json +11 -11
package/lib/hooks.js
CHANGED
|
@@ -46,7 +46,7 @@ const onCreateRollup = async (rollup, ctx, indexdb) => {
|
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
const ensureRollupValidator = async (address, rollupAddress, ctx, indexdb) => {
|
|
49
|
+
const ensureRollupValidator = async (address, rollupAddress, ctx, indexdb, upsert = true) => {
|
|
50
50
|
const doc = await indexdb.rollupValidator.get(address);
|
|
51
51
|
if (doc) {
|
|
52
52
|
if (!doc.pk || !doc.endpoint) {
|
|
@@ -54,11 +54,15 @@ const ensureRollupValidator = async (address, rollupAddress, ctx, indexdb) => {
|
|
|
54
54
|
const validator = rollup.validators.find((v) => v.address === address);
|
|
55
55
|
doc.pk = validator.pk;
|
|
56
56
|
doc.endpoint = validator.endpoint;
|
|
57
|
+
doc.rollup = rollup.address;
|
|
57
58
|
return indexdb.rollupValidator.update(address, doc);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
return doc;
|
|
61
62
|
}
|
|
63
|
+
if (upsert === false) {
|
|
64
|
+
throw new Error('Rollup validator not found and upsert is disabled');
|
|
65
|
+
}
|
|
62
66
|
|
|
63
67
|
const stakeAddress = toStakeAddress(address, rollupAddress);
|
|
64
68
|
const [rollup, stake, account] = await Promise.all([
|
|
@@ -106,6 +110,7 @@ const onCreateRollupBlock = async (block, ctx, indexdb) => {
|
|
|
106
110
|
try {
|
|
107
111
|
const doc = await ensureRollupValidator(address, rollupState.address, ctx, indexdb);
|
|
108
112
|
|
|
113
|
+
doc.rollup = rollupState.address;
|
|
109
114
|
doc.renaissanceTime = block.genesisTime;
|
|
110
115
|
doc.verifiedBlockCount += 1;
|
|
111
116
|
if (address === proposer) {
|
|
@@ -186,6 +191,10 @@ const onStake = async (tx, ctx, indexdb) => {
|
|
|
186
191
|
}
|
|
187
192
|
|
|
188
193
|
const address = tx.tx.from;
|
|
194
|
+
if (rollup.validators.find((x) => x.address === address) === undefined) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
189
198
|
const stakeAddress = toStakeAddress(address, rollup.address);
|
|
190
199
|
const doc = await ensureRollupValidator(address, rollup.address, ctx, indexdb);
|
|
191
200
|
|
|
@@ -210,7 +219,7 @@ const onRevokeStake = async (tx, ctx, indexdb) => {
|
|
|
210
219
|
}
|
|
211
220
|
|
|
212
221
|
const address = tx.tx.from;
|
|
213
|
-
const doc = await ensureRollupValidator(address, rollup.address, ctx, indexdb);
|
|
222
|
+
const doc = await ensureRollupValidator(address, rollup.address, ctx, indexdb, false);
|
|
214
223
|
const receipt = ctx.txState.receipts.find((x) => x.address === stake.address);
|
|
215
224
|
const change = receipt.changes.find((x) => x.target === rollup.tokenAddress);
|
|
216
225
|
|
package/lib/index.js
CHANGED
|
@@ -542,16 +542,18 @@ module.exports = class OCAPResolver {
|
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
const result = await this._doPaginatedSearch('listRollupValidators', args, 'validators', null, ctx);
|
|
545
|
-
const stakes =
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
545
|
+
const stakes = (
|
|
546
|
+
await Promise.all(
|
|
547
|
+
result.validators.map((x) => {
|
|
548
|
+
const stakeAddress = toStakeAddress(x.address, args.rollupAddress);
|
|
549
|
+
return this.runAsLambda((txn) => this.statedb.stake.get(stakeAddress, { txn }));
|
|
550
|
+
})
|
|
551
|
+
)
|
|
552
|
+
).filter(Boolean);
|
|
551
553
|
result.validators.forEach((x) => {
|
|
552
554
|
const stakeAddress = toStakeAddress(x.address, args.rollupAddress);
|
|
553
555
|
const stake = stakes.find((s) => s.address === stakeAddress);
|
|
554
|
-
x.availableStake = stake.tokens[rollup.tokenAddress];
|
|
556
|
+
x.availableStake = stake ? stake.tokens[rollup.tokenAddress] : '0';
|
|
555
557
|
});
|
|
556
558
|
|
|
557
559
|
return result;
|
|
@@ -562,21 +564,21 @@ module.exports = class OCAPResolver {
|
|
|
562
564
|
return { results: [] };
|
|
563
565
|
}
|
|
564
566
|
|
|
565
|
-
const doSearch = async (type) => {
|
|
566
|
-
const result = await this.indexdb[type].get(
|
|
567
|
-
return result ? { type, id:
|
|
567
|
+
const doSearch = async (type, keyword) => {
|
|
568
|
+
const result = await this.indexdb[type].get(keyword);
|
|
569
|
+
return result ? { type, id: keyword } : null;
|
|
568
570
|
};
|
|
569
571
|
|
|
570
572
|
const entitiesByDid = ['account', 'asset', 'delegation', 'factory', 'token', 'stake', 'rollup'];
|
|
571
573
|
if (isValidDid(args.keyword)) {
|
|
572
|
-
const results = await Promise.all(entitiesByDid.map(doSearch));
|
|
574
|
+
const results = await Promise.all(entitiesByDid.map((type) => doSearch(type, args.keyword)));
|
|
573
575
|
return { results: results.filter(Boolean) };
|
|
574
576
|
}
|
|
575
577
|
|
|
576
578
|
if (states.Joi.hashRegexp.test(args.keyword)) {
|
|
577
579
|
const results = await Promise.all([
|
|
578
|
-
|
|
579
|
-
|
|
580
|
+
doSearch('tx', args.keyword.toUpperCase()),
|
|
581
|
+
doSearch('rollupBlock', args.keyword),
|
|
580
582
|
]);
|
|
581
583
|
return { results: results.filter(Boolean) };
|
|
582
584
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.13.
|
|
6
|
+
"version": "1.13.36",
|
|
7
7
|
"description": "GraphQL resolver built upon ocap statedb and GQL layer",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"jest": "^26.6.3"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@arcblock/did": "1.13.
|
|
26
|
-
"@arcblock/did-util": "1.13.
|
|
27
|
-
"@ocap/config": "1.13.
|
|
28
|
-
"@ocap/indexdb": "1.13.
|
|
29
|
-
"@ocap/mcrypto": "1.13.
|
|
30
|
-
"@ocap/message": "1.13.
|
|
31
|
-
"@ocap/state": "1.13.
|
|
32
|
-
"@ocap/tx-protocols": "1.13.
|
|
33
|
-
"@ocap/util": "1.13.
|
|
25
|
+
"@arcblock/did": "1.13.36",
|
|
26
|
+
"@arcblock/did-util": "1.13.36",
|
|
27
|
+
"@ocap/config": "1.13.36",
|
|
28
|
+
"@ocap/indexdb": "1.13.36",
|
|
29
|
+
"@ocap/mcrypto": "1.13.36",
|
|
30
|
+
"@ocap/message": "1.13.36",
|
|
31
|
+
"@ocap/state": "1.13.36",
|
|
32
|
+
"@ocap/tx-protocols": "1.13.36",
|
|
33
|
+
"@ocap/util": "1.13.36",
|
|
34
34
|
"debug": "^4.3.2",
|
|
35
35
|
"lodash": "^4.17.21"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "856b0a35bdc74c11d18f19f49bfa9cd2a85dd8db"
|
|
38
38
|
}
|