@ocap/resolver 1.18.165 → 1.19.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.
- package/lib/hooks.js +22 -20
- package/lib/index.js +8 -5
- 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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
}
|
|
199
|
-
|
|
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 =
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
6
|
+
"version": "1.19.0",
|
|
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.
|
|
26
|
-
"@arcblock/did-util": "1.
|
|
27
|
-
"@arcblock/validator": "1.
|
|
28
|
-
"@ocap/config": "1.
|
|
29
|
-
"@ocap/indexdb": "1.
|
|
30
|
-
"@ocap/mcrypto": "1.
|
|
31
|
-
"@ocap/message": "1.
|
|
32
|
-
"@ocap/state": "1.
|
|
33
|
-
"@ocap/tx-protocols": "1.
|
|
34
|
-
"@ocap/util": "1.
|
|
25
|
+
"@arcblock/did": "1.19.0",
|
|
26
|
+
"@arcblock/did-util": "1.19.0",
|
|
27
|
+
"@arcblock/validator": "1.19.0",
|
|
28
|
+
"@ocap/config": "1.19.0",
|
|
29
|
+
"@ocap/indexdb": "1.19.0",
|
|
30
|
+
"@ocap/mcrypto": "1.19.0",
|
|
31
|
+
"@ocap/message": "1.19.0",
|
|
32
|
+
"@ocap/state": "1.19.0",
|
|
33
|
+
"@ocap/tx-protocols": "1.19.0",
|
|
34
|
+
"@ocap/util": "1.19.0",
|
|
35
35
|
"debug": "^4.3.6",
|
|
36
36
|
"lodash": "^4.17.21"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "1b6fac03988fb18507c8ef4c21de282762005f87"
|
|
39
39
|
}
|