Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## Polymesh version

This release is compatible with Polymesh v7.3-v8.0
This release is compatible with Polymesh v8.0

## Getting Started

Expand Down
23 changes: 2 additions & 21 deletions src/api/client/AccountManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ export class AccountManagement {
},
context
);
this.subsidizeAccount = createProcedureMethod(
{ getProcedureAndArgs: args => [subsidizeAccount, { ...args, isV7Method: true }] },
context
);
this.acceptSubsidy = createProcedureMethod(
{ getProcedureAndArgs: args => [acceptSubsidy, args] },
context
Expand All @@ -134,7 +130,7 @@ export class AccountManagement {
context
);
this.approveSubsidy = createProcedureMethod(
{ getProcedureAndArgs: args => [subsidizeAccount, { ...args, isV7Method: false }] },
{ getProcedureAndArgs: args => [subsidizeAccount, { ...args }] },
context
);
this.createMultiSigAccount = createProcedureMethod(
Expand Down Expand Up @@ -197,43 +193,28 @@ export class AccountManagement {
*/
public unfreezeSecondaryAccounts: NoArgsProcedureMethod<void>;

/**
* Send an Authorization Request to an Account to subsidize its transaction fees
*
* @note this will create an {@link AuthorizationRequest | Authorization Request} which has to be accepted by the `beneficiary` Account.
* An {@link Account} or {@link Identity} can fetch its pending Authorization Requests by calling {@link api/entities/common/namespaces/Authorizations!Authorizations.getReceived | authorizations.getReceived}.
* Also, an Account or Identity can directly fetch the details of an Authorization Request by calling {@link api/entities/common/namespaces/Authorizations!Authorizations.getOne | authorizations.getOne}
*
* @deprecated use {@link approveSubsidy} instead from chain v8
*/
public subsidizeAccount: ProcedureMethod<SubsidizeAccountParams, AuthorizationRequest>;

/**
* Approves a subsidy request
*
* This is to be called in by the paying key to approve allowance with respect to a beneficiary key.
*
* @note this will create a pending subsidies entry, which has to be accepted by the `beneficiary` Account. Pending subsidies for a beneficiary can be fetched by calling {@link api/entities/Subsidies!Subsidies.getPendingSubsidies | subsidies.getPendingSubsidies}.
*
* @throws
* - if called for a v7 chain
* - if same allowance amount is pending for acceptance with respect to same beneficiary
* @throws if same allowance amount is pending for acceptance with respect to same beneficiary
*/
public approveSubsidy: ProcedureMethod<SubsidizeAccountParams, void>;

/**
* Accepts a pending subsidy request from subsidizer
*
* @note Only the beneficiary can accept an already approved subsidy request. Pending subsidies for a beneficiary can be fetched by calling {@link api/entities/Subsidies!Subsidies.getPendingSubsidies | subsidies.getPendingSubsidies}.
* @note this is only available from chain v8
*/
public acceptSubsidy: ProcedureMethod<AcceptSubsidyParams, void>;

/**
* Revokes an already approved subsidy request
*
* @note Only the subsidizer can revoke an already approved subsidy request. Pending subsidies for a beneficiary can be fetched by calling {@link api/entities/Subsidies!Subsidies.getPendingSubsidies | subsidies.getPendingSubsidies}.
* @note this is only available from chain v8
*/
public revokeSubsidy: ProcedureMethod<RevokeSubsidyParams, void>;

Expand Down
80 changes: 4 additions & 76 deletions src/api/client/Claims.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Vec } from '@polkadot/types';
import { IdentityClaim } from '@polymeshassociation/polymesh-types/polkadot/polymesh';
import BigNumber from 'bignumber.js';
import { filter, flatten, isEqual, uniqBy, uniqWith } from 'lodash';
import { isEqual, uniqBy, uniqWith } from 'lodash';

import {
Context,
Expand All @@ -17,7 +15,6 @@ import {
} from '~/middleware/queries/claims';
import { ClaimsOrderBy, Query } from '~/middleware/types';
import {
CddClaim,
ClaimData,
ClaimOperation,
ClaimScope,
Expand All @@ -43,12 +40,8 @@ import {
bigNumberToU32,
bytesToString,
claimTypeInputToMiddlewareClaimTypeDetails,
identityIdToString,
meshClaimToClaim,
momentToDate,
scopeToMiddlewareScope,
signerToString,
stringToIdentityId,
toCustomClaimTypeWithIdentity,
toIdentityWithClaimsArray,
u32ToBigNumber,
Expand Down Expand Up @@ -240,7 +233,7 @@ export class Claims {
);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
targetIssuers = flatten(groupedTargets!.map(groupedTarget => groupedTarget.keys!));
targetIssuers = groupedTargets!.map(groupedTarget => groupedTarget.keys!).flat();
}

// note: pagination count is based on the target issuers and not the claims count
Expand Down Expand Up @@ -386,71 +379,6 @@ export class Claims {
);
}

/**
* Retrieve the list of CDD claims for a target Identity
*
* @deprecated CDD claims are no longer supported with v8 chains
*
* @param opts.target - Identity for which to fetch CDD claims (optional, defaults to the signing Identity)
* @param opts.includeExpired - whether to include expired claims. Defaults to true
*/
public async getCddClaims(
opts: {
target?: string | Identity;
includeExpired?: boolean;
} = {}
): Promise<ClaimData<CddClaim>[]> {
const {
context,
context: {
polymeshApi: { call },
},
} = this;

if (!context.isV7) {
throw new PolymeshError({
code: ErrorCode.NotSupported,
message: 'CDD claims are no longer supported in chain v8',
});
}

const { identityApi: identity } = call;

if (!identity) {
return [];
}

const { target, includeExpired = true } = opts;

const did = await getDid(target, context);

const rawDid = stringToIdentityId(did, context);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: Vec<IdentityClaim> = await (identity as any).validCddClaims(rawDid, null);

const data: ClaimData<CddClaim>[] = [];

result.forEach(optClaim => {
const { claimIssuer, issuanceDate, lastUpdateDate, expiry: rawExpiry, claim } = optClaim;

const expiry = rawExpiry.isSome ? momentToDate(rawExpiry.unwrap()) : null;

if ((!includeExpired && (expiry === null || expiry > new Date())) || includeExpired) {
data.push({
target: new Identity({ did }, context),
issuer: new Identity({ did: identityIdToString(claimIssuer) }, context),
issuedAt: momentToDate(issuanceDate),
lastUpdatedAt: momentToDate(lastUpdateDate),
expiry,
claim: meshClaimToClaim(claim) as CddClaim,
});
}
});

return data;
}

/**
* @hidden
*/
Expand All @@ -475,7 +403,7 @@ export class Claims {

const identitiesWithClaims = issuers.map(identity => ({
identity,
claims: filter(identityClaimsFromChain, ({ issuer }) => issuer.isEqual(identity)),
claims: identityClaimsFromChain.filter(({ issuer }) => issuer.isEqual(identity)),
}));

return {
Expand Down Expand Up @@ -539,7 +467,7 @@ export class Claims {
);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
claimIssuers = flatten(groupedIssuers!.map(groupedAggregate => groupedAggregate.keys!));
claimIssuers = groupedIssuers!.map(groupedAggregate => groupedAggregate.keys!).flat();
}

// note: pagination count is based on the claim issuers and not the claims count
Expand Down
61 changes: 0 additions & 61 deletions src/api/client/Identities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import {
allowIdentityToCreatePortfolios,
attestPrimaryKeyRotation,
AuthorizationRequest,
ChildIdentity,
Context,
createChildIdentities,
createChildIdentity,
createPortfolios,
Identity,
NumberedPortfolio,
Expand All @@ -19,8 +16,6 @@ import {
import {
AllowIdentityToCreatePortfoliosParams,
AttestPrimaryKeyRotationParams,
CreateChildIdentitiesParams,
CreateChildIdentityParams,
NoArgsProcedureMethod,
ProcedureMethod,
RegisterIdentityParams,
Expand Down Expand Up @@ -96,20 +91,6 @@ export class Identities {
context
);

this.createChild = createProcedureMethod(
{
getProcedureAndArgs: args => [createChildIdentity, args],
},
context
);

this.createChildren = createProcedureMethod(
{
getProcedureAndArgs: args => [createChildIdentities, args],
},
context
);

this.allowIdentityToCreatePortfolios = createProcedureMethod(
{ getProcedureAndArgs: args => [allowIdentityToCreatePortfolios, args] },
context
Expand Down Expand Up @@ -210,55 +191,13 @@ export class Identities {
return this.context.getIdentity(args.did);
}

/**
* Create a ChildIdentity instance from a DID
*
* @throws if there is no ChildIdentity with the passed DID
*
* @deprecated Child identities are no longer supported in chain v8
*/
public getChildIdentity(args: { did: string }): Promise<ChildIdentity> {
// NOSONAR
return this.context.getChildIdentity(args.did);
}

/**
* Return whether the supplied Identity/DID exists
*/
public isIdentityValid(args: { identity: Identity | string }): Promise<boolean> {
return asIdentity(args.identity, this.context).exists();
}

/**
* Creates a child identity and makes the `secondaryKey` as the primary key of the child identity
*
* @note the given `secondaryKey` is removed as secondary key from the signing Identity
*
* @throws if
* - the transaction signer is not the primary account of which the `secondaryKey` is a secondary key
* - the `secondaryKey` can't be unlinked (can happen when it's part of a multisig with some balance)
* - the signing account is not a primary key
* - the signing Identity is already a child of some other identity
*
* @deprecated Child identities are no longer supported in chain v8
*/
public createChild: ProcedureMethod<CreateChildIdentityParams, ChildIdentity>;

/**
* Create child identities using off chain authorization
*
* @note the list of `key` provided in the params should not be linked to any other account
*
* @throws if
* - the signing account is not a primary key
* - the signing Identity is already a child of some other identity
* - `expiresAt` is not a future date
* - the any `key` in `childKeyAuths` is already linked to an Identity
*
* @deprecated Child identities are no longer supported in chain v8
*/
public createChildren: ProcedureMethod<CreateChildIdentitiesParams, ChildIdentity[]>;

/**
* Gives permission to the Identity to create Portfolios on behalf of the signing Identity
*
Expand Down
9 changes: 4 additions & 5 deletions src/api/client/Staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
PaginationOptions,
ProcedureMethod,
ResultSet,
SetStakingControllerParams,
SetStakingPayeeParams,
StakingCommission,
StakingEraInfo,
Expand Down Expand Up @@ -87,7 +86,8 @@ export class Staking {

this.setController = createProcedureMethod(
{
getProcedureAndArgs: args => [setStakingController, args],
getProcedureAndArgs: () => [setStakingController, undefined],
voidArgs: true,
},
context
);
Expand Down Expand Up @@ -134,12 +134,11 @@ export class Staking {
public nominate: ProcedureMethod<NominateValidatorsParams, void>;

/**
* Allow for a stash account to update its controller
* Allow for a stash account to update its controller so the stash becomes its own controller
*
* @note the transaction must be signed by a stash account
* @note Polymesh v8 makes it so the stash will become its own controller account
*/
public setController: ProcedureMethod<SetStakingControllerParams, void>;
public setController: NoArgsProcedureMethod<void>;

/**
* Allow for a stash account to update where it's staking rewards are deposited
Expand Down
23 changes: 1 addition & 22 deletions src/api/client/__tests__/AccountManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,6 @@ describe('AccountManagement class', () => {
});
});

describe('method: subsidizeAccount', () => {
it('should prepare the procedure with the correct arguments and context, and return the resulting transaction', async () => {
const args = {
beneficiary: 'someAccount',
allowance: new BigNumber(1000),
};

const expectedTransaction =
'someTransaction' as unknown as PolymeshTransaction<AuthorizationRequest>;

when(procedureMockUtils.getPrepareMock())
.calledWith({ args: { ...args, isV7Method: true }, transformer: undefined }, context, {})
.mockResolvedValue(expectedTransaction);

const tx = await accountManagement.subsidizeAccount(args); // NOSONAR

expect(tx).toEqual(expectedTransaction);
});
});

describe('method: acceptSubsidy', () => {
it('should prepare the procedure with the correct arguments and context, and return the resulting transaction', async () => {
const args = {
Expand Down Expand Up @@ -247,7 +227,7 @@ describe('AccountManagement class', () => {
'someTransaction' as unknown as PolymeshTransaction<AuthorizationRequest>;

when(procedureMockUtils.getPrepareMock())
.calledWith({ args: { ...args, isV7Method: false }, transformer: undefined }, context, {})
.calledWith({ args, transformer: undefined }, context, {})
.mockResolvedValue(expectedTransaction);

const tx = await accountManagement.approveSubsidy(args);
Expand Down Expand Up @@ -439,7 +419,6 @@ describe('AccountManagement class', () => {
it('should prepare the procedure with the correct arguments and context, and return the resulting transaction', async () => {
const args = {
ownerAuth: new BigNumber(1),
cddAuth: new BigNumber(2),
};

const expectedTransaction = 'someTransaction' as unknown as PolymeshTransaction<void>;
Expand Down
Loading
Loading