Skip to content

Commit

Permalink
feat: 🎸 add raw ID to BaseAsset class
Browse files Browse the repository at this point in the history
add getter method to return asset ID in hex format
  • Loading branch information
polymath-eric committed Oct 30, 2024
1 parent 0fab0c7 commit 9513775
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/api/entities/Asset/Base/BaseAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
UnsubCallback,
VenueFilteringDetails,
} from '~/types';
import { tickerToDid } from '~/utils';
import { tickerToDid, uuidToHex } from '~/utils';
import {
assetIdentifierToSecurityIdentifier,
assetToMeshAssetId,
Expand Down Expand Up @@ -89,10 +89,19 @@ export class BaseAsset extends Entity<UniqueIdentifiers, string> {
public ticker?: string;

/**
* Unique ID of the Asset
* Unique ID of the Asset in UUID format
*/
public id: string;

/**
* Unique ID of the Asset in hex format
*
* @note Although UUID format is the usual representation of asset IDs, generic polkadot/substrate tools usually expect it in hex format
*/
public get rawId(): string {
return uuidToHex(this.id);
}

/**
* Transfer ownership of the Asset to another Identity. This generates an authorization request that must be accepted
* by the recipient
Expand Down
8 changes: 8 additions & 0 deletions src/api/entities/Asset/__tests__/Base/BaseAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ describe('BaseAsset class', () => {
dsMockUtils.cleanup();
});

describe('method: rawId', () => {
it('should return the id in hex format', () => {
const result = asset.rawId;

expect(result).toEqual('0x12341234123412341234123412341234');
});
});

describe('method: setVenueFiltering', () => {
it('should prepare the procedure with the correct arguments and context, and return the resulting transaction', async () => {
const enabled = true;
Expand Down
4 changes: 1 addition & 3 deletions src/api/procedures/__tests__/createAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ describe('createAsset procedure', () => {
});

when(stringToTickerSpy).calledWith(ticker, mockContext).mockReturnValue(rawTicker);
when(stringToAssetIdSpy)
.calledWith(uuidToHex(assetId), mockContext)
.mockReturnValue(rawAssetId);
when(stringToAssetIdSpy).calledWith(assetId, mockContext).mockReturnValue(rawAssetId);
when(bigNumberToBalanceSpy)
.calledWith(initialSupply, mockContext, isDivisible)
.mockReturnValue(rawInitialSupply);
Expand Down
3 changes: 1 addition & 2 deletions src/api/procedures/createAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
TxTags,
} from '~/types';
import { BatchTransactionSpec, ProcedureAuthorization, TxWithArgs } from '~/types/internal';
import { uuidToHex } from '~/utils';
import {
assetDocumentToDocument,
bigNumberToBalance,
Expand Down Expand Up @@ -299,7 +298,7 @@ export async function prepareCreateAsset(
assetId = ticker!;
} else {
assetId = await context.getSigningAccount().getNextAssetId();
rawAssetId = stringToAssetId(uuidToHex(assetId), context);
rawAssetId = stringToAssetId(assetId, context);
}

let transactions = [];
Expand Down

0 comments on commit 9513775

Please sign in to comment.