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 09189febe..6d4efc513 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 @@ -110,18 +110,18 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { let assertionPromise; - if (isOperationV0) { - if (!assertionId) { - assertionId = await this.tripleStoreService.getLatestAssertionId( - TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, - ual, - ); - - this.logger.info( - `Found assertion id: ${assertionId}, operation id ${operationId}, ual: ${ual}`, - ); - } + if (!assertionId) { + assertionId = await this.tripleStoreService.getLatestAssertionId( + TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, + ual, + ); + + this.logger.info( + `Found assertion id: ${assertionId}, operation id ${operationId}, ual: ${ual}`, + ); + } + if (assertionId) { // DO NOT RUN THIS IF !assertionId assertionPromise = this.tripleStoreService .getV6Assertion(TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT, assertionId) @@ -145,10 +145,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { blockchain, ); - return [ - ...(fallbackResult.public ?? []), - ...(fallbackResult.private ?? []), - ]; + return fallbackResult; } this.operationIdService.emitChangeEvent( @@ -161,11 +158,21 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { }); } else { if (!knowledgeAssetId) { - knowledgeAssetId = await this.blockchainModuleManager.getKnowledgeAssetsRange( - blockchain, - contract, - knowledgeCollectionId, - ); + try { + knowledgeAssetId = await this.blockchainModuleManager.getKnowledgeAssetsRange( + blockchain, + contract, + knowledgeCollectionId, + ); + } catch (error) { + // Asset created on old content asset storage contract + // TODO: actually it could be other error so we should check that, or add try catch to getKARange function + knowledgeAssetId = { + startTokenId: 1, + endTokenId: 1, + burned: [], + }; + } } assertionPromise = this.tripleStoreService .getAssertion( @@ -208,7 +215,9 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand { const [assertion, metadata] = await Promise.all(promises); const responseData = { - assertion, + assertion: isOperationV0 + ? [...(assertion.public ?? []), ...(assertion.private ?? [])] + : assertion, ...(includeMetadata && metadata && { metadata }), }; 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 409f50452..f3f0e5842 100644 --- a/src/commands/protocols/get/sender/get-find-shard-command.js +++ b/src/commands/protocols/get/sender/get-find-shard-command.js @@ -22,10 +22,7 @@ class GetFindShardCommand extends FindShardCommand { getOperationCommandSequence(nodePartOfShard, commandData) { const sequence = []; if (nodePartOfShard) { - // If operationV0 and no assertionId found go directly to networkGet - if (!commandData.isOperationV0 || commandData.assertionId) { - sequence.push('localGetCommand'); - } + sequence.push('localGetCommand'); } sequence.push('networkGetCommand'); 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 67a75d61f..1b5423490 100644 --- a/src/commands/protocols/get/sender/get-validate-asset-command.js +++ b/src/commands/protocols/get/sender/get-validate-asset-command.js @@ -53,6 +53,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( diff --git a/src/commands/protocols/get/sender/local-get-command.js b/src/commands/protocols/get/sender/local-get-command.js index 39165d0e5..11001d308 100644 --- a/src/commands/protocols/get/sender/local-get-command.js +++ b/src/commands/protocols/get/sender/local-get-command.js @@ -34,6 +34,7 @@ class LocalGetCommand extends Command { knowledgeCollectionId, contentType, assertionId, + isOperationV0, } = command.data; let { knowledgeAssetId } = command.data; await this.operationIdService.updateOperationIdStatus( @@ -140,11 +141,20 @@ class LocalGetCommand extends Command { } else { // TODO: Do this in clean way if (!knowledgeAssetId) { - knowledgeAssetId = await this.blockchainModuleManager.getKnowledgeAssetsRange( - blockchain, - contract, - knowledgeCollectionId, - ); + try { + knowledgeAssetId = await this.blockchainModuleManager.getKnowledgeAssetsRange( + blockchain, + contract, + knowledgeCollectionId, + ); + } catch (error) { + // Asset created on old content asset storage contract + knowledgeAssetId = { + startTokenId: 1, + endTokenId: 1, + burned: [], + }; + } } assertionPromise = this.tripleStoreService .getAssertion( @@ -188,9 +198,12 @@ class LocalGetCommand extends Command { const [assertion, metadata] = await Promise.all(promises); const responseData = { - assertion, + assertion: isOperationV0 + ? [...(assertion?.public ?? []), ...(assertion?.private ?? [])] + : assertion, ...(includeMetadata && metadata && { metadata }), }; + if (assertion?.public?.length || assertion?.private?.length || assertion?.length) { await this.operationService.markOperationAsCompleted( operationId, 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 6cd5d3c24..cf2e0cd52 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,6 +7,7 @@ import { OPERATION_STATUS, OPERATION_ID_STATUS, PRIVATE_HASH_SUBJECT_PREFIX, + OLD_CONTENT_STORAGE_MAP, } from '../../../../../constants/constants.js'; class GetRequestCommand extends ProtocolRequestCommand { @@ -68,7 +69,13 @@ class GetRequestCommand extends ProtocolRequestCommand { } async handleAck(command, responseData) { - const { blockchain, contract, knowledgeCollectionId, knowledgeAssetId } = command.data; + const { blockchain, contract, knowledgeCollectionId, knowledgeAssetId, isOperationV0 } = + command.data; + + const isOldContract = Object.values(OLD_CONTENT_STORAGE_MAP).some((ca) => + ca.toLowerCase().includes(contract.toLowerCase()), + ); + if (responseData?.assertion?.public) { // Only whole collection can be validated not particular KA @@ -92,31 +99,47 @@ class GetRequestCommand extends ProtocolRequestCommand { publicKnowledgeAssetsTriplesGrouped.push( ...kcTools.groupNquadsBySubject(privateHashTriples, true), ); - try { - await this.validationService.validateDatasetOnBlockchain( - publicKnowledgeAssetsTriplesGrouped.map((t) => t.sort()).flat(), - blockchain, - contract, - knowledgeCollectionId, - ); - - // This is added as support when get starts supporting private for curated paranet - // TODO: This needs to be fixed when paranets are introduced - if (responseData.assertion?.private?.length) - await this.validationService.validatePrivateMerkleRoot( - responseData.assertion.public, - responseData.assertion.private, + + if (!isOldContract) { + try { + await this.validationService.validateDatasetOnBlockchain( + publicKnowledgeAssetsTriplesGrouped.map((t) => t.sort()).flat(), + blockchain, + contract, + knowledgeCollectionId, ); - } catch (e) { - return this.handleNack(command, { - errorMessage: e.message, - }); + + // This is added as support when get starts supporting private for curated paranet + // TODO: This needs to be fixed when paranets are introduced + if (responseData.assertion?.private?.length) + await this.validationService.validatePrivateMerkleRoot( + responseData.assertion.public, + responseData.assertion.private, + ); + } catch (e) { + return this.handleNack(command, { + errorMessage: e.message, + }); + } } } + + let updatedResponseData = responseData; + + if (isOperationV0) { + // TODO: Extract converting assertion into one array from the object into 1 function since its used for v0 + const assertion = [ + ...(responseData.assertion?.public ?? []), + ...(responseData.assertion?.private ?? []), + ]; + + updatedResponseData = { ...responseData, assertion }; + } + await this.operationService.processResponse( command, OPERATION_REQUEST_STATUS.COMPLETED, - responseData, + updatedResponseData, ); return ProtocolRequestCommand.empty(); diff --git a/src/controllers/http-api/v0/bid-suggestion-http-api-controller-v0.js b/src/controllers/http-api/v0/bid-suggestion-http-api-controller-v0.js index 252f7eeb6..e70c5d33b 100644 --- a/src/controllers/http-api/v0/bid-suggestion-http-api-controller-v0.js +++ b/src/controllers/http-api/v0/bid-suggestion-http-api-controller-v0.js @@ -10,7 +10,7 @@ class BidSuggestionController extends BaseController { async handleRequest(req, res) { try { - const { blockchain, epochsNumber, assertionSize } = req.body; + const { blockchain, epochsNumber, assertionSize } = req.query; const promises = [ this.blockchainModuleManager.getTimeUntilNextEpoch(blockchain), this.blockchainModuleManager.getEpochLength(blockchain),