From 24db899805f9fe7828ebec625da0cd6e6800f5b8 Mon Sep 17 00:00:00 2001 From: tipusinghaw Date: Sun, 8 Oct 2023 22:04:25 +0530 Subject: [PATCH] feat:endorser sumbit transaction Signed-off-by: tipusinghaw Signed-off-by: KulkarniShashank --- .../src/agent-service.controller.ts | 4 ++++ .../src/ecosystem/ecosystem.controller.ts | 17 +++++++++++++++-- .../interfaces/ecosystem.interfaces.ts | 13 +++++++++++++ apps/ecosystem/src/ecosystem.service.ts | 10 +++++----- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/apps/agent-service/src/agent-service.controller.ts b/apps/agent-service/src/agent-service.controller.ts index 38c658264..8b1b4dfce 100644 --- a/apps/agent-service/src/agent-service.controller.ts +++ b/apps/agent-service/src/agent-service.controller.ts @@ -116,4 +116,8 @@ export class AgentServiceController { async signTransaction(payload: { url: string, apiKey: string, signEndorsementPayload:string }): Promise { return this.agentServiceService.signTransaction(payload.url, payload.apiKey, payload.signEndorsementPayload); } + @MessagePattern({ cmd: 'agent-submit-transaction' }) + async submitTransaction(payload: { url: string, apiKey: string, submitEndorsementPayload:string }): Promise { + return this.agentServiceService.sumbitTransaction(payload.url, payload.apiKey, payload.submitEndorsementPayload); + } } diff --git a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts index 746620081..8421faf9a 100644 --- a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts +++ b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts @@ -159,7 +159,7 @@ export class EcosystemController { @Post('/:orgId/transaction/schema') @ApiOperation({ summary: 'Request new schema', description: 'Request new schema' }) @ApiResponse({ status: 201, description: 'Success', type: ApiResponseDto }) - @UseGuards(AuthGuard('jwt')) + // @UseGuards(AuthGuard('jwt')) @ApiBearerAuth() async requestSchemaTransaction(@Body() requestSchemaPayload: RequestSchemaDto, @Param('orgId') orgId: number, @Res() res: Response): Promise { await this.ecosystemService.schemaEndorsementRequest(requestSchemaPayload, orgId); @@ -173,7 +173,7 @@ export class EcosystemController { @Post('transaction/sign/:endorsementId') @ApiOperation({ summary: 'Sign transaction', description: 'Sign transaction' }) @ApiResponse({ status: 201, description: 'Success', type: ApiResponseDto }) - @UseGuards(AuthGuard('jwt')) + // @UseGuards(AuthGuard('jwt')) @ApiBearerAuth() async SignEndorsementRequests(@Param('endorsementId') endorsementId: string, @Res() res: Response): Promise { await this.ecosystemService.signTransaction(endorsementId); @@ -184,6 +184,19 @@ export class EcosystemController { return res.status(HttpStatus.CREATED).json(finalResponse); } + @Post('transaction/sumbit/:endorsementId') + @ApiOperation({ summary: 'Sumbit transaction', description: 'Sumbit transaction' }) + @ApiResponse({ status: 201, description: 'Success', type: ApiResponseDto }) + // @UseGuards(AuthGuard('jwt')) + @ApiBearerAuth() + async SumbitEndorsementRequests(@Param('endorsementId') endorsementId: string, @Res() res: Response): Promise { + await this.ecosystemService.submitTransaction(endorsementId); + const finalResponse: IResponseType = { + statusCode: HttpStatus.CREATED, + message: ResponseMessages.ecosystem.success.sign + }; + return res.status(HttpStatus.CREATED).json(finalResponse); + } /** * * @param bulkInvitationDto diff --git a/apps/ecosystem/interfaces/ecosystem.interfaces.ts b/apps/ecosystem/interfaces/ecosystem.interfaces.ts index fb0e27946..7657ef28c 100644 --- a/apps/ecosystem/interfaces/ecosystem.interfaces.ts +++ b/apps/ecosystem/interfaces/ecosystem.interfaces.ts @@ -49,3 +49,16 @@ export interface SignedTransactionMessage { signedTransaction: string; }; } + +export interface EndorsementTransactionPayload { + id: string; + endorserDid: string; + authorDid: string; + requestPayload: string; + responsePayload: string; + status: string; + ecosystemOrgId: string; + ecosystemOrgs?: { + orgId: string; + }; +} diff --git a/apps/ecosystem/src/ecosystem.service.ts b/apps/ecosystem/src/ecosystem.service.ts index 37bc1bf30..8d7a4e718 100644 --- a/apps/ecosystem/src/ecosystem.service.ts +++ b/apps/ecosystem/src/ecosystem.service.ts @@ -103,14 +103,14 @@ export class EcosystemService { try { const { orgId, status, invitationId } = acceptRejectInvitation; const invitation = await this.ecosystemRepository.getEcosystemInvitationById(invitationId); - + if (!invitation) { throw new NotFoundException(ResponseMessages.ecosystem.error.invitationNotFound); } const updatedInvitation = await this.updateEcosystemInvitation(invitationId, orgId, status); if (!updatedInvitation) { - throw new NotFoundException(ResponseMessages.ecosystem.error.invitationNotUpdate); + throw new NotFoundException(ResponseMessages.ecosystem.error.invitationNotUpdate); } if (status === Invitation.REJECTED) { @@ -124,13 +124,13 @@ export class EcosystemService { throw new NotFoundException(ResponseMessages.ecosystem.error.orgsNotUpdate); } return ResponseMessages.ecosystem.success.invitationAccept; - + } catch (error) { this.logger.error(`acceptRejectInvitations: ${error}`); throw new RpcException(error.response ? error.response : error); } } - + async updatedEcosystemOrgs(orgId: string, ecosystemId: string, ecosystemRoleId: string): Promise { try { const data = { @@ -153,7 +153,7 @@ export class EcosystemService { */ async updateEcosystemInvitation(invitationId: string, orgId: string, status: string): Promise { try { - + const data = { status, orgId: String(orgId)