diff --git a/examples/demo.js b/examples/demo.js index a8347c4a..bf9e7452 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -66,6 +66,7 @@ function divider() { epochsNum: 2, minimumNumberOfFinalizationConfirmations: 3, minimumNumberOfNodeReplications: 1, + localStore: true, }); console.timeEnd('Publish (1 replication, 3 finalizations)'); diff --git a/managers/asset-operations-manager.js b/managers/asset-operations-manager.js index b7dae4e8..edace7ea 100644 --- a/managers/asset-operations-manager.js +++ b/managers/asset-operations-manager.js @@ -231,6 +231,7 @@ export default class AssetOperationsManager { payer, minimumNumberOfFinalizationConfirmations, minimumNumberOfNodeReplications, + localStore, } = this.inputService.getAssetCreateArguments(options); this.validationService.validateAssetCreate( @@ -470,6 +471,23 @@ export default class AssetOperationsManager { frequency, ); } + let localStoreResult; + if (localStore) { + let retry = 0; + do { + // eslint-disable-next-line no-await-in-loop + localStoreResult = await this.nodeApiService.localStore( + endpoint, + port, + authToken, + datasetRoot, + dataset, + blockchain.name, + UAL, + ); + retry += 1; + } while (!localStoreResult?.status && retry < 6); + } return { UAL, @@ -486,6 +504,7 @@ export default class AssetOperationsManager { }, numberOfConfirmations: finalityStatusResult, requiredConfirmations: minimumNumberOfFinalizationConfirmations, + ...(localStore && { localStore: localStoreResult }), }, }; } diff --git a/services/input-service.js b/services/input-service.js index 2d1b089e..63bbb58a 100644 --- a/services/input-service.js +++ b/services/input-service.js @@ -30,6 +30,7 @@ export default class InputService { minimumNumberOfFinalizationConfirmations: this.getMinimumNumberOfFinalizationConfirmations(options) ?? 3, minimumNumberOfNodeReplications: this.getMinimumNumberOfNodeReplications(options), + localStore: this.getLocalStore(options), }; } @@ -415,4 +416,8 @@ export default class InputService { getAssertionCachedLocally(options) { return options.assertionCachedLocally ?? false; } + + getLocalStore(options) { + return options.localStore ?? false; + } } diff --git a/services/node-api-service/implementations/http-service.js b/services/node-api-service/implementations/http-service.js index 6ce9cca6..fafd47e4 100644 --- a/services/node-api-service/implementations/http-service.js +++ b/services/node-api-service/implementations/http-service.js @@ -61,6 +61,26 @@ export default class HttpService { } } + async localStore(endpoint, port, authToken, datasetRoot, dataset, blockchain, UAL) { + try { + const response = await axios({ + method: 'post', + url: `${this.getBaseUrl(endpoint, port)}/local-store`, + data: { + datasetRoot, + dataset, + blockchain, + UAL, + }, + headers: this.prepareRequestConfig(authToken), + }); + + return response.data; + } catch (error) { + throw Error(`Unable to local store: ${error.message}`); + } + } + async get( endpoint, port,