diff --git a/package-lock.json b/package-lock.json
index 6f6de7da0..7bc0de04c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "origintrail_node",
- "version": "8.0.0-sigma.14",
+ "version": "8.0.0-sigma.15",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "origintrail_node",
- "version": "8.0.0-sigma.14",
+ "version": "8.0.0-sigma.15",
"license": "ISC",
"dependencies": {
"@comunica/query-sparql": "^2.4.3",
diff --git a/package.json b/package.json
index ce65fce55..4ccd2d9d1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
- "version": "8.0.0-sigma.14",
+ "version": "8.0.0-sigma.15",
"description": "OTNode V8",
"main": "index.js",
"type": "module",
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 a5058454a..09189febe 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
@@ -34,13 +34,12 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
blockchain,
contract,
knowledgeCollectionId,
- knowledgeAssetId,
ual,
includeMetadata,
isOperationV0,
} = commandData;
- let { assertionId } = commandData;
+ let { assertionId, knowledgeAssetId } = commandData;
// if (paranetUAL) {
// const paranetNodeAccessPolicy = await this.blockchainModuleManager.getNodesAccessPolicy(
@@ -161,6 +160,13 @@ class HandleGetRequestCommand extends HandleProtocolMessageCommand {
return result.split('\n').filter((res) => res.length > 0);
});
} else {
+ if (!knowledgeAssetId) {
+ knowledgeAssetId = await this.blockchainModuleManager.getKnowledgeAssetsRange(
+ blockchain,
+ contract,
+ knowledgeCollectionId,
+ );
+ }
assertionPromise = this.tripleStoreService
.getAssertion(
blockchain,
diff --git a/src/commands/protocols/get/sender/local-get-command.js b/src/commands/protocols/get/sender/local-get-command.js
index 0054c3344..39165d0e5 100644
--- a/src/commands/protocols/get/sender/local-get-command.js
+++ b/src/commands/protocols/get/sender/local-get-command.js
@@ -16,6 +16,7 @@ class LocalGetCommand extends Command {
this.paranetService = ctx.paranetService;
this.ualService = ctx.ualService;
this.repositoryModuleManager = ctx.repositoryModuleManager;
+ this.blockchainModuleManager = ctx.blockchainModuleManager;
this.errorType = ERROR_TYPE.GET.GET_LOCAL_ERROR;
}
@@ -31,10 +32,10 @@ class LocalGetCommand extends Command {
includeMetadata,
contract,
knowledgeCollectionId,
- knowledgeAssetId,
contentType,
assertionId,
} = command.data;
+ let { knowledgeAssetId } = command.data;
await this.operationIdService.updateOperationIdStatus(
operationId,
blockchain,
@@ -137,6 +138,14 @@ class LocalGetCommand extends Command {
: result;
})();
} else {
+ // TODO: Do this in clean way
+ if (!knowledgeAssetId) {
+ knowledgeAssetId = await this.blockchainModuleManager.getKnowledgeAssetsRange(
+ blockchain,
+ contract,
+ knowledgeCollectionId,
+ );
+ }
assertionPromise = this.tripleStoreService
.getAssertion(
blockchain,
diff --git a/src/modules/blockchain/blockchain-module-manager.js b/src/modules/blockchain/blockchain-module-manager.js
index 82e24561c..9e6f691ea 100644
--- a/src/modules/blockchain/blockchain-module-manager.js
+++ b/src/modules/blockchain/blockchain-module-manager.js
@@ -181,6 +181,13 @@ class BlockchainModuleManager extends BaseModuleManager {
]);
}
+ async getKnowledgeAssetsRange(blockchain, assetStorageContractAddress, knowledgeCollectionId) {
+ return this.callImplementationFunction(blockchain, 'getKnowledgeAssetsRange', [
+ assetStorageContractAddress,
+ knowledgeCollectionId,
+ ]);
+ }
+
async getParanetKnowledgeAssetsCount(blockchain, paranetId) {
return this.callImplementationFunction(blockchain, 'getParanetKnowledgeAssetsCount', [
paranetId,
diff --git a/src/modules/blockchain/implementation/web3-service.js b/src/modules/blockchain/implementation/web3-service.js
index b45969757..34149490e 100644
--- a/src/modules/blockchain/implementation/web3-service.js
+++ b/src/modules/blockchain/implementation/web3-service.js
@@ -932,6 +932,37 @@ class Web3Service {
return Number(knowledgeCollectionSize);
}
+ async getKnowledgeAssetsRange(assetStorageContractAddress, knowledgeCollectionId) {
+ const assetStorageContractInstance =
+ this.assetStorageContracts[assetStorageContractAddress.toString().toLowerCase()];
+ if (!assetStorageContractInstance)
+ throw new Error('Unknown asset storage contract address');
+ const knowledgeAssetsRange = await this.callContractFunction(
+ assetStorageContractInstance,
+ 'getKnowledgeAssetsRange',
+ [knowledgeCollectionId],
+ );
+ return {
+ startTokenId: Number(
+ knowledgeAssetsRange[0]
+ .sub(BigNumber.from(knowledgeCollectionId - 1).mul('0x0f4240'))
+ .toString(),
+ ),
+ endTokenId: Number(
+ knowledgeAssetsRange[1]
+ .sub(BigNumber.from(knowledgeCollectionId - 1).mul('0x0f4240'))
+ .toString(),
+ ),
+ burned: knowledgeAssetsRange[2].map((burned) =>
+ Number(
+ burned
+ .sub(BigNumber.from(knowledgeCollectionId - 1).mul('0x0f4240'))
+ .toString(),
+ ),
+ ),
+ };
+ }
+
async getMinimumStake() {
const minimumStake = await this.callContractFunction(
this.contracts.ParametersStorage,
diff --git a/src/modules/triple-store/implementation/ot-triple-store.js b/src/modules/triple-store/implementation/ot-triple-store.js
index b82d2ecc9..8a986c41c 100644
--- a/src/modules/triple-store/implementation/ot-triple-store.js
+++ b/src/modules/triple-store/implementation/ot-triple-store.js
@@ -291,52 +291,48 @@ class OtTripleStore {
await this.queryVoid(repository, query);
}
- async getKnowledgeCollectionNamedGraphs(repository, ual, visibility) {
+ async getKnowledgeCollectionNamedGraphs(repository, tokenIds, ual, visibility) {
+ const namedGraphs = Array.from(
+ { length: tokenIds.endTokenId - tokenIds.startTokenId + 1 },
+ (_, i) => tokenIds.startTokenId + i,
+ )
+ .filter((id) => !tokenIds.burned.includes(id))
+ .map((id) => `${ual}/${id}`);
const assertion = {};
if (visibility === TRIPLES_VISIBILITY.PUBLIC || visibility === TRIPLES_VISIBILITY.ALL) {
const query = `
PREFIX schema:
CONSTRUCT {
?s ?p ?o .
- }
- WHERE {
- {
- SELECT ?s ?p ?o ?g
- WHERE {
- GRAPH ?g {
- ?s ?p ?o .
- }
- FILTER (
- STRSTARTS(STR(?g), "${ual}")
- && STRENDS(STR(?g), "${TRIPLES_VISIBILITY.PUBLIC}")
- )
- }
- ORDER BY ?g ?s ?p ?o
+ }
+ WHERE {
+ GRAPH ?g {
+ ?s ?p ?o .
}
- }`;
+ VALUES ?g {
+ ${namedGraphs
+ .map((graph) => `<${graph}/${TRIPLES_VISIBILITY.PUBLIC}>`)
+ .join('\n')}
+ }
+ }`;
assertion.public = await this.construct(repository, query);
}
if (visibility === TRIPLES_VISIBILITY.PRIVATE || visibility === TRIPLES_VISIBILITY.ALL) {
const query = `
- PREFIX schema:
- CONSTRUCT {
- ?s ?p ?o .
+ PREFIX schema:
+ CONSTRUCT {
+ ?s ?p ?o .
+ }
+ WHERE {
+ GRAPH ?g {
+ ?s ?p ?o .
}
- WHERE {
- {
- SELECT ?s ?p ?o ?g
- WHERE {
- GRAPH ?g {
- ?s ?p ?o .
- }
- FILTER (
- STRSTARTS(STR(?g), "${ual}")
- && STRENDS(STR(?g), "${TRIPLES_VISIBILITY.PRIVATE}")
- )
- }
- ORDER BY ?g ?s ?p ?o
- }
- }`;
+ VALUES ?g {
+ ${namedGraphs
+ .map((graph) => `<${graph}/${TRIPLES_VISIBILITY.PRIVATE}>`)
+ .join('\n')}
+ }
+ }`;
assertion.private = await this.construct(repository, query);
}
diff --git a/src/modules/triple-store/triple-store-module-manager.js b/src/modules/triple-store/triple-store-module-manager.js
index e3694103a..cde1972f0 100644
--- a/src/modules/triple-store/triple-store-module-manager.js
+++ b/src/modules/triple-store/triple-store-module-manager.js
@@ -137,11 +137,18 @@ class TripleStoreModuleManager extends BaseModuleManager {
}
}
- async getKnowledgeCollectionNamedGraphs(implementationName, repository, ual, visibility, sort) {
+ async getKnowledgeCollectionNamedGraphs(
+ implementationName,
+ repository,
+ ual,
+ tokenIds,
+ visibility,
+ sort,
+ ) {
if (this.getImplementation(implementationName)) {
return this.getImplementation(
implementationName,
- ).module.getKnowledgeCollectionNamedGraphs(repository, ual, visibility, sort);
+ ).module.getKnowledgeCollectionNamedGraphs(repository, tokenIds, ual, visibility, sort);
}
}
diff --git a/src/service/triple-store-service.js b/src/service/triple-store-service.js
index f37280856..8ab9214ac 100644
--- a/src/service/triple-store-service.js
+++ b/src/service/triple-store-service.js
@@ -380,26 +380,27 @@ class TripleStoreService {
repository = TRIPLE_STORE_REPOSITORY.DKG,
) {
// TODO: Use stateId
- const ual = `did:dkg:${blockchain}/${contract}/${knowledgeCollectionId}${
- knowledgeAssetId ? `/${knowledgeAssetId}` : ''
- }`;
-
- this.logger.debug(`Getting Assertion with the UAL: ${ual}.`);
+ let ual = `did:dkg:${blockchain}/${contract}/${knowledgeCollectionId}`;
let nquads;
- if (knowledgeAssetId) {
+ if (typeof knowledgeAssetId === 'string') {
+ ual = `${ual}/${knowledgeAssetId}`;
+ this.logger.debug(`Getting Assertion with the UAL: ${ual}.`);
nquads = await this.tripleStoreModuleManager.getKnowledgeAssetNamedGraph(
this.repositoryImplementations[repository],
repository,
// TODO: Add state with implemented update
`${ual}`,
+ knowledgeAssetId,
visibility,
);
} else {
+ this.logger.debug(`Getting Assertion with the UAL: ${ual}.`);
nquads = await this.tripleStoreModuleManager.getKnowledgeCollectionNamedGraphs(
this.repositoryImplementations[repository],
repository,
ual,
+ knowledgeAssetId,
visibility,
);
}