Skip to content

Commit

Permalink
feat: 🎸 support asset IDs as uuids
Browse files Browse the repository at this point in the history
also return the assetId as `asset` in the response when creating an
asset
  • Loading branch information
polymath-eric committed Nov 1, 2024
1 parent c45f077 commit e2b1883
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 76 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@polymeshassociation/fireblocks-signing-manager": "^2.5.0",
"@polymeshassociation/hashicorp-vault-signing-manager": "^3.4.0",
"@polymeshassociation/local-signing-manager": "^3.3.0",
"@polymeshassociation/polymesh-sdk": "26.0.0-beta.1",
"@polymeshassociation/polymesh-sdk": "^26.1.0",
"@polymeshassociation/signing-manager-types": "^3.2.0",
"class-transformer": "0.5.1",
"class-validator": "^0.14.0",
Expand Down
44 changes: 27 additions & 17 deletions src/assets/assets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ApiTags,
ApiUnprocessableEntityResponse,
} from '@nestjs/swagger';
import { Asset } from '@polymeshassociation/polymesh-sdk/types';

import { AssetsService } from '~/assets/assets.service';
import { createAssetDetailsModel } from '~/assets/assets.util';
Expand All @@ -23,6 +24,7 @@ import { SetAssetDocumentsDto } from '~/assets/dto/set-asset-documents.dto';
import { AgentOperationModel } from '~/assets/models/agent-operation.model';
import { AssetDetailsModel } from '~/assets/models/asset-details.model';
import { AssetDocumentModel } from '~/assets/models/asset-document.model';
import { CreatedAssetModel } from '~/assets/models/created-asset.model';
import { IdentityBalanceModel } from '~/assets/models/identity-balance.model';
import { RequiredMediatorsModel } from '~/assets/models/required-mediators.model';
import { authorizationRequestResolver } from '~/authorizations/authorizations.util';
Expand All @@ -33,7 +35,7 @@ import { TransactionBaseDto } from '~/common/dto/transaction-base-dto';
import { TransferOwnershipDto } from '~/common/dto/transfer-ownership.dto';
import { PaginatedResultsModel } from '~/common/models/paginated-results.model';
import { TransactionQueueModel } from '~/common/models/transaction-queue.model';
import { handleServiceResult, TransactionResponseModel } from '~/common/utils';
import { handleServiceResult, TransactionResolver, TransactionResponseModel } from '~/common/utils';
import { MetadataService } from '~/metadata/metadata.service';
import { GlobalMetadataModel } from '~/metadata/models/global-metadata.model';

