dkg.js 6.1.2 → 6.2.1
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/constants.js +44 -1
- package/dist/dkg.min.js +1 -1
- package/managers/network-operations-manager.js +22 -14
- package/package.json +2 -2
- package/services/blockchain-service/blockchain-service-base.js +44 -18
- package/services/input-service.js +16 -6
- package/services/node-api-service/implementations/http-service.js +13 -8
- package/services/validation-service.js +13 -0
|
@@ -14,27 +14,35 @@ class NetworkOperationsManager {
|
|
|
14
14
|
* @returns {BigInt} Suggested bid for publishing Knowledge Asset with given parameters.
|
|
15
15
|
*/
|
|
16
16
|
async getBidSuggestion(publicAssertionId, sizeInBytes, options = {}) {
|
|
17
|
-
const {
|
|
18
|
-
|
|
17
|
+
const {
|
|
18
|
+
blockchain,
|
|
19
|
+
endpoint,
|
|
20
|
+
port,
|
|
21
|
+
epochsNum,
|
|
22
|
+
hashFunctionId,
|
|
23
|
+
authToken,
|
|
24
|
+
bidSuggestionRange,
|
|
25
|
+
} = this.inputService.getBidSuggestionArguments(options);
|
|
19
26
|
|
|
20
27
|
const contentAssetStorageAddress = await this.blockchainService.getContractAddress(
|
|
21
28
|
'ContentAssetStorage',
|
|
22
29
|
blockchain,
|
|
23
30
|
);
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
),
|
|
32
|
+
const response = await this.nodeApiService.getBidSuggestion(
|
|
33
|
+
endpoint,
|
|
34
|
+
port,
|
|
35
|
+
authToken,
|
|
36
|
+
blockchain.name,
|
|
37
|
+
epochsNum,
|
|
38
|
+
sizeInBytes,
|
|
39
|
+
contentAssetStorageAddress,
|
|
40
|
+
publicAssertionId,
|
|
41
|
+
hashFunctionId,
|
|
42
|
+
bidSuggestionRange,
|
|
37
43
|
);
|
|
44
|
+
|
|
45
|
+
return typeof response === 'string' ? BigInt(response) : response;
|
|
38
46
|
}
|
|
39
47
|
}
|
|
40
48
|
module.exports = NetworkOperationsManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dkg.js",
|
|
3
|
-
"version": "6.1
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"assertion-tools": "^2.1.0",
|
|
33
33
|
"axios": "^0.27.2",
|
|
34
|
-
"dkg-evm-module": "^4.
|
|
34
|
+
"dkg-evm-module": "^4.2.4",
|
|
35
35
|
"ethers": "^6.1.0",
|
|
36
36
|
"jsonld": "^8.1.0",
|
|
37
37
|
"web3": "^1.7.3"
|
|
@@ -8,7 +8,7 @@ const ContentAssetStorageAbi = require('dkg-evm-module/abi/ContentAssetStorage.j
|
|
|
8
8
|
const UnfinalizedStateStorageAbi = require('dkg-evm-module/abi/UnfinalizedStateStorage.json');
|
|
9
9
|
const ContentAssetAbi = require('dkg-evm-module/abi/ContentAsset.json');
|
|
10
10
|
const TokenAbi = require('dkg-evm-module/abi/Token.json');
|
|
11
|
-
const { OPERATIONS_STEP_STATUS } = require('../../constants');
|
|
11
|
+
const { OPERATIONS_STEP_STATUS, DEFAULT_GAS_PRICE } = require('../../constants');
|
|
12
12
|
const emptyHooks = require('../../util/empty-hooks.js');
|
|
13
13
|
|
|
14
14
|
class BlockchainServiceBase {
|
|
@@ -64,15 +64,25 @@ class BlockchainServiceBase {
|
|
|
64
64
|
gasPrice = Math.round(response.data.average * 1e9);
|
|
65
65
|
}
|
|
66
66
|
} else {
|
|
67
|
-
gasPrice = Web3.utils.toWei(
|
|
67
|
+
gasPrice = Web3.utils.toWei(
|
|
68
|
+
blockchain.name.startsWith('otp')
|
|
69
|
+
? DEFAULT_GAS_PRICE.OTP
|
|
70
|
+
: DEFAULT_GAS_PRICE.GNOSIS,
|
|
71
|
+
'Gwei',
|
|
72
|
+
);
|
|
68
73
|
}
|
|
69
74
|
return gasPrice;
|
|
70
75
|
} catch (error) {
|
|
71
76
|
// eslint-disable-next-line no-console
|
|
72
77
|
console.warn(
|
|
73
|
-
`Failed to fetch the gas price from the network: ${error}. Using default value:
|
|
78
|
+
`Failed to fetch the gas price from the network: ${error}. Using default value: 2 Gwei.`,
|
|
79
|
+
);
|
|
80
|
+
return Web3.utils.toWei(
|
|
81
|
+
blockchain.name.startsWith('otp')
|
|
82
|
+
? DEFAULT_GAS_PRICE.OTP
|
|
83
|
+
: DEFAULT_GAS_PRICE.GNOSIS,
|
|
84
|
+
'Gwei',
|
|
74
85
|
);
|
|
75
|
-
return Web3.utils.toWei('100', 'Gwei');
|
|
76
86
|
}
|
|
77
87
|
}
|
|
78
88
|
|
|
@@ -531,22 +541,38 @@ class BlockchainServiceBase {
|
|
|
531
541
|
|
|
532
542
|
async getGasPrice(blockchain) {
|
|
533
543
|
const web3Instance = await this.getWeb3Instance(blockchain);
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
+
try {
|
|
545
|
+
let gasPrice;
|
|
546
|
+
if (blockchain.name.startsWith('otp')) {
|
|
547
|
+
gasPrice = await web3Instance.eth.getGasPrice();
|
|
548
|
+
} else if (blockchain.name.startsWith('gnosis')) {
|
|
549
|
+
const response = await axios.get(blockchain.gasPriceOracleLink);
|
|
550
|
+
if (blockchain.name.split(':')[1] === '100') {
|
|
551
|
+
gasPrice = Number(response.result, 10);
|
|
552
|
+
} else if (blockchain.name.split(':')[1] === '10200') {
|
|
553
|
+
gasPrice = Math.round(response.data.average * 1e9);
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
gasPrice = Web3.utils.toWei(
|
|
557
|
+
blockchain.name.startsWith('otp')
|
|
558
|
+
? DEFAULT_GAS_PRICE.OTP
|
|
559
|
+
: DEFAULT_GAS_PRICE.GNOSIS,
|
|
560
|
+
'Gwei',
|
|
561
|
+
);
|
|
544
562
|
}
|
|
545
|
-
|
|
546
|
-
|
|
563
|
+
return gasPrice;
|
|
564
|
+
} catch (error) {
|
|
565
|
+
// eslint-disable-next-line no-console
|
|
566
|
+
console.warn(
|
|
567
|
+
`Failed to fetch the gas price from the network: ${error}. Using default value: 2 Gwei.`,
|
|
568
|
+
);
|
|
569
|
+
return Web3.utils.toWei(
|
|
570
|
+
blockchain.name.startsWith('otp')
|
|
571
|
+
? DEFAULT_GAS_PRICE.OTP
|
|
572
|
+
: DEFAULT_GAS_PRICE.GNOSIS,
|
|
573
|
+
'Gwei',
|
|
574
|
+
);
|
|
547
575
|
}
|
|
548
|
-
|
|
549
|
-
return gasPrice;
|
|
550
576
|
}
|
|
551
577
|
|
|
552
578
|
async getWalletBalances(blockchain) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
DEFAULT_PARAMETERS,
|
|
3
|
+
DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS,
|
|
4
|
+
BLOCKCHAINS,
|
|
5
|
+
LOW_BID_SUGGESTION,
|
|
6
|
+
} = require('../constants');
|
|
2
7
|
|
|
3
8
|
class InputService {
|
|
4
9
|
constructor(config = {}) {
|
|
@@ -13,6 +18,7 @@ class InputService {
|
|
|
13
18
|
epochsNum: this.getEpochsNum(options),
|
|
14
19
|
hashFunctionId: this.getHashFunctionId(options),
|
|
15
20
|
authToken: this.getAuthToken(options),
|
|
21
|
+
bidSuggestionRange: this.getBidSuggestionRange(options),
|
|
16
22
|
};
|
|
17
23
|
}
|
|
18
24
|
|
|
@@ -150,11 +156,11 @@ class InputService {
|
|
|
150
156
|
}
|
|
151
157
|
|
|
152
158
|
getScoreFunctionId(options) {
|
|
153
|
-
|
|
154
|
-
options.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
const environment =
|
|
160
|
+
options.environment ?? this.config.environment ?? DEFAULT_PARAMETERS.ENVIRONMENT;
|
|
161
|
+
const blockchainName = this.getBlockchain(options).name;
|
|
162
|
+
|
|
163
|
+
return DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS[environment][blockchainName];
|
|
158
164
|
}
|
|
159
165
|
|
|
160
166
|
getEpochsNum(options) {
|
|
@@ -196,6 +202,10 @@ class InputService {
|
|
|
196
202
|
getAuthToken(options) {
|
|
197
203
|
return options.auth?.token ?? this.config?.auth?.token ?? null;
|
|
198
204
|
}
|
|
205
|
+
|
|
206
|
+
getBidSuggestionRange(options) {
|
|
207
|
+
return options.bidSuggestionRange ?? LOW_BID_SUGGESTION;
|
|
208
|
+
}
|
|
199
209
|
}
|
|
200
210
|
|
|
201
211
|
module.exports = InputService;
|
|
@@ -31,19 +31,24 @@ class HttpService {
|
|
|
31
31
|
contentAssetStorageAddress,
|
|
32
32
|
firstAssertionId,
|
|
33
33
|
hashFunctionId,
|
|
34
|
+
bidSuggestionRange,
|
|
34
35
|
) {
|
|
35
36
|
try {
|
|
37
|
+
const params = {
|
|
38
|
+
blockchain,
|
|
39
|
+
epochsNumber,
|
|
40
|
+
assertionSize,
|
|
41
|
+
contentAssetStorageAddress,
|
|
42
|
+
firstAssertionId,
|
|
43
|
+
hashFunctionId,
|
|
44
|
+
};
|
|
45
|
+
if (bidSuggestionRange != null) {
|
|
46
|
+
params.bidSuggestionRange = bidSuggestionRange;
|
|
47
|
+
}
|
|
36
48
|
const response = await axios({
|
|
37
49
|
method: 'get',
|
|
38
50
|
url: `${endpoint}:${port}/bid-suggestion`,
|
|
39
|
-
params
|
|
40
|
-
blockchain,
|
|
41
|
-
epochsNumber,
|
|
42
|
-
assertionSize,
|
|
43
|
-
contentAssetStorageAddress,
|
|
44
|
-
firstAssertionId,
|
|
45
|
-
hashFunctionId,
|
|
46
|
-
},
|
|
51
|
+
params,
|
|
47
52
|
headers: this.prepareRequestConfig(authToken),
|
|
48
53
|
});
|
|
49
54
|
|
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
OPERATIONS,
|
|
8
8
|
GET_OUTPUT_FORMATS,
|
|
9
9
|
QUERY_TYPES,
|
|
10
|
+
BID_SUGGESTION_RANGE_ENUM,
|
|
10
11
|
} = require('../constants.js');
|
|
11
12
|
const { nodeSupported } = require('./utilities.js');
|
|
12
13
|
|
|
@@ -402,5 +403,17 @@ class ValidationService {
|
|
|
402
403
|
this.validateRequiredParam('newOwner', newOwner);
|
|
403
404
|
this.validateParamType('newOwner', newOwner, 'string');
|
|
404
405
|
}
|
|
406
|
+
|
|
407
|
+
validateGetBidSuggestion(bidSuggestionRange) {
|
|
408
|
+
this.validateBidSuggestionRange(bidSuggestionRange);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
validateBidSuggestionRange(bidSuggestionRange) {
|
|
412
|
+
if (!BID_SUGGESTION_RANGE_ENUM.includes(bidSuggestionRange)) {
|
|
413
|
+
throw Error(
|
|
414
|
+
`Invalid bidSuggestionRange parametar: supported parametars ${BID_SUGGESTION_RANGE_ENUM}`,
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
405
418
|
}
|
|
406
419
|
module.exports = ValidationService;
|