Skip to content

Commit

Permalink
Merge pull request #3568 from OriginTrail/fix/fixes-for-backwards-com…
Browse files Browse the repository at this point in the history
…patibility

Backwards compatibiltiy fixes
  • Loading branch information
Mihajlo-Pavlovic authored Dec 20, 2024
2 parents 6712b00 + 092fecb commit 55afd4f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
ual,
);

if (!assertionId) {
assertionId = await this.tripleStoreService.getLatestAssertionId(
TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT,
ual,
);
}

if (!assertionId) {
return {
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK,
Expand All @@ -144,7 +137,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
operationId,
blockchain,
);
return result;
return result.split('\n').filter((res) => res.length > 0);
});
} else {
assertionPromise = this.tripleStoreService
Expand Down
53 changes: 34 additions & 19 deletions src/commands/protocols/get/sender/get-validate-asset-command.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import ValidateAssetCommand from '../../../common/validate-asset-command.js';
import Command from '../../../command.js';
import { OPERATION_ID_STATUS, ERROR_TYPE } from '../../../../constants/constants.js';
import {
OPERATION_ID_STATUS,
ERROR_TYPE,
OLD_CONTENT_STORAGE_MAP,
} from '../../../../constants/constants.js';

class GetValidateAssetCommand extends ValidateAssetCommand {
constructor(ctx) {
Expand Down Expand Up @@ -49,30 +53,41 @@ class GetValidateAssetCommand extends ValidateAssetCommand {
blockchain,
);
// TODO: Update to validate knowledge asset index
const isValidUal = isOperationV0
? true
: await this.validationService.validateUal(blockchain, contract, knowledgeCollectionId);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_VALIDATE_UAL_END,
operationId,
blockchain,
);
if (
!isOperationV0 &&
Object.values(OLD_CONTENT_STORAGE_MAP).every(
(ca) => !ca.toLowerCase().includes(contract.toLowerCase()),
)
) {
const isValidUal = await this.validationService.validateUal(
blockchain,
contract,
knowledgeCollectionId,
);

if (!isValidUal) {
await this.handleError(
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_VALIDATE_UAL_END,
operationId,
blockchain,
`Get for operation id: ${operationId}, UAL: ${ual}: there is no asset with this UAL.`,
this.errorType,
);
return Command.empty();

if (!isValidUal) {
await this.handleError(
operationId,
blockchain,
`Get for operation id: ${operationId}, UAL: ${ual}: there is no asset with this UAL.`,
this.errorType,
);
return Command.empty();
}

await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
OPERATION_ID_STATUS.GET.GET_VALIDATE_ASSET_END,
);
}

await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
OPERATION_ID_STATUS.GET.GET_VALIDATE_ASSET_END,
);
return this.continueSequence(
{
...command.data,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/protocols/get/sender/local-get-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class LocalGetCommand extends Command {

if (assertionId) {
assertionPromise = (async () => {
let result = null;
let result = {};
for (const repository of [
TRIPLE_STORE_REPOSITORIES.PRIVATE_CURRENT,
TRIPLE_STORE_REPOSITORIES.PUBLIC_CURRENT,
Expand All @@ -124,7 +124,7 @@ class LocalGetCommand extends Command {
);
}

return result;
return result.split('\n').filter((res) => res.length > 0);
})();
} else {
assertionPromise = this.tripleStoreService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class PublishFindShardCommand extends FindShardCommand {

getOperationCommandSequence(nodePartOfShard, commandData) {
const sequence = [];
sequence.push(
commandData.isOperationV0 ? 'validateAssetCommand' : 'publishValidateAssetCommand',
);
if (!commandData.isOperationV0) {
sequence.push('publishValidateAssetCommand');
}

if (nodePartOfShard && !commandData.isOperationV0) {
sequence.push('localStoreCommand');
} else {
Expand Down
20 changes: 19 additions & 1 deletion src/commands/query/query-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,25 @@ class QueryCommand extends Command {
OPERATION_ID_STATUS.QUERY.QUERY_CONSTRUCT_QUERY_START,
operationId,
);
data = await this.tripleStoreService.construct(query, repository);

if (Array.isArray(repository)) {
const dataV6 = await this.tripleStoreService.construct(
query,
repository[0],
);
const dataV8 = await this.tripleStoreService.construct(
query,
repository[1],
);

data = this.dataService.removeDuplicateObjectsFromArray([
...dataV6,
...dataV8,
]);
} else {
data = await this.tripleStoreService.construct(query, repository);
}

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.QUERY.QUERY_CONSTRUCT_QUERY_END,
operationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LocalStoreController extends BaseController {

await this.operationIdService.cacheOperationIdDataToFile(operationId, cachedAssertions);

const commandSequence = ['validateAssetCommand', 'localStoreCommand'];
const commandSequence = ['localStoreCommand'];

await this.commandExecutor.add({
name: commandSequence[0],
Expand Down

0 comments on commit 55afd4f

Please sign in to comment.