dkg.js 6.0.13 → 6.0.14
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 +7 -0
- package/dist/dkg.min.js +1 -1
- package/examples/demo.js +75 -30
- package/index.js +8 -4
- package/managers/assertion-operations-manager.js +68 -0
- package/managers/asset-operations-manager.js +119 -47
- package/managers/blockchain-operations-manager.js +13 -1
- package/managers/graph-operations-manager.js +1 -1
- package/managers/network-operations-manager.js +47 -0
- package/managers/node-operations-manager.js +1 -1
- package/package.json +2 -2
- package/services/blockchain-service/implementations/node-blockchain-service.js +2 -3
- package/services/input-service.js +11 -0
- package/services/utilities.js +5 -7
- package/services/validation-service.js +7 -1
- package/managers/index-operations-manager.js +0 -3
package/examples/demo.js
CHANGED
|
@@ -26,6 +26,35 @@ function divider() {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
(async () => {
|
|
29
|
+
const content = {
|
|
30
|
+
public: {
|
|
31
|
+
'@context': ['https://schema.org'],
|
|
32
|
+
'@id': 'uuid:1',
|
|
33
|
+
company: 'OT',
|
|
34
|
+
user: {
|
|
35
|
+
'@id': 'uuid:user:1',
|
|
36
|
+
},
|
|
37
|
+
city: {
|
|
38
|
+
'@id': 'uuid:belgrade',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
private: {
|
|
42
|
+
'@context': ['https://schema.org'],
|
|
43
|
+
'@graph': [
|
|
44
|
+
{
|
|
45
|
+
'@id': 'uuid:user:1',
|
|
46
|
+
name: 'Adam',
|
|
47
|
+
lastname: 'Smith',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
'@id': 'uuid:belgrade',
|
|
51
|
+
title: 'Belgrade',
|
|
52
|
+
postCode: '11000',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
29
58
|
divider();
|
|
30
59
|
|
|
31
60
|
const nodeInfo = await DkgClient.node.info();
|
|
@@ -34,37 +63,53 @@ function divider() {
|
|
|
34
63
|
|
|
35
64
|
divider();
|
|
36
65
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
'@id': 'uuid:belgrade',
|
|
60
|
-
title: 'Belgrade',
|
|
61
|
-
postCode: '11000',
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
+
const assertions = await DkgClient.assertion.formatGraph(content);
|
|
67
|
+
console.log('======================== ASSERTIONS FORMATTED');
|
|
68
|
+
console.log(JSON.stringify(assertions));
|
|
69
|
+
|
|
70
|
+
divider();
|
|
71
|
+
|
|
72
|
+
const publicAssertionId = await DkgClient.assertion.getPublicAssertionId(content);
|
|
73
|
+
console.log('======================== PUBLIC ASSERTION ID (MERKLE ROOT) CALCULATED');
|
|
74
|
+
console.log(publicAssertionId);
|
|
75
|
+
|
|
76
|
+
divider();
|
|
77
|
+
|
|
78
|
+
const publicAssertionSize = await DkgClient.assertion.getSizeInBytes(content);
|
|
79
|
+
console.log('======================== PUBLIC ASSERTION SIZE CALCULATED');
|
|
80
|
+
console.log(publicAssertionSize);
|
|
81
|
+
|
|
82
|
+
divider();
|
|
83
|
+
|
|
84
|
+
const bidSuggestion = await DkgClient.network.getBidSuggestion(
|
|
85
|
+
publicAssertionId,
|
|
86
|
+
publicAssertionSize,
|
|
66
87
|
{ epochsNum: 2 },
|
|
67
88
|
);
|
|
89
|
+
console.log('======================== BID SUGGESTION CALCULATED');
|
|
90
|
+
console.log(bidSuggestion);
|
|
91
|
+
|
|
92
|
+
divider();
|
|
93
|
+
|
|
94
|
+
const increaseAllowanceResult = await DkgClient.asset.increaseAllowance(bidSuggestion);
|
|
95
|
+
console.log('======================== ALLOWANCE INCREASED');
|
|
96
|
+
console.log(increaseAllowanceResult);
|
|
97
|
+
|
|
98
|
+
divider();
|
|
99
|
+
|
|
100
|
+
const decreaseAllowanceResult = await DkgClient.asset.decreaseAllowance(bidSuggestion);
|
|
101
|
+
console.log('======================== ALLOWANCE DECREASED');
|
|
102
|
+
console.log(decreaseAllowanceResult);
|
|
103
|
+
|
|
104
|
+
divider();
|
|
105
|
+
|
|
106
|
+
const setAllowanceResult = await DkgClient.asset.setAllowance(bidSuggestion);
|
|
107
|
+
console.log('======================== ALLOWANCE SET');
|
|
108
|
+
console.log(setAllowanceResult);
|
|
109
|
+
|
|
110
|
+
divider();
|
|
111
|
+
|
|
112
|
+
const createAssetResult = await DkgClient.asset.create(content, { epochsNum: 2 });
|
|
68
113
|
console.log('======================== ASSET CREATED');
|
|
69
114
|
console.log(createAssetResult);
|
|
70
115
|
|
|
@@ -187,7 +232,7 @@ function divider() {
|
|
|
187
232
|
divider();
|
|
188
233
|
|
|
189
234
|
queryResult = await DkgClient.graph.query(
|
|
190
|
-
'construct { ?s ?p ?o } where { ?s ?p ?o . <uuid:1> ?p ?o }',
|
|
235
|
+
'construct { ?s ?p ?o } where { ?s ?p ?o . <uuid:user:1> ?p ?o }',
|
|
191
236
|
'CONSTRUCT',
|
|
192
237
|
{ graphState: 'HISTORICAL', graphLocation: 'LOCAL_KG' },
|
|
193
238
|
);
|
package/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// managers
|
|
2
|
+
const AssertionOperationsManager = require('./managers/assertion-operations-manager.js');
|
|
2
3
|
const AssetOperationsManager = require('./managers/asset-operations-manager.js');
|
|
3
4
|
const BlockchainOperationsManager = require('./managers/blockchain-operations-manager');
|
|
4
5
|
const GraphOperationsManager = require('./managers/graph-operations-manager.js');
|
|
6
|
+
const NetworkOperationsManager = require('./managers/network-operations-manager.js');
|
|
5
7
|
const NodeOperationsManager = require('./managers/node-operations-manager.js');
|
|
6
8
|
|
|
7
9
|
const BaseServiceManager = require('./services/base-service-manager.js');
|
|
@@ -11,10 +13,12 @@ class DkgClient {
|
|
|
11
13
|
const baseServiceManager = new BaseServiceManager(config);
|
|
12
14
|
const services = baseServiceManager.getServices();
|
|
13
15
|
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.node = new NodeOperationsManager(
|
|
16
|
+
this.assertion = new AssertionOperationsManager(services);
|
|
17
|
+
this.asset = new AssetOperationsManager(services);
|
|
18
|
+
this.blockhain = new BlockchainOperationsManager(services);
|
|
19
|
+
this.node = new NodeOperationsManager(services);
|
|
20
|
+
this.graph = new GraphOperationsManager(services);
|
|
21
|
+
this.network = new NetworkOperationsManager(services);
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
24
|
module.exports = DkgClient;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const { assertionMetadata, calculateRoot, formatGraph } = require('assertion-tools');
|
|
2
|
+
|
|
3
|
+
class AssertionOperationsManager {
|
|
4
|
+
constructor(services) {
|
|
5
|
+
this.nodeApiService = services.nodeApiService;
|
|
6
|
+
this.inputService = services.inputService;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Formats the content provided, producing both a public and, if available, a private assertion.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} content - The content object containing optional public and private properties.
|
|
13
|
+
* @returns {Promise<Object>} a promise that resolves with an object containing the
|
|
14
|
+
* formatted public assertion and, if available, the private assertion.
|
|
15
|
+
*/
|
|
16
|
+
async formatGraph(content) {
|
|
17
|
+
return formatGraph(content);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Calculates and returns the Merkle root of the public assertion from the provided content.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} content - The content object containing optional public and private properties.
|
|
24
|
+
* @returns {Promise<String>} a promise that resolves with a string representing the
|
|
25
|
+
* Merkle root of the formatted public assertion.
|
|
26
|
+
*/
|
|
27
|
+
async getPublicAssertionId(content) {
|
|
28
|
+
const assertions = await formatGraph(content);
|
|
29
|
+
return calculateRoot(assertions.public);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Calculates and returns the size in bytes of the public assertion from the provided content.
|
|
34
|
+
*
|
|
35
|
+
* @param {Object} content - The content object containing optional public and private properties.
|
|
36
|
+
* @returns {Promise<Number>} a promise that resolves with a number representing the
|
|
37
|
+
* size in bytes of the formatted public assertion.
|
|
38
|
+
*/
|
|
39
|
+
async getSizeInBytes(content) {
|
|
40
|
+
const assertions = await formatGraph(content);
|
|
41
|
+
return assertionMetadata.getAssertionSizeInBytes(assertions.public);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Calculates and returns the number of triples of the public assertion from the provided content.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} content - The content object containing optional public and private properties.
|
|
48
|
+
* @returns {Promise<Number>} a promise that resolves with a number representing the
|
|
49
|
+
* number of triples of the formatted public assertion.
|
|
50
|
+
*/
|
|
51
|
+
async getTriplesNumber(content) {
|
|
52
|
+
const assertions = await formatGraph(content);
|
|
53
|
+
return assertionMetadata.getAssertionTriplesNumber(assertions.public);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Calculates and returns the number of chunks of the public assertion from the provided content.
|
|
58
|
+
*
|
|
59
|
+
* @param {Object} content - The content object containing optional public and private properties.
|
|
60
|
+
* @returns {Promise<Number>} a promise that resolves with a number representing the
|
|
61
|
+
* number of chunks of the formatted public assertion.
|
|
62
|
+
*/
|
|
63
|
+
async getChunksNumber(content) {
|
|
64
|
+
const assertions = await formatGraph(content);
|
|
65
|
+
return assertionMetadata.getAssertionChunksNumber(assertions.public);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
module.exports = AssertionOperationsManager;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const { assertionMetadata,
|
|
1
|
+
const { assertionMetadata, calculateRoot, formatGraph } = require('assertion-tools');
|
|
2
2
|
const { ethers, ZeroHash } = require('ethers');
|
|
3
3
|
const {
|
|
4
|
-
isEmptyObject,
|
|
5
4
|
deriveUAL,
|
|
6
5
|
getOperationStatusObject,
|
|
7
6
|
resolveUAL,
|
|
@@ -24,17 +23,68 @@ const emptyHooks = require('../util/empty-hooks');
|
|
|
24
23
|
const { STORE_TYPES, ASSET_STATES } = require('../constants');
|
|
25
24
|
|
|
26
25
|
class AssetOperationsManager {
|
|
27
|
-
constructor(
|
|
26
|
+
constructor(services) {
|
|
28
27
|
this.nodeApiService = services.nodeApiService;
|
|
29
28
|
this.validationService = services.validationService;
|
|
30
29
|
this.blockchainService = services.blockchainService;
|
|
31
30
|
this.inputService = services.inputService;
|
|
32
31
|
}
|
|
33
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Sets allowance to a given quantity of tokens.
|
|
35
|
+
* @async
|
|
36
|
+
* @param {BigInt} tokenAmount - The amount of tokens (Wei) to set the allowance.
|
|
37
|
+
* @param {Object} [options={}] - Additional options for increasing allowance - currently only blockchain option expected.
|
|
38
|
+
* @returns {Object} Object containing hash of blockchain transaction and status.
|
|
39
|
+
*/
|
|
40
|
+
async setAllowance(tokenAmount, options = {}) {
|
|
41
|
+
const blockchain = this.inputService.getBlockchain(options);
|
|
42
|
+
|
|
43
|
+
this.validationService.validateSetAllowance(blockchain);
|
|
44
|
+
|
|
45
|
+
const serviceAgreementV1Address = await this.blockchainService.getContractAddress(
|
|
46
|
+
'ServiceAgreementV1',
|
|
47
|
+
blockchain,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const currentAllowance = BigInt(
|
|
51
|
+
await this.blockchainService.callContractFunction(
|
|
52
|
+
'Token',
|
|
53
|
+
'allowance',
|
|
54
|
+
[blockchain.publicKey, serviceAgreementV1Address],
|
|
55
|
+
blockchain,
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const allowanceDifference = tokenAmount - currentAllowance;
|
|
60
|
+
|
|
61
|
+
let receipt;
|
|
62
|
+
if (allowanceDifference > 0) {
|
|
63
|
+
receipt = await this.blockchainService.executeContractFunction(
|
|
64
|
+
'Token',
|
|
65
|
+
'increaseAllowance',
|
|
66
|
+
[serviceAgreementV1Address, allowanceDifference],
|
|
67
|
+
blockchain,
|
|
68
|
+
);
|
|
69
|
+
} else if (allowanceDifference < 0) {
|
|
70
|
+
receipt = await this.blockchainService.executeContractFunction(
|
|
71
|
+
'Token',
|
|
72
|
+
'decreaseAllowance',
|
|
73
|
+
[serviceAgreementV1Address, -allowanceDifference],
|
|
74
|
+
blockchain,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
transactionHash: receipt.transactionHash,
|
|
80
|
+
status: receipt.status,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
34
84
|
/**
|
|
35
85
|
* Increases allowance for a set quantity of tokens.
|
|
36
86
|
* @async
|
|
37
|
-
* @param {
|
|
87
|
+
* @param {BigInt} tokenAmount - The amount of tokens (Wei) to increase the allowance for.
|
|
38
88
|
* @param {Object} [options={}] - Additional options for increasing allowance - currently only blockchain option expected.
|
|
39
89
|
* @returns {Object} Object containing hash of blockchain transaction and status.
|
|
40
90
|
*/
|
|
@@ -64,7 +114,7 @@ class AssetOperationsManager {
|
|
|
64
114
|
/**
|
|
65
115
|
* Decreases allowance for a set quantity of tokens.
|
|
66
116
|
* @async
|
|
67
|
-
* @param {
|
|
117
|
+
* @param {BigInt} tokenAmount - The amount of tokens (Wei) to decrease the allowance for.
|
|
68
118
|
* @param {Object} [options={}] - Additional options for decreasing allowance - currently only blockchain option expected.
|
|
69
119
|
* @returns {Object} Object containing hash of blockchain transaction and status.
|
|
70
120
|
*/
|
|
@@ -101,6 +151,12 @@ class AssetOperationsManager {
|
|
|
101
151
|
};
|
|
102
152
|
}
|
|
103
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Gets current allowance in Wei.
|
|
156
|
+
* @async
|
|
157
|
+
* @param {Object} [options={}] - Additional options for decreasing allowance - currently only blockchain option expected.
|
|
158
|
+
* @returns {BigInt} Current allowance (Wei).
|
|
159
|
+
*/
|
|
104
160
|
async getCurrentAllowance(options = {}) {
|
|
105
161
|
const blockchain = this.inputService.getBlockchain(options);
|
|
106
162
|
|
|
@@ -116,7 +172,7 @@ class AssetOperationsManager {
|
|
|
116
172
|
blockchain,
|
|
117
173
|
);
|
|
118
174
|
|
|
119
|
-
return allowance;
|
|
175
|
+
return BigInt(allowance);
|
|
120
176
|
}
|
|
121
177
|
|
|
122
178
|
/**
|
|
@@ -167,25 +223,10 @@ class AssetOperationsManager {
|
|
|
167
223
|
authToken,
|
|
168
224
|
);
|
|
169
225
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
privateAssertionId = calculateRoot(privateAssertion);
|
|
175
|
-
}
|
|
176
|
-
const publicGraph = {
|
|
177
|
-
'@graph': [
|
|
178
|
-
jsonContent.public && !isEmptyObject(jsonContent.public)
|
|
179
|
-
? jsonContent.public
|
|
180
|
-
: null,
|
|
181
|
-
jsonContent.private && !isEmptyObject(jsonContent.private)
|
|
182
|
-
? {
|
|
183
|
-
[PRIVATE_ASSERTION_PREDICATE]: privateAssertionId,
|
|
184
|
-
}
|
|
185
|
-
: null,
|
|
186
|
-
],
|
|
187
|
-
};
|
|
188
|
-
const publicAssertion = await formatAssertion(publicGraph);
|
|
226
|
+
const {
|
|
227
|
+
public: publicAssertion,
|
|
228
|
+
private: privateAssertion,
|
|
229
|
+
} = await formatGraph(jsonContent);
|
|
189
230
|
const publicAssertionSizeInBytes =
|
|
190
231
|
assertionMetadata.getAssertionSizeInBytes(publicAssertion);
|
|
191
232
|
|
|
@@ -247,7 +288,7 @@ class AssetOperationsManager {
|
|
|
247
288
|
if (privateAssertion?.length) {
|
|
248
289
|
assertions.push({
|
|
249
290
|
...resolvedUAL,
|
|
250
|
-
assertionId:
|
|
291
|
+
assertionId: calculateRoot(privateAssertion),
|
|
251
292
|
assertion: privateAssertion,
|
|
252
293
|
storeType: STORE_TYPES.TRIPLE,
|
|
253
294
|
});
|
|
@@ -640,25 +681,10 @@ class AssetOperationsManager {
|
|
|
640
681
|
|
|
641
682
|
const { tokenId } = resolveUAL(UAL);
|
|
642
683
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
privateAssertionId = calculateRoot(privateAssertion);
|
|
648
|
-
}
|
|
649
|
-
const publicGraph = {
|
|
650
|
-
'@graph': [
|
|
651
|
-
jsonContent.public && !isEmptyObject(jsonContent.public)
|
|
652
|
-
? jsonContent.public
|
|
653
|
-
: null,
|
|
654
|
-
jsonContent.private && !isEmptyObject(jsonContent.private)
|
|
655
|
-
? {
|
|
656
|
-
[PRIVATE_ASSERTION_PREDICATE]: privateAssertionId,
|
|
657
|
-
}
|
|
658
|
-
: null,
|
|
659
|
-
],
|
|
660
|
-
};
|
|
661
|
-
const publicAssertion = await formatAssertion(publicGraph);
|
|
684
|
+
const {
|
|
685
|
+
public: publicAssertion,
|
|
686
|
+
private: privateAssertion
|
|
687
|
+
} = await formatGraph(jsonContent);
|
|
662
688
|
const publicAssertionSizeInBytes =
|
|
663
689
|
assertionMetadata.getAssertionSizeInBytes(publicAssertion);
|
|
664
690
|
|
|
@@ -720,7 +746,7 @@ class AssetOperationsManager {
|
|
|
720
746
|
if (privateAssertion?.length) {
|
|
721
747
|
assertions.push({
|
|
722
748
|
...resolvedUAL,
|
|
723
|
-
assertionId:
|
|
749
|
+
assertionId: calculateRoot(privateAssertion),
|
|
724
750
|
assertion: privateAssertion,
|
|
725
751
|
storeType: STORE_TYPES.PENDING,
|
|
726
752
|
});
|
|
@@ -778,12 +804,22 @@ class AssetOperationsManager {
|
|
|
778
804
|
};
|
|
779
805
|
}
|
|
780
806
|
|
|
807
|
+
/**
|
|
808
|
+
* Wait for the finalization of an asset update operation.
|
|
809
|
+
* @async
|
|
810
|
+
* @param {string} UAL - The Universal Asset Locator of the asset.
|
|
811
|
+
* @param {Object} [options={}] - Optional parameters for waiting.
|
|
812
|
+
* @param {string} [options.blockchain] - The blockchain to monitor the update on.
|
|
813
|
+
* @param {number} [options.frequency] - The polling frequency in seconds.
|
|
814
|
+
* @param {number} [options.maxNumberOfRetries] - The maximum number of retries before giving up.
|
|
815
|
+
* @returns {Object} - An object containing the UAL and operation status.
|
|
816
|
+
*/
|
|
781
817
|
async waitFinalization(UAL, options = {}) {
|
|
782
818
|
const blockchain = this.inputService.getBlockchain(options);
|
|
783
819
|
const frequency = this.inputService.getFrequency(options);
|
|
784
820
|
const maxNumberOfRetries = this.inputService.getMaxNumberOfRetries(options);
|
|
785
821
|
|
|
786
|
-
this.validationService.validateWaitAssetUpdateFinalization(UAL, blockchain);
|
|
822
|
+
this.validationService.validateWaitAssetUpdateFinalization(UAL, blockchain, frequency, maxNumberOfRetries);
|
|
787
823
|
|
|
788
824
|
const { tokenId } = resolveUAL(UAL);
|
|
789
825
|
const response = {
|
|
@@ -823,6 +859,13 @@ class AssetOperationsManager {
|
|
|
823
859
|
};
|
|
824
860
|
}
|
|
825
861
|
|
|
862
|
+
/**
|
|
863
|
+
* Cancel a previously initiated update operation for an asset.
|
|
864
|
+
* @async
|
|
865
|
+
* @param {string} UAL - The Universal Asset Locator of the asset.
|
|
866
|
+
* @param {Object} [options={}] - Optional parameters for blockchain service.
|
|
867
|
+
* @returns {Object} - An object containing the UAL and operation status.
|
|
868
|
+
*/
|
|
826
869
|
async cancelUpdate(UAL, options = {}) {
|
|
827
870
|
const blockchain = this.inputService.getBlockchain(options);
|
|
828
871
|
|
|
@@ -970,6 +1013,13 @@ class AssetOperationsManager {
|
|
|
970
1013
|
};
|
|
971
1014
|
}
|
|
972
1015
|
|
|
1016
|
+
/**
|
|
1017
|
+
* Burn an asset on a specified blockchain.
|
|
1018
|
+
* @async
|
|
1019
|
+
* @param {string} UAL - The Universal Asset Locator of the asset.
|
|
1020
|
+
* @param {Object} [options={}] - Optional parameters for blockchain service.
|
|
1021
|
+
* @returns {Object} An object containing the UAL and operation status.
|
|
1022
|
+
*/
|
|
973
1023
|
async burn(UAL, options = {}) {
|
|
974
1024
|
const blockchain = this.inputService.getBlockchain(options);
|
|
975
1025
|
|
|
@@ -984,6 +1034,14 @@ class AssetOperationsManager {
|
|
|
984
1034
|
};
|
|
985
1035
|
}
|
|
986
1036
|
|
|
1037
|
+
/**
|
|
1038
|
+
* Extend the storing period of an asset on a specified blockchain.
|
|
1039
|
+
* @async
|
|
1040
|
+
* @param {string} UAL - The Universal Asset Locator of the asset.
|
|
1041
|
+
* @param {number} epochsNumber - Nmber of epochs for the extension.
|
|
1042
|
+
* @param {Object} [options={}] - Additional options for asset storing period extension.
|
|
1043
|
+
* @returns {Object} An object containing the UAL and operation status.
|
|
1044
|
+
*/
|
|
987
1045
|
async extendStoringPeriod(UAL, epochsNumber, options = {}) {
|
|
988
1046
|
const blockchain = this.inputService.getBlockchain(options);
|
|
989
1047
|
const tokenAmount = this.inputService.getTokenAmount(options);
|
|
@@ -1043,6 +1101,13 @@ class AssetOperationsManager {
|
|
|
1043
1101
|
};
|
|
1044
1102
|
}
|
|
1045
1103
|
|
|
1104
|
+
/**
|
|
1105
|
+
* Add tokens for an asset on the specified blockchain to a ongoing publishing operation.
|
|
1106
|
+
* @async
|
|
1107
|
+
* @param {string} UAL - The Universal Asset Locator of the asset.
|
|
1108
|
+
* @param {Object} [options={}] - Additional options for adding tokens.
|
|
1109
|
+
* @returns {Object} An object containing the UAL and operation status.
|
|
1110
|
+
*/
|
|
1046
1111
|
async addTokens(UAL, options = {}) {
|
|
1047
1112
|
const blockchain = this.inputService.getBlockchain(options);
|
|
1048
1113
|
const tokenAmount = this.inputService.getTokenAmount(options);
|
|
@@ -1097,6 +1162,13 @@ class AssetOperationsManager {
|
|
|
1097
1162
|
};
|
|
1098
1163
|
}
|
|
1099
1164
|
|
|
1165
|
+
/**
|
|
1166
|
+
* Add tokens for an asset on the specified blockchain to a ongoing update operation.
|
|
1167
|
+
* @async
|
|
1168
|
+
* @param {string} UAL - The Universal Asset Locator of the asset.
|
|
1169
|
+
* @param {Object} [options={}] - Additional options for adding tokens.
|
|
1170
|
+
* @returns {Object} An object containing the UAL and operation status.
|
|
1171
|
+
*/
|
|
1100
1172
|
async addUpdateTokens(UAL, options = {}) {
|
|
1101
1173
|
const blockchain = this.inputService.getBlockchain(options);
|
|
1102
1174
|
const tokenAmount = this.inputService.getTokenAmount(options);
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
|
|
2
2
|
class BlockchainOperationsManager {
|
|
3
3
|
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(services) {
|
|
5
5
|
this.blockchainService = services.blockchainService;
|
|
6
6
|
this.inputService = services.inputService;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Retrieve the current gas price.
|
|
11
|
+
* @async
|
|
12
|
+
* @param {Object} [options={}] - Optional parameters for blockchain service.
|
|
13
|
+
* @returns {Promise<string>} - A promise that resolves to the current gas price.
|
|
14
|
+
*/
|
|
9
15
|
async getGasPrice(options = {}){
|
|
10
16
|
const blockchain = this.inputService.getBlockchain(options);
|
|
11
17
|
return this.blockchainService.getGasPrice(blockchain);
|
|
12
18
|
}
|
|
13
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Retrieve the wallet balances.
|
|
22
|
+
* @async
|
|
23
|
+
* @param {Object} [options={}] - Optional parameters for blockchain service.
|
|
24
|
+
* @returns {Promise<Object>} - A promise that resolves to an object containing wallet balances.
|
|
25
|
+
*/
|
|
14
26
|
async getWalletBalances(options = {}){
|
|
15
27
|
const blockchain = this.inputService.getBlockchain(options);
|
|
16
28
|
return this.blockchainService.getWalletBalances(blockchain);
|
|
@@ -2,7 +2,7 @@ const { OPERATIONS } = require('../constants');
|
|
|
2
2
|
const { deriveRepository } = require('../services/utilities.js');
|
|
3
3
|
|
|
4
4
|
class GraphOperationsManager {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(services) {
|
|
6
6
|
this.nodeApiService = services.nodeApiService;
|
|
7
7
|
this.validationService = services.validationService;
|
|
8
8
|
this.inputService = services.inputService;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class NetworkOperationsManager {
|
|
2
|
+
constructor(services) {
|
|
3
|
+
this.inputService = services.inputService;
|
|
4
|
+
this.blockchainService = services.blockchainService;
|
|
5
|
+
this.nodeApiService = services.nodeApiService;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sends request to the DKG node in order to get suggested bid for given parameters.
|
|
10
|
+
* @async
|
|
11
|
+
* @param {string} publicAssertionId - Merkle Root of the data.
|
|
12
|
+
* @param {number} sizeInBytes - Size of the data in bytes.
|
|
13
|
+
* @param {Object} [options={}] - Additional options for getting bid suggestion.
|
|
14
|
+
* @returns {BigInt} Suggested bid for publishing Knowledge Asset with given parameters.
|
|
15
|
+
*/
|
|
16
|
+
async getBidSuggestion(publicAssertionId, sizeInBytes, options = {}) {
|
|
17
|
+
const {
|
|
18
|
+
blockchain,
|
|
19
|
+
endpoint,
|
|
20
|
+
port,
|
|
21
|
+
epochsNum,
|
|
22
|
+
hashFunctionId,
|
|
23
|
+
authToken,
|
|
24
|
+
} = this.inputService.getBidSuggestionArguments(options);
|
|
25
|
+
|
|
26
|
+
const contentAssetStorageAddress = await this.blockchainService.getContractAddress(
|
|
27
|
+
'ContentAssetStorage',
|
|
28
|
+
blockchain,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return BigInt(
|
|
32
|
+
await this.nodeApiService.getBidSuggestion(
|
|
33
|
+
endpoint,
|
|
34
|
+
port,
|
|
35
|
+
authToken,
|
|
36
|
+
blockchain.name.startsWith('otp') ? 'otp' : blockchain.name,
|
|
37
|
+
epochsNum,
|
|
38
|
+
sizeInBytes,
|
|
39
|
+
contentAssetStorageAddress,
|
|
40
|
+
publicAssertionId,
|
|
41
|
+
hashFunctionId,
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
module.exports = NetworkOperationsManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dkg.js",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.14",
|
|
4
4
|
"description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/OriginTrail/dkg.js/tree/main#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"assertion-tools": "^2.0
|
|
32
|
+
"assertion-tools": "^2.1.0",
|
|
33
33
|
"axios": "^0.27.2",
|
|
34
34
|
"dkg-evm-module": "^4.0.4",
|
|
35
35
|
"ethers": "^6.1.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const Web3 = require('web3');
|
|
2
|
-
const { WEBSOCKET_PROVIDER_OPTIONS } = require('../../../constants.js');
|
|
2
|
+
const { TRANSACTION_RETRY_ERRORS, WEBSOCKET_PROVIDER_OPTIONS } = require('../../../constants.js');
|
|
3
3
|
const BlockchainServiceBase = require('../blockchain-service-base.js');
|
|
4
4
|
|
|
5
5
|
class NodeBlockchainService extends BlockchainServiceBase {
|
|
@@ -83,8 +83,7 @@ class NodeBlockchainService extends BlockchainServiceBase {
|
|
|
83
83
|
if (
|
|
84
84
|
!transactionRetried &&
|
|
85
85
|
blockchain.handleNotMinedError &&
|
|
86
|
-
(e.message.includes(
|
|
87
|
-
e.message.includes('already known'))
|
|
86
|
+
TRANSACTION_RETRY_ERRORS.some((errorMsg) => e.message.toLowerCase().includes(errorMsg))
|
|
88
87
|
) {
|
|
89
88
|
transactionRetried = true;
|
|
90
89
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -5,6 +5,17 @@ class InputService {
|
|
|
5
5
|
this.config = config;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
getBidSuggestionArguments(options) {
|
|
9
|
+
return {
|
|
10
|
+
blockchain: this.getBlockchain(options),
|
|
11
|
+
endpoint: this.getEndpoint(options),
|
|
12
|
+
port: this.getPort(options),
|
|
13
|
+
epochsNum: this.getEpochsNum(options),
|
|
14
|
+
hashFunctionId: this.getHashFunctionId(options),
|
|
15
|
+
authToken: this.getAuthToken(options),
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
8
19
|
getAssetCreateArguments(options) {
|
|
9
20
|
return {
|
|
10
21
|
blockchain: this.getBlockchain(options),
|
package/services/utilities.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
const jsonld = require('jsonld');
|
|
2
2
|
const { GRAPH_LOCATIONS, GRAPH_STATES, OT_NODE_TRIPLE_STORE_REPOSITORIES } = require('../constants.js');
|
|
3
3
|
|
|
4
|
+
function isEmptyObject(obj) {
|
|
5
|
+
return Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
module.exports = {
|
|
5
9
|
nodeSupported() {
|
|
6
10
|
return typeof window === 'undefined';
|
|
7
11
|
},
|
|
8
|
-
isEmptyObject
|
|
9
|
-
// eslint-disable-next-line no-unreachable-loop
|
|
10
|
-
for (const key in object) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return true;
|
|
14
|
-
},
|
|
12
|
+
isEmptyObject,
|
|
15
13
|
toNumber(hex) {
|
|
16
14
|
return parseInt(hex.slice(2), 16);
|
|
17
15
|
},
|