Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V8] V8 release create operations #174

Open
wants to merge 30 commits into
base: v8/develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f048691
Create, localStore, update v8 SDK updates
brkagithub Nov 22, 2024
b75abb9
Minor changes for ot node
brkagithub Nov 25, 2024
4755dea
Remove contract param from node API publish
brkagithub Nov 25, 2024
9664a97
Merge branch 'v8/develop' into v8/release-create-operation
brkagithub Nov 25, 2024
4de777a
Rename node api publish params + small fix
brkagithub Nov 25, 2024
ca0eea9
check whether status is not completed instead of whether it failed
brkagithub Nov 26, 2024
f65ac32
Update demo.js
brkagithub Nov 26, 2024
ec65446
Add create collection
brkagithub Nov 26, 2024
10eb6c6
Add missing constant
brkagithub Nov 26, 2024
9590770
Trim start and trim end each triple
brkagithub Nov 26, 2024
07c64f2
Updated dkg-evm-module, added publishOperationId argument
u-hubar Nov 28, 2024
0ee77a4
Added addLabels function and condition validation
ilijaMar Nov 29, 2024
562e616
Added addLabels function and condition validation (#177)
ilijaMar Nov 29, 2024
b533da6
[V8] Implement graph.get (#176)
aleksaelezovic Nov 29, 2024
6e99e46
Revert "Added addLabels function and condition validation (#177)" (#178)
Mihajlo-Pavlovic Nov 29, 2024
476d7e0
Added extra <>
ilijaMar Dec 3, 2024
ede5a0e
Changes for get follow the node (#180)
Mihajlo-Pavlovic Dec 3, 2024
3239571
Added LABEL_PREFIX constant
ilijaMar Dec 3, 2024
92ad383
[V8] Implement graph.query (#175)
aleksaelezovic Dec 4, 2024
e9d1009
Finality implementation
brkagithub Dec 4, 2024
f255370
Merge remote-tracking branch 'origin/v8/release-create-operation' int…
brkagithub Dec 4, 2024
19796cf
Improve finality dkg js
brkagithub Dec 4, 2024
d379bf1
Merge pull request #184 from OriginTrail/feature/node-finality
brkagithub Dec 4, 2024
fecfff7
Merge pull request #179 from OriginTrail/v8/addLabels
brkagithub Dec 4, 2024
2700326
fix query api
Mihajlo-Pavlovic Dec 4, 2024
e364e82
fix query api
Mihajlo-Pavlovic Dec 4, 2024
ca645fc
Merge branch 'v8/release-create-operation' into v8/feature/query
Mihajlo-Pavlovic Dec 4, 2024
28819f4
Merge pull request #183 from OriginTrail/v8/feature/query
brkagithub Dec 4, 2024
082d333
Changed package to use ES JS, added new assertion-tools
u-hubar Dec 4, 2024
2199560
New option–for–get to fetch subject ual (#189)
Mihajlo-Pavlovic Dec 9, 2024
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
11 changes: 11 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
@@ -96,6 +96,7 @@ const OPERATIONS = {
LOCAL_STORE: 'local-store',
QUERY: 'query',
PUBLISH_PARANET: 'publishParanet',
FINALITY: 'finality',
};

const OPERATION_STATUSES = {
@@ -104,6 +105,14 @@ const OPERATION_STATUSES = {
FAILED: 'FAILED',
};

const OPERATION_DELAYS = {
FINALITY: 2000,
};

const OPERATION_ATTEMPTS = {
FINALITY: 5,
};

const ASSERTION_STATES = {
LATEST: 'latest',
LATEST_FINALIZED: 'latest_finalized',
@@ -242,6 +251,8 @@ module.exports = {
WEBSOCKET_PROVIDER_OPTIONS,
OPERATIONS,
OPERATION_STATUSES,
OPERATION_DELAYS,
OPERATION_ATTEMPTS,
ASSERTION_STATES,
CONTENT_TYPES,
GET_OUTPUT_FORMATS,
46 changes: 42 additions & 4 deletions managers/asset-operations-manager.js
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ const {
deriveUAL,
getOperationStatusObject,
resolveUAL,
sleepForMilliseconds,
} = require('../services/utilities.js');
const {
OPERATIONS,
@@ -24,6 +25,8 @@ const {
STORE_TYPES,
ZERO_ADDRESS,
CHUNK_BYTE_SIZE,
OPERATION_DELAYS,
OPERATION_ATTEMPTS,
} = require('../constants.js');
const emptyHooks = require('../util/empty-hooks');

@@ -72,7 +75,8 @@ class AssetOperationsManager {

if (prefixes[2] !== blockchain.name.split(':')[0]) {
throw new Error(
`Invalid blockchain name in the UAL prefix. Expected: '${blockchain.name.split(':')[0]
`Invalid blockchain name in the UAL prefix. Expected: '${
blockchain.name.split(':')[0]
}'. Received: '${prefixes[2]}'.`,
);
}
@@ -269,7 +273,6 @@ class AssetOperationsManager {
*/
async create(content, options = {}, stepHooks = emptyHooks) {
this.validationService.validateJsonldOrNquads(content);

const {
blockchain,
endpoint,
@@ -284,6 +287,7 @@ class AssetOperationsManager {
authToken,
paranetUAL,
payer,
minimumNumberOfNodeReplications,
} = this.inputService.getAssetCreateArguments(options);

this.validationService.validateAssetCreate(
@@ -301,8 +305,9 @@ class AssetOperationsManager {
authToken,
paranetUAL,
payer,
minimumNumberOfNodeReplications,
);

let dataset;

if (typeof content === 'string') {
@@ -418,7 +423,39 @@ class AssetOperationsManager {

const UAL = deriveUAL(blockchain.name, contentAssetStorageAddress, tokenId);

// node finality api check for UAL
const delayBetweenAttempts = OPERATION_DELAYS.FINALITY;
let finalityOperationResult = null;

for (let attempt = 0; attempt < OPERATION_ATTEMPTS.FINALITY; attempt++) {
try {
const finalityOperationId = await this.nodeApiService.finality(
endpoint,
port,
authToken,
blockchain.name,
UAL,
minimumNumberOfNodeReplications,
);

finalityOperationResult = await this.nodeApiService.getOperationResult(
endpoint,
port,
authToken,
OPERATIONS.FINALITY,
maxNumberOfRetries,
frequency,
finalityOperationId,
);

if (finalityOperationResult.status === 'COMPLETED') break;
} catch (error) {
console.error(`Attempt ${attempt + 1} failed:`, error.message);
}

if (attempt < OPERATION_ATTEMPTS.FINALITY - 1) {
await sleepForMilliseconds(delayBetweenAttempts);
}
}

return {
UAL,
@@ -427,6 +464,7 @@ class AssetOperationsManager {
operation: {
mintKnowledgeAsset: mintKnowledgeAssetReceipt,
publish: getOperationStatusObject(publishOperationResult, publishOperationId),
finality: finalityOperationResult,
},
};
}
54 changes: 42 additions & 12 deletions managers/graph-operations-manager.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const {
OPERATIONS,
GET_OUTPUT_FORMATS,
CHUNK_BYTE_SIZE,
OPERATION_STATUSES
CHUNK_BYTE_SIZE,
OPERATION_STATUSES,
OPERATION_DELAYS,
OPERATION_ATTEMPTS,
} = require('../constants.js');
const {
getOperationStatusObject,
toNQuads,
toJSONLD,
formatDataset,
@@ -19,6 +20,7 @@ const {
getOperationStatusObject,
resolveUAL,
deriveUAL,
sleepForMilliseconds,
} = require('../services/utilities.js');
const emptyHooks = require('../util/empty-hooks.js');

@@ -110,10 +112,7 @@ class GraphOperationsManager {

return {
operation: {
get: getOperationStatusObject(
getOperationResult,
getOperationId,
),
get: getOperationStatusObject(getOperationResult, getOperationId),
},
};
}
@@ -139,10 +138,7 @@ class GraphOperationsManager {
return {
assertion: formattedAssertion,
operation: {
get: getOperationStatusObject(
getOperationResult,
getOperationId,
),
get: getOperationStatusObject(getOperationResult, getOperationId),
},
};
}
@@ -226,6 +222,7 @@ class GraphOperationsManager {
authToken,
paranetUAL,
payer,
minimumNumberOfNodeReplications,
} = this.inputService.getAssetCreateArguments(options);

this.validationService.validateAssetCreate(
@@ -243,6 +240,7 @@ class GraphOperationsManager {
authToken,
paranetUAL,
payer,
minimumNumberOfNodeReplications,
);

let dataset;
@@ -360,14 +358,46 @@ class GraphOperationsManager {

const UAL = deriveUAL(blockchain.name, contentAssetStorageAddress, tokenId);

// node finality api check for UAL
const delayBetweenAttempts = OPERATION_DELAYS.FINALITY;
let finalityOperationResult = null;

for (let attempt = 0; attempt < OPERATION_ATTEMPTS.FINALITY; attempt++) {
try {
const finalityOperationId = await this.nodeApiService.finality(
endpoint,
port,
authToken,
blockchain.name,
UAL,
minimumNumberOfNodeReplications,
);

finalityOperationResult = await this.nodeApiService.getOperationResult(
endpoint,
port,
authToken,
OPERATIONS.FINALITY,
maxNumberOfRetries,
frequency,
finalityOperationId,
);

if (finalityOperationResult.status === 'COMPLETED') break;
} catch (error) {
console.error(`Attempt ${attempt + 1} failed:`, error.message);
}

if (attempt < OPERATION_ATTEMPTS.FINALITY - 1) {
await sleepForMilliseconds(delayBetweenAttempts);
}
}
return {
UAL,
datasetRoot,
operation: {
mintKnowledgeAsset: mintKnowledgeAssetReceipt,
publish: getOperationStatusObject(publishOperationResult, publishOperationId),
finality: finalityOperationResult,
},
};
}
15 changes: 14 additions & 1 deletion services/input-service.js
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ class InputService {
authToken: this.getAuthToken(options),
paranetUAL: this.getParanetUAL(options),
payer: this.getPayer(options),
minimumNumberOfNodeReplications: this.getMinimumNumberOfNodeReplications(options) ?? 5,
};
}

@@ -287,7 +288,11 @@ class InputService {
}

getIncludeMetadata(options) {
return options.includeMetadata ?? this.config.includeMetadata ?? DEFAULT_PARAMETERS.INCLUDE_METADATA;
return (
options.includeMetadata ??
this.config.includeMetadata ??
DEFAULT_PARAMETERS.INCLUDE_METADATA
);
}

getContentType(options) {
@@ -326,6 +331,14 @@ class InputService {
return options.payer ?? this.config.payer ?? null;
}

getMinimumNumberOfNodeReplications(options) {
return (
options.minimumNumberOfNodeReplications ??
this.config.minimumNumberOfNodeReplications ??
null
);
}

getParanetName(options) {
return options.paranetName ?? null;
}
26 changes: 25 additions & 1 deletion services/node-api-service/implementations/http-service.js
Original file line number Diff line number Diff line change
@@ -131,7 +131,17 @@ class HttpService {
}
}

async get(endpoint, port, authToken, UAL, state, includeMetadata, contentType, hashFunctionId, paranetUAL) {
async get(
endpoint,
port,
authToken,
UAL,
state,
includeMetadata,
contentType,
hashFunctionId,
paranetUAL,
) {
try {
const response = await axios({
method: 'post',
@@ -198,6 +208,20 @@ class HttpService {
}
}

async finality(endpoint, port, authToken, blockchain, ual, minimumNumberOfNodeReplications) {
try {
const response = await axios({
method: 'post',
url: `${endpoint}:${port}/finality`,
data: { ual, blockchain, minimumNumberOfNodeReplications },
headers: this.prepareRequestConfig(authToken),
});
return response.data.operationId;
} catch (error) {
throw Error(`Unable to query: ${error.message}`);
}
}

async getOperationResult(
endpoint,
port,
14 changes: 14 additions & 0 deletions services/validation-service.js
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ class ValidationService {
authToken,
paranetUAL,
payer,
minimumNumberOfNodeReplications,
) {
this.validateContent(content);
this.validateBlockchain(blockchain, OPERATIONS.PUBLISH);
@@ -88,6 +89,7 @@ class ValidationService {
this.validateAuthToken(authToken);
this.validateParanetUAL(paranetUAL);
this.validatePayer(payer);
this.validateMinimumNumberOfNodeReplications(minimumNumberOfNodeReplications);
}

validateAssetGet(
@@ -547,6 +549,18 @@ class ValidationService {
this.validateAddress(payer);
}

validateMinimumNumberOfNodeReplications(minimumNumberOfNodeReplications) {
this.validateRequiredParam(
'minimumNumberOfNodeReplications',
minimumNumberOfNodeReplications,
);
this.validateParamType(
'minimumNumberOfNodeReplications',
minimumNumberOfNodeReplications,
'number',
);
}

validateValidate(validate) {
this.validateRequiredParam('validate', validate);
this.validateParamType('validate', validate, 'boolean');