diff --git a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js index b01b1e377..1f8474e9a 100644 --- a/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js +++ b/src/commands/protocols/get/receiver/v1.0.0/v1-0-0-handle-get-request-command.js @@ -37,9 +37,11 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { knowledgeAssetId, ual, includeMetadata, - assertionId, + isOperationV0, } = commandData; + let { assertionId } = commandData; + // if (paranetUAL) { // const paranetNodeAccessPolicy = await this.blockchainModuleManager.getNodesAccessPolicy( // blockchain, @@ -109,7 +111,31 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { let assertionPromise; - if (assertionId) { + if (isOperationV0) { + if (!assertionId) { + assertionId = await this.tripleStoreService.getLatestAssertionId( + TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + ual, + ); + + if (!assertionId) { + assertionId = await this.tripleStoreService.getLatestAssertionId( + TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + ual, + ); + } + + if (!assertionId) { + return { + messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK, + messageData: { errorMessage: `Unable to find assertion ${ual}` }, + }; + } + + this.logger.info( + `Found assertion id: ${assertionId}, operation id ${operationId}, ual: ${ual}`, + ); + } assertionPromise = this.tripleStoreService .getV6Assertion(TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, assertionId) .then((result) => { diff --git a/src/commands/protocols/get/sender/get-assertion-merkle-root-command.js b/src/commands/protocols/get/sender/get-assertion-merkle-root-command.js index 7ffc0d321..e5346592a 100644 --- a/src/commands/protocols/get/sender/get-assertion-merkle-root-command.js +++ b/src/commands/protocols/get/sender/get-assertion-merkle-root-command.js @@ -1,11 +1,12 @@ import Command from '../../../command.js'; -import { ERROR_TYPE } from '../../../../constants/constants.js'; +import { ERROR_TYPE, TRIPLE_STORE_REPOSITORIES } from '../../../../constants/constants.js'; class GetAssertionMerkleRootCommand extends Command { constructor(ctx) { super(ctx); this.operationService = ctx.getService; this.blockchainModuleManager = ctx.blockchainModuleManager; + this.tripleStoreService = ctx.tripleStoreService; this.errorType = ERROR_TYPE.GET.GET_ASSERTION_ID_ERROR; } @@ -15,19 +16,23 @@ class GetAssertionMerkleRootCommand extends Command { * @param command */ async execute(command) { - const { operationId, blockchain, contract, knowledgeCollectionId } = command.data; - this.logger.info( - `Getting assertion id for token id: ${knowledgeCollectionId}, contract: ${contract}, operation id: ${operationId} on blockchain: ${blockchain}`, - ); + const { operationId, ual } = command.data; + this.logger.info(`Getting assertion id and operation id ${operationId} for ual: ${ual}`); - const assertionId = await this.blockchainModuleManager.getLatestAssertionId( - blockchain, - contract, - knowledgeCollectionId, + let assertionId = await this.tripleStoreService.getLatestAssertionId( + TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + ual, ); + if (!assertionId) { + assertionId = await this.tripleStoreService.getLatestAssertionId( + TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + ual, + ); + } + this.logger.info( - `Found assertion id: ${assertionId} for token id: ${knowledgeCollectionId}, contract: ${contract} on blockchain: ${blockchain} for operation id: ${operationId}`, + `Found assertion id: ${assertionId}, operation id ${operationId}, ual: ${ual}`, ); return this.continueSequence({ ...command.data, assertionId }, command.sequence); } diff --git a/src/commands/protocols/get/sender/get-find-shard-command.js b/src/commands/protocols/get/sender/get-find-shard-command.js index f3f0e5842..409f50452 100644 --- a/src/commands/protocols/get/sender/get-find-shard-command.js +++ b/src/commands/protocols/get/sender/get-find-shard-command.js @@ -22,7 +22,10 @@ class GetFindShardCommand extends FindShardCommand { getOperationCommandSequence(nodePartOfShard, commandData) { const sequence = []; if (nodePartOfShard) { - sequence.push('localGetCommand'); + // If operationV0 and no assertionId found go directly to networkGet + if (!commandData.isOperationV0 || commandData.assertionId) { + sequence.push('localGetCommand'); + } } sequence.push('networkGetCommand'); diff --git a/src/commands/protocols/get/sender/get-schedule-messages-command.js b/src/commands/protocols/get/sender/get-schedule-messages-command.js index d59bb6897..9ec9eb44b 100644 --- a/src/commands/protocols/get/sender/get-schedule-messages-command.js +++ b/src/commands/protocols/get/sender/get-schedule-messages-command.js @@ -26,6 +26,8 @@ class GetScheduleMessagesCommand extends ProtocolScheduleMessagesCommand { paranetUAL: command.data.paranetUAL, paranetId: command.data.paranetId, paranetMetadata: command.data.paranetMetadata, + assertionId: command.data.isOperationV0, + isOperationV0: command.data.assertionId, }; } diff --git a/src/commands/protocols/get/sender/v1.0.0/v1-0-0-get-request-command.js b/src/commands/protocols/get/sender/v1.0.0/v1-0-0-get-request-command.js index 786001ab3..84a727a52 100644 --- a/src/commands/protocols/get/sender/v1.0.0/v1-0-0-get-request-command.js +++ b/src/commands/protocols/get/sender/v1.0.0/v1-0-0-get-request-command.js @@ -47,6 +47,8 @@ class GetRequestCommand extends ProtocolRequestCommand { ual, paranetUAL, paranetId, + isOperationV0, + assertionId, } = command.data; return { @@ -58,6 +60,8 @@ class GetRequestCommand extends ProtocolRequestCommand { ual, paranetUAL, paranetId, + isOperationV0, + assertionId, }; } diff --git a/src/controllers/http-api/v0/get-http-api-controller-v0.js b/src/controllers/http-api/v0/get-http-api-controller-v0.js index 02698057c..02b66bb6f 100644 --- a/src/controllers/http-api/v0/get-http-api-controller-v0.js +++ b/src/controllers/http-api/v0/get-http-api-controller-v0.js @@ -64,7 +64,6 @@ class GetController extends BaseController { // const commandSequence = []; - commandSequence.push('getValidateAssetCommand'); if ( !tripleStoreMigrationAlreadyExecuted && diff --git a/src/controllers/rpc/get-rpc-controller.js b/src/controllers/rpc/get-rpc-controller.js index 571d1511e..32b242b84 100644 --- a/src/controllers/rpc/get-rpc-controller.js +++ b/src/controllers/rpc/get-rpc-controller.js @@ -37,6 +37,8 @@ class GetController extends BaseController { state: message.data.state ?? DEFAULT_GET_STATE, paranetUAL: message.data.paranetUAL, paranetId: message.data.paranetId, + isOperationV0: message.data.isOperationV0, + assertionId: message.data.assertionId, }, transactional: false, }); diff --git a/src/modules/triple-store/implementation/ot-triple-store.js b/src/modules/triple-store/implementation/ot-triple-store.js index 208495b53..ae9b64c41 100644 --- a/src/modules/triple-store/implementation/ot-triple-store.js +++ b/src/modules/triple-store/implementation/ot-triple-store.js @@ -512,6 +512,21 @@ class OtTripleStore { this.select(repository, query); } + async getLatestAssertionId(repository, ual) { + const query = `SELECT ?assertionId + WHERE { + GRAPH { + <${ual}> ?p ?assertionId + } + }`; + + const data = await this.select(repository, query); + + const latestAssertionId = data?.[0]?.assertionId; + + return latestAssertionId; + } + async construct(repository, query) { return this._executeQuery(repository, query, MEDIA_TYPES.N_QUADS); } diff --git a/src/modules/triple-store/triple-store-module-manager.js b/src/modules/triple-store/triple-store-module-manager.js index 5a39daf25..e3694103a 100644 --- a/src/modules/triple-store/triple-store-module-manager.js +++ b/src/modules/triple-store/triple-store-module-manager.js @@ -223,6 +223,15 @@ class TripleStoreModuleManager extends BaseModuleManager { } } + async getLatestAssertionId(implementationName, repository, ual) { + if (this.getImplementation(implementationName)) { + return this.getImplementation(implementationName).module.getLatestAssertionId( + repository, + ual, + ); + } + } + async construct(implementationName, repository, query) { if (this.getImplementation(implementationName)) { return this.getImplementation(implementationName).module.construct(repository, query); diff --git a/src/service/triple-store-service.js b/src/service/triple-store-service.js index f0a0ae6bc..d0a002cc5 100644 --- a/src/service/triple-store-service.js +++ b/src/service/triple-store-service.js @@ -460,6 +460,16 @@ class TripleStoreService { return nquads; } + async getLatestAssertionId(repository, ual) { + const nquads = await this.tripleStoreModuleManager.getLatestAssertionId( + this.repositoryImplementations[repository], + repository, + ual, + ); + + return nquads; + } + async construct(query, repository = TRIPLE_STORE_REPOSITORY.DKG) { return this.tripleStoreModuleManager.construct( this.repositoryImplementations[repository] ??