@ocap/resolver 1.18.9 → 1.18.11
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 +54 -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,45 @@ 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': { create: 2, update: 20 },
|
|
70
|
+
'fg:t:transfer_v2': { create: 2, update: 20 },
|
|
71
|
+
'fg:t:transfer_v3': { create: 9, update: 16 },
|
|
72
|
+
'fg:t:exchange_v2': { create: 1, update: 18 },
|
|
73
|
+
|
|
74
|
+
'fg:t:create_rollup': { create: 2, update: 1 },
|
|
75
|
+
'fg:t:update_rollup': { create: 1, update: 2 },
|
|
76
|
+
'fg:t:pause_rollup': { create: 1, update: 2 },
|
|
77
|
+
'fg:t:resume_rollup': { create: 1, update: 2 },
|
|
78
|
+
'fg:t:join_rollup': { create: 2, update: 3 },
|
|
79
|
+
'fg:t:leave_rollup': { create: 2, update: 3 },
|
|
80
|
+
'fg:t:create_rollup_block': { create: 2, update: 38 },
|
|
81
|
+
'fg:t:migrate_rollup_contract': { create: 1, update: 2 },
|
|
82
|
+
'fg:t:migrate_rollup_token': { create: 1, update: 1 },
|
|
83
|
+
'fg:t:claim_block_reward': { create: 2, update: 38 },
|
|
84
|
+
};
|
|
85
|
+
|
|
47
86
|
const formatData = (data) => {
|
|
48
87
|
if (!data) {
|
|
49
88
|
return data;
|
|
@@ -631,6 +670,20 @@ module.exports = class OCAPResolver {
|
|
|
631
670
|
return { results: [] };
|
|
632
671
|
}
|
|
633
672
|
|
|
673
|
+
async estimateGas(args = {}) {
|
|
674
|
+
const { typeUrl = '' } = args;
|
|
675
|
+
if (!typeUrl || !maxGasOps[typeUrl]) {
|
|
676
|
+
throw new CustomError('INVALID_REQUEST', 'Unknown tx typeUrl');
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const { txGas, maxTxSize } = this.config.transaction;
|
|
680
|
+
const estimate = maxGasOps[args.typeUrl];
|
|
681
|
+
let totalGas = new BN(txGas.price * txGas.dataStorage * maxTxSize[args.typeUrl]);
|
|
682
|
+
totalGas = totalGas.add(new BN(txGas.price * txGas.createState * (estimate.create + 1))); // 1 = tx insert
|
|
683
|
+
totalGas = totalGas.add(new BN(txGas.price * txGas.updateState * estimate.update));
|
|
684
|
+
return { estimate: { max: totalGas.toString(10) } };
|
|
685
|
+
}
|
|
686
|
+
|
|
634
687
|
listBlocks() {
|
|
635
688
|
return { blocks: [] };
|
|
636
689
|
}
|
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.11",
|
|
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.11",
|
|
26
|
+
"@arcblock/did-util": "1.18.11",
|
|
27
|
+
"@arcblock/validator": "1.18.11",
|
|
28
|
+
"@ocap/config": "1.18.11",
|
|
29
|
+
"@ocap/indexdb": "1.18.11",
|
|
30
|
+
"@ocap/mcrypto": "1.18.11",
|
|
31
|
+
"@ocap/message": "1.18.11",
|
|
32
|
+
"@ocap/state": "1.18.11",
|
|
33
|
+
"@ocap/tx-protocols": "1.18.11",
|
|
34
|
+
"@ocap/util": "1.18.11",
|
|
35
35
|
"debug": "^4.3.4",
|
|
36
36
|
"lodash": "^4.17.21"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "1ecbf39c3bb6a8e91caf9c648a4eb3da5b65043d"
|
|
39
39
|
}
|