Skip to content

Commit e2b1883

Browse files
committed
feat: 🎸 support asset IDs as uuids
also return the assetId as `asset` in the response when creating an asset
1 parent c45f077 commit e2b1883

File tree

19 files changed

+154
-76
lines changed

19 files changed

+154
-76
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@polymeshassociation/fireblocks-signing-manager": "^2.5.0",
5050
"@polymeshassociation/hashicorp-vault-signing-manager": "^3.4.0",
5151
"@polymeshassociation/local-signing-manager": "^3.3.0",
52-
"@polymeshassociation/polymesh-sdk": "26.0.0-beta.1",
52+
"@polymeshassociation/polymesh-sdk": "^26.1.0",
5353
"@polymeshassociation/signing-manager-types": "^3.2.0",
5454
"class-transformer": "0.5.1",
5555
"class-validator": "^0.14.0",

‎src/assets/assets.controller.ts‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ApiTags,
1111
ApiUnprocessableEntityResponse,
1212
} from '@nestjs/swagger';
13+
import { Asset } from '@polymeshassociation/polymesh-sdk/types';
1314

1415
import { AssetsService } from '~/assets/assets.service';
1516
import { createAssetDetailsModel } from '~/assets/assets.util';
@@ -23,6 +24,7 @@ import { SetAssetDocumentsDto } from '~/assets/dto/set-asset-documents.dto';
2324
import { AgentOperationModel } from '~/assets/models/agent-operation.model';
2425
import { AssetDetailsModel } from '~/assets/models/asset-details.model';
2526
import { AssetDocumentModel } from '~/assets/models/asset-document.model';
27+
import { CreatedAssetModel } from '~/assets/models/created-asset.model';
2628
import { IdentityBalanceModel } from '~/assets/models/identity-balance.model';
2729
import { RequiredMediatorsModel } from '~/assets/models/required-mediators.model';
2830
import { authorizationRequestResolver } from '~/authorizations/authorizations.util';
@@ -33,7 +35,7 @@ import { TransactionBaseDto } from '~/common/dto/transaction-base-dto';
3335
import { TransferOwnershipDto } from '~/common/dto/transfer-ownership.dto';
3436
import { PaginatedResultsModel } from '~/common/models/paginated-results.model';
3537
import { TransactionQueueModel } from '~/common/models/transaction-queue.model';
36-
import { handleServiceResult, TransactionResponseModel } from '~/common/utils';
38+
import { handleServiceResult, TransactionResolver, TransactionResponseModel } from '~/common/utils';
3739
import { MetadataService } from '~/metadata/metadata.service';
3840
import { GlobalMetadataModel } from '~/metadata/models/global-metadata.model';
3941

