Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2243 trustchain retirement support #4513

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
206ee02
WIP: Add token retirement info in trustchain.
Nov 22, 2024
b349d6b
Add receiving token info.
Dec 5, 2024
40731c6
WIP 2243
Dec 11, 2024
7f3da4d
WIP: 2 2243
Dec 12, 2024
70b73df
WIP 3: 2243
Dec 12, 2024
55fc2ff
WIP: Add check indexer availability status.
Dec 16, 2024
e03af02
WIP: Merge stash fix.
Dec 16, 2024
bdc01ca
WIP: Map retirements.
Dec 16, 2024
e0f3c00
[skip ci] Add swagger.yaml
envision-ci-agent Dec 16, 2024
79c68e3
Remove debug code of WIP commits.
Dec 17, 2024
5749ddd
Merge branch 'develop' into feature/2243-trustchain-retirement-support
Dec 17, 2024
495c400
Improve trust chain component.
Dec 18, 2024
9b21e87
Improve new trust chain.
Dec 18, 2024
db1dd67
[skip ci] Add swagger.yaml
envision-ci-agent Dec 18, 2024
4a1ef45
Add target field to vp document.
Dec 19, 2024
4e35950
Add sequence number for retirement message for hedera explorer.
Dec 19, 2024
c983b49
Merge branch 'feature/2243-trustchain-retirement-support' of https://…
Dec 19, 2024
939a204
[skip ci] Add swagger.yaml
envision-ci-agent Dec 19, 2024
1d44a67
Add retirements and message order for advanced view.
Dec 19, 2024
7902a8e
Merge branch 'feature/2243-trustchain-retirement-support' of https://…
Dec 19, 2024
d366570
Fix single token retirement display.
Dec 20, 2024
e6712be
Add hedera explorer to old trust chain retirement message.
Dec 20, 2024
9232211
Add retirement messages ordering in new trust chain.
Dec 20, 2024
346d787
Merge branch 'develop' into feature/2243-trustchain-retirement-support
Dec 21, 2024
fc420ad
Simplify logic and improve readability.
Dec 21, 2024
c27ddb6
[skip ci] Add swagger.yaml
envision-ci-agent Dec 21, 2024
5701695
Simplify logic and improve readability.
Dec 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1846,6 +1848,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 @@ -3197,4 +3215,12 @@ export class Guardians extends NatsService {
public async previewSchemaRule(zip: any, owner: IOwner) {
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, {});
}
}
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 @@ -2063,7 +2063,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 @@ -2098,7 +2099,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 @@ -2170,6 +2171,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 @@ -52,6 +52,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
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@
<div class="message-owner">{{message.__issuer}}</div>
</div>
</ng-container>

<ng-container *ngIf="message.__ifRetireMessage">
<div class="message-header">
<mat-icon>receipt</mat-icon>
Retirement
</div>
<div class="message-data">
<div *ngIf="message.documents[0]?.credentialSubject[0]?.contractId" class="message-name">
Contract ID: <span>{{message.documents[0].credentialSubject[0].contractId}}</span>
</div>
<div *ngIf="message.documents[0]?.credentialSubject[0]?.user" class="message-name">
User ID: <span>{{message.documents[0].credentialSubject[0].user}}</span>
</div>
</div>
</ng-container>
</div>
</div>
</div>
Expand Down Expand Up @@ -730,6 +745,75 @@
</div>
</div>
</ng-container>

<ng-container *ngIf="selected.__ifRetireMessage">
<div class="document-header">
<mat-icon>receipt</mat-icon>
Retirement message
</div>

<div class="field-delimiter" data-label="Document"></div>

<div class="field" *ngIf="selected.documents">
<div class="field-name">Document artifact:</div>
<div class="field-value">
<span class="field-link" (click)="onOpenDocument(selected)">Open document</span>
</div>
</div>

<div class="field-delimiter" data-label="Retirement Information"></div>
<div class="field">
<div class="field-name">Contract ID:</div>
<div class="field-value">{{selected.documents[0].credentialSubject[0].contractId}}</div>
</div>
<div class="field" *ngIf="selected.owner">
<div class="field-name">User ID:</div>
<div class="field-value">{{selected.documents[0].credentialSubject[0].user}}</div>
</div>
<div class="field" *ngIf="selected.consensusTimestamp">
<div class="field-name">Transaction:</div>
<div class="field-value">{{selected.consensusTimestamp}}</div>
</div>
<div *ngFor="let token of selected.documents[0].credentialSubject[0]?.tokens">
<div class="field-delimiter"></div>
<div class="field">
<div class="field-name">Token ID:</div>
<div class="field-value">{{token.tokenId}}</div>
</div>
<div class="field" *ngIf="token.serials && token.serials.length > 0">
<div class="field-name">Instance ID:</div>
<div class="field-value">{{token.serials.join(', ')}}</div>
</div>
<div class="field" *ngIf="!token.serials || token.serials.length <= 0">
<div class="field-name">Amount:</div>
<div class="field-value">{{token.count}}</div>
</div>
</div>

<div class="field-delimiter" data-label="Hedera Information"></div>

<div class="field">
<div class="field-name">Topic ID:</div>
<div class="field-value">
<hedera-explorer type="topics"
[params]="selected.topicId">{{selected.topicId}}</hedera-explorer>
</div>
</div>
<div class="field">
<div class="field-name">Message ID:</div>
<div class="field-value">
<hedera-explorer type="topics" [params]="selected.topicId" subType="messages"
[subParams]="selected.sequenceNumber">{{selected.consensusTimestamp}}</hedera-explorer>
</div>
</div>
<div class="field">
<div class="field-name">Owner:</div>
<div class="field-value">
<hedera-explorer type="accounts"
[params]="selected.owner">{{selected.owner}}</hedera-explorer>
</div>
</div>
</ng-container>
</div>
</div>
</div>
Expand Down
Loading
Loading