Skip to content

Commit

Permalink
feat: getIdentifiers method draft
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Mar 23, 2020
1 parent c45ff37 commit 2dcab84
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 22 deletions.
9 changes: 8 additions & 1 deletion src/Polymesh.ts
Expand Up @@ -5,7 +5,7 @@ import { BigNumber } from 'bignumber.js';
import { polymesh } from 'polymesh-types/definitions';
import { Link } from 'polymesh-types/types';

import { TickerReservation } from '~/api/entities';
import { SecurityToken, TickerReservation } from '~/api/entities';
import { reserveTicker, ReserveTickerParams } from '~/api/procedures';
import { PolymeshError, TransactionQueue } from '~/base';
import { Context } from '~/context';
Expand Down Expand Up @@ -182,4 +182,11 @@ export class Polymesh {
message: `There is no reservation for ${ticker} ticker`,
});
}

/**
*
*/
public getToken(): SecurityToken {
return new SecurityToken({ ticker: 'MAIA' }, this.context);
}
}
30 changes: 30 additions & 0 deletions src/api/entities/SecurityToken/index.ts
Expand Up @@ -2,6 +2,7 @@ import { Identity } from '~/api/entities/Identity';
import { modifyToken, ModifyTokenParams } from '~/api/procedures';
import { Entity, TransactionQueue } from '~/base';
import { Context } from '~/context';
import { TokenIdentifier, TokenIdentifierType } from '~/types';
import {
assetTypeToString,
balanceToBigNumber,
Expand Down Expand Up @@ -114,4 +115,33 @@ export class SecurityToken extends Entity<UniqueIdentifiers> {
const fundingRound = await asset.fundingRound(ticker);
return fundingRoundNameToString(fundingRound);
}

/**
* Retrive the Security Token's asset identifiers list
*/
public async getIdentifiers(): Promise<TokenIdentifier[]> {
const {
context: {
polymeshApi: {
query: { asset },
},
},
ticker,
} = this;

const identifierTypes = Object.keys(TokenIdentifierType);
console.log(identifierTypes);

// Object.keys(TokenIdentifierType).map(type => )

/*
const assetIdentifiers = await asset.identifiers.multi([
[ticker, ''],
[ticker, ''],
]);
*/

const result = [] as TokenIdentifier[];
return result;
}
}
4 changes: 2 additions & 2 deletions src/api/entities/TickerReservation/__tests__/index.ts
Expand Up @@ -8,7 +8,7 @@ import { reserveTicker } from '~/api/procedures';
import { createSecurityToken } from '~/api/procedures/createSecurityToken';
import { Entity, TransactionQueue } from '~/base';
import { polkadotMockUtils } from '~/testUtils/mocks';
import { KnownTokenIdentifierType, KnownTokenType, TickerReservationStatus } from '~/types';
import { KnownTokenType, TickerReservationStatus, TokenIdentifierType } from '~/types';

import { TickerReservation } from '../';

