Skip to content

Commit

Permalink
Feature/2243 trustchain retirement support (#4513)
Browse files Browse the repository at this point in the history
* WIP: Add token retirement info in trustchain.

* Add receiving token info.

* WIP 2243

* WIP: 2 2243

* WIP 3: 2243

* WIP: Add check indexer availability status.
Change trust chain component.
Add api, services.
Add styles.

* WIP: Merge stash fix.

* WIP: Map retirements.

* [skip ci] Add swagger.yaml

* Remove debug code of WIP commits.

* Improve trust chain component.
Add interfaces.
Add receiving transaction timestamp.

* Improve new trust chain.
Improve trust chain.

* [skip ci] Add swagger.yaml

* Add target field to vp document.
Fix token retirement schema.

* Add sequence number for retirement message for hedera explorer.

* [skip ci] Add swagger.yaml

* Add retirements and message order for advanced view.

* Fix single token retirement display.

* Add hedera explorer to old trust chain retirement message.

* Add retirement messages ordering in new trust chain.

* Simplify logic and improve readability.

* [skip ci] Add swagger.yaml

* Simplify logic and improve readability.

Signed-off-by: Dariy Miseldzhani <[email protected]>

* fix build
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* fix build
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix build
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix build
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

---------

Signed-off-by: Dariy Miseldzhani <[email protected]>
Signed-off-by: simvalery <[email protected]>
Co-authored-by: Dariy Miseldzhani <[email protected]>
Co-authored-by: envision-ci-agent <[email protected]>
Co-authored-by: simvalery <[email protected]>
  • Loading branch information
4 people authored Jan 17, 2025
1 parent 81902b3 commit f785764
Show file tree
Hide file tree
Showing 34 changed files with 2,219 additions and 1,503 deletions.
33 changes: 32 additions & 1 deletion api-gateway/src/api/service/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, HttpCode, HttpException, HttpStatus, Post, Query } from '@nestjs/common';
import { Body, Controller, Get, HttpCode, HttpException, HttpStatus, Post, Query } from '@nestjs/common';
import { ApiInternalServerErrorResponse, ApiBody, ApiOkResponse, ApiOperation, ApiTags, ApiExtraModels, ApiQuery } from '@nestjs/swagger';
import { EntityOwner, Permissions } from '@guardian/interfaces';
import { FilterDocumentsDTO, FilterModulesDTO, FilterPoliciesDTO, FilterSchemasDTO, FilterSearchPoliciesDTO, InternalServerErrorDTO, CompareDocumentsDTO, CompareModulesDTO, ComparePoliciesDTO, CompareSchemasDTO, SearchPoliciesDTO, FilterToolsDTO, CompareToolsDTO, FilterSearchBlocksDTO, SearchBlocksDTO, Examples } from '#middlewares';
Expand Down Expand Up @@ -947,4 +947,35 @@ export class AnalyticsApi {
await InternalException(error, this.logger);
}
}

/**
* Get Indexer availability
*/
@Get('/checkIndexer')
@Auth(
Permissions.POLICIES_POLICY_EXECUTE,
)
@ApiOperation({
summary: 'Get Indexer Availability.',
description: 'Returns Indexer Availability (true/false).',
})
@ApiOkResponse({
description: 'Successful operation.',
type: Boolean,
})
@ApiInternalServerErrorResponse({
description: 'Internal server error.',
type: InternalServerErrorDTO
})
@HttpCode(HttpStatus.OK)
async checkIndexerAvailability(
@AuthUser() user: IAuthUser
): Promise<boolean> {
const guardians = new Guardians();
try {
return await guardians.getIndexerAvailability();
} catch (error) {
await InternalException(error, this.logger);
}
}
}
52 changes: 52 additions & 0 deletions api-gateway/src/api/service/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1719,5 +1719,57 @@ export class ContractsApi {
await InternalException(error, this.logger);
}
}

