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 6d4efc513..1b76bdad7 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,6 +37,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { ual, includeMetadata, isOperationV0, + isOldContract, } = commandData; let { assertionId, knowledgeAssetId } = commandData; @@ -109,6 +110,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { ); let assertionPromise; + let notMigrated = false; if (!assertionId) { assertionId = await this.tripleStoreService.getLatestAssertionId( @@ -148,6 +150,10 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { return fallbackResult; } + if (!isOperationV0) { + notMigrated = true; + } + this.operationIdService.emitChangeEvent( OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_END, operationId, @@ -215,9 +221,10 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { const [assertion, metadata] = await Promise.all(promises); const responseData = { - assertion: isOperationV0 - ? [...(assertion.public ?? []), ...(assertion.private ?? [])] - : assertion, + assertion: + (isOperationV0 || notMigrated) && isOldContract + ? [...(assertion.public ?? []), ...(assertion.private ?? [])] + : assertion, ...(includeMetadata && metadata && { metadata }), }; diff --git a/src/commands/protocols/get/sender/get-validate-asset-command.js b/src/commands/protocols/get/sender/get-validate-asset-command.js index 1b5423490..9831b5c2c 100644 --- a/src/commands/protocols/get/sender/get-validate-asset-command.js +++ b/src/commands/protocols/get/sender/get-validate-asset-command.js @@ -1,10 +1,6 @@ import ValidateAssetCommand from '../../../common/validate-asset-command.js'; import Command from '../../../command.js'; -import { - OPERATION_ID_STATUS, - ERROR_TYPE, - OLD_CONTENT_STORAGE_MAP, -} from '../../../../constants/constants.js'; +import { OPERATION_ID_STATUS, ERROR_TYPE } from '../../../../constants/constants.js'; class GetValidateAssetCommand extends ValidateAssetCommand { constructor(ctx) { @@ -27,8 +23,15 @@ class GetValidateAssetCommand extends ValidateAssetCommand { * @param command */ async execute(command) { - const { operationId, blockchain, contract, knowledgeCollectionId, ual, isOperationV0 } = - command.data; + const { + operationId, + blockchain, + contract, + knowledgeCollectionId, + ual, + isOperationV0, + isOldContract, + } = command.data; await this.operationIdService.updateOperationIdStatus( operationId, blockchain, @@ -53,13 +56,7 @@ class GetValidateAssetCommand extends ValidateAssetCommand { blockchain, ); // TODO: Update to validate knowledge asset index - // TODO: Use isOldContract as variable and pass it through with command.data since it's used - if ( - !isOperationV0 && - Object.values(OLD_CONTENT_STORAGE_MAP).every( - (ca) => !ca.toLowerCase().includes(contract.toLowerCase()), - ) - ) { + if (!isOperationV0 && !isOldContract) { const isValidUal = await this.validationService.validateUal( blockchain, contract, diff --git a/src/commands/protocols/get/sender/local-get-command.js b/src/commands/protocols/get/sender/local-get-command.js index 11001d308..79d2bc472 100644 --- a/src/commands/protocols/get/sender/local-get-command.js +++ b/src/commands/protocols/get/sender/local-get-command.js @@ -35,6 +35,7 @@ class LocalGetCommand extends Command { contentType, assertionId, isOperationV0, + isOldContract, } = command.data; let { knowledgeAssetId } = command.data; await this.operationIdService.updateOperationIdStatus( @@ -103,23 +104,13 @@ class LocalGetCommand extends Command { ); let assertionPromise; + let notMigrated = false; if (assertionId) { assertionPromise = (async () => { let result = null; - for (const repository of [ - TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, - ]) { - // eslint-disable-next-line no-await-in-loop - result = await this.tripleStoreService.getV6Assertion(repository, assertionId); - if (result?.length) { - break; - } - } - - if (!result?.length) { + if (!isOperationV0) { result = await this.tripleStoreService.getAssertion( blockchain, contract, @@ -128,6 +119,35 @@ class LocalGetCommand extends Command { contentType, ); } + + if (!result?.length) { + for (const repository of [ + TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT, + TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + ]) { + // eslint-disable-next-line no-await-in-loop + result = await this.tripleStoreService.getV6Assertion( + repository, + assertionId, + ); + if (result?.length) { + if (!isOperationV0) { + notMigrated = true; + } + break; + } + } + if (!result?.length && isOperationV0) { + result = await this.tripleStoreService.getAssertion( + blockchain, + contract, + knowledgeCollectionId, + knowledgeAssetId, + contentType, + ); + } + } + this.operationIdService.emitChangeEvent( OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END, operationId, @@ -198,9 +218,10 @@ class LocalGetCommand extends Command { const [assertion, metadata] = await Promise.all(promises); const responseData = { - assertion: isOperationV0 - ? [...(assertion?.public ?? []), ...(assertion?.private ?? [])] - : assertion, + assertion: + (isOperationV0 || notMigrated) && isOldContract + ? [...(assertion?.public ?? []), ...(assertion?.private ?? [])] + : assertion, ...(includeMetadata && metadata && { metadata }), }; 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 cf2e0cd52..d292d9e9b 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 @@ -7,7 +7,6 @@ import { OPERATION_STATUS, OPERATION_ID_STATUS, PRIVATE_HASH_SUBJECT_PREFIX, - OLD_CONTENT_STORAGE_MAP, } from '../../../../../constants/constants.js'; class GetRequestCommand extends ProtocolRequestCommand { @@ -52,6 +51,7 @@ class GetRequestCommand extends ProtocolRequestCommand { paranetId, isOperationV0, assertionId, + isOldContract, } = command.data; return { @@ -65,16 +65,19 @@ class GetRequestCommand extends ProtocolRequestCommand { paranetId, isOperationV0, assertionId, + isOldContract, }; } async handleAck(command, responseData) { - const { blockchain, contract, knowledgeCollectionId, knowledgeAssetId, isOperationV0 } = - command.data; - - const isOldContract = Object.values(OLD_CONTENT_STORAGE_MAP).some((ca) => - ca.toLowerCase().includes(contract.toLowerCase()), - ); + const { + blockchain, + contract, + knowledgeCollectionId, + knowledgeAssetId, + isOperationV0, + isOldContract, + } = command.data; if (responseData?.assertion?.public) { // Only whole collection can be validated not particular KA 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 39c1f370c..60569f7b5 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 @@ -65,14 +65,13 @@ class GetController extends BaseController { // Get assertionId - datasetRoot // + const isOldContract = Object.values(OLD_CONTENT_STORAGE_MAP).some((ca) => + ca.toLowerCase().includes(contract.toLowerCase()), + ); + const commandSequence = []; - if ( - !tripleStoreMigrationAlreadyExecuted && - Object.values(OLD_CONTENT_STORAGE_MAP) - .map((ca) => ca.toLowerCase()) - .includes(contract.toLowerCase()) - ) { + if (!tripleStoreMigrationAlreadyExecuted && isOldContract) { commandSequence.push('getAssertionMerkleRootCommand'); } @@ -91,6 +90,7 @@ class GetController extends BaseController { knowledgeAssetId, operationId, paranetUAL, + isOldContract, contentType: contentType ?? TRIPLES_VISIBILITY.ALL, isOperationV0: true, }, diff --git a/src/controllers/http-api/v1/get-http-api-controller-v1.js b/src/controllers/http-api/v1/get-http-api-controller-v1.js index 1993bca28..56cb167ac 100644 --- a/src/controllers/http-api/v1/get-http-api-controller-v1.js +++ b/src/controllers/http-api/v1/get-http-api-controller-v1.js @@ -66,15 +66,14 @@ class GetController extends BaseController { // Get assertionId - datasetRoot // + const isOldContract = Object.values(OLD_CONTENT_STORAGE_MAP).some((ca) => + ca.toLowerCase().includes(contract.toLowerCase()), + ); + const commandSequence = []; commandSequence.push('getValidateAssetCommand'); - if ( - !tripleStoreMigrationAlreadyExecuted && - Object.values(OLD_CONTENT_STORAGE_MAP) - .map((ca) => ca.toLowerCase()) - .includes(contract.toLowerCase()) - ) { + if (!tripleStoreMigrationAlreadyExecuted && isOldContract) { commandSequence.push('getAssertionMerkleRootCommand'); } @@ -93,6 +92,7 @@ class GetController extends BaseController { knowledgeAssetId, operationId, paranetUAL, + isOldContract, contentType: contentType ?? TRIPLES_VISIBILITY.ALL, }, transactional: false, diff --git a/src/controllers/rpc/get-rpc-controller.js b/src/controllers/rpc/get-rpc-controller.js index 32b242b84..d587e9144 100644 --- a/src/controllers/rpc/get-rpc-controller.js +++ b/src/controllers/rpc/get-rpc-controller.js @@ -39,6 +39,7 @@ class GetController extends BaseController { paranetId: message.data.paranetId, isOperationV0: message.data.isOperationV0, assertionId: message.data.assertionId, + isOldContract: message.data.isOldContract, }, transactional: false, });