Skip to content

Commit

Permalink
Merge pull request #1775 from OriginTrail/v6/develop
Browse files Browse the repository at this point in the history
OriginTrail 6.0.0-beta.1.24 Testnet Prerelease
  • Loading branch information
NZT48 authored Feb 23, 2022
2 parents 405c4ba + 85cc1e9 commit e7428c6
Show file tree
Hide file tree
Showing 18 changed files with 476 additions and 8,729 deletions.
48 changes: 47 additions & 1 deletion external/blazegraph-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,61 @@ class BlazegraphService {

if (nquads.length) {
nquads = nquads.toString();
nquads = nquads.replace(/_:genid(.){37}/gm, '_:$1');
nquads = nquads.split('\n');
nquads = nquads.filter((x) => x !== '');
nquads = await this.transformBlankNodes(nquads);
} else {
nquads = null;
}
return { nquads, isAsset };
}

async transformBlankNodes(nquads) {
// Find minimum blank node value to assign it to _:c14n0
let minimumBlankNodeValue = -1;
for (const nquad of nquads) {
if (nquad.includes('_:t')) {
const blankNodes = nquad.split(' ').filter((s) => s.includes('_:t'));
for (const bn of blankNodes) {
const bnValue = Number(bn.substring(3));
if (minimumBlankNodeValue === -1 || minimumBlankNodeValue > bnValue) {
minimumBlankNodeValue = bnValue;
}
}
}
}

// Transform blank nodes, example: _:t145 -> _:c14n3
let bnName;
for (const nquadIndex in nquads) {
const nquad = nquads[nquadIndex];
if (nquad.includes('_:t')) {
const blankNodes = nquad.split(' ').filter((s) => s.includes('_:t'));
for (const bn of blankNodes) {
const bnValue = Number(bn.substring(3));
bnName = `_:c14n${bnValue - minimumBlankNodeValue}`;
nquads[nquadIndex] = nquad.replace(bn, bnName);
}
}
}

return nquads;
}

async assertionsByAsset(uri) {
const query = `PREFIX schema: <http://schema.org/>
SELECT ?assertionId ?issuer ?timestamp
WHERE {
?assertionId schema:hasUALs "${uri}" ;
schema:hasTimestamp ?timestamp ;
schema:hasIssuer ?issuer .
}
ORDER BY DESC(?timestamp)`;
const result = await this.execute(query);

return result.results.bindings;
}

async findAssertions(nquads) {
const query = `SELECT ?g
WHERE {
Expand Down
15 changes: 15 additions & 0 deletions external/graphdb-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ class GraphdbService {
return { nquads, isAsset };
}


async assertionsByAsset(uri) {
const query = `PREFIX schema: <http://schema.org/>
SELECT ?assertionId ?issuer ?timestamp
WHERE {
?assertionId schema:hasUALs "${uri}" ;
schema:hasTimestamp ?timestamp ;
schema:hasIssuer ?issuer .
}
ORDER BY DESC(?timestamp)`;
let result = await this.execute(query);

return JSON.parse(result).results.bindings;
}

async findAssertions(nquads) {
const query = `SELECT ?g
WHERE {
Expand Down
19 changes: 12 additions & 7 deletions external/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Libp2pService {
}

initializationObject.peerId = this.config.peerId;
this.workerPool = this.config.workerPool;

Libp2p.create(initializationObject).then((node) => {
this.node = node;
Expand Down Expand Up @@ -166,21 +167,20 @@ class Libp2pService {
return bl;
}
)

try {
data = JSON.parse(data);
data = await this.workerPool.exec('JSONParse', [data.toString()]);
this.logger.info(`Receiving message from ${handlerProps.connection.remotePeer._idB58String} to ${this.config.id}: event=${eventName};`);
if (!async) {
const result = await handler(data);
this.logger.info(`Sending response from ${this.config.id} to ${handlerProps.connection.remotePeer._idB58String}: event=${eventName};`);

const stringifiedData = await this.workerPool.exec('JSONStringify', [result]);
await pipe(
[JSON.stringify(result)],
[Buffer.from(stringifiedData)],
stream,
)
} else {
await pipe(
[JSON.stringify(['ack'])],
['ack'],
stream
)

Expand All @@ -198,7 +198,7 @@ class Libp2pService {
Event_name: constants.ERROR_TYPE.LIBP2P_HANDLE_MSG_ERROR,
});
await pipe(
[JSON.stringify(['ack'])],
['ack'],
stream
)

Expand All @@ -209,8 +209,9 @@ class Libp2pService {
async sendMessage(eventName, data, peerId) {
this.logger.info(`Sending message from ${this.config.id} to ${peerId._idB58String}: event=${eventName};`);
const {stream} = await this.node.dialProtocol(peerId, eventName);
const stringifiedData = await this.workerPool.exec('JSONStringify', [data]);
const response = await pipe(
[JSON.stringify(data)],
[Buffer.from(stringifiedData)],
stream,
async function (source) {
const bl = new BufferList()
Expand All @@ -222,6 +223,10 @@ class Libp2pService {
},
)

if(response.toString() === 'ack') {
return null;
}

return JSON.parse(response);
}

Expand Down
9 changes: 9 additions & 0 deletions frameDocuments/erc721.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"context": {
"@context": "https://www.schema.org/"
},
"frame": {
"@context": "https://www.schema.org/",
"@type": "ERC721"
}
}
6 changes: 0 additions & 6 deletions frameDocuments/nft.json

This file was deleted.

16 changes: 16 additions & 0 deletions installer/data/blazegraph.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#/lib/systemd/system/blazegraph.service

[Unit]
Description=Blazegraph - OriginTrail V6 Stage 1 Beta Node
Documentation=https://github.com/OriginTrail/ot-node
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/
ExecStart=/bin/java -jar /root/blazegraph.jar
Restart=on-failure

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion installer/data/otnode.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[Unit]
Description=OriginTrail V6 Stage 1 Beta Node
Documentation=https://github.com/OriginTrail/ot-node/
After=network.target graphdb.service
After=network.target graphdb.service blazegraph.service

[Service]
Type=simple
Expand Down
Loading

0 comments on commit e7428c6

Please sign in to comment.