/**
* Get a list of all retire vcs from Indexer
*/
@Get('/retireIndexer')
@Auth(
Permissions.CONTRACTS_DOCUMENT_READ,
// UserRole.STANDARD_REGISTRY,
// UserRole.USER
)
@ApiOperation({
summary: 'Return a list of all retire vcs from Indexer.',
description: 'Returns all retire vcs from Indexer.',
})
@ApiQuery({
name: 'contractTopicId',
type: String,
description: 'The topic id of contract',
required: true,
example: '0.0.0000000',
})
@ApiOkResponse({
description: 'Successful operation.',
isArray: true,
headers: pageHeader,
schema: {
type: 'array',
items: {
type: 'object'
}
}
})
@ApiInternalServerErrorResponse({
description: 'Internal server error.',
type: InternalServerErrorDTO,
})
@ApiExtraModels(RetirePoolDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.OK)
async getRetireVCsFromIndexer(
@AuthUser() user: IAuthUser,
@Response() res: any,
@Query('contractTopicId') contractTopicId: string,
): Promise<any[]> {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();
const [vcs, count] = await guardians.getRetireVCsFromIndexer(owner, contractTopicId);
return res.header('X-Total-Count', count).send(vcs);
} catch (error) {
await InternalException(error, this.logger);
}
}
//#endregion
}
26 changes: 26 additions & 0 deletions api-gateway/src/helpers/guardians.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
IContract,
IDidObject,
IOwner,
IRetirementMessage,
IRetirePool,
IRetireRequest,
ISchema,
IToken,
ITokenInfo,
IUser,
IVC,
IVCDocument,
IVPDocument,
MessageAPI,
Expand Down Expand Up @@ -1852,6 +1854,22 @@ export class Guardians extends NatsService {
});
}

/**
* Get retire VCs from Indexer
* @param owner
* @param contractTopicId
* @returns Retire VCs from Indexer and count
*/
public async getRetireVCsFromIndexer(
owner: IOwner,
contractTopicId: string
): Promise<[IRetirementMessage[], number]> {
return await this.sendMessage(ContractAPI.GET_RETIRE_VCS_FROM_INDEXER, {
owner,
contractTopicId
});
}

//#endregion

/**
Expand Down Expand Up @@ -3204,6 +3222,14 @@ export class Guardians extends NatsService {
return await this.sendMessage(MessageAPI.PREVIEW_SCHEMA_RULE_FILE, { zip, owner });
}


/**
* Get Indexer availability
*/
public async getIndexerAvailability(): Promise<boolean> {
return await this.sendMessage(MessageAPI.GET_INDEXER_AVAILABILITY, {});
}

/**
* Create policy label
*
Expand Down
6 changes: 4 additions & 2 deletions common/src/database-modules/database-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,8 @@ export class DatabaseServer extends AbstractDatabaseServer {
wasTransferNeeded: boolean,
transferSerials: number[],
transferAmount: number,
tokenIds: string[]
tokenIds: string[],
target: string
]
> {
const mintRequests = await this.getMintRequests({
Expand Down Expand Up @@ -2100,7 +2101,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
if (vpDocument.tokenId) {
tokenIds.add(vpDocument.tokenId);
}

const target = mintRequests?.[0]?.target;
for (const mintRequest of mintRequests) {
if (mintRequest.error) {
errors.push(mintRequest.error);
Expand Down Expand Up @@ -2172,6 +2173,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
transferSerials,
transferAmount,
[...tokenIds],
target,
];
}

Expand Down
3 changes: 2 additions & 1 deletion common/src/interfaces/database-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,8 @@ export abstract class AbstractDatabaseServer {
wasTransferNeeded: boolean,
transferSerials: number[],
transferAmount: number,
tokenIds: string[]
tokenIds: string[],
target: string,
]
>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class UserRetirePoolsDialogComponent implements OnInit {

loadPools() {
this.loading = true;

this.contractService
.getRetirePools({
pageIndex: this.pageIndex,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CommonModule, DatePipe } from '@angular/common';
import { MaterialModule } from 'src/app/modules/common/material.module';
import { FormsModule } from '@angular/forms';
import { DragDropModule } from '@angular/cdk/drag-drop';
Expand Down Expand Up @@ -295,6 +295,7 @@ import { RequestDocumentBlockDialog } from './policy-viewer/blocks/request-docum
WizardService,
DialogService,
PolicyProgressService,
DatePipe,
{
provide: CONFIGURATION_ERRORS,
useValue: new Map()
Expand Down
Loading

0 comments on commit f785764

Please sign in to comment.