Expand Down Expand Up @@ -219,7 +219,7 @@ describe('TickerReservation class', () => {
totalSupply: new BigNumber(100),
isDivisible: true,
tokenType: KnownTokenType.Equity,
tokenIdentifiers: [{ type: KnownTokenIdentifierType.Isin, value: '12345' }],
tokenIdentifiers: [{ type: TokenIdentifierType.Isin, value: '12345' }],
fundingRound: 'Series A',
};

Expand Down
5 changes: 2 additions & 3 deletions src/api/procedures/__tests__/createSecurityToken.ts
Expand Up @@ -23,7 +23,6 @@ import { Context } from '~/context';
import { entityMockUtils, polkadotMockUtils, procedureMockUtils } from '~/testUtils/mocks';
import { Mocked } from '~/testUtils/types';
import {
KnownTokenIdentifierType,
KnownTokenType,
RoleType,
TickerReservationStatus,
Expand Down Expand Up @@ -98,7 +97,7 @@ describe('createSecurityToken procedure', () => {
tokenType = KnownTokenType.Equity;
tokenIdentifiers = [
{
type: KnownTokenIdentifierType.Isin,
type: TokenIdentifierType.Isin,
value: '12345',
},
];
Expand All @@ -117,7 +116,7 @@ describe('createSecurityToken procedure', () => {
rawType = polkadotMockUtils.createMockAssetType(tokenType);
rawIdentifiers = tokenIdentifiers.map(({ type, value }) => {
return [
polkadotMockUtils.createMockIdentifierType(type as KnownTokenIdentifierType),
polkadotMockUtils.createMockIdentifierType(type as TokenIdentifierType),
polkadotMockUtils.createMockAssetIdentifier(value),
];
});
Expand Down
5 changes: 3 additions & 2 deletions src/types/index.ts
Expand Up @@ -97,12 +97,13 @@ export enum KnownTokenType {
*/
export type TokenType = KnownTokenType | { custom: string };

export enum KnownTokenIdentifierType {
export enum TokenIdentifierType {
Isin = 'isin',
Cusip = 'cusip',
}

export type TokenIdentifierType = KnownTokenIdentifierType | { custom: string };
// NOTE: query.asset.identifiers doesn’t support custom identifier types properly for now
// export type TokenIdentifierType = KnownTokenIdentifierType | { custom: string };

/**
* Alphanumeric standardized security identifier
Expand Down
8 changes: 4 additions & 4 deletions src/utils/__tests__/index.ts
Expand Up @@ -19,7 +19,7 @@ import sinon, { SinonStub } from 'sinon';

import { PostTransactionValue } from '~/base';
import { polkadotMockUtils } from '~/testUtils/mocks';
import { KnownTokenIdentifierType, KnownTokenType } from '~/types';
import { KnownTokenType, TokenIdentifierType } from '~/types';

import {
assetIdentifierToString,
Expand Down Expand Up @@ -482,7 +482,7 @@ describe('tokenIdentifierTypeToIdentifierType and identifierTypeToString', () =>
});

test('tokenIdentifierTypeToIdentifierType should convert a TokenIdentifierType to a polkadot IdentifierType object', () => {
const value = KnownTokenIdentifierType.Isin;
const value = TokenIdentifierType.Isin;
const fakeResult = ('IsinEnum' as unknown) as IdentifierType;
const context = polkadotMockUtils.getContextInstance();

Expand All @@ -496,13 +496,13 @@ describe('tokenIdentifierTypeToIdentifierType and identifierTypeToString', () =>
});

test('identifierTypeToString should convert a polkadot IdentifierType object to a string', () => {
let fakeResult = KnownTokenIdentifierType.Isin;
let fakeResult = TokenIdentifierType.Isin;
let identifierType = polkadotMockUtils.createMockIdentifierType(fakeResult);

let result = identifierTypeToString(identifierType);
expect(result).toEqual(fakeResult);

fakeResult = KnownTokenIdentifierType.Cusip;
fakeResult = TokenIdentifierType.Cusip;
identifierType = polkadotMockUtils.createMockIdentifierType(fakeResult);

result = identifierTypeToString(identifierType);
Expand Down
13 changes: 3 additions & 10 deletions src/utils/index.ts
Expand Up @@ -22,14 +22,7 @@ import {

import { PolymeshError, PostTransactionValue } from '~/base';
import { Context } from '~/context';
import {
ErrorCode,
KnownTokenIdentifierType,
KnownTokenType,
TokenDocument,
TokenIdentifierType,
TokenType,
} from '~/types';
import { ErrorCode, KnownTokenType, TokenDocument, TokenIdentifierType, TokenType } from '~/types';
import {
Extrinsics,
MapMaybePostTransactionValue,
Expand Down Expand Up @@ -225,10 +218,10 @@ export function tokenIdentifierTypeToIdentifierType(
*/
export function identifierTypeToString(type: IdentifierType): string {
if (type.isCusip) {
return KnownTokenIdentifierType.Cusip;
return TokenIdentifierType.Cusip;
}
if (type.isIsin) {
return KnownTokenIdentifierType.Isin;
return TokenIdentifierType.Isin;
}

return u8aToString(type.asCustom);
Expand Down

0 comments on commit 2dcab84

Please sign in to comment.