From c3e5627e49e5fe7ae0cecca83a6f8cd819e005e6 Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Fri, 6 Sep 2024 15:44:33 +0200 Subject: [PATCH 1/2] Add transaction receipts to responses --- examples/demo.js | 12 ++ examples/paranet-demo.js | 5 +- managers/asset-operations-manager.js | 144 +++++++++++------- managers/paranet-operations-manager.js | 38 ++--- .../blockchain-service-base.js | 2 +- 5 files changed, 117 insertions(+), 84 deletions(-) diff --git a/examples/demo.js b/examples/demo.js index 7c35b31..b5755cf 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -252,6 +252,18 @@ function divider() { divider(); + const extendStoringResult = await DkgClient.asset.extendStoringPeriod(createAssetResult.UAL, 2); + console.log(`======================== ASSET STORING PERIOD EXTENDED`); + console.log(extendStoringResult); + + divider(); + + const addTokensResult = await DkgClient.asset.addTokens(createAssetResult.UAL, {tokenAmount: 1000}); + console.log(`======================== ADD TOKENS FOR AN ASSET`); + console.log(addTokensResult); + + divider(); + const newOwner = '0x2ACa90078563133db78085F66e6B8Cf5531623Ad'; const transferResult = await DkgClient.asset.transfer(createAssetResult.UAL, newOwner); console.log(`======================== ASSET TRANSFERRED TO ${newOwner}`); diff --git a/examples/paranet-demo.js b/examples/paranet-demo.js index 28ddc31..1c9ce9a 100644 --- a/examples/paranet-demo.js +++ b/examples/paranet-demo.js @@ -103,8 +103,9 @@ function divider() { console.log(paranetServiceUAL); divider(); - await DkgClient.paranet.addServices(paranetAssetResult.UAL, [ createServiceKAResult.UAL]); + const addServiceToParanet = await DkgClient.paranet.addServices(paranetAssetResult.UAL, [createServiceKAResult.UAL,]); console.log('======================== SERVICE ADDED TO PARANET'); + console.log(addServiceToParanet); divider(); content = { @@ -154,7 +155,7 @@ function divider() { divider(); let claimable = await DkgClient.paranet.getClaimableMinerReward(paranetAssetResult.UAL); - console.log('======================== KA MINER REWARD TO CLAIM') + console.log('======================== KA MINER REWARD TO CLAIM'); console.log(claimable); divider(); diff --git a/managers/asset-operations-manager.js b/managers/asset-operations-manager.js index 444d737..ee392f3 100644 --- a/managers/asset-operations-manager.js +++ b/managers/asset-operations-manager.js @@ -149,10 +149,7 @@ class AssetOperationsManager { ); } - return { - transactionHash: receipt.transactionHash, - status: receipt.status, - }; + return receipt; } /** @@ -179,10 +176,7 @@ class AssetOperationsManager { blockchain, ); - return { - transactionHash: receipt.transactionHash, - status: receipt.status, - }; + return receipt; } /** @@ -219,10 +213,7 @@ class AssetOperationsManager { blockchain, ); - return { - transactionHash: receipt.transactionHash, - status: receipt.status, - }; + return receipt; } /** @@ -296,7 +287,7 @@ class AssetOperationsManager { immutable, tokenAmount, authToken, - paranetUAL + paranetUAL, ); const { public: publicAssertion, private: privateAssertion } = await formatGraph( @@ -333,8 +324,9 @@ class AssetOperationsManager { )); let tokenId; - if(paranetUAL == null) { - tokenId = await this.blockchainService.createAsset( + let receipt; + if (paranetUAL == null) { + [tokenId, receipt] = await this.blockchainService.createAsset( { publicAssertionId, assertionSize: publicAssertionSizeInBytes, @@ -352,7 +344,7 @@ class AssetOperationsManager { ); } else { const { contract: paranetKaContract, tokenId: paranetTokenId } = resolveUAL(paranetUAL); - tokenId = await this.blockchainService.createAsset( + [tokenId, receipt] = await this.blockchainService.createAsset( { publicAssertionId, assertionSize: publicAssertionSizeInBytes, @@ -394,7 +386,7 @@ class AssetOperationsManager { const UAL = deriveUAL(blockchain.name, contentAssetStorageAddress, tokenId); - let operationId = await this.nodeApiService.publish( + let publishOperationId = await this.nodeApiService.publish( endpoint, port, authToken, @@ -406,53 +398,60 @@ class AssetOperationsManager { hashFunctionId, ); - let operationResult = await this.nodeApiService.getOperationResult( + let publishOperationResult = await this.nodeApiService.getOperationResult( endpoint, port, authToken, OPERATIONS.PUBLISH, maxNumberOfRetries, frequency, - operationId, + publishOperationId, ); - if (operationResult.status === OPERATION_STATUSES.FAILED) { + if (publishOperationResult.status === OPERATION_STATUSES.FAILED) { return { UAL, assertionId: publicAssertionId, - operation: getOperationStatusObject(operationResult, operationId), + operation: getOperationStatusObject(publishOperationResult, publishOperationId), }; } - operationId = await this.nodeApiService.localStore( + let localStoreOperationId = await this.nodeApiService.localStore( endpoint, port, authToken, assertions, ); - operationResult = await this.nodeApiService.getOperationResult( + let localStoreOperationResult = await this.nodeApiService.getOperationResult( endpoint, port, authToken, OPERATIONS.LOCAL_STORE, maxNumberOfRetries, DEFAULT_GET_LOCAL_STORE_RESULT_FREQUENCY, - operationId, + localStoreOperationId, ); stepHooks.afterHook({ status: OPERATIONS_STEP_STATUS.CREATE_ASSET_COMPLETED, data: { - operationId, - operationResult, + localStoreOperationId, + localStoreOperationResult, }, }); return { UAL, publicAssertionId, - operation: getOperationStatusObject(operationResult, operationId), + operation: { + mintKnowledgeAssetReceipt: receipt, + publish: getOperationStatusObject(publishOperationResult, publishOperationId), + localStore: getOperationStatusObject( + localStoreOperationResult, + localStoreOperationId, + ), + }, }; } @@ -813,7 +812,7 @@ class AssetOperationsManager { ); } - await this.blockchainService.updateAsset( + let receipt = await this.blockchainService.updateAsset( tokenId, publicAssertionId, publicAssertionSizeInBytes, @@ -847,32 +846,35 @@ class AssetOperationsManager { }); } - let operationId = await this.nodeApiService.localStore( + let localStoreOperationId = await this.nodeApiService.localStore( endpoint, port, authToken, assertions, ); - let operationResult = await this.nodeApiService.getOperationResult( + let localStoreOperationResult = await this.nodeApiService.getOperationResult( endpoint, port, authToken, OPERATIONS.LOCAL_STORE, maxNumberOfRetries, DEFAULT_GET_LOCAL_STORE_RESULT_FREQUENCY, - operationId, + localStoreOperationId, ); - if (operationResult.status === OPERATION_STATUSES.FAILED) { + if (localStoreOperationResult.status === OPERATION_STATUSES.FAILED) { return { UAL, assertionId: publicAssertionId, - operation: getOperationStatusObject(operationResult, operationId), + operation: getOperationStatusObject( + localStoreOperationResult, + localStoreOperationId, + ), }; } - operationId = await this.nodeApiService.update( + let UpdateOperationId = await this.nodeApiService.update( endpoint, port, authToken, @@ -883,19 +885,23 @@ class AssetOperationsManager { tokenId, hashFunctionId, ); - operationResult = await this.nodeApiService.getOperationResult( + let updateOperationResult = await this.nodeApiService.getOperationResult( endpoint, port, authToken, OPERATIONS.UPDATE, maxNumberOfRetries, frequency, - operationId, + UpdateOperationId, ); return { UAL, publicAssertionId, - operation: getOperationStatusObject(operationResult, operationId), + operation: { + updateKnowledgeAssetReceipt: receipt, + localStore: getOperationStatusObject(localStoreOperationResult, UpdateOperationId), + update: getOperationStatusObject(updateOperationResult, localStoreOperationId), + }, }; } @@ -972,11 +978,15 @@ class AssetOperationsManager { this.validationService.validateAssetUpdateCancel(UAL, blockchain); const { tokenId } = resolveUAL(UAL); - await this.blockchainService.cancelAssetUpdate(tokenId, blockchain); + let receipt = await this.blockchainService.cancelAssetUpdate(tokenId, blockchain); return { UAL, - operation: getOperationStatusObject({ status: 'COMPLETED' }, null), + operation: { + status: getOperationStatusObject({ status: 'COMPLETED' }, null), + cancelKnowledgeAssetUpdateReceipt: receipt, + }, + cancelAssetUpdateReceipt: receipt, }; } @@ -994,12 +1004,15 @@ class AssetOperationsManager { this.validationService.validateAssetTransfer(UAL, newOwner, blockchain); const { tokenId } = resolveUAL(UAL); - await this.blockchainService.transferAsset(tokenId, newOwner, blockchain); + let receipt = await this.blockchainService.transferAsset(tokenId, newOwner, blockchain); const owner = await this.blockchainService.getAssetOwner(tokenId, blockchain); return { UAL, owner, - operation: getOperationStatusObject({ status: 'COMPLETED' }, null), + operation: { + status: getOperationStatusObject({ status: 'COMPLETED' }, null), + transferAssetReceipt: receipt, + }, }; } @@ -1126,11 +1139,13 @@ class AssetOperationsManager { this.validationService.validateAssetBurn(UAL, blockchain); const { tokenId } = resolveUAL(UAL); - await this.blockchainService.burnAsset(tokenId, blockchain); - + let receipt = await this.blockchainService.burnAsset(tokenId, blockchain); return { UAL, - operation: getOperationStatusObject({ status: 'COMPLETED' }, null), + operation: { + status: getOperationStatusObject({ status: 'COMPLETED' }, null), + burnKnowledgeAssetReceipt: receipt, + }, }; } @@ -1188,7 +1203,7 @@ class AssetOperationsManager { ); } - await this.blockchainService.extendAssetStoringPeriod( + let receipt = await this.blockchainService.extendAssetStoringPeriod( tokenId, epochsNumber, tokenAmountInWei, @@ -1197,7 +1212,10 @@ class AssetOperationsManager { return { UAL, - operation: getOperationStatusObject({ status: 'COMPLETED' }, null), + operation: { + status: getOperationStatusObject({ status: 'COMPLETED' }, null), + extendKnowledgeAssetStoringPeriodReceipt: receipt, + }, }; } @@ -1254,11 +1272,14 @@ class AssetOperationsManager { } } - await this.blockchainService.addTokens(tokenId, tokenAmountInWei, blockchain); + let receipt = await this.blockchainService.addTokens(tokenId, tokenAmountInWei, blockchain); return { UAL, - operation: getOperationStatusObject({ status: 'COMPLETED' }, null), + operation: { + status: getOperationStatusObject({ status: 'COMPLETED' }, null), + addTokensForKnowledgeAssetReceipt: receipt, + }, }; } @@ -1314,11 +1335,18 @@ class AssetOperationsManager { } } - await this.blockchainService.addUpdateTokens(tokenId, tokenAmountInWei, blockchain); + let receipt = await this.blockchainService.addUpdateTokens( + tokenId, + tokenAmountInWei, + blockchain, + ); return { UAL, - operation: getOperationStatusObject({ status: 'COMPLETED' }, null), + operation: { + status: getOperationStatusObject({ status: 'COMPLETED' }, null), + addUpdateKnowledgeAssetTokenReceipt: receipt, + }, }; } @@ -1386,27 +1414,27 @@ class AssetOperationsManager { async submitToParanet(UAL, paranetUAL, options = {}) { const blockchain = this.inputService.getBlockchain(options); - this.validationService.validateSubmitToParanet( - UAL, - paranetUAL, - blockchain, - ); + this.validationService.validateSubmitToParanet(UAL, paranetUAL, blockchain); const { contract, tokenId } = resolveUAL(UAL); const { contract: paranetContract, tokenId: paranetTokenId } = resolveUAL(paranetUAL); - await this.blockchainService.submitToParanet({ + let receipt = await this.blockchainService.submitToParanet( + { paranetContract, paranetTokenId, contract, tokenId, }, - blockchain + blockchain, ); return { UAL, - operation: getOperationStatusObject({ status: 'COMPLETED' }, null), + operation: { + status: getOperationStatusObject({ status: 'COMPLETED' }, null), + submitKnowledgeAssetToParanetReceipt: receipt, + }, }; } } diff --git a/managers/paranet-operations-manager.js b/managers/paranet-operations-manager.js index 0d5732b..83bcc32 100644 --- a/managers/paranet-operations-manager.js +++ b/managers/paranet-operations-manager.js @@ -42,7 +42,7 @@ class ParanetOperationsManager { const { contract, tokenId } = resolveUAL(UAL); - await this.blockchainService.registerParanet({ + let receipt = await this.blockchainService.registerParanet({ contract, tokenId, paranetName, @@ -53,6 +53,7 @@ class ParanetOperationsManager { return { paranetUAL: UAL, + createParanetReceipt: receipt }; } @@ -91,7 +92,7 @@ class ParanetOperationsManager { if(incentiveType === INCENTIVE_TYPE.NEUROWEB) { const {contract, tokenId} = resolveUAL(paranetUAL); - await this.blockchainService.deployNeuroIncentivesPool({ + let receipt = await this.blockchainService.deployNeuroIncentivesPool({ contract, tokenId, tracToNeuroEmissionMultiplier, @@ -109,7 +110,8 @@ class ParanetOperationsManager { return { paranetUAL, - incentivesPoolContractAddress: neuroIncentivesPoolAddress + incentivesPoolContractAddress: neuroIncentivesPoolAddress, + deployNeuroIncentivesPoolReceipt: receipt }; } @@ -146,7 +148,7 @@ class ParanetOperationsManager { const { contract, tokenId } = resolveUAL(UAL); - await this.blockchainService.registerParanetService({ + let receipt = await this.blockchainService.registerParanetService({ contract, tokenId, paranetServiceName, @@ -157,7 +159,8 @@ class ParanetOperationsManager { ); return { - serviceUAL: UAL + serviceUAL: UAL, + createParanetServiceReceipt: receipt }; } @@ -186,7 +189,7 @@ class ParanetOperationsManager { processedServicesArray.push([ serviceContract, serviceTokenId ]); } - await this.blockchainService.addParanetServices({ + let receipt = await this.blockchainService.addParanetServices({ contract, tokenId, processedServicesArray @@ -196,7 +199,8 @@ class ParanetOperationsManager { return { paranetUAL, - paranetServiceUALs + paranetServiceUALs, + addServicesToParanetReceipt: receipt }; } @@ -223,10 +227,7 @@ class ParanetOperationsManager { const receipt = await this.blockchainService.claimKnowledgeMinerReward(paranetId, blockchain); - return { - transactionHash: receipt.transactionHash, - status: receipt.status, - }; + return receipt; } /** @@ -251,10 +252,7 @@ class ParanetOperationsManager { ); const receipt = await this.blockchainService.claimVoterReward(paranetId, blockchain); - return { - transactionHash: receipt.transactionHash, - status: receipt.status, - }; + return receipt; } /** @@ -279,10 +277,7 @@ class ParanetOperationsManager { ); const receipt = await this.blockchainService.claimOperatorReward(paranetId, blockchain); - return { - transactionHash: receipt.transactionHash, - status: receipt.status, - }; + return receipt; } /** @@ -444,10 +439,7 @@ class ParanetOperationsManager { end: updatingKnowledgeAssetStates.length }, blockchain); - return { - transactionHash: receipt.transactionHash, - status: receipt.status, - }; + return receipt; } return { diff --git a/services/blockchain-service/blockchain-service-base.js b/services/blockchain-service/blockchain-service-base.js index 7bc50c8..2425e8e 100644 --- a/services/blockchain-service/blockchain-service-base.js +++ b/services/blockchain-service/blockchain-service-base.js @@ -285,7 +285,7 @@ class BlockchainServiceBase { data: { tokenId }, }); - return tokenId; + return [tokenId, receipt]; } catch (error) { if (tokensNeeded > 0) { await this.executeContractFunction( From 4a96374c66617d1d642b0142bf0333a2f2a1b083 Mon Sep 17 00:00:00 2001 From: Zvonimir Sculac Date: Tue, 10 Sep 2024 11:54:43 +0200 Subject: [PATCH 2/2] Apply PR suggestions --- managers/asset-operations-manager.js | 72 ++++++++----------- managers/paranet-operations-manager.js | 32 ++++++--- .../blockchain-service-base.js | 2 +- 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/managers/asset-operations-manager.js b/managers/asset-operations-manager.js index ee392f3..1d76d4d 100644 --- a/managers/asset-operations-manager.js +++ b/managers/asset-operations-manager.js @@ -149,7 +149,11 @@ class AssetOperationsManager { ); } - return receipt; + return { + operation: receipt, + transactionHash: receipt.transactionHash, + status: receipt.status, + }; } /** @@ -176,7 +180,11 @@ class AssetOperationsManager { blockchain, ); - return receipt; + return { + operation: receipt, + transactionHash: receipt.transactionHash, + status: receipt.status, + }; } /** @@ -213,7 +221,11 @@ class AssetOperationsManager { blockchain, ); - return receipt; + return { + operation: receipt, + transactionHash: receipt.transactionHash, + status: receipt.status, + }; } /** @@ -326,7 +338,7 @@ class AssetOperationsManager { let tokenId; let receipt; if (paranetUAL == null) { - [tokenId, receipt] = await this.blockchainService.createAsset( + ({tokenId, receipt} = await this.blockchainService.createAsset( { publicAssertionId, assertionSize: publicAssertionSizeInBytes, @@ -341,10 +353,10 @@ class AssetOperationsManager { null, blockchain, stepHooks, - ); + )); } else { const { contract: paranetKaContract, tokenId: paranetTokenId } = resolveUAL(paranetUAL); - [tokenId, receipt] = await this.blockchainService.createAsset( + ({tokenId, receipt} = await this.blockchainService.createAsset( { publicAssertionId, assertionSize: publicAssertionSizeInBytes, @@ -359,7 +371,7 @@ class AssetOperationsManager { paranetTokenId, blockchain, stepHooks, - ); + )); } const resolvedUAL = { @@ -445,7 +457,7 @@ class AssetOperationsManager { UAL, publicAssertionId, operation: { - mintKnowledgeAssetReceipt: receipt, + mintKnowledgeAsset: receipt, publish: getOperationStatusObject(publishOperationResult, publishOperationId), localStore: getOperationStatusObject( localStoreOperationResult, @@ -874,7 +886,7 @@ class AssetOperationsManager { }; } - let UpdateOperationId = await this.nodeApiService.update( + let updateOperationId = await this.nodeApiService.update( endpoint, port, authToken, @@ -892,14 +904,14 @@ class AssetOperationsManager { OPERATIONS.UPDATE, maxNumberOfRetries, frequency, - UpdateOperationId, + updateOperationId, ); return { UAL, publicAssertionId, operation: { - updateKnowledgeAssetReceipt: receipt, - localStore: getOperationStatusObject(localStoreOperationResult, UpdateOperationId), + updateKnowledgeAsset: receipt, + localStore: getOperationStatusObject(localStoreOperationResult, updateOperationId), update: getOperationStatusObject(updateOperationResult, localStoreOperationId), }, }; @@ -982,11 +994,7 @@ class AssetOperationsManager { return { UAL, - operation: { - status: getOperationStatusObject({ status: 'COMPLETED' }, null), - cancelKnowledgeAssetUpdateReceipt: receipt, - }, - cancelAssetUpdateReceipt: receipt, + operation: receipt, }; } @@ -1009,10 +1017,7 @@ class AssetOperationsManager { return { UAL, owner, - operation: { - status: getOperationStatusObject({ status: 'COMPLETED' }, null), - transferAssetReceipt: receipt, - }, + operation: receipt, }; } @@ -1142,10 +1147,7 @@ class AssetOperationsManager { let receipt = await this.blockchainService.burnAsset(tokenId, blockchain); return { UAL, - operation: { - status: getOperationStatusObject({ status: 'COMPLETED' }, null), - burnKnowledgeAssetReceipt: receipt, - }, + operation: receipt, }; } @@ -1212,10 +1214,7 @@ class AssetOperationsManager { return { UAL, - operation: { - status: getOperationStatusObject({ status: 'COMPLETED' }, null), - extendKnowledgeAssetStoringPeriodReceipt: receipt, - }, + operation: receipt, }; } @@ -1276,10 +1275,7 @@ class AssetOperationsManager { return { UAL, - operation: { - status: getOperationStatusObject({ status: 'COMPLETED' }, null), - addTokensForKnowledgeAssetReceipt: receipt, - }, + operation: receipt, }; } @@ -1343,10 +1339,7 @@ class AssetOperationsManager { return { UAL, - operation: { - status: getOperationStatusObject({ status: 'COMPLETED' }, null), - addUpdateKnowledgeAssetTokenReceipt: receipt, - }, + operation: receipt }; } @@ -1431,10 +1424,7 @@ class AssetOperationsManager { return { UAL, - operation: { - status: getOperationStatusObject({ status: 'COMPLETED' }, null), - submitKnowledgeAssetToParanetReceipt: receipt, - }, + operation: receipt }; } } diff --git a/managers/paranet-operations-manager.js b/managers/paranet-operations-manager.js index 83bcc32..979d967 100644 --- a/managers/paranet-operations-manager.js +++ b/managers/paranet-operations-manager.js @@ -53,7 +53,7 @@ class ParanetOperationsManager { return { paranetUAL: UAL, - createParanetReceipt: receipt + operation: receipt }; } @@ -111,7 +111,7 @@ class ParanetOperationsManager { return { paranetUAL, incentivesPoolContractAddress: neuroIncentivesPoolAddress, - deployNeuroIncentivesPoolReceipt: receipt + operation: receipt }; } @@ -160,7 +160,7 @@ class ParanetOperationsManager { return { serviceUAL: UAL, - createParanetServiceReceipt: receipt + operation: receipt }; } @@ -200,7 +200,7 @@ class ParanetOperationsManager { return { paranetUAL, paranetServiceUALs, - addServicesToParanetReceipt: receipt + operation: receipt }; } @@ -227,7 +227,11 @@ class ParanetOperationsManager { const receipt = await this.blockchainService.claimKnowledgeMinerReward(paranetId, blockchain); - return receipt; + return { + operation: receipt, + transactionHash: receipt.transactionHash, + status: receipt.status, + }; } /** @@ -252,7 +256,11 @@ class ParanetOperationsManager { ); const receipt = await this.blockchainService.claimVoterReward(paranetId, blockchain); - return receipt; + return { + operation: receipt, + transactionHash: receipt.transactionHash, + status: receipt.status, + }; } /** @@ -277,7 +285,11 @@ class ParanetOperationsManager { ); const receipt = await this.blockchainService.claimOperatorReward(paranetId, blockchain); - return receipt; + return { + operation: receipt, + transactionHash: receipt.transactionHash, + status: receipt.status, + }; } /** @@ -439,7 +451,11 @@ class ParanetOperationsManager { end: updatingKnowledgeAssetStates.length }, blockchain); - return receipt; + return { + operation: receipt, + transactionHash: receipt.transactionHash, + status: receipt.status, + }; } return { diff --git a/services/blockchain-service/blockchain-service-base.js b/services/blockchain-service/blockchain-service-base.js index 2425e8e..e9a49cc 100644 --- a/services/blockchain-service/blockchain-service-base.js +++ b/services/blockchain-service/blockchain-service-base.js @@ -285,7 +285,7 @@ class BlockchainServiceBase { data: { tokenId }, }); - return [tokenId, receipt]; + return { tokenId, receipt }; } catch (error) { if (tokensNeeded > 0) { await this.executeContractFunction(