Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
feat!: rename sendTransaction and applyStateTransition to broadcast (#…
Browse files Browse the repository at this point in the history
…287)

BREAKING CHANGE: sendTransaction and applyStateTransition renamed to broadcastTransaction and broadcastStateTransition
  • Loading branch information
Konstantin Shuplenkov authored Jul 28, 2020
1 parent 88f9d66 commit de97ffd
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
SendTransactionResponse,
BroadcastTransactionResponse,
} = require('@dashevo/dapi-grpc');


Expand All @@ -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<SendTransactionResponse>}
* @returns {Promise<BroadcastTransactionResponse>}
*/
async function sendTransactionHandler(call) {
async function broadcastTransactionHandler(call) {
const { request } = call;

const serializedTransactionBinary = request.getTransaction();
Expand Down Expand Up @@ -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;
26 changes: 13 additions & 13 deletions lib/grpcServer/handlers/core/coreHandlersFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,8 +41,8 @@ const getStatusHandlerFactory = require(
const getTransactionHandlerFactory = require(
'./getTransactionHandlerFactory',
);
const sendTransactionHandlerFactory = require(
'./sendTransactionHandlerFactory',
const broadcastTransactionHandlerFactory = require(
'./broadcastTransactionHandlerFactory',
);

/**
Expand Down Expand Up @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
} = require('@dashevo/grpc-common');

const {
ApplyStateTransitionResponse,
BroadcastStateTransitionResponse,
} = require('@dashevo/dapi-grpc');

const AbciResponseError = require('../../../errors/AbciResponseError');
Expand All @@ -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<ApplyStateTransitionResponse>}
* @return {Promise<BroadcastStateTransitionResponse>}
*/
async function applyStateTransitionHandler(call) {
async function broadcastStateTransitionHandler(call) {
const { request } = call;
const stByteArray = request.getStateTransition();

Expand Down Expand Up @@ -63,10 +63,10 @@ function applyStateTransitionHandlerFactory(rpcClient, handleAbciResponseError)
);
}

return new ApplyStateTransitionResponse();
return new BroadcastStateTransitionResponse();
}

return applyStateTransitionHandler;
return broadcastStateTransitionHandler;
}

module.exports = applyStateTransitionHandlerFactory;
module.exports = broadcastStateTransitionHandlerFactory;
26 changes: 13 additions & 13 deletions lib/grpcServer/handlers/platform/platformHandlersFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,8 +43,8 @@ const handleAbciResponseError = require('../handleAbciResponseError');
const getIdentityHandlerFactory = require(
'./getIdentityHandlerFactory',
);
const applyStateTransitionHandlerFactory = require(
'./applyStateTransitionHandlerFactory',
const broadcastStateTransitionHandlerFactory = require(
'./broadcastStateTransitionHandlerFactory',
);
const getDocumentsHandlerFactory = require(
'./getDocumentsHandlerFactory',
Expand All @@ -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
Expand Down Expand Up @@ -165,7 +165,7 @@ function platformHandlersFactory(rpcClient, driveStateRepository) {
);

return {
applyStateTransition: wrappedApplyStateTransition,
broadcastStateTransition: wrappedBroadcastStateTransition,
getIdentity: wrappedGetIdentity,
getDocuments: wrappedGetDocuments,
getDataContract: wrappedGetDataContract,
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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'));
});
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ const {
} = require('@dashevo/grpc-common');

const {
ApplyStateTransitionResponse,
BroadcastStateTransitionResponse,
} = require('@dashevo/dapi-grpc');

const DashPlatformProtocol = require('@dashevo/dpp');
const getDataContractFixture = require('@dashevo/dpp/lib/test/fixtures/getDataContractFixture');

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;
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('applyStateTransitionHandlerFactory', () => {

handleAbciResponseErrorMock = this.sinon.stub();

applyStateTransitionHandler = applyStateTransitionHandlerFactory(
broadcastStateTransitionHandler = broadcastStateTransitionHandlerFactory(
rpcClientMock,
handleAbciResponseErrorMock,
);
Expand All @@ -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) {
Expand All @@ -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();
});
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit de97ffd

Please sign in to comment.