Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
774 changes: 471 additions & 303 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
NETWORK_MESSAGE_TYPES,
OPERATION_ID_STATUS,
TRIPLES_VISIBILITY,
TRIPLE_STORE_REPOSITORY,
} from '../../../../../constants/constants.js';

class HandleGetRequestCommand extends HandleProtocolMessageCommand {
Expand Down Expand Up @@ -36,6 +37,7 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
knowledgeAssetId,
ual,
includeMetadata,
subjectUAL,
} = commandData;

// if (paranetUAL) {
Expand Down Expand Up @@ -97,7 +99,33 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
// };
// }
// }
// TODO: Add telemetry events and fix old wrong ones in here
if (subjectUAL) {
const subjectUALPairs = await this.tripleStoreService.findAllSubjectsWithGraphNames(
TRIPLE_STORE_REPOSITORY.DKG,
ual,
);

if (subjectUALPairs.subjectUALPairs?.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
subjectUALPairs,
[
OPERATION_ID_STATUS.GET.GET_LOCAL_END,
OPERATION_ID_STATUS.GET.GET_END,
OPERATION_ID_STATUS.COMPLETED,
],
);
}

return subjectUALPairs.subjectUALPairs?.length
? { messageType: NETWORK_MESSAGE_TYPES.RESPONSES.ACK, messageData: subjectUALPairs }
: {
messageType: NETWORK_MESSAGE_TYPES.RESPONSES.NACK,
messageData: { errorMessage: `Unable to find assertion ${ual}` },
};
}
const promises = [];
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_REMOTE_GET_ASSERTION_START,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GetScheduleMessagesCommand extends ProtocolScheduleMessagesCommand {
knowledgeAssetId: command.data.knowledgeAssetId,
includeMetadata: command.data.includeMetadata,
ual: command.data.ual,
subjectUAL: command.data.subjectUAL,
assetSync: command.data.assetSync,
paranetSync: command.data.paranetSync,
paranetTokenId: command.data.paranetTokenId,
Expand Down
241 changes: 142 additions & 99 deletions src/commands/protocols/get/sender/local-get-command.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Command from '../../../command.js';
import { OPERATION_ID_STATUS, ERROR_TYPE } from '../../../../constants/constants.js';
import {
OPERATION_ID_STATUS,
ERROR_TYPE,
TRIPLES_VISIBILITY,
TRIPLE_STORE_REPOSITORY,
} from '../../../../constants/constants.js';

class LocalGetCommand extends Command {
constructor(ctx) {
Expand Down Expand Up @@ -28,6 +33,8 @@ class LocalGetCommand extends Command {
contract,
knowledgeCollectionId,
knowledgeAssetId,
subjectUAL,
ual,
contentType,
} = command.data;
await this.operationIdService.updateOperationIdStatus(
Expand All @@ -36,122 +43,158 @@ class LocalGetCommand extends Command {
OPERATION_ID_STATUS.GET.GET_LOCAL_START,
);

// const response = {};

// if (paranetUAL) {
// const paranetRepository = this.paranetService.getParanetRepositoryName(paranetUAL);

// const ual = this.ualService.deriveUAL(blockchain, contract, tokenId);
// const syncedAssetRecord =
// await this.repositoryModuleManager.getParanetSyncedAssetRecordByUAL(ual);

// const nquads = await this.tripleStoreService.getAssertion(
// paranetRepository,
// syncedAssetRecord.publicAssertionId,
// );

// let privateNquads;
// if (syncedAssetRecord.privateAssertionId) {
// privateNquads = await this.tripleStoreService.getAssertion(
// paranetRepository,
// syncedAssetRecord.privateAssertionId,
// );
// }

// if (nquads?.length) {
// response.assertion = nquads;
// if (privateNquads?.length) {
// response.privateAssertion = privateNquads;
// }
// } else {
// this.handleError(
// operationId,
// blockchain,
// `Couldn't find locally asset with ${ual} in paranet ${paranetUAL}`,
// this.errorType,
// );
// }

// await this.operationService.markOperationAsCompleted(
// operationId,
// blockchain,
// response,
// [
// OPERATION_ID_STATUS.GET.GET_LOCAL_END,
// OPERATION_ID_STATUS.GET.GET_END,
// OPERATION_ID_STATUS.COMPLETED,
// ],
// );

// return Command.empty();
// }

// else {

const promises = [];
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_START,
operationId,
blockchain,
);
const assertionPromise = this.tripleStoreService
.getAssertion(
if (subjectUAL) {
// const response = {};

// if (paranetUAL) {
// const paranetRepository = this.paranetService.getParanetRepositoryName(paranetUAL);

// const ual = this.ualService.deriveUAL(blockchain, contract, tokenId);
// const syncedAssetRecord =
// await this.repositoryModuleManager.getParanetSyncedAssetRecordByUAL(ual);

// const nquads = await this.tripleStoreService.getAssertion(
// paranetRepository,
// syncedAssetRecord.publicAssertionId,
// );

// let privateNquads;
// if (syncedAssetRecord.privateAssertionId) {
// privateNquads = await this.tripleStoreService.getAssertion(
// paranetRepository,
// syncedAssetRecord.privateAssertionId,
// );
// }

// if (nquads?.length) {
// response.assertion = nquads;
// if (privateNquads?.length) {
// response.privateAssertion = privateNquads;
// }
// } else {
// this.handleError(
// operationId,
// blockchain,
// `Couldn't find locally asset with ${ual} in paranet ${paranetUAL}`,
// this.errorType,
// );
// }

// await this.operationService.markOperationAsCompleted(
// operationId,
// blockchain,
// response,
// [
// OPERATION_ID_STATUS.GET.GET_LOCAL_END,
// OPERATION_ID_STATUS.GET.GET_END,
// OPERATION_ID_STATUS.COMPLETED,
// ],
// );

// return Command.empty();
// }

// else {

this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_SUBJECT_UAL_START,
operationId,
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
contentType,
)
.then((result) => {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END,
);
// TODO: Rename this to better reflect content
const subjectUALPairs = await this.tripleStoreService.findAllSubjectsWithGraphNames(
TRIPLE_STORE_REPOSITORY.DKG,
ual,
);
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_SUBJECT_UAL_START,
operationId,
blockchain,
);
if (subjectUALPairs.subjectUALPairs?.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
subjectUALPairs,
[
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_SUBJECT_UAL_START,
OPERATION_ID_STATUS.GET.GET_LOCAL_END,
OPERATION_ID_STATUS.GET.GET_END,
OPERATION_ID_STATUS.COMPLETED,
],
);
return result;
});
promises.push(assertionPromise);

if (includeMetadata) {
return Command.empty();
}
} else {
const promises = [];
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_METADATA_START,
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_START,
operationId,
blockchain,
);
const metadataPromise = this.tripleStoreService
.getAssertionMetadata(blockchain, contract, knowledgeCollectionId, knowledgeAssetId)
const assertionPromise = this.tripleStoreService
.getAssertion(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
contentType ?? TRIPLES_VISIBILITY.ALL,
)
.then((result) => {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_METADATA_END,
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_END,
operationId,
blockchain,
);
return result;
});
promises.push(metadataPromise);
}