@@ -72,7 +74,7 @@ export class AssetsController {
7274
name: 'asset',
7375
description: 'The Asset (Ticker/Asset ID) whose details are to be fetched',
7476
type: 'string',
75-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
77+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
7678
})
7779
@ApiOkResponse({
7880
description: 'Basic details of the Asset',
@@ -94,7 +96,7 @@ export class AssetsController {
9496
name: 'asset',
9597
description: 'The Asset (Ticker/Asset ID) whose holders are to be fetched',
9698
type: 'string',
97-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
99+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
98100
})
99101
@ApiQuery({
100102
name: 'size',
@@ -146,7 +148,7 @@ export class AssetsController {
146148
name: 'asset',
147149
description: 'The Asset (Ticker/Asset ID) whose attached documents are to be fetched',
148150
type: 'string',
149-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
151+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
150152
})
151153
@ApiQuery({
152154
name: 'size',
@@ -203,7 +205,7 @@ export class AssetsController {
203205
name: 'asset',
204206
description: 'The Asset (Ticker/Asset ID) whose documents are to be updated',
205207
type: 'string',
206-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
208+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
207209
})
208210
@ApiOkResponse({
209211
description: 'Details of the transaction',
@@ -231,7 +233,7 @@ export class AssetsController {
231233
name: 'asset',
232234
description: 'The Asset (Ticker/Asset ID) to issue',
233235
type: 'string',
234-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
236+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
235237
})
236238
@ApiTransactionResponse({
237239
description: 'Details about the transaction',
@@ -266,7 +268,15 @@ export class AssetsController {
266268
@Post('create')
267269
public async createAsset(@Body() params: CreateAssetDto): Promise<TransactionResponseModel> {
268270
const result = await this.assetsService.createAsset(params);
269-
return handleServiceResult(result);
271+
272+
const resolver: TransactionResolver<Asset> = ({ result: asset, transactions, details }) =>
273+
new CreatedAssetModel({
274+
asset,
275+
transactions,
276+
details,
277+
});
278+
279+
return handleServiceResult(result, resolver);
270280
}
271281

272282
@ApiOperation({
@@ -278,7 +288,7 @@ export class AssetsController {
278288
name: 'asset',
279289
description: 'The Asset (Ticker/Asset ID) whose ownership is to be transferred',
280290
type: 'string',
281-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
291+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
282292
})
283293
@ApiTransactionResponse({
284294
description: 'Newly created Authorization Request along with transaction details',
@@ -329,7 +339,7 @@ export class AssetsController {
329339
name: 'asset',
330340
description: 'The Asset (Ticker/Asset ID) to freeze',
331341
type: 'string',
332-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
342+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
333343
})
334344
@ApiTransactionResponse({
335345
description: 'Details about the transaction',
@@ -360,7 +370,7 @@ export class AssetsController {
360370
name: 'asset',
361371
description: 'The Asset (Ticker/Asset ID) to unfreeze',
362372
type: 'string',
363-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
373+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
364374
})
365375
@ApiTransactionResponse({
366376
description: 'Details about the transaction',
@@ -390,7 +400,7 @@ export class AssetsController {
390400
name: 'asset',
391401
description: 'The Asset (Ticker/Asset ID) to be transferred',
392402
type: 'string',
393-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
403+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
394404
})
395405
@ApiTransactionResponse({
396406
description: 'Details about the transaction',
@@ -420,7 +430,7 @@ export class AssetsController {
420430
name: 'asset',
421431
description: 'The Asset (Ticker/Asset ID) whose operation history is to be fetched',
422432
type: 'string',
423-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
433+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
424434
})
425435
@ApiOkResponse({
426436
description: 'List of operations grouped by the agent Identity who performed them',
@@ -445,7 +455,7 @@ export class AssetsController {
445455
name: 'asset',
446456
description: 'The Asset (Ticker/Asset ID) whose required mediators is to be fetched',
447457
type: 'string',
448-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
458+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
449459
})
450460
@ApiOkResponse({
451461
description: 'The required mediators for the asset',
@@ -470,7 +480,7 @@ export class AssetsController {
470480
name: 'asset',
471481
description: 'The Asset (Ticker/Asset ID) to set required mediators for',
472482
type: 'string',
473-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
483+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
474484
})
475485
@ApiTransactionResponse({
476486
description: 'Details about the transaction',
@@ -496,7 +506,7 @@ export class AssetsController {
496506
name: 'asset',
497507
description: 'The Asset (Ticker/Asset ID) to set required mediators for',
498508
type: 'string',
499-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
509+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
500510
})
501511
@ApiTransactionResponse({
502512
description: 'Details about the transaction',
@@ -522,7 +532,7 @@ export class AssetsController {
522532
name: 'asset',
523533
description: 'The Asset (Ticker/Asset ID) to pre-approve',
524534
type: 'string',
525-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
535+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
526536
})
527537
@ApiTransactionResponse({
528538
description: 'Details about the transaction',
@@ -552,7 +562,7 @@ export class AssetsController {
552562
name: 'asset',
553563
description: 'The Asset (Ticker/Asset ID) to remove pre-approval for',
554564
type: 'string',
555-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
565+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
556566
})
557567
@ApiTransactionResponse({
558568
description: 'Details about the transaction',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* istanbul ignore file */
2+
3+
import { ApiPropertyOptional } from '@nestjs/swagger';
4+
import { Asset } from '@polymeshassociation/polymesh-sdk/types';
5+
6+
import { FromEntity } from '~/common/decorators/transformation';
7+
import { TransactionQueueModel } from '~/common/models/transaction-queue.model';
8+
9+
export class CreatedAssetModel extends TransactionQueueModel {
10+
@ApiPropertyOptional({
11+
description: 'The newly created Asset ID',
12+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
13+
})
14+
@FromEntity()
15+
readonly asset: Asset;
16+
17+
constructor(model: CreatedAssetModel) {
18+
const { transactions, details, ...rest } = model;
19+
super({ transactions, details });
20+
21+
Object.assign(this, rest);
22+
}
23+
}

‎src/checkpoints/checkpoints.controller.ts‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class CheckpointsController {
5757
name: 'asset',
5858
description: 'The Asset (Ticker/Asset ID) whose attached Checkpoints are to be fetched',
5959
type: 'string',
60-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
60+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
6161
})
6262
@ApiQuery({
6363
name: 'size',
@@ -112,7 +112,7 @@ export class CheckpointsController {
112112
name: 'asset',
113113
description: 'The Asset (Ticker/Asset ID) whose Checkpoint is to be fetched',
114114
type: 'string',
115-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
115+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
116116
})
117117
@ApiParam({
118118
name: 'id',
@@ -148,7 +148,7 @@ export class CheckpointsController {
148148
name: 'asset',
149149
description: 'The Asset (Ticker/Asset ID) for which the Checkpoint is to be created',
150150
type: 'string',
151-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
151+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
152152
})
153153
@ApiTransactionResponse({
154154
description: 'Details of the newly created Checkpoint',
@@ -185,7 +185,7 @@ export class CheckpointsController {
185185
description:
186186
'The Asset (Ticker/Asset ID) whose attached Checkpoint Schedules are to be fetched',
187187
type: 'string',
188-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
188+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
189189
})
190190
@ApiArrayResponse(CheckpointScheduleModel, {
191191
description: 'List of active Schedules which create Checkpoints for a specific Asset',
@@ -217,7 +217,7 @@ export class CheckpointsController {
217217
name: 'asset',
218218
description: 'The Asset (Ticker/Asset ID) whose Checkpoint Schedule is to be fetched',
219219
type: 'string',
220-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
220+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
221221
})
222222
@ApiParam({
223223
name: 'id',
@@ -258,7 +258,7 @@ export class CheckpointsController {
258258
name: 'asset',
259259
description: 'The Asset (Ticker/Asset ID) for which the Checkpoint creation is to be scheduled',
260260
type: 'string',
261-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
261+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
262262
})
263263
@ApiTransactionResponse({
264264
description: 'Details of the newly created Checkpoint Schedule',
@@ -309,7 +309,7 @@ export class CheckpointsController {
309309
name: 'asset',
310310
description: 'The Asset (Ticker/Asset ID) for which to fetch holder balances',
311311
type: 'string',
312-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
312+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
313313
})
314314
@ApiParam({
315315
name: 'id',
@@ -401,7 +401,7 @@ export class CheckpointsController {
401401
name: 'asset',
402402
description: 'The Asset (Ticker/Asset ID) for which the Schedule is to be deleted',
403403
type: 'string',
404-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
404+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
405405
})
406406
@ApiParam({
407407
name: 'id',
@@ -437,7 +437,7 @@ export class CheckpointsController {
437437
name: 'asset',
438438
description: 'The Asset (Ticker/Asset ID) whose Checkpoints are to be fetched',
439439
type: 'string',
440-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
440+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
441441
})
442442
@ApiParam({
443443
name: 'scheduleId',
@@ -474,7 +474,7 @@ export class CheckpointsController {
474474
name: 'asset',
475475
description: 'The Asset (Ticker/Asset ID) for which Schedule complexity is to be fetched',
476476
type: 'string',
477-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
477+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
478478
})
479479
@ApiNotFoundResponse({
480480
description: 'The Asset was not found',
@@ -506,7 +506,7 @@ export class CheckpointsController {
506506
name: 'asset',
507507
description: 'The Asset (Ticker/Asset ID) whose Checkpoint Schedule is to be fetched',
508508
type: 'string',
509-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
509+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
510510
})
511511
@ApiParam({
512512
name: 'id',

‎src/checkpoints/models/checkpoint-schedule.model.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class CheckpointScheduleModel {
1717
@ApiProperty({
1818
description: 'The Asset (Asset ID/Ticker) whose Checkpoints will be created with this Schedule',
1919
type: 'string',
20-
example: '0xa3616b82e8e1080aedc952ea28b9db8b',
20+
example: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
2121
})
2222
readonly asset: string;
2323

‎src/common/decorators/validation.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* eslint-disable @typescript-eslint/explicit-function-return-type */
44
import { applyDecorators } from '@nestjs/common';
55
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
6+
import { isHexUuid, isUuid } from '@polymeshassociation/polymesh-sdk/utils';
67
import {
78
IsHexadecimal,
89
IsUppercase,
@@ -42,9 +43,8 @@ export function IsTicker(validationOptions?: ValidationOptions) {
4243
);
4344
}
4445

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

5050
export function IsAsset(validationOptions?: ValidationOptions) {

‎src/common/models/extrinsic.model.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class ExtrinsicModel {
6464
example: [
6565
{
6666
name: 'asset',
67-
value: '0xa3616b82e8e1080aedc952ea28b9db8b',
67+
value: '3616b82e-8e10-80ae-dc95-2ea28b9db8b3',
6868
},
6969
],
7070
})

0 commit comments

Comments
 (0)