Expand Down Expand Up @@ -72,7 +74,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose details are to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiOkResponse({
description: 'Basic details of the Asset',
Expand All @@ -94,7 +96,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose holders are to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiQuery({
name: 'size',
Expand Down Expand Up @@ -146,7 +148,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose attached documents are to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiQuery({
name: 'size',
Expand Down Expand Up @@ -203,7 +205,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose documents are to be updated',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiOkResponse({
description: 'Details of the transaction',
Expand Down Expand Up @@ -231,7 +233,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) to issue',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details about the transaction',
Expand Down Expand Up @@ -266,7 +268,15 @@ export class AssetsController {
@Post('create')
public async createAsset(@Body() params: CreateAssetDto): Promise<TransactionResponseModel> {
const result = await this.assetsService.createAsset(params);
return handleServiceResult(result);

const resolver: TransactionResolver<Asset> = ({ result: asset, transactions, details }) =>
new CreatedAssetModel({
asset,
transactions,
details,
});

return handleServiceResult(result, resolver);
}

@ApiOperation({
Expand All @@ -278,7 +288,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose ownership is to be transferred',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Newly created Authorization Request along with transaction details',
Expand Down Expand Up @@ -329,7 +339,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) to freeze',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details about the transaction',
Expand Down Expand Up @@ -360,7 +370,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) to unfreeze',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details about the transaction',
Expand Down Expand Up @@ -390,7 +400,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) to be transferred',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details about the transaction',
Expand Down Expand Up @@ -420,7 +430,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose operation history is to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiOkResponse({
description: 'List of operations grouped by the agent Identity who performed them',
Expand All @@ -445,7 +455,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose required mediators is to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiOkResponse({
description: 'The required mediators for the asset',
Expand All @@ -470,7 +480,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) to set required mediators for',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details about the transaction',
Expand All @@ -496,7 +506,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) to set required mediators for',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details about the transaction',
Expand All @@ -522,7 +532,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) to pre-approve',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details about the transaction',
Expand Down Expand Up @@ -552,7 +562,7 @@ export class AssetsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) to remove pre-approval for',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details about the transaction',
Expand Down
23 changes: 23 additions & 0 deletions src/assets/models/created-asset.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* istanbul ignore file */

import { ApiPropertyOptional } from '@nestjs/swagger';
import { Asset } from '@polymeshassociation/polymesh-sdk/types';

import { FromEntity } from '~/common/decorators/transformation';
import { TransactionQueueModel } from '~/common/models/transaction-queue.model';

export class CreatedAssetModel extends TransactionQueueModel {
@ApiPropertyOptional({
description: 'The newly created Asset ID',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@FromEntity()
readonly asset: Asset;

constructor(model: CreatedAssetModel) {
const { transactions, details, ...rest } = model;
super({ transactions, details });

Object.assign(this, rest);
}
}
22 changes: 11 additions & 11 deletions src/checkpoints/checkpoints.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose attached Checkpoints are to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiQuery({
name: 'size',
Expand Down Expand Up @@ -112,7 +112,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose Checkpoint is to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiParam({
name: 'id',
Expand Down Expand Up @@ -148,7 +148,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) for which the Checkpoint is to be created',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details of the newly created Checkpoint',
Expand Down Expand Up @@ -185,7 +185,7 @@ export class CheckpointsController {
description:
'The Asset (Ticker/Asset ID) whose attached Checkpoint Schedules are to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiArrayResponse(CheckpointScheduleModel, {
description: 'List of active Schedules which create Checkpoints for a specific Asset',
Expand Down Expand Up @@ -217,7 +217,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose Checkpoint Schedule is to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiParam({
name: 'id',
Expand Down Expand Up @@ -258,7 +258,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) for which the Checkpoint creation is to be scheduled',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiTransactionResponse({
description: 'Details of the newly created Checkpoint Schedule',
Expand Down Expand Up @@ -309,7 +309,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) for which to fetch holder balances',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiParam({
name: 'id',
Expand Down Expand Up @@ -401,7 +401,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) for which the Schedule is to be deleted',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiParam({
name: 'id',
Expand Down Expand Up @@ -437,7 +437,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose Checkpoints are to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiParam({
name: 'scheduleId',
Expand Down Expand Up @@ -474,7 +474,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) for which Schedule complexity is to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiNotFoundResponse({
description: 'The Asset was not found',
Expand Down Expand Up @@ -506,7 +506,7 @@ export class CheckpointsController {
name: 'asset',
description: 'The Asset (Ticker/Asset ID) whose Checkpoint Schedule is to be fetched',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
@ApiParam({
name: 'id',
Expand Down
2 changes: 1 addition & 1 deletion src/checkpoints/models/checkpoint-schedule.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class CheckpointScheduleModel {
@ApiProperty({
description: 'The Asset (Asset ID/Ticker) whose Checkpoints will be created with this Schedule',
type: 'string',
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
})
readonly asset: string;

Expand Down
4 changes: 2 additions & 2 deletions src/common/decorators/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { applyDecorators } from '@nestjs/common';
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { isHexUuid, isUuid } from '@polymeshassociation/polymesh-sdk/utils';
import {
IsHexadecimal,
IsUppercase,
Expand Down Expand Up @@ -42,9 +43,8 @@ export function IsTicker(validationOptions?: ValidationOptions) {
);
}

const assetIdRegex = /0x[0-9a-fA-F]{32}/;
export const isAssetId = (id: string): boolean => {
return assetIdRegex.test(id);
return isHexUuid(id) || isUuid(id);
};

export function IsAsset(validationOptions?: ValidationOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/models/extrinsic.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ExtrinsicModel {
example: [
{
name: 'asset',
value: '0xa3616b82e8e1080aedc952ea28b9db8b',
value: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
},
],
})
Expand Down
Loading

0 comments on commit e2b1883

Please sign in to comment.