const [assertion, metadata] = await Promise.all(promises);
promises.push(assertionPromise);

const responseData = {
assertion,
...(includeMetadata && metadata && { metadata }),
};
if (assertion.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
responseData,
[
OPERATION_ID_STATUS.GET.GET_LOCAL_END,
OPERATION_ID_STATUS.GET.GET_END,
OPERATION_ID_STATUS.COMPLETED,
],
);
if (includeMetadata) {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_METADATA_START,
operationId,
blockchain,
);
const metadataPromise = this.tripleStoreService
.getAssertionMetadata(
blockchain,
contract,
knowledgeCollectionId,
knowledgeAssetId,
)
.then((result) => {
this.operationIdService.emitChangeEvent(
OPERATION_ID_STATUS.GET.GET_LOCAL_GET_ASSERTION_METADATA_END,
operationId,
blockchain,
);
return result;
});
promises.push(metadataPromise);
}

const [assertion, metadata] = await Promise.all(promises);

const responseData = {
assertion,
...(includeMetadata && metadata && { metadata }),
};
if (assertion.length) {
await this.operationService.markOperationAsCompleted(
operationId,
blockchain,
responseData,
[
OPERATION_ID_STATUS.GET.GET_LOCAL_END,
OPERATION_ID_STATUS.GET.GET_END,
OPERATION_ID_STATUS.COMPLETED,
],
);

return Command.empty();
return Command.empty();
}
}
// }

await this.operationIdService.updateOperationIdStatus(
operationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GetRequestCommand extends ProtocolRequestCommand {
knowledgeAssetId,
includeMetadata,
ual,
subjectUAL,
paranetUAL,
paranetId,
} = command.data;
Expand All @@ -56,6 +57,7 @@ class GetRequestCommand extends ProtocolRequestCommand {
knowledgeAssetId,
includeMetadata,
ual,
subjectUAL,
paranetUAL,
paranetId,
};
Expand Down
2 changes: 2 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ export const OPERATION_ID_STATUS = {
GET_FIND_NODES_PROCESS_FOUND_NODES_START: 'GET_FIND_NODES_PROCESS_FOUND_NODES_START',
GET_FIND_NODES_PROCESS_FOUND_NODES_END: 'GET_FIND_NODES_PROCESS_FOUND_NODES_END',
GET_END: 'GET_END',
GET_LOCAL_GET_SUBJECT_UAL_START: 'GET_LOCAL_GET_SUBJECT_UAL_START',
GET_LOCAL_GET_SUBJECT_UAL_END: 'GET_LOCAL_GET_SUBJECT_UAL_END',
},
QUERY: {
QUERY_INIT_START: 'QUERY_INIT_START',
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/http-api/v0/get-http-api-controller-v0.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GetController extends BaseController {
let knowledgeCollectionId;
let knowledgeAssetId;
try {
const { id, paranetUAL, includeMetadata, contentType } = req.body;
const { id, paranetUAL, includeMetadata, subjectUAL, contentType } = req.body;
({ blockchain, contract, knowledgeCollectionId, knowledgeAssetId } =
this.ualService.resolveUAL(id));

Expand All @@ -64,6 +64,7 @@ class GetController extends BaseController {
contract,
knowledgeCollectionId,
knowledgeAssetId,
subjectUAL,
operationId,
paranetUAL,
contentType: contentType ?? TRIPLES_VISIBILITY.ALL,
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/http-api/v0/request-schema/get-schema-v0.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ export default () => ({
paranetUAL: {
type: ['string', 'null'],
},
subjectUAL: {
type: 'boolean',
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class FinalityController extends BaseController {
const { ual } = req.query;

const finality = await this.repositoryModuleManager.getFinalityAcksCount(ual || '');
console.log(finality);

if (typeof finality !== 'number')
return this.returnResponse(res, 400, {
Expand Down
Loading