@ocap/resolver 1.18.150 → 1.18.152
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/index.js +64 -5
- package/lib/token-flow.js +3 -2
- package/package.json +12 -12
package/lib/index.js
CHANGED
|
@@ -190,8 +190,6 @@ module.exports = class OCAPResolver {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
this.buildMigrationChain();
|
|
194
|
-
|
|
195
193
|
this.executor = createExecutor({
|
|
196
194
|
filter,
|
|
197
195
|
runAsLambda: typeof statedb.runAsLambda === 'function' ? statedb.runAsLambda.bind(statedb) : null,
|
|
@@ -331,12 +329,13 @@ module.exports = class OCAPResolver {
|
|
|
331
329
|
return JSON.stringify(this.config);
|
|
332
330
|
}
|
|
333
331
|
|
|
334
|
-
getAccountState({ address, traceMigration = true }, ctx) {
|
|
332
|
+
getAccountState({ address, traceMigration = true, expandContext = true }, ctx) {
|
|
335
333
|
return this._getState({
|
|
336
334
|
table: 'account',
|
|
337
335
|
id: address,
|
|
338
336
|
dataKey: 'data',
|
|
339
337
|
extraParams: { traceMigration },
|
|
338
|
+
expandContext,
|
|
340
339
|
onRead: async (state) => {
|
|
341
340
|
if (state) {
|
|
342
341
|
if (state.tokens) {
|
|
@@ -965,7 +964,9 @@ module.exports = class OCAPResolver {
|
|
|
965
964
|
tx.receipts = getTxReceipts(tx, { config: this.config });
|
|
966
965
|
}
|
|
967
966
|
|
|
968
|
-
|
|
967
|
+
const typeUrl = get(tx, 'tx.itxJson.type_url');
|
|
968
|
+
|
|
969
|
+
if (typeUrl === 'fg:t:revoke_withdraw' || typeUrl === 'fg:t:approve_withdraw') {
|
|
969
970
|
const withdrawHash = get(tx, 'tx.itxJson.withdraw_tx_hash');
|
|
970
971
|
// Avoid infinite loop by invalid data
|
|
971
972
|
if (withdrawHash && withdrawHash !== tx.hash) {
|
|
@@ -975,10 +976,25 @@ module.exports = class OCAPResolver {
|
|
|
975
976
|
}
|
|
976
977
|
|
|
977
978
|
// https://github.com/blocklet/abt-wallet/issues/681
|
|
978
|
-
if (
|
|
979
|
+
if (typeUrl === 'fg:t:deposit_token' || typeUrl === 'fg:t:withdraw_token') {
|
|
979
980
|
tx.receipts = getTxReceipts(tx, { config: this.config });
|
|
980
981
|
}
|
|
981
982
|
|
|
983
|
+
if (typeUrl === 'fg:t:account_migrate') {
|
|
984
|
+
const fromState = await this.getAccountState({
|
|
985
|
+
address: tx.tx.from,
|
|
986
|
+
traceMigration: false,
|
|
987
|
+
expandContext: false,
|
|
988
|
+
});
|
|
989
|
+
if (fromState) {
|
|
990
|
+
tx.receipts = getTxReceipts(tx, { config: this.config, fromState });
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
if (typeUrl === 'fg:t:declare') {
|
|
995
|
+
tx.receipts = getTxReceipts(tx, { config: this.config, time: tx.time });
|
|
996
|
+
}
|
|
997
|
+
|
|
982
998
|
tx.receipts = mergeTxReceipts(tx.receipts);
|
|
983
999
|
tx.tokenSymbols = await this.getTxTokenSymbols(tx);
|
|
984
1000
|
|
|
@@ -1153,6 +1169,49 @@ module.exports = class OCAPResolver {
|
|
|
1153
1169
|
migrationChain.buildChains(migrationTxs);
|
|
1154
1170
|
this.migrationChain = migrationChain;
|
|
1155
1171
|
}
|
|
1172
|
+
|
|
1173
|
+
async getMigrationChain() {
|
|
1174
|
+
if (!this.migrationChain) {
|
|
1175
|
+
await this.buildMigrationChain();
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
return this.migrationChain;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
/** fix accounts field of legacy approve_withdraw transactions in indexdb */
|
|
1182
|
+
async fixApproveWithdrawAccounts() {
|
|
1183
|
+
const approveWithdrawTxs = await this._getAllResults('transactions', (paging) =>
|
|
1184
|
+
this.listTransactions({
|
|
1185
|
+
paging,
|
|
1186
|
+
typeFilter: { types: ['approve_withdraw'] },
|
|
1187
|
+
validityFilter: { validity: ['VALID'] },
|
|
1188
|
+
})
|
|
1189
|
+
);
|
|
1190
|
+
|
|
1191
|
+
const updatedTxs = await Promise.all(
|
|
1192
|
+
approveWithdrawTxs.map(async (tx) => {
|
|
1193
|
+
const withdrawHash = tx.tx?.itxJson?.withdraw_tx_hash;
|
|
1194
|
+
|
|
1195
|
+
if (!withdrawHash) return;
|
|
1196
|
+
|
|
1197
|
+
const indexdbTx = await this.indexdb.tx.get(tx.hash);
|
|
1198
|
+
const withdrawTx = await this.getTx({ hash: withdrawHash });
|
|
1199
|
+
const from = withdrawTx?.tx?.from;
|
|
1200
|
+
|
|
1201
|
+
if (!from || !indexdbTx) return;
|
|
1202
|
+
|
|
1203
|
+
const accounts = uniq((indexdbTx.accounts || []).concat([from]).filter(Boolean));
|
|
1204
|
+
debug('fixApproveWithdrawAccounts', { tx, from, accounts });
|
|
1205
|
+
|
|
1206
|
+
// update indexdb
|
|
1207
|
+
const updatedTx = await this.indexdb.tx.update(tx.hash, { accounts });
|
|
1208
|
+
// eslint-disable-next-line consistent-return
|
|
1209
|
+
return updatedTx;
|
|
1210
|
+
})
|
|
1211
|
+
);
|
|
1212
|
+
|
|
1213
|
+
return updatedTxs.filter(Boolean);
|
|
1214
|
+
}
|
|
1156
1215
|
};
|
|
1157
1216
|
|
|
1158
1217
|
module.exports.formatData = formatData;
|
package/lib/token-flow.js
CHANGED
|
@@ -4,6 +4,7 @@ const { BN, fromTokenToUnit } = require('@ocap/util');
|
|
|
4
4
|
const { schemas, Joi } = require('@arcblock/validator');
|
|
5
5
|
const { CustomError } = require('@ocap/util/lib/error');
|
|
6
6
|
const uniq = require('lodash/uniq');
|
|
7
|
+
const { FORGE_TOKEN_HOLDER } = require('@ocap/state/lib/states/tx');
|
|
7
8
|
const debug = require('debug')(require('../package.json').name);
|
|
8
9
|
|
|
9
10
|
const ZERO = new BN(0);
|
|
@@ -122,11 +123,11 @@ const getTransferFlow = (tx, tokenAddress) => {
|
|
|
122
123
|
};
|
|
123
124
|
|
|
124
125
|
const getVaultAccounts = (config) => {
|
|
125
|
-
return Object.values(config.vaults).flat();
|
|
126
|
+
return Object.values(config.vaults).flat().concat(FORGE_TOKEN_HOLDER);
|
|
126
127
|
};
|
|
127
128
|
|
|
128
129
|
const fixMigrateReceipts = async ({ accountAddress, tx }, resolver) => {
|
|
129
|
-
const
|
|
130
|
+
const migrationChain = await resolver.getMigrationChain();
|
|
130
131
|
const address = migrationChain.findAddressAtTime(accountAddress, new Date(tx.time));
|
|
131
132
|
const migrations = migrationChain.getMigrationHistory(accountAddress);
|
|
132
133
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.18.
|
|
6
|
+
"version": "1.18.152",
|
|
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.
|
|
26
|
-
"@arcblock/did-util": "1.18.
|
|
27
|
-
"@arcblock/validator": "1.18.
|
|
28
|
-
"@ocap/config": "1.18.
|
|
29
|
-
"@ocap/indexdb": "1.18.
|
|
30
|
-
"@ocap/mcrypto": "1.18.
|
|
31
|
-
"@ocap/message": "1.18.
|
|
32
|
-
"@ocap/state": "1.18.
|
|
33
|
-
"@ocap/tx-protocols": "1.18.
|
|
34
|
-
"@ocap/util": "1.18.
|
|
25
|
+
"@arcblock/did": "1.18.152",
|
|
26
|
+
"@arcblock/did-util": "1.18.152",
|
|
27
|
+
"@arcblock/validator": "1.18.152",
|
|
28
|
+
"@ocap/config": "1.18.152",
|
|
29
|
+
"@ocap/indexdb": "1.18.152",
|
|
30
|
+
"@ocap/mcrypto": "1.18.152",
|
|
31
|
+
"@ocap/message": "1.18.152",
|
|
32
|
+
"@ocap/state": "1.18.152",
|
|
33
|
+
"@ocap/tx-protocols": "1.18.152",
|
|
34
|
+
"@ocap/util": "1.18.152",
|
|
35
35
|
"debug": "^4.3.6",
|
|
36
36
|
"lodash": "^4.17.21"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "4f31d06aa2a15b57a7d00fdec6241376f10ee873"
|
|
39
39
|
}
|