@ocap/resolver 1.18.8 → 1.18.10
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 +53 -1
- package/package.json +12 -12
package/lib/index.js
CHANGED
|
@@ -16,7 +16,7 @@ const { types } = require('@ocap/mcrypto');
|
|
|
16
16
|
const { fromTypeUrl } = require('@ocap/message');
|
|
17
17
|
const { toStakeAddress } = require('@arcblock/did-util');
|
|
18
18
|
const { fromPublicKey, toTypeInfo, isValid: isValidDid } = require('@arcblock/did');
|
|
19
|
-
const { toBN, fromTokenToUnit } = require('@ocap/util');
|
|
19
|
+
const { BN, toBN, fromTokenToUnit } = require('@ocap/util');
|
|
20
20
|
const { DEFAULT_TOKEN_DECIMAL } = require('@ocap/util/lib/constant');
|
|
21
21
|
const { createExecutor } = require('@ocap/tx-protocols');
|
|
22
22
|
const { decodeAnySafe } = require('@ocap/tx-protocols/lib/util');
|
|
@@ -44,6 +44,44 @@ const { getInstance: getTokenCacheInstance } = require('./token-cache');
|
|
|
44
44
|
const noop = (x) => x;
|
|
45
45
|
const CHAIN_ADDR = md5('OCAP_CHAIN_ADDR');
|
|
46
46
|
|
|
47
|
+
const maxGasOps = {
|
|
48
|
+
'fg:t:declare': { create: 0, update: 0 },
|
|
49
|
+
'fg:t:account_migrate': { create: 2, update: 1 },
|
|
50
|
+
'fg:t:delegate': { create: 3, update: 1 },
|
|
51
|
+
'fg:t:revoke_delegate': { create: 1, update: 2 },
|
|
52
|
+
|
|
53
|
+
'fg:t:create_asset': { create: 2, update: 1 },
|
|
54
|
+
'fg:t:update_asset': { create: 1, update: 2 },
|
|
55
|
+
|
|
56
|
+
'fg:t:create_factory': { create: 2, update: 1 },
|
|
57
|
+
'fg:t:acquire_asset_v2': { create: 2, update: 12 },
|
|
58
|
+
'fg:t:acquire_asset_v3': { create: 3, update: 12 },
|
|
59
|
+
'fg:t:mint_asset': { create: 3, update: 10 },
|
|
60
|
+
|
|
61
|
+
'fg:t:create_token': { create: 2, update: 2 },
|
|
62
|
+
'fg:t:deposit_token_v2': { create: 3, update: 3 },
|
|
63
|
+
'fg:t:withdraw_token_v2': { create: 2, update: 3 },
|
|
64
|
+
|
|
65
|
+
'fg:t:stake': { create: 2, update: 18 },
|
|
66
|
+
'fg:t:revoke_stake': { create: 1, update: 2 },
|
|
67
|
+
'fg:t:claim_stake': { create: 2, update: 18 },
|
|
68
|
+
|
|
69
|
+
'fg:t:transfer_v2': { create: 3, update: 9 },
|
|
70
|
+
'fg:t:transfer_v3': { create: 9, update: 16 },
|
|
71
|
+
'fg:t:exchange_v2': { create: 1, update: 18 },
|
|
72
|
+
|
|
73
|
+
'fg:t:create_rollup': { create: 2, update: 1 },
|
|
74
|
+
'fg:t:update_rollup': { create: 1, update: 2 },
|
|
75
|
+
'fg:t:pause_rollup': { create: 1, update: 2 },
|
|
76
|
+
'fg:t:resume_rollup': { create: 1, update: 2 },
|
|
77
|
+
'fg:t:join_rollup': { create: 2, update: 3 },
|
|
78
|
+
'fg:t:leave_rollup': { create: 2, update: 3 },
|
|
79
|
+
'fg:t:create_rollup_block': { create: 2, update: 38 },
|
|
80
|
+
'fg:t:migrate_rollup_contract': { create: 1, update: 2 },
|
|
81
|
+
'fg:t:migrate_rollup_token': { create: 1, update: 1 },
|
|
82
|
+
'fg:t:claim_block_reward': { create: 2, update: 38 },
|
|
83
|
+
};
|
|
84
|
+
|
|
47
85
|
const formatData = (data) => {
|
|
48
86
|
if (!data) {
|
|
49
87
|
return data;
|
|
@@ -631,6 +669,20 @@ module.exports = class OCAPResolver {
|
|
|
631
669
|
return { results: [] };
|
|
632
670
|
}
|
|
633
671
|
|
|
672
|
+
async estimateGas(args = {}) {
|
|
673
|
+
const { typeUrl = '' } = args;
|
|
674
|
+
if (!typeUrl || !maxGasOps[typeUrl]) {
|
|
675
|
+
throw new CustomError('INVALID_REQUEST', 'Unknown tx typeUrl');
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const { txGas, maxTxSize } = this.config.transaction;
|
|
679
|
+
const estimate = maxGasOps[args.typeUrl];
|
|
680
|
+
let totalGas = new BN(txGas.price * txGas.dataStorage * maxTxSize[args.typeUrl]);
|
|
681
|
+
totalGas = totalGas.add(new BN(txGas.price * txGas.createState * (estimate.create + 1))); // 1 = tx insert
|
|
682
|
+
totalGas = totalGas.add(new BN(txGas.price * txGas.updateState * estimate.update));
|
|
683
|
+
return { estimate: { max: totalGas.toString(10) } };
|
|
684
|
+
}
|
|
685
|
+
|
|
634
686
|
listBlocks() {
|
|
635
687
|
return { blocks: [] };
|
|
636
688
|
}
|
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.10",
|
|
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": "^27.5.1"
|
|
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.10",
|
|
26
|
+
"@arcblock/did-util": "1.18.10",
|
|
27
|
+
"@arcblock/validator": "1.18.10",
|
|
28
|
+
"@ocap/config": "1.18.10",
|
|
29
|
+
"@ocap/indexdb": "1.18.10",
|
|
30
|
+
"@ocap/mcrypto": "1.18.10",
|
|
31
|
+
"@ocap/message": "1.18.10",
|
|
32
|
+
"@ocap/state": "1.18.10",
|
|
33
|
+
"@ocap/tx-protocols": "1.18.10",
|
|
34
|
+
"@ocap/util": "1.18.10",
|
|
35
35
|
"debug": "^4.3.4",
|
|
36
36
|
"lodash": "^4.17.21"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "1c857951c380626c02c423d00a7b7e8c0a63faa2"
|
|
39
39
|
}
|