diff --git a/lib/grpcServer/handlers/core/sendTransactionHandlerFactory.js b/lib/grpcServer/handlers/core/broadcastTransactionHandlerFactory.js similarity index 76% rename from lib/grpcServer/handlers/core/sendTransactionHandlerFactory.js rename to lib/grpcServer/handlers/core/broadcastTransactionHandlerFactory.js index 114a30ebf..d5e0618be 100644 --- a/lib/grpcServer/handlers/core/sendTransactionHandlerFactory.js +++ b/lib/grpcServer/handlers/core/broadcastTransactionHandlerFactory.js @@ -1,5 +1,5 @@ const { - SendTransactionResponse, + BroadcastTransactionResponse, } = require('@dashevo/dapi-grpc'); @@ -15,15 +15,15 @@ const { Transaction } = require('@dashevo/dashcore-lib'); /** * @param {InsightAPI} insightAPI - * @returns {sendTransactionHandler} + * @returns {broadcastTransactionHandler} */ -function sendTransactionHandlerFactory(insightAPI) { +function broadcastTransactionHandlerFactory(insightAPI) { /** - * @typedef sendTransactionHandler + * @typedef broadcastTransactionHandler * @param {Object} call - * @returns {Promise} + * @returns {Promise} */ - async function sendTransactionHandler(call) { + async function broadcastTransactionHandler(call) { const { request } = call; const serializedTransactionBinary = request.getTransaction(); @@ -60,13 +60,13 @@ function sendTransactionHandlerFactory(insightAPI) { throw e; } - const response = new SendTransactionResponse(); + const response = new BroadcastTransactionResponse(); response.setTransactionId(transactionId); return response; } - return sendTransactionHandler; + return broadcastTransactionHandler; } -module.exports = sendTransactionHandlerFactory; +module.exports = broadcastTransactionHandlerFactory; diff --git a/lib/grpcServer/handlers/core/coreHandlersFactory.js b/lib/grpcServer/handlers/core/coreHandlersFactory.js index a5b684bde..7de9e66f0 100644 --- a/lib/grpcServer/handlers/core/coreHandlersFactory.js +++ b/lib/grpcServer/handlers/core/coreHandlersFactory.js @@ -14,13 +14,13 @@ const { } = require('@dashevo/grpc-common'); const { - SendTransactionRequest, + BroadcastTransactionRequest, GetTransactionRequest, GetStatusRequest, GetBlockRequest, pbjs: { - SendTransactionRequest: PBJSSendTransactionRequest, - SendTransactionResponse: PBJSSendTransactionResponse, + BroadcastTransactionRequest: PBJSBroadcastTransactionRequest, + BroadcastTransactionResponse: PBJSBroadcastTransactionResponse, GetTransactionRequest: PBJSGetTransactionRequest, GetTransactionResponse: PBJSGetTransactionResponse, GetStatusRequest: PBJSGetStatusRequest, @@ -41,8 +41,8 @@ const getStatusHandlerFactory = require( const getTransactionHandlerFactory = require( './getTransactionHandlerFactory', ); -const sendTransactionHandlerFactory = require( - './sendTransactionHandlerFactory', +const broadcastTransactionHandlerFactory = require( + './broadcastTransactionHandlerFactory', ); /** @@ -91,24 +91,24 @@ function coreHandlersFactory(insightAPI) { wrapInErrorHandler(getTransactionHandler), ); - // sendTransaction - const sendTransactionHandler = sendTransactionHandlerFactory(insightAPI); - const wrappedSendTransaction = jsonToProtobufHandlerWrapper( + // broadcastTransaction + const broadcastTransactionHandler = broadcastTransactionHandlerFactory(insightAPI); + const wrappedBroadcastTransaction = jsonToProtobufHandlerWrapper( jsonToProtobufFactory( - SendTransactionRequest, - PBJSSendTransactionRequest, + BroadcastTransactionRequest, + PBJSBroadcastTransactionRequest, ), protobufToJsonFactory( - PBJSSendTransactionResponse, + PBJSBroadcastTransactionResponse, ), - wrapInErrorHandler(sendTransactionHandler), + wrapInErrorHandler(broadcastTransactionHandler), ); return { getBlock: wrappedGetBlock, getStatus: wrappedGetStatus, getTransaction: wrappedGetTransaction, - sendTransaction: wrappedSendTransaction, + broadcastTransaction: wrappedBroadcastTransaction, }; } diff --git a/lib/grpcServer/handlers/platform/applyStateTransitionHandlerFactory.js b/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js similarity index 74% rename from lib/grpcServer/handlers/platform/applyStateTransitionHandlerFactory.js rename to lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js index b42835903..c88d753f1 100644 --- a/lib/grpcServer/handlers/platform/applyStateTransitionHandlerFactory.js +++ b/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js @@ -7,7 +7,7 @@ const { } = require('@dashevo/grpc-common'); const { - ApplyStateTransitionResponse, + BroadcastStateTransitionResponse, } = require('@dashevo/dapi-grpc'); const AbciResponseError = require('../../../errors/AbciResponseError'); @@ -16,17 +16,17 @@ const AbciResponseError = require('../../../errors/AbciResponseError'); * @param {jaysonClient} rpcClient * @param {handleAbciResponseError} handleAbciResponseError * - * @returns {applyStateTransitionHandler} + * @returns {broadcastStateTransitionHandler} */ -function applyStateTransitionHandlerFactory(rpcClient, handleAbciResponseError) { +function broadcastStateTransitionHandlerFactory(rpcClient, handleAbciResponseError) { /** - * @typedef applyStateTransitionHandler + * @typedef broadcastStateTransitionHandler * * @param {Object} call * - * @return {Promise} + * @return {Promise} */ - async function applyStateTransitionHandler(call) { + async function broadcastStateTransitionHandler(call) { const { request } = call; const stByteArray = request.getStateTransition(); @@ -63,10 +63,10 @@ function applyStateTransitionHandlerFactory(rpcClient, handleAbciResponseError) ); } - return new ApplyStateTransitionResponse(); + return new BroadcastStateTransitionResponse(); } - return applyStateTransitionHandler; + return broadcastStateTransitionHandler; } -module.exports = applyStateTransitionHandlerFactory; +module.exports = broadcastStateTransitionHandlerFactory; diff --git a/lib/grpcServer/handlers/platform/platformHandlersFactory.js b/lib/grpcServer/handlers/platform/platformHandlersFactory.js index fff5cd509..4f516895d 100644 --- a/lib/grpcServer/handlers/platform/platformHandlersFactory.js +++ b/lib/grpcServer/handlers/platform/platformHandlersFactory.js @@ -14,15 +14,15 @@ const { } = require('@dashevo/grpc-common'); const { - ApplyStateTransitionRequest, + ApplyStateTransitionRequest: BroadcastStateTransitionRequest, GetIdentityRequest, GetDataContractRequest, GetDocumentsRequest, GetIdentityByFirstPublicKeyRequest, GetIdentityIdByFirstPublicKeyRequest, pbjs: { - ApplyStateTransitionRequest: PBJSApplyStateTransitionRequest, - ApplyStateTransitionResponse: PBJSApplyStateTransitionResponse, + ApplyStateTransitionRequest: PBJSBroadcastStateTransitionRequest, + ApplyStateTransitionResponse: PBJSBroadcastStateTransitionResponse, GetIdentityRequest: PBJSGetIdentityRequest, GetIdentityResponse: PBJSGetIdentityResponse, GetDataContractRequest: PBJSGetDataContractRequest, @@ -43,8 +43,8 @@ const handleAbciResponseError = require('../handleAbciResponseError'); const getIdentityHandlerFactory = require( './getIdentityHandlerFactory', ); -const applyStateTransitionHandlerFactory = require( - './applyStateTransitionHandlerFactory', +const broadcastStateTransitionHandlerFactory = require( + './broadcastStateTransitionHandlerFactory', ); const getDocumentsHandlerFactory = require( './getDocumentsHandlerFactory', @@ -67,21 +67,21 @@ const getIdentityIdByFirstPublicKeyHandlerFactory = require( function platformHandlersFactory(rpcClient, driveStateRepository) { const wrapInErrorHandler = wrapInErrorHandlerFactory(log); - // applyStateTransition - const applyStateTransitionHandler = applyStateTransitionHandlerFactory( + // broadcastStateTransition + const broadcastStateTransitionHandler = broadcastStateTransitionHandlerFactory( rpcClient, handleAbciResponseError, ); - const wrappedApplyStateTransition = jsonToProtobufHandlerWrapper( + const wrappedBroadcastStateTransition = jsonToProtobufHandlerWrapper( jsonToProtobufFactory( - ApplyStateTransitionRequest, - PBJSApplyStateTransitionRequest, + BroadcastStateTransitionRequest, + PBJSBroadcastStateTransitionRequest, ), protobufToJsonFactory( - PBJSApplyStateTransitionResponse, + PBJSBroadcastStateTransitionResponse, ), - wrapInErrorHandler(applyStateTransitionHandler), + wrapInErrorHandler(broadcastStateTransitionHandler), ); // getIdentity @@ -165,7 +165,7 @@ function platformHandlersFactory(rpcClient, driveStateRepository) { ); return { - applyStateTransition: wrappedApplyStateTransition, + broadcastStateTransition: wrappedBroadcastStateTransition, getIdentity: wrappedGetIdentity, getDocuments: wrappedGetDocuments, getDataContract: wrappedGetDataContract, diff --git a/package-lock.json b/package-lock.json index 0dd242457..0f30ff2fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -182,9 +182,9 @@ } }, "@dashevo/dapi-grpc": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/@dashevo/dapi-grpc/-/dapi-grpc-0.14.0.tgz", - "integrity": "sha512-eMx9OF80uxHFHD3gZ1Yro5pLTpgTuNQiy0Kts3mRDIjVyqgMbthIeYVcyzOwARs6FJrJfX18QnQ4kUt9b1ILKQ==", + "version": "0.15.0-dev.1", + "resolved": "https://registry.npmjs.org/@dashevo/dapi-grpc/-/dapi-grpc-0.15.0-dev.1.tgz", + "integrity": "sha512-2yfLGF3UsVmYRfbKsTRqI9NbL+gS9zF0J5iypiqgeEK4foDRV3zfhwGBGorJq9SWdYc+n7AtVS1OhFICkstIkw==", "requires": { "@dashevo/grpc-common": "^0.3.0", "google-protobuf": "^3.12.2", diff --git a/package.json b/package.json index 6cf5b66ff..353b4c382 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "all": true }, "dependencies": { - "@dashevo/dapi-grpc": "~0.14.0", + "@dashevo/dapi-grpc": "~0.15.0-dev.1", "@dashevo/dashcore-lib": "~0.18.11", "@dashevo/dashd-rpc": "^2.0.0", "@dashevo/dpp": "~0.14.0", diff --git a/test/unit/grpcServer/handlers/core/sendTransactionHandlerFactory.js b/test/unit/grpcServer/handlers/core/broadcastTransactionHandlerFactory.js similarity index 84% rename from test/unit/grpcServer/handlers/core/sendTransactionHandlerFactory.js rename to test/unit/grpcServer/handlers/core/broadcastTransactionHandlerFactory.js index 35f06d64c..fdef4d988 100644 --- a/test/unit/grpcServer/handlers/core/sendTransactionHandlerFactory.js +++ b/test/unit/grpcServer/handlers/core/broadcastTransactionHandlerFactory.js @@ -9,20 +9,20 @@ const { const { Transaction } = require('@dashevo/dashcore-lib'); const { - SendTransactionResponse, + BroadcastTransactionResponse, } = require('@dashevo/dapi-grpc'); -const sendTransactionHandlerFactory = require('../../../../../lib/grpcServer/handlers/core/sendTransactionHandlerFactory'); +const broadcastTransactionHandlerFactory = require('../../../../../lib/grpcServer/handlers/core/broadcastTransactionHandlerFactory'); const GrpcCallMock = require('../../../../../lib/test/mock/GrpcCallMock'); -describe('sendTransactionHandlerFactory', () => { +describe('broadcastTransactionHandlerFactory', () => { let call; let insightAPIMock; let request; let serializedTransaction; let transactionId; - let sendTransactionHandler; + let broadcastTransactionHandler; beforeEach(function beforeEach() { const rawTransaction = '0300000001086a3640a4a88a85d5720ecb69a93d0aef1cfa759d1242835e4abaf4168b924d000000006b483045022100ed608a9742913c94e057798297a6a96ed40c41dc61209e6887df51ea5755234802207f5733ef592f3df59bc6d39749ac5f1a771b32263ce16982b1aacc80ff1358cd012103323aa9dd83ba005b1b1e61b36cba27c2e0f64bacb57c34243fc7ef2751fff6edffffffff021027000000000000166a1481b21f3898087a0d1905140c7db8d7db00acd13954a09a3b000000001976a91481b21f3898087a0d1905140c7db8d7db00acd13988ac00000000'; @@ -41,13 +41,13 @@ describe('sendTransactionHandlerFactory', () => { sendTransaction: this.sinon.stub().resolves(transactionId), }; - sendTransactionHandler = sendTransactionHandlerFactory(insightAPIMock); + broadcastTransactionHandler = broadcastTransactionHandlerFactory(insightAPIMock); }); it('should return valid result', async () => { - const result = await sendTransactionHandler(call); + const result = await broadcastTransactionHandler(call); - expect(result).to.be.an.instanceOf(SendTransactionResponse); + expect(result).to.be.an.instanceOf(BroadcastTransactionResponse); expect(result.getTransactionId()).to.equal(transactionId); expect(insightAPIMock.sendTransaction).to.be.calledOnceWith(serializedTransaction.toString('hex')); }); @@ -57,7 +57,7 @@ describe('sendTransactionHandlerFactory', () => { request.getTransaction.returns(serializedTransaction); try { - await sendTransactionHandler(call); + await broadcastTransactionHandler(call); expect.fail('should thrown InvalidArgumentGrpcError error'); } catch (e) { @@ -72,7 +72,7 @@ describe('sendTransactionHandlerFactory', () => { request.getTransaction.returns(serializedTransaction); try { - await sendTransactionHandler(call); + await broadcastTransactionHandler(call); expect.fail('should thrown InvalidArgumentGrpcError error'); } catch (e) { @@ -87,7 +87,7 @@ describe('sendTransactionHandlerFactory', () => { request.getTransaction.returns(serializedTransaction); try { - await sendTransactionHandler(call); + await broadcastTransactionHandler(call); expect.fail('should thrown InvalidArgumentGrpcError error'); } catch (e) { diff --git a/test/unit/grpcServer/handlers/platform/applyStateTransitionHandlerFactory.js b/test/unit/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js similarity index 83% rename from test/unit/grpcServer/handlers/platform/applyStateTransitionHandlerFactory.js rename to test/unit/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js index 46de2dde7..533bdd961 100644 --- a/test/unit/grpcServer/handlers/platform/applyStateTransitionHandlerFactory.js +++ b/test/unit/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js @@ -7,7 +7,7 @@ const { } = require('@dashevo/grpc-common'); const { - ApplyStateTransitionResponse, + BroadcastStateTransitionResponse, } = require('@dashevo/dapi-grpc'); const DashPlatformProtocol = require('@dashevo/dpp'); @@ -15,14 +15,14 @@ const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataCo const GrpcCallMock = require('../../../../../lib/test/mock/GrpcCallMock'); -const applyStateTransitionHandlerFactory = require( - '../../../../../lib/grpcServer/handlers/platform/applyStateTransitionHandlerFactory', +const broadcastStateTransitionHandlerFactory = require( + '../../../../../lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory', ); -describe('applyStateTransitionHandlerFactory', () => { +describe('broadcastStateTransitionHandlerFactory', () => { let call; let rpcClientMock; - let applyStateTransitionHandler; + let broadcastStateTransitionHandler; let response; let stateTransitionFixture; let log; @@ -69,7 +69,7 @@ describe('applyStateTransitionHandlerFactory', () => { handleAbciResponseErrorMock = this.sinon.stub(); - applyStateTransitionHandler = applyStateTransitionHandlerFactory( + broadcastStateTransitionHandler = broadcastStateTransitionHandlerFactory( rpcClientMock, handleAbciResponseErrorMock, ); @@ -83,7 +83,7 @@ describe('applyStateTransitionHandlerFactory', () => { call.request.getStateTransition.returns(null); try { - await applyStateTransitionHandler(call); + await broadcastStateTransitionHandler(call); expect.fail('InvalidArgumentGrpcError was not thrown'); } catch (e) { @@ -95,11 +95,11 @@ describe('applyStateTransitionHandlerFactory', () => { }); it('should return valid result', async () => { - const result = await applyStateTransitionHandler(call); + const result = await broadcastStateTransitionHandler(call); const tx = stateTransitionFixture.serialize().toString('base64'); - expect(result).to.be.an.instanceOf(ApplyStateTransitionResponse); + expect(result).to.be.an.instanceOf(BroadcastStateTransitionResponse); expect(rpcClientMock.request).to.be.calledOnceWith('broadcast_tx_commit', { tx }); expect(handleAbciResponseErrorMock).to.not.be.called(); }); @@ -115,7 +115,7 @@ describe('applyStateTransitionHandlerFactory', () => { rpcClientMock.request.resolves(response); try { - await applyStateTransitionHandler(call); + await broadcastStateTransitionHandler(call); expect.fail('InternalGrpcError was not thrown'); } catch (e) { @@ -133,7 +133,7 @@ describe('applyStateTransitionHandlerFactory', () => { rpcClientMock.request.resolves(response); try { - await applyStateTransitionHandler(call); + await broadcastStateTransitionHandler(call); expect.fail('InternalGrpcError was not thrown'); } catch (e) { @@ -147,7 +147,7 @@ describe('applyStateTransitionHandlerFactory', () => { response.error = error; try { - await applyStateTransitionHandler(call); + await broadcastStateTransitionHandler(call); } catch (e) { expect(e.message).to.equal(error.message); expect(e.data).to.equal(error.data);