Skip to content

Commit

Permalink
feat: use different values for different batch extrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
monitz87 committed May 28, 2020
1 parent e82a321 commit e218003
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/api/procedures/addClaims.ts
@@ -1,6 +1,6 @@
import { Moment } from '@polkadot/types/interfaces';
import { chunk } from 'lodash';
import { Claim as MeshClaim } from 'polymesh-types/types';
import { Claim as MeshClaim, TxTags } from 'polymesh-types/types';

import { Identity } from '~/api/entities';
import { PolymeshError, Procedure } from '~/base';
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function prepareAddClaims(
});
}

chunk(addClaimItems, MAX_BATCH_ELEMENTS).forEach(itemChunk => {
chunk(addClaimItems, MAX_BATCH_ELEMENTS[TxTags.identity.AddClaimsBatch]).forEach(itemChunk => {
this.addTransaction(tx.identity.addClaimsBatch, { batchSize: itemChunk.length }, itemChunk);
});
}
Expand Down
33 changes: 19 additions & 14 deletions src/api/procedures/consumeAuthorizationRequests.ts
Expand Up @@ -2,6 +2,7 @@ import { chunk } from 'lodash';

import { AuthorizationRequest } from '~/api/entities';
import { Procedure } from '~/base';
import { TxTags } from '~/polkadot';
import { authTargetToAuthIdentifier, numberToU64 } from '~/utils';
import { MAX_BATCH_ELEMENTS } from '~/utils/constants';

Expand Down Expand Up @@ -35,24 +36,28 @@ export async function prepareConsumeAuthorizationRequests(

if (accept) {
const requestIds = liveRequests.map(({ authId }) => numberToU64(authId, context));
chunk(requestIds, MAX_BATCH_ELEMENTS).forEach(idChunk => {
this.addTransaction(
tx.identity.batchAcceptAuthorization,
{ batchSize: idChunk.length },
idChunk
);
});
chunk(requestIds, MAX_BATCH_ELEMENTS[TxTags.identity.BatchAcceptAuthorization]).forEach(
idChunk => {
this.addTransaction(
tx.identity.batchAcceptAuthorization,
{ batchSize: idChunk.length },
idChunk
);
}
);
} else {
const authIdentifiers = liveRequests.map(({ authId, targetIdentity }) =>
authTargetToAuthIdentifier({ authId, did: targetIdentity.did }, context)
);
chunk(authIdentifiers, MAX_BATCH_ELEMENTS).forEach(identifierChunk => {
this.addTransaction(
tx.identity.batchRemoveAuthorization,
{ batchSize: identifierChunk.length },
identifierChunk
);
});
chunk(authIdentifiers, MAX_BATCH_ELEMENTS[TxTags.identity.BatchRemoveAuthorization]).forEach(
identifierChunk => {
this.addTransaction(
tx.identity.batchRemoveAuthorization,
{ batchSize: identifierChunk.length },
identifierChunk
);
}
);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/api/procedures/issueTokens.ts
Expand Up @@ -3,10 +3,10 @@ import { chunk } from 'lodash';

import { SecurityToken } from '~/api/entities';
import { PolymeshError, Procedure } from '~/base';
import { IdentityId } from '~/polkadot';
import { IdentityId, TxTags } from '~/polkadot';
import { ErrorCode, IssuanceData, Role, RoleType, TransferStatus } from '~/types';
import { numberToBalance, stringToIdentityId, stringToTicker, valueToDid } from '~/utils';
import { MAX_BATCH_ELEMENTS,MAX_DECIMALS, MAX_TOKEN_AMOUNT } from '~/utils/constants';
import { MAX_BATCH_ELEMENTS, MAX_DECIMALS, MAX_TOKEN_AMOUNT } from '~/utils/constants';

export interface IssueTokensParams {
issuanceData: IssuanceData[];
Expand Down Expand Up @@ -104,9 +104,10 @@ export async function prepareIssueTokens(
});
}

const investorChunks = chunk(investors, MAX_BATCH_ELEMENTS);
const maxElements = MAX_BATCH_ELEMENTS[TxTags.asset.BatchIssue];
const investorChunks = chunk(investors, maxElements);

chunk(balances, MAX_BATCH_ELEMENTS).forEach((balanceChunk, index) => {
chunk(balances, maxElements).forEach((balanceChunk, index) => {
this.addTransaction(
asset.batchIssue,
{ batchSize: issuanceData.length },
Expand Down
14 changes: 10 additions & 4 deletions src/api/procedures/revokeClaims.ts
@@ -1,5 +1,5 @@
import { chunk } from 'lodash';
import { Claim as MeshClaim } from 'polymesh-types/types';
import { Claim as MeshClaim, TxTags } from 'polymesh-types/types';

import { Identity } from '~/api/entities';
import { PolymeshError, Procedure } from '~/base';
Expand Down Expand Up @@ -57,9 +57,15 @@ export async function prepareRevokeClaims(
});
}

chunk(revokeClaimItems, MAX_BATCH_ELEMENTS).forEach(itemChunk => {
this.addTransaction(tx.identity.revokeClaimsBatch, { batchSize: itemChunk.length }, itemChunk);
});
chunk(revokeClaimItems, MAX_BATCH_ELEMENTS[TxTags.identity.RevokeClaimsBatch]).forEach(
itemChunk => {
this.addTransaction(
tx.identity.revokeClaimsBatch,
{ batchSize: itemChunk.length },
itemChunk
);
}
);
}

export const revokeClaims = new Procedure(prepareRevokeClaims);
13 changes: 10 additions & 3 deletions src/api/procedures/setTokenTrustedClaimIssuers.ts
@@ -1,7 +1,8 @@
import { chunk,difference } from 'lodash';
import { chunk, difference } from 'lodash';

import { Identity, SecurityToken } from '~/api/entities';
import { PolymeshError, Procedure } from '~/base';
import { TxTags } from '~/polkadot';
import { ErrorCode, Role, RoleType } from '~/types';
import { identityIdToString, stringToIdentityId, stringToTicker, valueToDid } from '~/utils';
import { MAX_BATCH_ELEMENTS } from '~/utils/constants';
Expand Down Expand Up @@ -58,7 +59,10 @@ export async function prepareSetTokenTrustedClaimIssuers(
}

if (rawCurrentClaimIssuers.length) {
chunk(rawCurrentClaimIssuers, MAX_BATCH_ELEMENTS).forEach(issuersChunk => {
chunk(
rawCurrentClaimIssuers,
MAX_BATCH_ELEMENTS[TxTags.complianceManager.RemoveDefaultTrustedClaimIssuersBatch]
).forEach(issuersChunk => {
this.addTransaction(
tx.complianceManager.removeDefaultTrustedClaimIssuersBatch,
{ batchSize: issuersChunk.length },
Expand All @@ -69,7 +73,10 @@ export async function prepareSetTokenTrustedClaimIssuers(
}

if (rawNewClaimIssuers.length) {
chunk(rawNewClaimIssuers, MAX_BATCH_ELEMENTS).forEach(issuersChunk => {
chunk(
rawNewClaimIssuers,
MAX_BATCH_ELEMENTS[TxTags.complianceManager.AddDefaultTrustedClaimIssuersBatch]
).forEach(issuersChunk => {
this.addTransaction(
tx.complianceManager.addDefaultTrustedClaimIssuersBatch,
{ batchSize: issuersChunk.length },
Expand Down
12 changes: 11 additions & 1 deletion src/utils/constants.ts
@@ -1,9 +1,19 @@
import BigNumber from 'bignumber.js';

import { TxTags } from '~/polkadot';

export const MAX_DECIMALS = 6;
export const MAX_TICKER_LENGTH = 12;
export const MAX_TOKEN_AMOUNT = new BigNumber(Math.pow(10, 12));
export const DUMMY_ACCOUNT_ID = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
export const HARVESTER_ENDPOINT =
'https://24pha89jxg.execute-api.us-east-1.amazonaws.com/dev/graphql';
export const MAX_BATCH_ELEMENTS = 500;
export const MAX_BATCH_ELEMENTS = {
[TxTags.asset.BatchIssue]: 500,
[TxTags.identity.BatchAcceptAuthorization]: 500,
[TxTags.identity.BatchRemoveAuthorization]: 500,
[TxTags.identity.AddClaimsBatch]: 500,
[TxTags.identity.RevokeClaimsBatch]: 500,
[TxTags.complianceManager.RemoveDefaultTrustedClaimIssuersBatch]: 500,
[TxTags.complianceManager.AddDefaultTrustedClaimIssuersBatch]: 500,
};

0 comments on commit e218003

Please sign in to comment.