@ocap/resolver 1.18.149 → 1.18.151
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 +56 -3
- package/lib/token-flow.js +4 -3
- package/package.json +12 -12
package/lib/index.js
CHANGED
|
@@ -331,12 +331,13 @@ module.exports = class OCAPResolver {
|
|
|
331
331
|
return JSON.stringify(this.config);
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
getAccountState({ address, traceMigration = true }, ctx) {
|
|
334
|
+
getAccountState({ address, traceMigration = true, expandContext = true }, ctx) {
|
|
335
335
|
return this._getState({
|
|
336
336
|
table: 'account',
|
|
337
337
|
id: address,
|
|
338
338
|
dataKey: 'data',
|
|
339
339
|
extraParams: { traceMigration },
|
|
340
|
+
expandContext,
|
|
340
341
|
onRead: async (state) => {
|
|
341
342
|
if (state) {
|
|
342
343
|
if (state.tokens) {
|
|
@@ -965,7 +966,9 @@ module.exports = class OCAPResolver {
|
|
|
965
966
|
tx.receipts = getTxReceipts(tx, { config: this.config });
|
|
966
967
|
}
|
|
967
968
|
|
|
968
|
-
|
|
969
|
+
const typeUrl = get(tx, 'tx.itxJson.type_url');
|
|
970
|
+
|
|
971
|
+
if (typeUrl === 'fg:t:revoke_withdraw' || typeUrl === 'fg:t:approve_withdraw') {
|
|
969
972
|
const withdrawHash = get(tx, 'tx.itxJson.withdraw_tx_hash');
|
|
970
973
|
// Avoid infinite loop by invalid data
|
|
971
974
|
if (withdrawHash && withdrawHash !== tx.hash) {
|
|
@@ -975,10 +978,25 @@ module.exports = class OCAPResolver {
|
|
|
975
978
|
}
|
|
976
979
|
|
|
977
980
|
// https://github.com/blocklet/abt-wallet/issues/681
|
|
978
|
-
if (
|
|
981
|
+
if (typeUrl === 'fg:t:deposit_token') {
|
|
979
982
|
tx.receipts = getTxReceipts(tx, { config: this.config });
|
|
980
983
|
}
|
|
981
984
|
|
|
985
|
+
if (typeUrl === 'fg:t:account_migrate') {
|
|
986
|
+
const fromState = await this.getAccountState({
|
|
987
|
+
address: tx.tx.from,
|
|
988
|
+
traceMigration: false,
|
|
989
|
+
expandContext: false,
|
|
990
|
+
});
|
|
991
|
+
if (fromState) {
|
|
992
|
+
tx.receipts = getTxReceipts(tx, { config: this.config, fromState });
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
if (typeUrl === 'fg:t:declare') {
|
|
997
|
+
tx.receipts = getTxReceipts(tx, { config: this.config, time: tx.time });
|
|
998
|
+
}
|
|
999
|
+
|
|
982
1000
|
tx.receipts = mergeTxReceipts(tx.receipts);
|
|
983
1001
|
tx.tokenSymbols = await this.getTxTokenSymbols(tx);
|
|
984
1002
|
|
|
@@ -1153,6 +1171,41 @@ module.exports = class OCAPResolver {
|
|
|
1153
1171
|
migrationChain.buildChains(migrationTxs);
|
|
1154
1172
|
this.migrationChain = migrationChain;
|
|
1155
1173
|
}
|
|
1174
|
+
|
|
1175
|
+
/** fix accounts field of legacy approve_withdraw transactions in indexdb */
|
|
1176
|
+
async fixApproveWithdrawAccounts() {
|
|
1177
|
+
const approveWithdrawTxs = await this._getAllResults('transactions', (paging) =>
|
|
1178
|
+
this.listTransactions({
|
|
1179
|
+
paging,
|
|
1180
|
+
typeFilter: { types: ['approve_withdraw'] },
|
|
1181
|
+
validityFilter: { validity: ['VALID'] },
|
|
1182
|
+
})
|
|
1183
|
+
);
|
|
1184
|
+
|
|
1185
|
+
const updatedTxs = await Promise.all(
|
|
1186
|
+
approveWithdrawTxs.map(async (tx) => {
|
|
1187
|
+
const withdrawHash = tx.tx?.itxJson?.withdraw_tx_hash;
|
|
1188
|
+
|
|
1189
|
+
if (!withdrawHash) return;
|
|
1190
|
+
|
|
1191
|
+
const indexdbTx = await this.indexdb.tx.get(tx.hash);
|
|
1192
|
+
const withdrawTx = await this.getTx({ hash: withdrawHash });
|
|
1193
|
+
const from = withdrawTx?.tx?.from;
|
|
1194
|
+
|
|
1195
|
+
if (!from || !indexdbTx) return;
|
|
1196
|
+
|
|
1197
|
+
const accounts = uniq((indexdbTx.accounts || []).concat([from]).filter(Boolean));
|
|
1198
|
+
debug('fixApproveWithdrawAccounts', { tx, from, accounts });
|
|
1199
|
+
|
|
1200
|
+
// update indexdb
|
|
1201
|
+
const updatedTx = await this.indexdb.tx.update(tx.hash, { accounts });
|
|
1202
|
+
// eslint-disable-next-line consistent-return
|
|
1203
|
+
return updatedTx;
|
|
1204
|
+
})
|
|
1205
|
+
);
|
|
1206
|
+
|
|
1207
|
+
return updatedTxs.filter(Boolean);
|
|
1208
|
+
}
|
|
1156
1209
|
};
|
|
1157
1210
|
|
|
1158
1211
|
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,7 +123,7 @@ 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) => {
|
|
@@ -170,8 +171,8 @@ const verifyAccountRisk = async ({ accountAddress, tokenAddress }, resolver, ctx
|
|
|
170
171
|
// Avoid circular query
|
|
171
172
|
if (checkedAccounts.has(address)) continue;
|
|
172
173
|
// skip trusted accounts
|
|
173
|
-
if (await resolver.filter.isTrusted(
|
|
174
|
-
checkedAccounts.set(
|
|
174
|
+
if (await resolver.filter.isTrusted(address)) {
|
|
175
|
+
checkedAccounts.set(address, {});
|
|
175
176
|
continue;
|
|
176
177
|
}
|
|
177
178
|
|
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.151",
|
|
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.151",
|
|
26
|
+
"@arcblock/did-util": "1.18.151",
|
|
27
|
+
"@arcblock/validator": "1.18.151",
|
|
28
|
+
"@ocap/config": "1.18.151",
|
|
29
|
+
"@ocap/indexdb": "1.18.151",
|
|
30
|
+
"@ocap/mcrypto": "1.18.151",
|
|
31
|
+
"@ocap/message": "1.18.151",
|
|
32
|
+
"@ocap/state": "1.18.151",
|
|
33
|
+
"@ocap/tx-protocols": "1.18.151",
|
|
34
|
+
"@ocap/util": "1.18.151",
|
|
35
35
|
"debug": "^4.3.6",
|
|
36
36
|
"lodash": "^4.17.21"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "ad9f0a1c3913c304a716247de283be2146b7105e"
|
|
39
39
|
}
|