From 478f54c703cab31ea2237a75f75fcc9b06bfc7b3 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 26 Jul 2019 10:23:37 +0200 Subject: [PATCH] Convert RPC classes to primitive classes or /srml types (#1192) * Convert RPC classes to primitive classes or /srml types * Lint passes... lokking at tests next. * Tests pass. * Types with basic docs (lots of work here) * Update StorageKey.spec.ts * Add injector to metadata doc generation * Fix import --- packages/api-derive/src/accounts/indexToId.ts | 4 +- .../balances/votingBalancesNominatorsFor.ts | 4 +- .../src/democracy/referendumInfos.ts | 4 +- .../src/democracy/referendumVotesFor.ts | 6 +- packages/api-derive/src/democracy/votes.ts | 4 +- .../api-derive/src/elections/approvalsOf.ts | 10 +- .../api-derive/src/elections/approvalsOfAt.ts | 6 +- .../src/elections/voterPositions.ts | 8 +- packages/api-derive/src/elections/voters.ts | 10 +- packages/api-derive/src/staking/info.ts | 12 +- .../api-derive/src/type/HeaderExtended.ts | 14 +- .../api-derive/src/util/approvalFlagToBool.ts | 4 +- .../src/util/approvalFlagsToBools.ts | 4 +- .../consts/fromMetadata/fromMetadata.spec.ts | 2 +- packages/api-metadata/src/consts/static.ts | 2 +- .../api-metadata/src/extrinsics/static.ts | 2 +- .../storage/fromMetadata/fromMetadata.spec.ts | 2 +- .../src/storage/fromMetadata/storage.spec.ts | 6 + .../storage/fromMetadata/substrate.spec.ts | 6 + .../src/storage/fromMetadata/substrate.ts | 4 +- packages/api-metadata/src/storage/static.ts | 2 +- packages/api/src/Base.ts | 6 +- packages/api/src/SignerPayload.ts | 6 +- packages/api/src/SubmittableExtrinsic.ts | 6 +- packages/api/src/types.ts | 8 +- packages/api/src/util/filterEvents.ts | 4 +- .../test/e2e/api/promise-alex-archive.spec.ts | 4 +- .../api/test/e2e/api/promise-alex.spec.ts | 8 +- .../test/e2e/api/promise-queries-dev.spec.ts | 4 +- .../api/test/e2e/api/promise-queries.spec.ts | 6 +- packages/api/test/e2e/api/promise-tx.spec.ts | 4 +- .../api/test/e2e/rpc-core/alexander.spec.ts | 8 +- packages/api/test/e2e/rpc-core/basics.spec.ts | 10 +- packages/api/test/e2e/rpc-core/chain.spec.ts | 6 +- packages/api/test/e2e/rpc-core/state.spec.ts | 4 +- .../api/test/e2e/rpc-core/subscribe.spec.ts | 3 +- packages/rpc-core/src/formatting.spec.ts | 2 +- packages/rpc-core/src/index.ts | 11 +- packages/rpc-provider/src/mock/index.ts | 8 +- packages/type-jsonrpc/src/types.ts | 8 +- packages/types/README.md | 4 +- packages/types/src/Metadata/types.ts | 4 +- .../types/src/Metadata/util/validateTypes.ts | 4 +- packages/types/src/Metadata/v0/Calls.ts | 8 +- packages/types/src/Metadata/v0/Events.ts | 30 +- packages/types/src/Metadata/v0/Metadata.ts | 12 +- packages/types/src/Metadata/v0/Modules.ts | 26 +- packages/types/src/Metadata/v0/Storage.ts | 18 +- packages/types/src/Metadata/v0/toV1.ts | 14 +- packages/types/src/Metadata/v1/Calls.ts | 16 +- packages/types/src/Metadata/v1/Metadata.ts | 26 +- packages/types/src/Metadata/v2/Metadata.ts | 26 +- packages/types/src/Metadata/v2/Storage.ts | 12 +- packages/types/src/Metadata/v3/Metadata.ts | 26 +- packages/types/src/Metadata/v3/Storage.ts | 12 +- packages/types/src/Metadata/v3/toV4.ts | 4 +- packages/types/src/Metadata/v4/Metadata.ts | 26 +- packages/types/src/Metadata/v4/Storage.ts | 12 +- packages/types/src/Metadata/v4/toV5.ts | 4 +- packages/types/src/Metadata/v5/Metadata.ts | 26 +- packages/types/src/Metadata/v5/Storage.ts | 12 +- packages/types/src/Metadata/v6/Constants.ts | 8 +- packages/types/src/Metadata/v6/Metadata.ts | 32 +- packages/types/src/Metadata/v7/Metadata.ts | 26 +- packages/types/src/Metadata/v7/Storage.ts | 8 +- packages/types/src/codec/AbstractArray.ts | 2 +- packages/types/src/codec/Compact.ts | 10 +- packages/types/src/codec/Linkage.ts | 6 +- packages/types/src/codec/Option.spec.ts | 5 + packages/types/src/codec/Struct.spec.ts | 6 +- .../src/codec/{Vector.spec.ts => Vec.spec.ts} | 16 +- .../types/src/codec/{Vector.ts => Vec.ts} | 20 +- .../src/codec/{VectorAny.ts => VecAny.ts} | 4 +- .../src/codec/{VectorFixed.ts => VecFixed.ts} | 20 +- packages/types/src/codec/createType.spec.ts | 6 +- packages/types/src/codec/createType.ts | 34 +- packages/types/src/codec/index.ts | 3 +- packages/types/src/index.types.ts | 1 - packages/types/src/interfaceRegistry.ts | 223 +++++----- .../types/src/primitive/AccountId.spec.ts | 13 +- .../src/{rpc => primitive}/Block.spec.ts | 4 +- .../types/src/{rpc => primitive}/Block.ts | 10 +- packages/types/src/primitive/Bytes.spec.ts | 11 +- packages/types/src/primitive/Bytes.ts | 13 +- .../types/src/primitive/ConsensusEngineId.ts | 77 ++++ .../src/{rpc => primitive}/Digest.spec.ts | 3 +- packages/types/src/primitive/Digest.ts | 194 ++++++++ packages/types/src/primitive/Event.ts | 27 +- packages/types/src/primitive/EventRecord.ts | 117 +---- .../src/{rpc => primitive}/Header.spec.ts | 0 .../types/src/{rpc => primitive}/Header.ts | 2 +- packages/types/src/primitive/KeyValue.spec.ts | 51 --- packages/types/src/primitive/KeyValue.ts | 75 ---- packages/types/src/primitive/Moment.ts | 8 - packages/types/src/primitive/Null.ts | 11 - packages/types/src/primitive/StorageData.ts | 13 - packages/types/src/primitive/index.ts | 39 +- .../types/src/rpc/ChainProperties.spec.ts | 31 -- packages/types/src/rpc/ChainProperties.ts | 26 -- packages/types/src/rpc/Digest.ts | 415 ------------------ packages/types/src/rpc/ExtrinsicStatus.ts | 144 ------ packages/types/src/rpc/Health.ts | 43 -- packages/types/src/rpc/NetworkState.ts | 13 - packages/types/src/rpc/PeerInfo.ts | 62 --- packages/types/src/rpc/RuntimeVersion.ts | 125 ------ packages/types/src/rpc/SignedBlock.ts | 50 --- packages/types/src/rpc/StorageChangeSet.ts | 46 -- packages/types/src/rpc/index.ts | 21 - packages/types/src/scripts/MetadataMd.ts | 2 + packages/types/src/scripts/srmlTS.ts | 60 +-- packages/types/src/srml/authorship/types.ts | 27 +- packages/types/src/srml/babe/types.ts | 8 +- packages/types/src/srml/balances/types.ts | 22 +- packages/types/src/srml/collective/types.ts | 24 +- packages/types/src/srml/consensus/types.ts | 8 +- packages/types/src/srml/contracts/types.ts | 86 ++-- packages/types/src/srml/definitions.ts | 3 + packages/types/src/srml/democracy/types.ts | 52 +-- packages/types/src/srml/deprecated/types.ts | 54 +-- packages/types/src/srml/elections/types.ts | 40 +- packages/types/src/srml/grandpa/types.ts | 53 ++- packages/types/src/srml/imOnline/types.ts | 27 +- packages/types/src/srml/index.ts | 4 + packages/types/src/srml/parachains/types.ts | 221 +++++----- .../src/srml/rpc/ChainProperties.spec.ts | 28 ++ .../{ => srml}/rpc/ExtrinsicStatus.spec.ts | 10 +- .../types/src/srml/rpc/KeyValueOption.spec.ts | 21 + .../src/{ => srml}/rpc/RuntimeVersion.spec.ts | 20 +- .../src/{ => srml}/rpc/SignedBlock.spec.ts | 18 +- .../{ => srml}/rpc/StorageChangeSet.spec.ts | 19 +- packages/types/src/srml/rpc/definitions.ts | 61 +++ packages/types/src/srml/rpc/types.ts | 171 ++++++++ .../types/src/srml/runtime/KeyValue.spec.ts | 45 ++ .../types/src/srml/runtime/definitions.ts | 3 + packages/types/src/srml/runtime/types.ts | 114 +++-- packages/types/src/srml/session/types.ts | 13 +- .../types/src/srml/staking/definitions.ts | 1 + packages/types/src/srml/staking/types.ts | 70 ++- .../system}/EventRecord.spec.ts | 33 +- packages/types/src/srml/system/definitions.ts | 21 +- packages/types/src/srml/system/types.ts | 67 ++- packages/types/src/srml/treasury/types.ts | 10 +- packages/types/src/srml/types.ts | 2 +- packages/types/src/types.ts | 2 +- 144 files changed, 1824 insertions(+), 2224 deletions(-) rename packages/types/src/codec/{Vector.spec.ts => Vec.spec.ts} (92%) rename packages/types/src/codec/{Vector.ts => Vec.ts} (76%) rename packages/types/src/codec/{VectorAny.ts => VecAny.ts} (88%) rename packages/types/src/codec/{VectorFixed.ts => VecFixed.ts} (71%) rename packages/types/src/{rpc => primitive}/Block.spec.ts (93%) rename packages/types/src/{rpc => primitive}/Block.ts (83%) create mode 100644 packages/types/src/primitive/ConsensusEngineId.ts rename packages/types/src/{rpc => primitive}/Digest.spec.ts (93%) create mode 100644 packages/types/src/primitive/Digest.ts rename packages/types/src/{rpc => primitive}/Header.spec.ts (100%) rename packages/types/src/{rpc => primitive}/Header.ts (98%) delete mode 100644 packages/types/src/primitive/KeyValue.spec.ts delete mode 100644 packages/types/src/primitive/KeyValue.ts delete mode 100644 packages/types/src/primitive/StorageData.ts delete mode 100644 packages/types/src/rpc/ChainProperties.spec.ts delete mode 100644 packages/types/src/rpc/ChainProperties.ts delete mode 100644 packages/types/src/rpc/Digest.ts delete mode 100644 packages/types/src/rpc/ExtrinsicStatus.ts delete mode 100644 packages/types/src/rpc/Health.ts delete mode 100644 packages/types/src/rpc/NetworkState.ts delete mode 100644 packages/types/src/rpc/PeerInfo.ts delete mode 100644 packages/types/src/rpc/RuntimeVersion.ts delete mode 100644 packages/types/src/rpc/SignedBlock.ts delete mode 100644 packages/types/src/rpc/StorageChangeSet.ts delete mode 100644 packages/types/src/rpc/index.ts create mode 100644 packages/types/src/srml/rpc/ChainProperties.spec.ts rename packages/types/src/{ => srml}/rpc/ExtrinsicStatus.spec.ts (71%) create mode 100644 packages/types/src/srml/rpc/KeyValueOption.spec.ts rename packages/types/src/{ => srml}/rpc/RuntimeVersion.spec.ts (60%) rename packages/types/src/{ => srml}/rpc/SignedBlock.spec.ts (77%) rename packages/types/src/{ => srml}/rpc/StorageChangeSet.spec.ts (70%) create mode 100644 packages/types/src/srml/rpc/definitions.ts create mode 100644 packages/types/src/srml/rpc/types.ts create mode 100644 packages/types/src/srml/runtime/KeyValue.spec.ts rename packages/types/src/{primitive => srml/system}/EventRecord.spec.ts (57%) diff --git a/packages/api-derive/src/accounts/indexToId.ts b/packages/api-derive/src/accounts/indexToId.ts index 2e288ec679..7d6af36f8f 100644 --- a/packages/api-derive/src/accounts/indexToId.ts +++ b/packages/api-derive/src/accounts/indexToId.ts @@ -6,7 +6,7 @@ import { Observable } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { ENUMSET_SIZE } from '@polkadot/types/primitive/AccountIndex'; -import { AccountId, AccountIndex, Vector } from '@polkadot/types'; +import { AccountId, AccountIndex, Vec } from '@polkadot/types'; import { drr } from '../util/drr'; @@ -30,7 +30,7 @@ export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | s ? _accountIndex : new AccountIndex(_accountIndex); - return (querySection.enumSet>(accountIndex.div(ENUMSET_SIZE))) + return (querySection.enumSet>(accountIndex.div(ENUMSET_SIZE))) .pipe( startWith([]), map((accounts): AccountId | undefined => diff --git a/packages/api-derive/src/balances/votingBalancesNominatorsFor.ts b/packages/api-derive/src/balances/votingBalancesNominatorsFor.ts index 9cde50607d..5f7d21ad9c 100644 --- a/packages/api-derive/src/balances/votingBalancesNominatorsFor.ts +++ b/packages/api-derive/src/balances/votingBalancesNominatorsFor.ts @@ -5,7 +5,7 @@ import { Observable, of } from 'rxjs'; import { switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId, AccountIndex, Address, Vector } from '@polkadot/types'; +import { AccountId, AccountIndex, Address, Vec } from '@polkadot/types'; import { idAndIndex } from '../accounts/idAndIndex'; import { DerivedBalances } from '../types'; @@ -17,7 +17,7 @@ export function votingBalancesNominatorsFor (api: ApiInterfaceRx): (address: Acc return idAndIndex(api)(address).pipe( switchMap(([accountId]): Observable => accountId - ? (api.query.staking.nominatorsFor>(accountId)) + ? (api.query.staking.nominatorsFor>(accountId)) : of([] as AccountId[]) ), switchMap(votingBalances(api)), diff --git a/packages/api-derive/src/democracy/referendumInfos.ts b/packages/api-derive/src/democracy/referendumInfos.ts index f2cb47e547..9becd9b2b2 100644 --- a/packages/api-derive/src/democracy/referendumInfos.ts +++ b/packages/api-derive/src/democracy/referendumInfos.ts @@ -8,7 +8,7 @@ import BN from 'bn.js'; import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { Option, Vector } from '@polkadot/types'; +import { Option, Vec } from '@polkadot/types'; import { ReferendumInfoExtended } from '../type'; import { drr } from '../util/drr'; @@ -19,7 +19,7 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) = return ( !ids || !ids.length ? of([] as Option[]) - : api.query.democracy.referendumInfoOf.multi(ids) as Observable>> + : api.query.democracy.referendumInfoOf.multi(ids) as Observable>> ).pipe( map((infos): Option[] => ids.map((id, index): Option => diff --git a/packages/api-derive/src/democracy/referendumVotesFor.ts b/packages/api-derive/src/democracy/referendumVotesFor.ts index d1fb9f96f1..17083c81ba 100644 --- a/packages/api-derive/src/democracy/referendumVotesFor.ts +++ b/packages/api-derive/src/democracy/referendumVotesFor.ts @@ -8,7 +8,7 @@ import BN from 'bn.js'; import { combineLatest, Observable, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId, Vector, Vote, createType } from '@polkadot/types'; +import { AccountId, Vec, Vote, createType } from '@polkadot/types'; import { DerivedBalances, DerivedReferendumVote } from '../types'; import { drr } from '../util/drr'; @@ -17,8 +17,8 @@ import { votingBalances } from '../balances/votingBalances'; export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | number) => Observable { return (referendumId: BN | number): Observable => - (api.query.democracy.votersFor>(referendumId)).pipe( - switchMap((votersFor): Observable<[Vector, Vote[], DerivedBalances[]]> => + (api.query.democracy.votersFor>(referendumId)).pipe( + switchMap((votersFor): Observable<[Vec, Vote[], DerivedBalances[]]> => combineLatest([ of(votersFor), votes(api)(referendumId as BN, votersFor), diff --git a/packages/api-derive/src/democracy/votes.ts b/packages/api-derive/src/democracy/votes.ts index 225811a78d..212e259bdb 100644 --- a/packages/api-derive/src/democracy/votes.ts +++ b/packages/api-derive/src/democracy/votes.ts @@ -5,7 +5,7 @@ import BN from 'bn.js'; import { Observable, of } from 'rxjs'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId, Vector, Vote } from '@polkadot/types'; +import { AccountId, Vec, Vote } from '@polkadot/types'; import { drr } from '../util/drr'; @@ -19,6 +19,6 @@ export function votes (api: ApiInterfaceRx): (referendumId: BN, accountIds?: Acc [referendumId, accountId] ) ) - ) as Observable>).pipe(drr()); + ) as Observable>).pipe(drr()); }; } diff --git a/packages/api-derive/src/elections/approvalsOf.ts b/packages/api-derive/src/elections/approvalsOf.ts index 8c7827dfe6..71a40a2951 100644 --- a/packages/api-derive/src/elections/approvalsOf.ts +++ b/packages/api-derive/src/elections/approvalsOf.ts @@ -6,7 +6,7 @@ import { ApprovalFlag, SetIndex } from '@polkadot/types/srml/elections/types'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Observable } from 'rxjs'; -import { AccountId, Vector } from '@polkadot/types'; +import { AccountId, Vec } from '@polkadot/types'; import { switchMap, map } from 'rxjs/operators'; import { approvalFlagsToBools } from '../util/approvalFlagsToBools'; import { drr } from '../util/drr'; @@ -27,11 +27,11 @@ export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observabl return (who: AccountId): Observable => (api.query.elections.nextVoterSet()) .pipe( - switchMap((nextVoterSet: SetIndex): Observable[]> => - api.query.elections.approvalsOf.multi([...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [who.toString(), i])) as any as Observable[]> + switchMap((nextVoterSet: SetIndex): Observable[]> => + api.query.elections.approvalsOf.multi([...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [who.toString(), i])) as any as Observable[]> ), - map((votes: Vector[]): boolean[][] => - votes.map((flags: Vector): boolean[] => approvalFlagsToBools(flags)) + map((votes: Vec[]): boolean[][] => + votes.map((flags: Vec): boolean[] => approvalFlagsToBools(flags)) ), drr() ); diff --git a/packages/api-derive/src/elections/approvalsOfAt.ts b/packages/api-derive/src/elections/approvalsOfAt.ts index 7127d224d4..d422cf98c2 100644 --- a/packages/api-derive/src/elections/approvalsOfAt.ts +++ b/packages/api-derive/src/elections/approvalsOfAt.ts @@ -6,7 +6,7 @@ import { ApprovalFlag, SetIndex } from '@polkadot/types/srml/elections/types'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Observable } from 'rxjs'; -import { AccountId, Vector } from '@polkadot/types'; +import { AccountId, Vec } from '@polkadot/types'; import { map } from 'rxjs/operators'; import { approvalFlagsToBools } from '../util/approvalFlagsToBools'; import { drr } from '../util/drr'; @@ -25,9 +25,9 @@ import { drr } from '../util/drr'; */ export function approvalsOfAt (api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable { return (who: AccountId, at: SetIndex): Observable => - (api.query.elections.approvalsOf>([who.toString(), at])) + (api.query.elections.approvalsOf>([who.toString(), at])) .pipe( - map((flags: Vector): boolean[] => approvalFlagsToBools(flags)), + map((flags: Vec): boolean[] => approvalFlagsToBools(flags)), drr() ); } diff --git a/packages/api-derive/src/elections/voterPositions.ts b/packages/api-derive/src/elections/voterPositions.ts index a4ee771f28..56a72e6a60 100644 --- a/packages/api-derive/src/elections/voterPositions.ts +++ b/packages/api-derive/src/elections/voterPositions.ts @@ -4,7 +4,7 @@ import { SetIndex } from '@polkadot/types/srml/elections/types'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId, Vector, Option, createType } from '@polkadot/types'; +import { AccountId, Vec, Option, createType } from '@polkadot/types'; import { DerivedVoterPositions } from '../types'; import BN from 'bn.js'; @@ -28,11 +28,11 @@ import { drr } from '../util/drr'; export function voterPositions (api: ApiInterfaceRx): () => Observable { return (): Observable => api.query.elections.nextVoterSet().pipe( - switchMap((nextVoterSet: SetIndex): Observable<[BN, Vector>[]]> => combineLatest( + switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec>[]]> => combineLatest( of(api.consts.elections.voterSetSize) as any as Observable, - api.query.elections.voters.multi([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i])) as any as Observable>[]> + api.query.elections.voters.multi([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i])) as any as Observable>[]> )), - map((result: [BN, Vector>[]]): DerivedVoterPositions => { + map((result: [BN, Vec>[]]): DerivedVoterPositions => { const [setSize, voters] = result; return voters.reduce((result: DerivedVoterPositions, vec, setIndex): DerivedVoterPositions => { vec.forEach((e, index): void => { diff --git a/packages/api-derive/src/elections/voters.ts b/packages/api-derive/src/elections/voters.ts index f248dc0ab1..7a3bd74daa 100644 --- a/packages/api-derive/src/elections/voters.ts +++ b/packages/api-derive/src/elections/voters.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId, Vector } from '@polkadot/types'; +import { AccountId, Vec } from '@polkadot/types'; import { DerivedVoterPositions } from '../types'; import { Observable } from 'rxjs'; @@ -23,12 +23,12 @@ import { voterPositions } from './voterPositions'; * }); * ``` */ -export function voters (api: ApiInterfaceRx): () => Observable> { - return (): Observable> => +export function voters (api: ApiInterfaceRx): () => Observable> { + return (): Observable> => voterPositions(api)().pipe( map( - (voterPositions: DerivedVoterPositions): Vector => - new Vector( + (voterPositions: DerivedVoterPositions): Vec => + new Vec( AccountId, Object.entries(voterPositions) .sort((a, b): 0 | 1 | -1 => a[1].globalIndex.cmp(b[1].globalIndex)) diff --git a/packages/api-derive/src/staking/info.ts b/packages/api-derive/src/staking/info.ts index ab3fab6ca3..51f7309790 100644 --- a/packages/api-derive/src/staking/info.ts +++ b/packages/api-derive/src/staking/info.ts @@ -12,7 +12,7 @@ import { DerivedStaking, DerivedUnlocking } from '../types'; import BN from 'bn.js'; import { combineLatest, Observable, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; -import { createType, AccountId, Option, Tuple, Vector } from '@polkadot/types'; +import { createType, AccountId, Option, Tuple, Vec } from '@polkadot/types'; import { isUndefined } from '@polkadot/util'; @@ -74,7 +74,7 @@ function redeemableSum (stakingLedger: StakingLedger | undefined, eraLength: BN, .reduce((curr, prev): BN => curr.add(prev.value.unwrap()), new BN(0)); } -function unwrapSessionIds (stashId: AccountId, validatorIds: AccountId[], auraIds: AccountId[], nextKeys: Option | Vector): { nextSessionId?: AccountId; sessionId?: AccountId } { +function unwrapSessionIds (stashId: AccountId, validatorIds: AccountId[], auraIds: AccountId[], nextKeys: Option | Vec): { nextSessionId?: AccountId; sessionId?: AccountId } { // for 2.x we have a Vec<(ValidatorId,Keys)> of the keys if (Array.isArray(nextKeys)) { const validatorIdx = validatorIds.indexOf(stashId); @@ -111,7 +111,7 @@ function withStashController (api: ApiInterfaceRx, accountId: AccountId, control // FIXME while we have 2.x and 1.x support, don't add this to .multi - // should be added when only 2.x api.query.aura && api.query.aura.authorities - ? api.query.aura.authorities>() + ? api.query.aura.authorities>() : of([] as AccountId[]), api.queryMulti([ api.query.session.queuedKeys @@ -124,7 +124,7 @@ function withStashController (api: ApiInterfaceRx, accountId: AccountId, control [api.query.staking.stakers, stashId], [api.query.staking.validators, stashId] ]) - ]) as Observable<[BN, BlockNumber, AccountId[], [Option | Vector, AccountId[], Option, [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]> + ]) as Observable<[BN, BlockNumber, AccountId[], [Option | Vec, AccountId[], Option, [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]> ).pipe( map(([eraLength, bestNumber, auraIds, [nextKeys, validatorIds, _stakingLedger, [nominators], rewardDestination, stakers, [validatorPrefs]]]): DerivedStaking => { const stakingLedger = _stakingLedger.unwrapOr(null) || undefined; @@ -159,7 +159,7 @@ function withControllerLedger (api: ApiInterfaceRx, accountId: AccountId, stakin // FIXME while we have 2.x and 1.x support, don't add this to .multi - // should be added when only 2.x api.query.aura && api.query.aura.authorities - ? api.query.aura.authorities>() + ? api.query.aura.authorities>() : of([] as AccountId[]), api.queryMulti([ api.query.session.queuedKeys @@ -171,7 +171,7 @@ function withControllerLedger (api: ApiInterfaceRx, accountId: AccountId, stakin [api.query.staking.stakers, stashId], [api.query.staking.validators, stashId] ]) - ]) as Observable<[AccountId[], [Option | Vector, AccountId[], [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]> + ]) as Observable<[AccountId[], [Option | Vec, AccountId[], [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]> ).pipe( map(([auraIds, [nextKeys, validatorIds, [nominators], rewardDestination, stakers, [validatorPrefs]]]): DerivedStaking => { const { nextSessionId, sessionId } = unwrapSessionIds(stashId, validatorIds, auraIds, nextKeys); diff --git a/packages/api-derive/src/type/HeaderExtended.ts b/packages/api-derive/src/type/HeaderExtended.ts index 5d91f591c2..ea1a51d460 100644 --- a/packages/api-derive/src/type/HeaderExtended.ts +++ b/packages/api-derive/src/type/HeaderExtended.ts @@ -25,27 +25,27 @@ export default class HeaderExtended extends Header { // extract from the substrate 2.0 PreRuntime digest if (pitem) { - const preRuntime = pitem.asPreRuntime; + const [engine, data] = pitem.asPreRuntime; - if (preRuntime.engine.isAura) { - slot = preRuntime.slot; + if (engine.isAura) { + slot = engine.extractSlot(data); } } else { const [citem] = header.digest.logsWith('Consensus'); // extract author from the consensus (substrate 1.0, digest) if (citem) { - const consensus = citem.asConsensus; + const [engine, data] = citem.asConsensus; - if (consensus.engine.isAura) { - slot = consensus.slot; + if (engine.isAura) { + slot = engine.extractSlot(data); } } else { const [sitem] = header.digest.logsWith('SealV0'); // extract author from the seal (pre substrate 1.0, backwards compat) if (sitem) { - slot = sitem.asSealV0.slot; + slot = sitem.asSealV0[0]; } } } diff --git a/packages/api-derive/src/util/approvalFlagToBool.ts b/packages/api-derive/src/util/approvalFlagToBool.ts index 99d4628297..dea3f47cd3 100644 --- a/packages/api-derive/src/util/approvalFlagToBool.ts +++ b/packages/api-derive/src/util/approvalFlagToBool.ts @@ -5,9 +5,9 @@ import { ApprovalFlag } from '@polkadot/types/srml/elections/types'; import BN from 'bn.js'; -import { Vector } from '@polkadot/types'; +import { Vec } from '@polkadot/types'; -export function approvalFlagToBool (flags: Vector): boolean[] { +export function approvalFlagToBool (flags: Vec): boolean[] { const bools: boolean[] = []; for (const flag of flags) { for (const bit of [...Array(flag.bitLength())].map((_, i): number => i)) { diff --git a/packages/api-derive/src/util/approvalFlagsToBools.ts b/packages/api-derive/src/util/approvalFlagsToBools.ts index 88fed43c04..b2fd43d7fe 100644 --- a/packages/api-derive/src/util/approvalFlagsToBools.ts +++ b/packages/api-derive/src/util/approvalFlagsToBools.ts @@ -4,9 +4,9 @@ import { ApprovalFlag } from '@polkadot/types/srml/elections/types'; -import { Vector } from '@polkadot/types'; +import { Vec } from '@polkadot/types'; -export function approvalFlagsToBools (flags: Vector): boolean[] { +export function approvalFlagsToBools (flags: Vec): boolean[] { const bools: boolean[] = []; flags.forEach((flag: ApprovalFlag): void => { diff --git a/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts b/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts index 75b93a7044..7ce0c0b8d0 100644 --- a/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts +++ b/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ClassOf, Metadata } from '@polkadot/types'; -import json from '@polkadot/types/Metadata/v6/static'; +import json from '@polkadot/types/Metadata/static'; import { injectDefinitions } from '@polkadot/types/srml'; import fromMetadata from '../fromMetadata'; diff --git a/packages/api-metadata/src/consts/static.ts b/packages/api-metadata/src/consts/static.ts index 81737d0ecd..549fde5824 100644 --- a/packages/api-metadata/src/consts/static.ts +++ b/packages/api-metadata/src/consts/static.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Metadata } from '@polkadot/types'; -import metadataRpc from '@polkadot/types/Metadata/v6/static'; +import metadataRpc from '@polkadot/types/Metadata/static'; import fromMetadata from './fromMetadata'; diff --git a/packages/api-metadata/src/extrinsics/static.ts b/packages/api-metadata/src/extrinsics/static.ts index c4c812fe53..963c57824a 100644 --- a/packages/api-metadata/src/extrinsics/static.ts +++ b/packages/api-metadata/src/extrinsics/static.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Metadata } from '@polkadot/types'; -import metadataRpc from '@polkadot/types/Metadata/v6/static'; +import metadataRpc from '@polkadot/types/Metadata/static'; import { ModulesWithMethods } from '@polkadot/types/primitive/Method'; import fromMetadata from './fromMetadata'; diff --git a/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts b/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts index 74db73c494..ebfa2e4159 100644 --- a/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts +++ b/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts @@ -4,7 +4,7 @@ import testingPairs from '@polkadot/keyring/testingPairs'; import { Metadata } from '@polkadot/types'; -import json from '@polkadot/types/Metadata/v6/static'; +import json from '@polkadot/types/Metadata/static'; import { injectDefinitions } from '@polkadot/types/srml'; import { u8aToHex } from '@polkadot/util'; diff --git a/packages/api-metadata/src/storage/fromMetadata/storage.spec.ts b/packages/api-metadata/src/storage/fromMetadata/storage.spec.ts index ce097303f1..9da17d835c 100644 --- a/packages/api-metadata/src/storage/fromMetadata/storage.spec.ts +++ b/packages/api-metadata/src/storage/fromMetadata/storage.spec.ts @@ -2,9 +2,15 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { injectDefinitions } from '@polkadot/types/srml'; + import { storage } from './storage'; describe('storage', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + it('should return well known keys', (): void => { expect(typeof storage.substrate).toBe('object'); diff --git a/packages/api-metadata/src/storage/fromMetadata/substrate.spec.ts b/packages/api-metadata/src/storage/fromMetadata/substrate.spec.ts index b90b15ba33..0c0074e2bc 100644 --- a/packages/api-metadata/src/storage/fromMetadata/substrate.spec.ts +++ b/packages/api-metadata/src/storage/fromMetadata/substrate.spec.ts @@ -2,9 +2,15 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { injectDefinitions } from '@polkadot/types/srml'; + import { authorityCount, authorityPrefix, changesTrieConfig, childStorageKeyPrefix, code, extrinsicIndex, heapPages } from './substrate'; describe('substrate', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + // @deprecated: The ':auth:' (authorityPrefix) and ':auth:len' (authorityCount) storage keys // have been removed in https://github.com/paritytech/substrate/pull/2802 it('authorityCount should return the correct storage key', (): void => { diff --git a/packages/api-metadata/src/storage/fromMetadata/substrate.ts b/packages/api-metadata/src/storage/fromMetadata/substrate.ts index 9f35c759f5..74d075b1f3 100644 --- a/packages/api-metadata/src/storage/fromMetadata/substrate.ts +++ b/packages/api-metadata/src/storage/fromMetadata/substrate.ts @@ -4,7 +4,7 @@ import { StorageEntryMetadata, StorageEntryModifier, StorageEntryType } from '@polkadot/types/Metadata/v6/Storage'; import { StorageEntry } from '@polkadot/types/primitive/StorageKey'; -import { Text, Vector } from '@polkadot/types'; +import { Text, Vec } from '@polkadot/types'; import createFunction from './createFunction'; @@ -18,7 +18,7 @@ const createRuntimeFunction = (method: string, key: string, { documentation, typ createFunction( { meta: { - documentation: new Vector(Text, [documentation]), + documentation: new Vec(Text, [documentation]), modifier: new StorageEntryModifier(1), // default type: new StorageEntryType(type, 0), toJSON: (): any => key diff --git a/packages/api-metadata/src/storage/static.ts b/packages/api-metadata/src/storage/static.ts index 81737d0ecd..549fde5824 100644 --- a/packages/api-metadata/src/storage/static.ts +++ b/packages/api-metadata/src/storage/static.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Metadata } from '@polkadot/types'; -import metadataRpc from '@polkadot/types/Metadata/v6/static'; +import metadataRpc from '@polkadot/types/Metadata/static'; import fromMetadata from './fromMetadata'; diff --git a/packages/api/src/Base.ts b/packages/api/src/Base.ts index bbeaa55dd2..ab2c495b8d 100644 --- a/packages/api/src/Base.ts +++ b/packages/api/src/Base.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ProviderInterface } from '@polkadot/rpc-provider/types'; -import { Hash } from '@polkadot/types/srml/types'; +import { Hash, RuntimeVersion, SignedBlock } from '@polkadot/types/srml/types'; import { AnyFunction, Codec, CodecArg, RegistryTypes } from '@polkadot/types/types'; import { ApiInterfaceRx, ApiInterfaceEvents, ApiOptions, ApiTypes, DecorateMethodOptions, @@ -23,7 +23,7 @@ import { Storage } from '@polkadot/api-metadata/storage/types'; import storageFromMeta from '@polkadot/api-metadata/storage/fromMetadata'; import RpcCore from '@polkadot/rpc-core'; import { WsProvider } from '@polkadot/rpc-provider'; -import { Event, getTypeRegistry, Metadata, Method, RuntimeVersion, SignedBlock, Null, U64 } from '@polkadot/types'; +import { Event, getTypeRegistry, Metadata, Method, Null, u64 } from '@polkadot/types'; import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage'; import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/primitive/Extrinsic/constants'; import { MethodFunction, ModulesWithMethods } from '@polkadot/types/primitive/Method'; @@ -697,7 +697,7 @@ export default abstract class ApiBase { ); decorated.size = decorateMethod( - (arg1?: CodecArg, arg2?: CodecArg): Observable => + (arg1?: CodecArg, arg2?: CodecArg): Observable => this._rpcCore.state.getStorageSize( creator.meta.type.isDoubleMap ? [creator, [arg1, arg2]] diff --git a/packages/api/src/SignerPayload.ts b/packages/api/src/SignerPayload.ts index 17143183a4..e0f7279189 100644 --- a/packages/api/src/SignerPayload.ts +++ b/packages/api/src/SignerPayload.ts @@ -5,7 +5,7 @@ import { Balance, BlockNumber, Hash, Index } from '@polkadot/types/srml/types'; import { SignerPayload as ISignerPayload } from './types'; -import { Address, ClassOf, Compact, ExtrinsicEra, Struct, U8, Method } from '@polkadot/types'; +import { Address, ClassOf, Compact, ExtrinsicEra, Struct, u8, Method } from '@polkadot/types'; export interface SignerPayloadType { address: Address; @@ -16,7 +16,7 @@ export interface SignerPayloadType { method: Method; nonce: Compact; tip: Compact; - version: U8; + version: u8; } export default class SignerPayload extends Struct.with({ @@ -28,7 +28,7 @@ export default class SignerPayload extends Struct.with({ method: Method, nonce: ClassOf('Compact'), tip: ClassOf('Compact'), - version: U8 + version: u8 }) { /** * @description Returns this as a SignerPayloadType. This works since the Struct.with injects all the getters automatically (just ensure the 2 definitiona are matching) diff --git a/packages/api/src/SubmittableExtrinsic.ts b/packages/api/src/SubmittableExtrinsic.ts index 9eeb8aed22..d986270924 100644 --- a/packages/api/src/SubmittableExtrinsic.ts +++ b/packages/api/src/SubmittableExtrinsic.ts @@ -2,14 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Hash, Index } from '@polkadot/types/srml/types'; +import { ExtrinsicStatus, EventRecord, Hash, Index, SignedBlock } from '@polkadot/types/srml/types'; import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types'; import { ApiInterfaceRx, ApiTypes } from './types'; import BN from 'bn.js'; import { Observable, combineLatest, of } from 'rxjs'; import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators'; -import { createType, AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Header, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types'; +import { createType, AccountId, Address, getTypeRegistry, Header, Method, Vec, ExtrinsicEra } from '@polkadot/types'; import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util'; import filterEvents from './util/filterEvents'; @@ -135,7 +135,7 @@ export default function createSubmittableExtrinsic ( return combineLatest([ api.rpc.chain.getBlock(blockHash) as Observable, - api.query.system.events.at(blockHash) as Observable> + api.query.system.events.at(blockHash) as Observable> ]).pipe( map(([signedBlock, allEvents]): SubmittableResult => { const result = new SubmittableResult({ diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index 20dc6c3fd4..1fa75305c9 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Hash } from '@polkadot/types/srml/types'; +import { Hash, RuntimeVersion } from '@polkadot/types/srml/types'; import { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types'; import BN from 'bn.js'; @@ -10,7 +10,7 @@ import { Observable } from 'rxjs'; import { DeriveCustom } from '@polkadot/api-derive'; import { Constants } from '@polkadot/api-metadata/consts/types'; import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types'; -import { RuntimeVersion, u64 as U64 } from '@polkadot/types'; +import { u64 } from '@polkadot/types'; import { MethodFunction } from '@polkadot/types/primitive/Method'; import { StorageEntry } from '@polkadot/types/primitive/StorageKey'; @@ -107,7 +107,7 @@ export interface StorageEntryObservable { hash: (arg1?: CodecArg, arg2?: CodecArg) => Observable; key: (arg1?: CodecArg, arg2?: CodecArg) => string; multi: (args: (CodecArg[] | CodecArg)[]) => Observable; - size: (arg1?: CodecArg, arg2?: CodecArg) => Observable; + size: (arg1?: CodecArg, arg2?: CodecArg) => Observable; } export interface StorageEntryPromiseOverloads { @@ -129,7 +129,7 @@ export interface StorageEntryPromise extends StorageEntryPromiseOverloads { hash: (arg1?: CodecArg, arg2?: CodecArg) => Promise; key: (arg1?: CodecArg, arg2?: CodecArg) => string; multi: StorageEntryPromiseMulti; - size: (arg1?: CodecArg, arg2?: CodecArg) => Promise; + size: (arg1?: CodecArg, arg2?: CodecArg) => Promise; } export type QueryableStorageEntry = diff --git a/packages/api/src/util/filterEvents.ts b/packages/api/src/util/filterEvents.ts index a7ab760d14..f1e8adb9bb 100644 --- a/packages/api/src/util/filterEvents.ts +++ b/packages/api/src/util/filterEvents.ts @@ -2,7 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { EventRecord, SignedBlock, U8a } from '@polkadot/types'; +import { EventRecord, SignedBlock } from '@polkadot/types/srml/types'; + +import { U8a } from '@polkadot/types'; import l from './logging'; diff --git a/packages/api/test/e2e/api/promise-alex-archive.spec.ts b/packages/api/test/e2e/api/promise-alex-archive.spec.ts index f8a0fe9d3d..ac145f58c2 100644 --- a/packages/api/test/e2e/api/promise-alex-archive.spec.ts +++ b/packages/api/test/e2e/api/promise-alex-archive.spec.ts @@ -2,8 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { SignedBlock } from '@polkadot/types/srml/types'; + import WsProvider from '@polkadot/rpc-provider/ws'; -import { Extrinsic, SignedBlock } from '@polkadot/types'; +import { Extrinsic } from '@polkadot/types'; import ApiPromise from '../../../src/promise'; import describeE2E from '../../util/describeE2E'; diff --git a/packages/api/test/e2e/api/promise-alex.spec.ts b/packages/api/test/e2e/api/promise-alex.spec.ts index 4adf245e35..964f5a475f 100644 --- a/packages/api/test/e2e/api/promise-alex.spec.ts +++ b/packages/api/test/e2e/api/promise-alex.spec.ts @@ -2,8 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { EventRecord } from '@polkadot/types/srml/types'; + import WsProvider from '@polkadot/rpc-provider/ws'; -import { AccountId, ClassOf, EventRecord, Header, Option, Vector } from '@polkadot/types'; +import { AccountId, ClassOf, Header, Option, Vec } from '@polkadot/types'; import ApiPromise from '../../../src/promise'; import describeE2E from '../../util/describeE2E'; @@ -72,13 +74,13 @@ describeE2E({ it('makes a query at a latest block (specified)', async (): Promise => { const header = await api.rpc.chain.getHeader() as Header; - const events = await api.query.system.events.at(header.hash) as Vector; + const events = await api.query.system.events.at(header.hash) as Vec; expect(events.length).not.toEqual(0); }); it('subscribes to events', (done): Promise<() => void> => { - return api.query.system.events((events: Vector): void => { + return api.query.system.events((events: Vec): void => { expect(events).not.toHaveLength(0); done(); }); diff --git a/packages/api/test/e2e/api/promise-queries-dev.spec.ts b/packages/api/test/e2e/api/promise-queries-dev.spec.ts index ceec7b705a..e0abaca58c 100644 --- a/packages/api/test/e2e/api/promise-queries-dev.spec.ts +++ b/packages/api/test/e2e/api/promise-queries-dev.spec.ts @@ -9,7 +9,7 @@ import BN from 'bn.js'; import { DerivedBalances } from '@polkadot/api-derive/types'; import testingPairs from '@polkadot/keyring/testingPairs'; import WsProvider from '@polkadot/rpc-provider/ws'; -import { Header, Option, U32, createType } from '@polkadot/types'; +import { Header, Option, u32, createType } from '@polkadot/types'; import ApiPromise from '../../../src/promise'; import describeE2E from '../../util/describeE2E'; @@ -65,7 +65,7 @@ describeE2E({ it('subscribes to queries (default)', (done): Promise<() => void> => { return ( - api.query.staking.minimumValidatorCount((defaultCount: U32): void => { + api.query.staking.minimumValidatorCount((defaultCount: u32): void => { expect(defaultCount.toNumber()).toBe(1); done(); diff --git a/packages/api/test/e2e/api/promise-queries.spec.ts b/packages/api/test/e2e/api/promise-queries.spec.ts index 1e9f5882de..a290741760 100644 --- a/packages/api/test/e2e/api/promise-queries.spec.ts +++ b/packages/api/test/e2e/api/promise-queries.spec.ts @@ -2,12 +2,12 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Hash, SessionIndex } from '@polkadot/types/srml/types'; +import { EventRecord, Hash, SessionIndex } from '@polkadot/types/srml/types'; import { HeaderExtended } from '@polkadot/api-derive'; import WsProvider from '@polkadot/rpc-provider/ws'; import { LinkageResult } from '@polkadot/types/codec/Linkage'; -import { EventRecord, Header, Option, Vector, createType } from '@polkadot/types'; +import { Header, Option, Vec, createType } from '@polkadot/types'; import ApiPromise from '../../../src/promise'; import describeE2E from '../../util/describeE2E'; @@ -80,7 +80,7 @@ describeE2E()('Promise e2e queries', (wsUrl): void => { it('makes a query at a latest block (specified)', async (): Promise => { const header = await api.rpc.chain.getHeader() as Header; - const events = await api.query.system.events.at(header.hash) as Vector; + const events = await api.query.system.events.at(header.hash) as Vec; expect(events.length).not.toEqual(0); diff --git a/packages/api/test/e2e/api/promise-tx.spec.ts b/packages/api/test/e2e/api/promise-tx.spec.ts index 99b4597e31..38030013bd 100644 --- a/packages/api/test/e2e/api/promise-tx.spec.ts +++ b/packages/api/test/e2e/api/promise-tx.spec.ts @@ -2,14 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Hash, Index } from '@polkadot/types/srml/types'; +import { EventRecord, Hash, Index, SignedBlock } from '@polkadot/types/srml/types'; import Keyring from '@polkadot/keyring'; import testingPairs from '@polkadot/keyring/testingPairs'; import WsProvider from '@polkadot/rpc-provider/ws'; import { u8aToHex } from '@polkadot/util'; import { randomAsHex } from '@polkadot/util-crypto'; -import { EventRecord, ExtrinsicEra, Header, SignedBlock } from '@polkadot/types'; +import { ExtrinsicEra, Header } from '@polkadot/types'; import { SubmittableResult } from '../../../src'; import ApiPromise from '../../../src/promise'; diff --git a/packages/api/test/e2e/rpc-core/alexander.spec.ts b/packages/api/test/e2e/rpc-core/alexander.spec.ts index 656b05eef5..e5f5ee0c26 100644 --- a/packages/api/test/e2e/rpc-core/alexander.spec.ts +++ b/packages/api/test/e2e/rpc-core/alexander.spec.ts @@ -2,9 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { SignedBlock, StorageChangeSet } from '@polkadot/types/srml/types'; + import storage from '@polkadot/api-metadata/storage/static'; import WsProvider from '@polkadot/rpc-provider/ws'; -import { ClassOf, SignedBlock, StorageChangeSet } from '@polkadot/types'; +import { ClassOf } from '@polkadot/types'; import Rpc from '@polkadot/rpc-core'; @@ -42,7 +44,7 @@ describe.skip('e2e Alexander - Polkadot', (): void => { .getBlock('0x627847bffdf5f3e01ac440d057dec6a37a12a6f329db7ef8367665574b76b5df') .subscribe((block: SignedBlock): void => { expect(block).toBeDefined(); - expect(block).toBeInstanceOf(SignedBlock); + expect(block).toBeInstanceOf(ClassOf('SignedBlock')); done(); }); }); @@ -52,7 +54,7 @@ describe.skip('e2e Alexander - Polkadot', (): void => { .getBlock('0x53416d53a4b1dfcae9165a89d193608e4aa770414f02267f5b2c4015a2e66091') .subscribe((block: SignedBlock): void => { expect(block).toBeDefined(); - expect(block).toBeInstanceOf(SignedBlock); + expect(block).toBeInstanceOf(ClassOf('SignedBlock')); done(); }); }); diff --git a/packages/api/test/e2e/rpc-core/basics.spec.ts b/packages/api/test/e2e/rpc-core/basics.spec.ts index 2f7d2022ce..f142dc35ca 100644 --- a/packages/api/test/e2e/rpc-core/basics.spec.ts +++ b/packages/api/test/e2e/rpc-core/basics.spec.ts @@ -2,7 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { ChainProperties, Extrinsic, Vector } from '@polkadot/types'; +import { ChainProperties } from '@polkadot/types/srml/types'; + +import { ClassOf, Extrinsic, Vec } from '@polkadot/types'; import WsProvider from '@polkadot/rpc-provider/ws'; import Rpc from '@polkadot/rpc-core'; @@ -18,8 +20,8 @@ describe.skip('e2e basics', (): void => { it('retrieves the pending extrinsics', (done): void => { rpc.author .pendingExtrinsics() - .subscribe((extrinsics: Vector): void => { - expect(extrinsics).toBeInstanceOf(Vector); + .subscribe((extrinsics: Vec): void => { + expect(extrinsics).toBeInstanceOf(Vec); done(); }); }); @@ -28,7 +30,7 @@ describe.skip('e2e basics', (): void => { rpc.system .properties() .subscribe((properties: ChainProperties): void => { - expect(properties).toBeInstanceOf(ChainProperties); + expect(properties).toBeInstanceOf(ClassOf('ChainProperties')); console.log('properties', properties); done(); }); diff --git a/packages/api/test/e2e/rpc-core/chain.spec.ts b/packages/api/test/e2e/rpc-core/chain.spec.ts index 1796972414..f6d88ee3c0 100644 --- a/packages/api/test/e2e/rpc-core/chain.spec.ts +++ b/packages/api/test/e2e/rpc-core/chain.spec.ts @@ -2,7 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Header, RuntimeVersion } from '@polkadot/types'; +import { RuntimeVersion } from '@polkadot/types/srml/types'; + +import { ClassOf, Header } from '@polkadot/types'; import WsProvider from '@polkadot/rpc-provider/ws'; import Rpc from '@polkadot/rpc-core'; @@ -33,7 +35,7 @@ describe.skip('e2e chain', (): void => { rpc.chain .getRuntimeVersion() .subscribe((version: RuntimeVersion): void => { - expect(version).toBeInstanceOf(RuntimeVersion); + expect(version).toBeInstanceOf(ClassOf('RuntimeVersion')); done(); }); }); diff --git a/packages/api/test/e2e/rpc-core/state.spec.ts b/packages/api/test/e2e/rpc-core/state.spec.ts index e4fc296793..ea425fdbcc 100644 --- a/packages/api/test/e2e/rpc-core/state.spec.ts +++ b/packages/api/test/e2e/rpc-core/state.spec.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Balance, Hash } from '@polkadot/types/srml/types'; +import { Balance, Hash, StorageData } from '@polkadot/types/srml/types'; import fs from 'fs'; import path from 'path'; @@ -14,7 +14,7 @@ import { Abi } from '@polkadot/api-contract'; import testingPairs from '@polkadot/keyring/testingPairs'; import { KeyringPair } from '@polkadot/keyring/types'; import WsProvider from '@polkadot/rpc-provider/ws'; -import { Bytes, Metadata, Moment, StorageData, StorageKey } from '@polkadot/types'; +import { Bytes, Metadata, Moment, StorageKey } from '@polkadot/types'; import Rpc from '@polkadot/rpc-core'; import flipperAbi from '../../../../api-contract/test/contracts/flipper.json'; diff --git a/packages/api/test/e2e/rpc-core/subscribe.spec.ts b/packages/api/test/e2e/rpc-core/subscribe.spec.ts index 589cf9f768..3389a35d41 100644 --- a/packages/api/test/e2e/rpc-core/subscribe.spec.ts +++ b/packages/api/test/e2e/rpc-core/subscribe.spec.ts @@ -2,7 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { StorageChangeSet } from '@polkadot/types'; +import { StorageChangeSet } from '@polkadot/types/srml/types'; + import WsProvider from '@polkadot/rpc-provider/ws'; import storage from '@polkadot/api-metadata/storage/static'; diff --git a/packages/rpc-core/src/formatting.spec.ts b/packages/rpc-core/src/formatting.spec.ts index 7fa3f46bbc..abf0909688 100644 --- a/packages/rpc-core/src/formatting.spec.ts +++ b/packages/rpc-core/src/formatting.spec.ts @@ -12,7 +12,7 @@ import { injectDefinitions } from '@polkadot/types/srml'; import rpcMetadataV3 from '@polkadot/types/Metadata/v3/static'; import rpcMetadataV4 from '@polkadot/types/Metadata/v4/static'; import rpcMetadataV5 from '@polkadot/types/Metadata/v5/static'; -import rpcMetadataV6 from '@polkadot/types/Metadata/v6/static'; +import rpcMetadataV6 from '@polkadot/types/Metadata/static'; import rpcMetadataV7 from '@polkadot/types/Metadata/v7/static'; import Api from '.'; diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index ab1db0ce75..819d926494 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -4,6 +4,7 @@ import { ProviderInterface } from '@polkadot/rpc-provider/types'; import { RpcSection, RpcMethod } from '@polkadot/jsonrpc/types'; +import { StorageChangeSet, StorageData } from '@polkadot/types/srml/types'; import { AnyJson, Codec } from '@polkadot/types/types'; import { RpcInterface, RpcInterfaceMethod, RpcInterfaceSection } from './types'; @@ -11,7 +12,7 @@ import memoizee from 'memoizee'; import { combineLatest, from, Observable, Observer, of, throwError } from 'rxjs'; import { catchError, map, publishReplay, refCount, switchMap } from 'rxjs/operators'; import interfaces from '@polkadot/jsonrpc'; -import { Option, StorageChangeSet, StorageData, StorageKey, Vector, createClass, createType } from '@polkadot/types'; +import { ClassOf, Option, StorageKey, Vec, createClass, createType } from '@polkadot/types'; import { ExtError, assert, isFunction, isNull, isNumber, logger } from '@polkadot/util'; const l = logger('rpc-core'); @@ -277,13 +278,13 @@ export default class Rpc implements RpcInterface { throw error; } - } else if (method.type === 'StorageChangeSet') { + } else if ((method.type as string) === 'StorageChangeSet') { // multiple return values (via state.storage subscription), decode the values // one at a time, all based on the query types. Three values can be returned - // - Base - There is a valid value, non-empty // - null - The storage key is empty (but in the resultset) // - undefined - The storage value is not in the resultset - return (params[0] as Vector).reduce((results, key: StorageKey): (Codec | undefined)[] => { + return (params[0] as Vec).reduce((results, key: StorageKey): (Codec | undefined)[] => { try { results.push(this.formatStorageSet(key, base as StorageChangeSet)); } catch (error) { @@ -323,9 +324,9 @@ export default class Rpc implements RpcInterface { // see if we have a result value for this specific key, fallback to the cache value // when the value in the set is not available, or is null/empty. - const { value } = base.changes.find(({ key, value }): boolean => + const [, value] = base.changes.find(([key, value]): boolean => value.isSome && key.toHex() === hexKey - ) || { value: this._storageCache.get(hexKey) || new Option(StorageData, null) }; + ) || [null, this._storageCache.get(hexKey) || new Option(ClassOf('StorageData'), null)]; // store the retrieved result - the only issue with this cache is that there is no // clearning of it, so very long running processes (not just a couple of hours, longer) diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index f9f1b69127..360824019d 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -3,6 +3,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { Codec } from '@polkadot/types/types'; import { ProviderInterface, ProviderInterfaceEmitted, ProviderInterfaceEmitCb } from '../types'; import { MockStateSubscriptions, MockStateSubscriptionCallback, MockStateDb } from './types'; @@ -11,10 +12,9 @@ import EventEmitter from 'eventemitter3'; import interfaces from '@polkadot/jsonrpc'; import testKeyring from '@polkadot/keyring/testing'; import storage from '@polkadot/api-metadata/storage/static'; -import { Codec } from '@polkadot/types/types'; import rpcMetadata from '@polkadot/types/Metadata/static'; import rpcSignedBlock from '@polkadot/types/json/SignedBlock.004.immortal.json'; -import { Header, RuntimeVersion, SignedBlock } from '@polkadot/types'; +import { createType, Header } from '@polkadot/types'; import { bnToU8a, logger, u8aToHex } from '@polkadot/util'; import { randomAsU8a } from '@polkadot/util-crypto'; @@ -48,10 +48,10 @@ export default class Mock implements ProviderInterface { private requests: Record string> = { // eslint-disable-next-line @typescript-eslint/no-unused-vars - chain_getBlock: (hash: string): any => new SignedBlock(rpcSignedBlock.result).toJSON(), + chain_getBlock: (hash: string): any => createType('SignedBlock', rpcSignedBlock.result).toJSON(), // eslint-disable-next-line @typescript-eslint/no-unused-vars chain_getBlockHash: (blockNumber: number): string => '0x1234', - chain_getRuntimeVersion: (): string => new RuntimeVersion().toHex(), + chain_getRuntimeVersion: (): string => createType('RuntimeVersion').toHex(), state_getStorage: (storage: MockStateDb, params: any[]): string => { return u8aToHex( storage[(params[0] as string)] diff --git a/packages/type-jsonrpc/src/types.ts b/packages/type-jsonrpc/src/types.ts index 002b74477e..3c02727776 100644 --- a/packages/type-jsonrpc/src/types.ts +++ b/packages/type-jsonrpc/src/types.ts @@ -2,14 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { CodecTypes } from '@polkadot/types/classes'; +// import { CodecTypes } from '@polkadot/types/classes'; type PubSub = [string, string, string]; export interface RpcParam { isOptional: boolean; name: string; - type: CodecTypes; + type: string; // CodecTypes; } export interface RpcMethodOpt { @@ -20,7 +20,7 @@ export interface RpcMethodOpt { isSubscription?: boolean; params: RpcParam[]; pubsub?: PubSub; - type: CodecTypes; + type: string; // CodecTypes; } export interface RpcMethod { @@ -34,7 +34,7 @@ export interface RpcMethod { params: RpcParam[]; pubsub: PubSub; section: string; - type: CodecTypes; + type: string; // CodecTypes; } export interface RpcSection { diff --git a/packages/types/README.md b/packages/types/README.md index 5b1fff4e46..a3edef6cf3 100644 --- a/packages/types/README.md +++ b/packages/types/README.md @@ -23,8 +23,8 @@ These are the base types of the codec. They are typically not used directly, but | [[U8a]] | A basic wrapper around Uint8Array. It will consume the full Uint8Array as passed to it | | [[U8aFixed]] | A U8a that manages a a sequence of bytes up to the specified bitLength | | [[UInt]] | A generic unsigned integer codec. It handles the encoding and decoding of Little Endian encoded numbers in Substrate | -| [[Vector]] | This manages codec arrays. Internally it keeps track of the length (as decoded) | -| [[VectorAny]] | This manages codec arrays, assuming that the inputs are already of type Codec | +| [[Vec]] | This manages codec arrays. Internally it keeps track of the length (as decoded) | +| [[VecAny]] | This manages codec arrays, assuming that the inputs are already of type Codec | ## Primitive types diff --git a/packages/types/src/Metadata/types.ts b/packages/types/src/Metadata/types.ts index 19b074894e..379952a8e4 100644 --- a/packages/types/src/Metadata/types.ts +++ b/packages/types/src/Metadata/types.ts @@ -2,10 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Vector } from '../codec'; +import { Vec } from '../codec'; import { Codec } from '../types'; export interface MetadataInterface extends Codec { - modules: Vector; + modules: Vec; getUniqTypes (throwError: boolean): string[]; } diff --git a/packages/types/src/Metadata/util/validateTypes.ts b/packages/types/src/Metadata/util/validateTypes.ts index 7941248f03..b091fbde4b 100644 --- a/packages/types/src/Metadata/util/validateTypes.ts +++ b/packages/types/src/Metadata/util/validateTypes.ts @@ -19,10 +19,10 @@ export default function validateTypes (types: string[], throwError: boolean): vo case TypeDefInfo.Compact: case TypeDefInfo.Option: - case TypeDefInfo.Vector: + case TypeDefInfo.Vec: return extractTypes([(decoded.sub as TypeDef).type]); - case TypeDefInfo.VectorFixed: + case TypeDefInfo.VecFixed: return extractTypes([(decoded.ext as TypeDefExtVecFixed).type]); case TypeDefInfo.Tuple: diff --git a/packages/types/src/Metadata/v0/Calls.ts b/packages/types/src/Metadata/v0/Calls.ts index ec897dd32a..0b571a5f9b 100644 --- a/packages/types/src/Metadata/v0/Calls.ts +++ b/packages/types/src/Metadata/v0/Calls.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import U16 from '../../primitive/U16'; @@ -42,15 +42,15 @@ export class OuterDispatchMetadata extends Struct { public constructor (value?: any) { super({ name: Text, - calls: Vector.with(OuterDispatchCall) + calls: Vec.with(OuterDispatchCall) }, value); } /** * @description The [[OuterDispathCall]] wrapped */ - public get calls (): Vector { - return this.get('calls') as Vector; + public get calls (): Vec { + return this.get('calls') as Vec; } /** diff --git a/packages/types/src/Metadata/v0/Events.ts b/packages/types/src/Metadata/v0/Events.ts index f218440170..ce910bf45c 100644 --- a/packages/types/src/Metadata/v0/Events.ts +++ b/packages/types/src/Metadata/v0/Events.ts @@ -4,7 +4,7 @@ import Struct from '../../codec/Struct'; import Tuple from '../../codec/Tuple'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; @@ -12,38 +12,38 @@ export class EventMetadata extends Struct { public constructor (value?: any) { super({ name: Text, - args: Vector.with(Type), - documentation: Vector.with(Text) + args: Vec.with(Type), + documentation: Vec.with(Text) }, value); } /** * @description The arguments of [[Type]] */ - public get args (): Vector { - return this.get('args') as Vector; + public get args (): Vec { + return this.get('args') as Vec; } /** * @description The arguments of [[Type]] * @deprecated Use `.args` instead */ - public get arguments (): Vector { + public get arguments (): Vec { return this.args; } /** * @description The [[Text]] documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } /** * @description The [[Text]] documentation * @deprecated Use `.documentation` instead. */ - public get docs (): Vector { + public get docs (): Vec { return this.documentation; } @@ -59,15 +59,15 @@ export class OuterEventEventMetadata extends Tuple { public constructor (value?: any) { super({ Text, - 'Vec': Vector.with(EventMetadata) + 'Vec': Vec.with(EventMetadata) }, value); } /** * @description The [[EventMetadata]] */ - public get events (): Vector { - return this[1] as Vector; + public get events (): Vec { + return this[1] as Vec; } /** @@ -82,15 +82,15 @@ export class OuterEventMetadata extends Struct { public constructor (value?: any) { super({ name: Text, - events: Vector.with(OuterEventEventMetadata) + events: Vec.with(OuterEventEventMetadata) }, value); } /** * @description The [[OuterEventEventMetadata]] */ - public get events (): Vector { - return this.get('events') as Vector; + public get events (): Vec { + return this.get('events') as Vec; } /** diff --git a/packages/types/src/Metadata/v0/Metadata.ts b/packages/types/src/Metadata/v0/Metadata.ts index 8b6fed26d7..42093f7d8a 100644 --- a/packages/types/src/Metadata/v0/Metadata.ts +++ b/packages/types/src/Metadata/v0/Metadata.ts @@ -8,7 +8,7 @@ import { hexToU8a, isHex, isU8a } from '@polkadot/util'; import Compact from '../../codec/Compact'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import { flattenUniq, validateTypes } from '../util'; import { OuterDispatchMetadata, OuterDispatchCall } from './Calls'; import { OuterEventMetadata, OuterEventEventMetadata } from './Events'; @@ -25,7 +25,7 @@ export default class MetadataV0 extends Struct implements MetadataInterface { + public get calls (): Vec { return (this.get('outerDispatch') as OuterDispatchMetadata).calls; } /** * @description Wrapped [[OuterEventEventMetadata]] */ - public get events (): Vector { + public get events (): Vec { return (this.get('outerEvent') as OuterEventMetadata).events; } /** * @description Wrapped [[RuntimeModuleMetadata]] */ - public get modules (): Vector { - return this.get('modules') as Vector; + public get modules (): Vec { + return this.get('modules') as Vec; } private get argNames (): string[][][] { diff --git a/packages/types/src/Metadata/v0/Modules.ts b/packages/types/src/Metadata/v0/Modules.ts index 8feedef304..71e8e9a726 100644 --- a/packages/types/src/Metadata/v0/Modules.ts +++ b/packages/types/src/Metadata/v0/Modules.ts @@ -4,7 +4,7 @@ import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; import U16 from '../../primitive/U16'; @@ -39,38 +39,38 @@ export class FunctionMetadata extends Struct { super({ id: U16, name: Text, - args: Vector.with(FunctionArgumentMetadata), - documentation: Vector.with(Text) + args: Vec.with(FunctionArgumentMetadata), + documentation: Vec.with(Text) }, value); } /** * @description The arguments of [[Type]] */ - public get args (): Vector { - return this.get('args') as Vector; + public get args (): Vec { + return this.get('args') as Vec; } /** * @description The [[FunctionArgumentMetadata]] for arguments * @deprecated Use `.args` instead */ - public get arguments (): Vector { - return this.get('arguments') as Vector; + public get arguments (): Vec { + return this.get('arguments') as Vec; } /** * @description The [[Text]] documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } /** * @description The [[Text]] documentation * @deprecated Use `.documentation` instead. */ - public get docs (): Vector { + public get docs (): Vec { return this.documentation; } @@ -93,15 +93,15 @@ export class CallMetadata extends Struct { public constructor (value?: any) { super({ name: Text, - functions: Vector.with(FunctionMetadata) + functions: Vec.with(FunctionMetadata) }, value); } /** * @description The functions available as [[FunctionMetadata]] */ - public get functions (): Vector { - return this.get('functions') as Vector; + public get functions (): Vec { + return this.get('functions') as Vec; } /** diff --git a/packages/types/src/Metadata/v0/Storage.ts b/packages/types/src/Metadata/v0/Storage.ts index 81964a7c13..efa714f05d 100644 --- a/packages/types/src/Metadata/v0/Storage.ts +++ b/packages/types/src/Metadata/v0/Storage.ts @@ -8,7 +8,7 @@ import { assert } from '@polkadot/util'; import Enum from '../../codec/Enum'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Bytes from '../../primitive/Bytes'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; @@ -131,7 +131,7 @@ export interface StorageFunctionMetadataValue { modifier: StorageFunctionModifier | AnyNumber; type: StorageFunctionType; fallback: Bytes; - documentation: Vector | string[]; + documentation: Vec | string[]; } export class StorageFunctionMetadata extends Struct { @@ -141,7 +141,7 @@ export class StorageFunctionMetadata extends Struct { modifier: StorageFunctionModifier, type: StorageFunctionType, fallback: Bytes, - documentation: Vector.with(Text) + documentation: Vec.with(Text) }, value); } @@ -163,15 +163,15 @@ export class StorageFunctionMetadata extends Struct { /** * @description The [[Text]] documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } /** * @description The [[Text]] documentation * @deprecated Use `.documentation` instead. */ - public get docs (): Vector { + public get docs (): Vec { return this.documentation; } @@ -201,15 +201,15 @@ export class StorageMetadata extends Struct { public constructor (value?: any) { super({ prefix: Text, - functions: Vector.with(StorageFunctionMetadata) + functions: Vec.with(StorageFunctionMetadata) }, value); } /** * @description The [[StorageFunctionMetadata]] for the section */ - public get functions (): Vector { - return this.get('functions') as Vector; + public get functions (): Vec { + return this.get('functions') as Vec; } /** diff --git a/packages/types/src/Metadata/v0/toV1.ts b/packages/types/src/Metadata/v0/toV1.ts index 592148aa3a..b18982ba01 100644 --- a/packages/types/src/Metadata/v0/toV1.ts +++ b/packages/types/src/Metadata/v0/toV1.ts @@ -5,7 +5,7 @@ import { stringUpperFirst } from '@polkadot/util'; -import { Option, Vector } from '../../codec'; +import { Option, Vec } from '../../codec'; import MetadataV0 from './Metadata'; import { RuntimeModuleMetadata } from './Modules'; import { Text } from '../../primitive'; @@ -16,23 +16,23 @@ import { StorageFunctionMetadata } from '../v1/Storage'; function toV1Calls (modul: RuntimeModuleMetadata): Option { return modul.module.call.functions.length === 0 - ? new Option(Vector.with(FunctionMetadata)) - : new Option(Vector.with(FunctionMetadata), modul.module.call.functions); + ? new Option(Vec.with(FunctionMetadata)) + : new Option(Vec.with(FunctionMetadata), modul.module.call.functions); } function toV1Events (metadataV0: MetadataV0, prefix: Text): Option { const events = metadataV0.events.find((event): boolean => event.name.eq(prefix)); return events - ? new Option(Vector.with(EventMetadata), events.events) - : new Option(Vector.with(EventMetadata)); + ? new Option(Vec.with(EventMetadata), events.events) + : new Option(Vec.with(EventMetadata)); } function toV1Storage (modul: RuntimeModuleMetadata): Option { return modul.storage.isNone - ? new Option(Vector.with(StorageFunctionMetadata)) + ? new Option(Vec.with(StorageFunctionMetadata)) : new Option( - Vector.with(StorageFunctionMetadata), + Vec.with(StorageFunctionMetadata), modul.storage.unwrap().functions ); } diff --git a/packages/types/src/Metadata/v1/Calls.ts b/packages/types/src/Metadata/v1/Calls.ts index 4fbe8b54d7..6ccea3a4a1 100644 --- a/packages/types/src/Metadata/v1/Calls.ts +++ b/packages/types/src/Metadata/v1/Calls.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; @@ -39,30 +39,30 @@ export class FunctionMetadata extends Struct { public constructor (value?: any) { super({ name: Text, - args: Vector.with(FunctionArgumentMetadata), - documentation: Vector.with(Text) + args: Vec.with(FunctionArgumentMetadata), + documentation: Vec.with(Text) }, value); } /** * @description The [[FunctionArgumentMetadata]] for arguments */ - public get args (): Vector { - return this.get('args') as Vector; + public get args (): Vec { + return this.get('args') as Vec; } /** * @description The [[Text]] documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } /** * @description The [[Text]] documentation * @deprecated Use `.documentation` instead. */ - public get docs (): Vector { + public get docs (): Vec { return this.documentation; } diff --git a/packages/types/src/Metadata/v1/Metadata.ts b/packages/types/src/Metadata/v1/Metadata.ts index 0dff7432df..7aeb6477ad 100644 --- a/packages/types/src/Metadata/v1/Metadata.ts +++ b/packages/types/src/Metadata/v1/Metadata.ts @@ -6,7 +6,7 @@ import { MetadataInterface } from '../types'; import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; @@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct { super({ name: Text, prefix: Text, - storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(FunctionMetadata)), - events: Option.with(Vector.with(EventMetadata)) + storage: Option.with(Vec.with(StorageFunctionMetadata)), + calls: Option.with(Vec.with(FunctionMetadata)), + events: Option.with(Vec.with(EventMetadata)) }, value); } /** * @description the module calls */ - public get calls (): Option> { - return this.get('calls') as Option>; + public get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - public get events (): Option> { - return this.get('events') as Option>; + public get events (): Option> { + return this.get('events') as Option>; } /** @@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct { /** * @description the associated module storage */ - public get storage (): Option> { - return this.get('storage') as Option>; + public get storage (): Option> { + return this.get('storage') as Option>; } } @@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct { export default class MetadataV1 extends Struct implements MetadataInterface { public constructor (value?: any) { super({ - modules: Vector.with(ModuleMetadata) + modules: Vec.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - public get modules (): Vector { - return this.get('modules') as Vector; + public get modules (): Vec { + return this.get('modules') as Vec; } private get callNames (): string[][][] { diff --git a/packages/types/src/Metadata/v2/Metadata.ts b/packages/types/src/Metadata/v2/Metadata.ts index 7b4ea05086..11de70f068 100644 --- a/packages/types/src/Metadata/v2/Metadata.ts +++ b/packages/types/src/Metadata/v2/Metadata.ts @@ -6,7 +6,7 @@ import { MetadataInterface } from '../types'; import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; @@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct { super({ name: Text, prefix: Text, - storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(FunctionMetadata)), - events: Option.with(Vector.with(EventMetadata)) + storage: Option.with(Vec.with(StorageFunctionMetadata)), + calls: Option.with(Vec.with(FunctionMetadata)), + events: Option.with(Vec.with(EventMetadata)) }, value); } /** * @description the module calls */ - public get calls (): Option> { - return this.get('calls') as Option>; + public get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - public get events (): Option> { - return this.get('events') as Option>; + public get events (): Option> { + return this.get('events') as Option>; } /** @@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct { /** * @description the associated module storage */ - public get storage (): Option> { - return this.get('storage') as Option>; + public get storage (): Option> { + return this.get('storage') as Option>; } } @@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct { export default class MetadataV2 extends Struct implements MetadataInterface { public constructor (value?: any) { super({ - modules: Vector.with(ModuleMetadata) + modules: Vec.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - public get modules (): Vector { - return this.get('modules') as Vector; + public get modules (): Vec { + return this.get('modules') as Vec; } private get callNames (): string[][][] { diff --git a/packages/types/src/Metadata/v2/Storage.ts b/packages/types/src/Metadata/v2/Storage.ts index 2ef36770e3..0969282e70 100644 --- a/packages/types/src/Metadata/v2/Storage.ts +++ b/packages/types/src/Metadata/v2/Storage.ts @@ -8,7 +8,7 @@ import { assert } from '@polkadot/util'; import Enum from '../../codec/Enum'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Bool from '../../primitive/Bool'; import Bytes from '../../primitive/Bytes'; import Text from '../../primitive/Text'; @@ -113,7 +113,7 @@ export interface StorageFunctionMetadataValue { modifier: StorageFunctionModifier | AnyNumber; type: StorageFunctionType; fallback: Bytes; - documentation: Vector | string[]; + documentation: Vec | string[]; } /** @@ -128,7 +128,7 @@ export class StorageFunctionMetadata extends Struct { modifier: StorageFunctionModifier, type: StorageFunctionType, fallback: Bytes, - documentation: Vector.with(Text) + documentation: Vec.with(Text) }, value); } @@ -143,15 +143,15 @@ export class StorageFunctionMetadata extends Struct { /** * @description The [[Text]] documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } /** * @description The [[Text]] documentation * @deprecated Use `.documentation` instead. */ - public get docs (): Vector { + public get docs (): Vec { return this.documentation; } diff --git a/packages/types/src/Metadata/v3/Metadata.ts b/packages/types/src/Metadata/v3/Metadata.ts index 81bc649c33..e4b452d7a9 100644 --- a/packages/types/src/Metadata/v3/Metadata.ts +++ b/packages/types/src/Metadata/v3/Metadata.ts @@ -6,7 +6,7 @@ import { MetadataInterface } from '../types'; import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; @@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct { super({ name: Text, prefix: Text, - storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(FunctionMetadata)), - events: Option.with(Vector.with(EventMetadata)) + storage: Option.with(Vec.with(StorageFunctionMetadata)), + calls: Option.with(Vec.with(FunctionMetadata)), + events: Option.with(Vec.with(EventMetadata)) }, value); } /** * @description the module calls */ - public get calls (): Option> { - return this.get('calls') as Option>; + public get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - public get events (): Option> { - return this.get('events') as Option>; + public get events (): Option> { + return this.get('events') as Option>; } /** @@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct { /** * @description the associated module storage */ - public get storage (): Option> { - return this.get('storage') as Option>; + public get storage (): Option> { + return this.get('storage') as Option>; } } @@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct { export default class MetadataV3 extends Struct implements MetadataInterface { public constructor (value?: any) { super({ - modules: Vector.with(ModuleMetadata) + modules: Vec.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - public get modules (): Vector { - return this.get('modules') as Vector; + public get modules (): Vec { + return this.get('modules') as Vec; } private get callNames (): string[][][] { diff --git a/packages/types/src/Metadata/v3/Storage.ts b/packages/types/src/Metadata/v3/Storage.ts index d628cb68b1..f3cde893ba 100644 --- a/packages/types/src/Metadata/v3/Storage.ts +++ b/packages/types/src/Metadata/v3/Storage.ts @@ -8,7 +8,7 @@ import { assert } from '@polkadot/util'; import Enum from '../../codec/Enum'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Bytes from '../../primitive/Bytes'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; @@ -146,7 +146,7 @@ export interface StorageFunctionMetadataValue { modifier: StorageFunctionModifier | AnyNumber; type: StorageFunctionType; fallback: Bytes; - documentation: Vector | string[]; + documentation: Vec | string[]; } /** @@ -161,7 +161,7 @@ export class StorageFunctionMetadata extends Struct { modifier: StorageFunctionModifier, type: StorageFunctionType, fallback: Bytes, - documentation: Vector.with(Text) + documentation: Vec.with(Text) }, value); } @@ -176,15 +176,15 @@ export class StorageFunctionMetadata extends Struct { /** * @description The [[Text]] documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } /** * @description The [[Text]] documentation * @deprecated Use `.documentation` instead. */ - public get docs (): Vector { + public get docs (): Vec { return this.documentation; } diff --git a/packages/types/src/Metadata/v3/toV4.ts b/packages/types/src/Metadata/v3/toV4.ts index 8848df0fff..553b56f389 100644 --- a/packages/types/src/Metadata/v3/toV4.ts +++ b/packages/types/src/Metadata/v3/toV4.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Option, Vector } from '../../codec'; +import { Option, Vec } from '../../codec'; import MetadataV3 from './Metadata'; import StorageHasher from '../../primitive/StorageHasher'; import MetadataV4 from '../v4'; @@ -57,7 +57,7 @@ export default function toV4 (metadataV3: MetadataV3): MetadataV4 { prefix: modul.prefix, storage: modul.storage.isSome ? new Option( - Vector.with(StorageFunctionMetadata), + Vec.with(StorageFunctionMetadata), modul.storage.unwrap().map(toV4StorageFunction) ) : undefined, diff --git a/packages/types/src/Metadata/v4/Metadata.ts b/packages/types/src/Metadata/v4/Metadata.ts index 168f50aac3..e90f149061 100644 --- a/packages/types/src/Metadata/v4/Metadata.ts +++ b/packages/types/src/Metadata/v4/Metadata.ts @@ -6,7 +6,7 @@ import { MetadataInterface } from '../types'; import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; @@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct { super({ name: Text, prefix: Text, - storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(FunctionMetadata)), - events: Option.with(Vector.with(EventMetadata)) + storage: Option.with(Vec.with(StorageFunctionMetadata)), + calls: Option.with(Vec.with(FunctionMetadata)), + events: Option.with(Vec.with(EventMetadata)) }, value); } /** * @description the module calls */ - public get calls (): Option> { - return this.get('calls') as Option>; + public get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - public get events (): Option> { - return this.get('events') as Option>; + public get events (): Option> { + return this.get('events') as Option>; } /** @@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct { /** * @description the associated module storage */ - public get storage (): Option> { - return this.get('storage') as Option>; + public get storage (): Option> { + return this.get('storage') as Option>; } } @@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct { export default class MetadataV4 extends Struct implements MetadataInterface { public constructor (value?: any) { super({ - modules: Vector.with(ModuleMetadata) + modules: Vec.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - public get modules (): Vector { - return this.get('modules') as Vector; + public get modules (): Vec { + return this.get('modules') as Vec; } private get callNames (): string[][][] { diff --git a/packages/types/src/Metadata/v4/Storage.ts b/packages/types/src/Metadata/v4/Storage.ts index 7ecafda049..cd301a81c0 100644 --- a/packages/types/src/Metadata/v4/Storage.ts +++ b/packages/types/src/Metadata/v4/Storage.ts @@ -8,7 +8,7 @@ import { assert } from '@polkadot/util'; import Enum from '../../codec/Enum'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Bool from '../../primitive/Bool'; import Bytes from '../../primitive/Bytes'; import StorageHasher from '../../primitive/StorageHasher'; @@ -190,7 +190,7 @@ export interface StorageFunctionMetadataValue { modifier: StorageFunctionModifier | AnyNumber; type: StorageFunctionType; fallback: Bytes; - documentation: Vector | string[]; + documentation: Vec | string[]; } /** @@ -205,7 +205,7 @@ export class StorageFunctionMetadata extends Struct { modifier: StorageFunctionModifier, type: StorageFunctionType, fallback: Bytes, - documentation: Vector.with(Text) + documentation: Vec.with(Text) }, value); } @@ -227,15 +227,15 @@ export class StorageFunctionMetadata extends Struct { /** * @description The [[Text]] documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } /** * @description The [[Text]] documentation * @deprecated Use `.documentation` instead. */ - public get docs (): Vector { + public get docs (): Vec { return this.documentation; } diff --git a/packages/types/src/Metadata/v4/toV5.ts b/packages/types/src/Metadata/v4/toV5.ts index 11419d7311..b00ba740a1 100644 --- a/packages/types/src/Metadata/v4/toV5.ts +++ b/packages/types/src/Metadata/v4/toV5.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Option, Vector } from '../../codec'; +import { Option, Vec } from '../../codec'; import Text from '../../primitive/Text'; import MetadataV4 from './Metadata'; import StorageHasher from '../../primitive/StorageHasher'; @@ -67,7 +67,7 @@ export default function toV5 (metadataV4: MetadataV4): MetadataV5 { prefix: modul.prefix, storage: modul.storage.isSome ? new Option( - Vector.with(StorageFunctionMetadata), + Vec.with(StorageFunctionMetadata), modul.storage.unwrap().map(toV5StorageFunction) ) : undefined, diff --git a/packages/types/src/Metadata/v5/Metadata.ts b/packages/types/src/Metadata/v5/Metadata.ts index be5dea4d15..e59f5effe5 100644 --- a/packages/types/src/Metadata/v5/Metadata.ts +++ b/packages/types/src/Metadata/v5/Metadata.ts @@ -6,7 +6,7 @@ import { MetadataInterface } from '../types'; import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; @@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct { super({ name: Text, prefix: Text, - storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(FunctionMetadata)), - events: Option.with(Vector.with(EventMetadata)) + storage: Option.with(Vec.with(StorageFunctionMetadata)), + calls: Option.with(Vec.with(FunctionMetadata)), + events: Option.with(Vec.with(EventMetadata)) }, value); } /** * @description the module calls */ - public get calls (): Option> { - return this.get('calls') as Option>; + public get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - public get events (): Option> { - return this.get('events') as Option>; + public get events (): Option> { + return this.get('events') as Option>; } /** @@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct { /** * @description the associated module storage */ - public get storage (): Option> { - return this.get('storage') as Option>; + public get storage (): Option> { + return this.get('storage') as Option>; } } @@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct { export default class MetadataV5 extends Struct implements MetadataInterface { public constructor (value?: any) { super({ - modules: Vector.with(ModuleMetadata) + modules: Vec.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - public get modules (): Vector { - return this.get('modules') as Vector; + public get modules (): Vec { + return this.get('modules') as Vec; } private get callNames (): string[][][] { diff --git a/packages/types/src/Metadata/v5/Storage.ts b/packages/types/src/Metadata/v5/Storage.ts index 147aa39420..29c0a056de 100644 --- a/packages/types/src/Metadata/v5/Storage.ts +++ b/packages/types/src/Metadata/v5/Storage.ts @@ -8,7 +8,7 @@ import { assert } from '@polkadot/util'; import Enum from '../../codec/Enum'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Bytes from '../../primitive/Bytes'; import StorageHasher from '../../primitive/StorageHasher'; import Text from '../../primitive/Text'; @@ -151,7 +151,7 @@ export interface StorageFunctionMetadataValue { modifier: StorageFunctionModifier | AnyNumber; type: StorageFunctionType; fallback: Bytes; - documentation: Vector | string[]; + documentation: Vec | string[]; } /** @@ -166,7 +166,7 @@ export class StorageFunctionMetadata extends Struct { modifier: StorageFunctionModifier, type: StorageFunctionType, fallback: Bytes, - documentation: Vector.with(Text) + documentation: Vec.with(Text) }, value); } @@ -188,15 +188,15 @@ export class StorageFunctionMetadata extends Struct { /** * @description The [[Text]] documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } /** * @description The [[Text]] documentation * @deprecated Use `.documentation` instead. */ - public get docs (): Vector { + public get docs (): Vec { return this.documentation; } diff --git a/packages/types/src/Metadata/v6/Constants.ts b/packages/types/src/Metadata/v6/Constants.ts index 591c286ba5..2ce2839d03 100644 --- a/packages/types/src/Metadata/v6/Constants.ts +++ b/packages/types/src/Metadata/v6/Constants.ts @@ -6,7 +6,7 @@ import Bytes from '../../primitive/Bytes'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; export class ModuleConstantMetadata extends Struct { public constructor (value?: any) { @@ -14,7 +14,7 @@ export class ModuleConstantMetadata extends Struct { name: Text, type: Type, value: Bytes, - documentation: Vector.with(Text) + documentation: Vec.with(Text) }, value); } @@ -42,7 +42,7 @@ export class ModuleConstantMetadata extends Struct { /** * @description The documentation */ - public get documentation (): Vector { - return this.get('documentation') as Vector; + public get documentation (): Vec { + return this.get('documentation') as Vec; } } diff --git a/packages/types/src/Metadata/v6/Metadata.ts b/packages/types/src/Metadata/v6/Metadata.ts index 293457c319..a1b5308191 100644 --- a/packages/types/src/Metadata/v6/Metadata.ts +++ b/packages/types/src/Metadata/v6/Metadata.ts @@ -6,7 +6,7 @@ import { MetadataInterface } from '../types'; import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; @@ -25,32 +25,32 @@ export class ModuleMetadata extends Struct { super({ name: Text, prefix: Text, - storage: Option.with(Vector.with(StorageEntryMetadata)), - calls: Option.with(Vector.with(FunctionMetadata)), - events: Option.with(Vector.with(EventMetadata)), - constants: Vector.with(ModuleConstantMetadata) + storage: Option.with(Vec.with(StorageEntryMetadata)), + calls: Option.with(Vec.with(FunctionMetadata)), + events: Option.with(Vec.with(EventMetadata)), + constants: Vec.with(ModuleConstantMetadata) }, value); } /** * @description the module calls */ - public get calls (): Option> { - return this.get('calls') as Option>; + public get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module constants */ - public get constants (): Vector { - return this.get('constants') as Vector; + public get constants (): Vec { + return this.get('constants') as Vec; } /** * @description the module events */ - public get events (): Option> { - return this.get('events') as Option>; + public get events (): Option> { + return this.get('events') as Option>; } /** @@ -70,8 +70,8 @@ export class ModuleMetadata extends Struct { /** * @description the associated module storage */ - public get storage (): Option> { - return this.get('storage') as Option>; + public get storage (): Option> { + return this.get('storage') as Option>; } } @@ -83,15 +83,15 @@ export class ModuleMetadata extends Struct { export default class MetadataV6 extends Struct implements MetadataInterface { public constructor (value?: any) { super({ - modules: Vector.with(ModuleMetadata) + modules: Vec.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - public get modules (): Vector { - return this.get('modules') as Vector; + public get modules (): Vec { + return this.get('modules') as Vec; } private get callNames (): string[][][] { diff --git a/packages/types/src/Metadata/v7/Metadata.ts b/packages/types/src/Metadata/v7/Metadata.ts index f217651455..c74af7bb87 100644 --- a/packages/types/src/Metadata/v7/Metadata.ts +++ b/packages/types/src/Metadata/v7/Metadata.ts @@ -6,7 +6,7 @@ import { MetadataInterface } from '../types'; import Option from '../../codec/Option'; import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; @@ -25,31 +25,31 @@ export class ModuleMetadata extends Struct { super({ name: Text, storage: Option.with(StorageMetadata), - calls: Option.with(Vector.with(FunctionMetadata)), - events: Option.with(Vector.with(EventMetadata)), - constants: Vector.with(ModuleConstantMetadata) + calls: Option.with(Vec.with(FunctionMetadata)), + events: Option.with(Vec.with(EventMetadata)), + constants: Vec.with(ModuleConstantMetadata) }, value); } /** * @description the module calls */ - public get calls (): Option> { - return this.get('calls') as Option>; + public get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module constants */ - public get constants (): Vector { - return this.get('constants') as Vector; + public get constants (): Vec { + return this.get('constants') as Vec; } /** * @description the module events */ - public get events (): Option> { - return this.get('events') as Option>; + public get events (): Option> { + return this.get('events') as Option>; } /** @@ -82,15 +82,15 @@ export class ModuleMetadata extends Struct { export default class MetadataV7 extends Struct implements MetadataInterface { public constructor (value?: any) { super({ - modules: Vector.with(ModuleMetadata) + modules: Vec.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - public get modules (): Vector { - return this.get('modules') as Vector; + public get modules (): Vec { + return this.get('modules') as Vec; } private get callNames (): string[][][] { diff --git a/packages/types/src/Metadata/v7/Storage.ts b/packages/types/src/Metadata/v7/Storage.ts index 868635fa02..bd38f606ca 100644 --- a/packages/types/src/Metadata/v7/Storage.ts +++ b/packages/types/src/Metadata/v7/Storage.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; +import Vec from '../../codec/Vec'; import Text from '../../primitive/Text'; import { DoubleMapType, MapType, PlainType, StorageEntryMetadata, StorageEntryMetadataValue, StorageEntryModifier, StorageEntryType } from '../v6/Storage'; @@ -24,15 +24,15 @@ export class StorageMetadata extends Struct { super({ prefix: Text, // NOTE renamed to items from entries (since Struct already has entries from Map) - items: Vector.with(StorageEntryMetadata) + items: Vec.with(StorageEntryMetadata) }, value); } /** * @description the storage entries */ - public get items (): Vector { - return this.get('items') as Vector; + public get items (): Vec { + return this.get('items') as Vec; } /** diff --git a/packages/types/src/codec/AbstractArray.ts b/packages/types/src/codec/AbstractArray.ts index c84339c6d9..13416129c4 100644 --- a/packages/types/src/codec/AbstractArray.ts +++ b/packages/types/src/codec/AbstractArray.ts @@ -104,7 +104,7 @@ export default abstract class AbstractArray extends Array im ); } - // Below are methods that we override. When we do a `new Vector(...).map()`, + // Below are methods that we override. When we do a `new Vec(...).map()`, // we want it to return an Array. We only override the methods that return a // new instance. diff --git a/packages/types/src/codec/Compact.ts b/packages/types/src/codec/Compact.ts index f2be420c74..1f9578226e 100644 --- a/packages/types/src/codec/Compact.ts +++ b/packages/types/src/codec/Compact.ts @@ -2,18 +2,20 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { AnyNumber, Constructor } from '../types'; + import BN from 'bn.js'; import { bnToBn, compactAddLength, compactFromU8a, compactStripLength, compactToU8a, hexToBn, isBn, isHex, isNumber, isString } from '@polkadot/util'; import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults'; import Moment from '../primitive/Moment'; -import { AnyNumber, Constructor } from '../types'; -import AbstractInt, { UIntBitLength } from './AbstractInt'; +import { UIntBitLength } from './AbstractInt'; +import UInt from './UInt'; import Base from './Base'; // List of codec types that are compact-encodable -export const COMPACT_ENCODABLE = [AbstractInt, Moment]; -export type CompactEncodable = AbstractInt | Moment; // FIXME is there a way to do it not-manually from the array? +export const COMPACT_ENCODABLE = [UInt, Moment]; +export type CompactEncodable = UInt | Moment; // FIXME is there a way to do it not-manually from the array? /** * @name Compact diff --git a/packages/types/src/codec/Linkage.ts b/packages/types/src/codec/Linkage.ts index 1f2a19fb37..7193a55116 100644 --- a/packages/types/src/codec/Linkage.ts +++ b/packages/types/src/codec/Linkage.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Struct, Option, Tuple, Vector } from '.'; +import { Struct, Option, Tuple, Vec } from '.'; import { Constructor, Codec } from '../types'; type TypeWithValues = [Constructor, any[]]; @@ -35,8 +35,8 @@ export default class Linkage extends Struct { export class LinkageResult extends Tuple { public constructor ([TypeKey, keys]: TypeWithValues, [TypeValue, values]: TypeWithValues) { super({ - Keys: Vector.with(TypeKey), - Values: Vector.with(TypeValue) + Keys: Vec.with(TypeKey), + Values: Vec.with(TypeValue) }, [keys, values]); } } diff --git a/packages/types/src/codec/Option.spec.ts b/packages/types/src/codec/Option.spec.ts index 048614b28e..51c7c52677 100644 --- a/packages/types/src/codec/Option.spec.ts +++ b/packages/types/src/codec/Option.spec.ts @@ -2,6 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { injectDefinitions } from '../srml'; import Option from './Option'; import Bytes from '../primitive/Bytes'; import U32 from '../primitive/U32'; @@ -23,6 +24,10 @@ const testEncode = (to: string, expected: any): void => }); describe('Option', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + it('converts undefined/null to empty', (): void => { expect(new Option(Text, undefined).isNone).toBe(true); expect(new Option(Text, null).isNone).toBe(true); diff --git a/packages/types/src/codec/Struct.spec.ts b/packages/types/src/codec/Struct.spec.ts index 5da0c0ffa4..c3d6574c0c 100644 --- a/packages/types/src/codec/Struct.spec.ts +++ b/packages/types/src/codec/Struct.spec.ts @@ -9,7 +9,7 @@ import U32 from '../primitive/U32'; import { injectDefinitions } from '../srml'; import { CodecTo } from '../types'; import Struct from './Struct'; -import Vector from './Vector'; +import Vec from './Vec'; describe('Struct', (): void => { beforeEach((): void => { @@ -66,7 +66,7 @@ describe('Struct', (): void => { it('decodes a more complicated type', (): void => { const s = new Struct({ - foo: Vector.with(Struct.with({ + foo: Vec.with(Struct.with({ bar: Text })) }, { foo: [{ bar: 1 }, { bar: 2 }] }); @@ -198,7 +198,7 @@ describe('Struct', (): void => { compactNumber: ClassOf('Compact'), optionNumber: ClassOf('Option'), counter: U32, - vector: Vector.with(AccountId) + vector: Vec.with(AccountId) }).toRawType() ).toEqual(JSON.stringify({ accountId: 'AccountId', diff --git a/packages/types/src/codec/Vector.spec.ts b/packages/types/src/codec/Vec.spec.ts similarity index 92% rename from packages/types/src/codec/Vector.spec.ts rename to packages/types/src/codec/Vec.spec.ts index 22d93fa2cd..71ee6792d3 100644 --- a/packages/types/src/codec/Vector.spec.ts +++ b/packages/types/src/codec/Vec.spec.ts @@ -11,14 +11,14 @@ import AccountId from '../primitive/AccountId'; import Method from '../primitive/Method'; import Text from '../primitive/Text'; import createType from './createType'; -import Vector from './Vector'; +import Vec from './Vec'; import Tuple from './Tuple'; -describe('Vector', (): void => { - let vector: Vector; +describe('Vec', (): void => { + let vector: Vec; beforeEach((): void => { - vector = new Vector(Text, ['1', '23', '345', '4567', new Text('56789')]); + vector = new Vec(Text, ['1', '23', '345', '4567', new Text('56789')]); Method.injectMethods(extrinsics); }); @@ -44,7 +44,7 @@ describe('Vector', (): void => { it('allows contruction via JSON', (): void => { expect( - new Vector(Text, ['6', '7']).toJSON() + new Vec(Text, ['6', '7']).toJSON() ).toEqual(['6', '7']); }); @@ -56,7 +56,7 @@ describe('Vector', (): void => { const test = createType('Vec<(PropIndex, Proposal, AccountId)>', new Uint8Array([ 4, 10, 0, 0, 0, 0, 3, 80, 123, 10, 9, 34, 48, 120, 52, 50, 34, 58, 32, 34, 48, 120, 52, 51, 34, 10, 125, 10, 209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79 ])); - const first = (test as Vector)[0] as Tuple; + const first = (test as Vec)[0] as Tuple; expect((first[0] as PropIndex).toNumber()).toEqual(10); expect((first[1] as Proposal).callIndex).toEqual(new Uint8Array([0, 3])); @@ -118,7 +118,7 @@ describe('Vector', (): void => { }); describe('utils', (): void => { - const vec = new Vector(Text, ['123', '456']); + const vec = new Vec(Text, ['123', '456']); it('compares against codec types', (): void => { expect(vec.eq([new Text('123'), new Text('456')])).toBe(true); @@ -130,7 +130,7 @@ describe('Vector', (): void => { it('finds the index of an value', (): void => { const myId = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; - const vec = new Vector(AccountId, [ + const vec = new Vec(AccountId, [ '5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw', '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty', '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' ]); diff --git a/packages/types/src/codec/Vector.ts b/packages/types/src/codec/Vec.ts similarity index 76% rename from packages/types/src/codec/Vector.ts rename to packages/types/src/codec/Vec.ts index d0f6848d2d..039030bdc3 100644 --- a/packages/types/src/codec/Vector.ts +++ b/packages/types/src/codec/Vec.ts @@ -12,24 +12,24 @@ import AbstractArray from './AbstractArray'; const MAX_LENGTH = 32768; /** - * @name Vector + * @name Vec * @description * This manages codec arrays. Internally it keeps track of the length (as decoded) and allows * construction with the passed `Type` in the constructor. It is an extension to Array, providing * specific encoding/decoding on top of the base type. */ -export default class Vector extends AbstractArray { +export default class Vec extends AbstractArray { private _Type: Constructor; - public constructor (Type: Constructor, value: Vector | Uint8Array | string | any[] = [] as any[]) { + public constructor (Type: Constructor, value: Vec | Uint8Array | string | any[] = [] as any[]) { super( - ...Vector.decodeVector(Type, value) + ...Vec.decodeVec(Type, value) ); this._Type = Type; } - public static decodeVector (Type: Constructor, value: Vector | Uint8Array | string | any[]): T[] { + public static decodeVec (Type: Constructor, value: Vec | Uint8Array | string | any[]): T[] { if (Array.isArray(value)) { return value.map((entry, index): T => { try { @@ -37,7 +37,7 @@ export default class Vector extends AbstractArray { ? entry : new Type(entry); } catch (error) { - console.error(`Unable to decode Vector on index ${index}`, error.message); + console.error(`Unable to decode Vec on index ${index}`, error.message); throw error; } @@ -47,19 +47,19 @@ export default class Vector extends AbstractArray { const u8a = u8aToU8a(value); const [offset, length] = Compact.decodeU8a(u8a); - assert(length.lten(MAX_LENGTH), `Vector length ${length.toString()} exceeds ${MAX_LENGTH}`); + assert(length.lten(MAX_LENGTH), `Vec length ${length.toString()} exceeds ${MAX_LENGTH}`); return decodeU8a(u8a.subarray(offset), new Array(length.toNumber()).fill(Type)) as T[]; } - public static with (Type: Constructor): Constructor> { - return class extends Vector { + public static with (Type: Constructor): Constructor> { + return class extends Vec { public constructor (value?: any[]) { super(Type, value); } public static Fallback = Type.Fallback - ? Vector.with(Type.Fallback) + ? Vec.with(Type.Fallback) : undefined; }; } diff --git a/packages/types/src/codec/VectorAny.ts b/packages/types/src/codec/VecAny.ts similarity index 88% rename from packages/types/src/codec/VectorAny.ts rename to packages/types/src/codec/VecAny.ts index cb8294a516..b7041b1390 100644 --- a/packages/types/src/codec/VectorAny.ts +++ b/packages/types/src/codec/VecAny.ts @@ -6,13 +6,13 @@ import { Codec } from '../types'; import AbstractArray from './AbstractArray'; /** - * @name VectorAny + * @name VecAny * @description * This manages codec arrays, assuming that the inputs are already of type Codec. Unlike * a vector, this can be used to manage array-like structures with variable arguments of * any types */ -export default class VectorAny extends AbstractArray { +export default class VecAny extends AbstractArray { /** * @description Returns the base runtime type name for this instance */ diff --git a/packages/types/src/codec/VectorFixed.ts b/packages/types/src/codec/VecFixed.ts similarity index 71% rename from packages/types/src/codec/VectorFixed.ts rename to packages/types/src/codec/VecFixed.ts index e6bcfa81eb..34336747bc 100644 --- a/packages/types/src/codec/VectorFixed.ts +++ b/packages/types/src/codec/VecFixed.ts @@ -7,26 +7,26 @@ import { Codec, Constructor } from '../types'; import { assert, isU8a, u8aConcat, compactToU8a } from '@polkadot/util'; import AbstractArray from './AbstractArray'; -import Vector from './Vector'; +import Vec from './Vec'; /** - * @name VectorFixed + * @name VecFixed * @description * This manages codec arrays of a fixed length */ -export default class VectorFixed extends AbstractArray { +export default class VecFixed extends AbstractArray { private _Type: Constructor; - public constructor (Type: Constructor, length: number, value: VectorFixed | Uint8Array | string | any[] = [] as any[]) { + public constructor (Type: Constructor, length: number, value: VecFixed | Uint8Array | string | any[] = [] as any[]) { super( - ...VectorFixed.decodeVectorFixed(Type, length, value) + ...VecFixed.decodeVecFixed(Type, length, value) ); this._Type = Type; } - public static decodeVectorFixed (Type: Constructor, allocLength: number, value: VectorFixed | Uint8Array | string | any[]): T[] { - const values = Vector.decodeVector( + public static decodeVecFixed (Type: Constructor, allocLength: number, value: VecFixed | Uint8Array | string | any[]): T[] { + const values = Vec.decodeVec( Type, isU8a(value) ? u8aConcat(compactToU8a(allocLength), value) @@ -42,14 +42,14 @@ export default class VectorFixed extends AbstractArray { return values; } - public static with (Type: Constructor, length: number): Constructor> { - return class extends VectorFixed { + public static with (Type: Constructor, length: number): Constructor> { + return class extends VecFixed { public constructor (value?: any[]) { super(Type, length, value); } public static Fallback = Type.Fallback - ? VectorFixed.with(Type.Fallback, length) + ? VecFixed.with(Type.Fallback, length) : undefined; }; } diff --git a/packages/types/src/codec/createType.spec.ts b/packages/types/src/codec/createType.spec.ts index 5597741b55..e6e975ce86 100644 --- a/packages/types/src/codec/createType.spec.ts +++ b/packages/types/src/codec/createType.spec.ts @@ -86,7 +86,7 @@ describe('getTypeValue', (): void => { } }, { - info: TypeDefInfo.Vector, + info: TypeDefInfo.Vec, type: 'Vec', sub: { info: TypeDefInfo.Plain, @@ -118,7 +118,7 @@ describe('getTypeValue', (): void => { type: 'Text' }, { - info: TypeDefInfo.Vector, + info: TypeDefInfo.Vec, type: 'Vec<(Bool, u128)>', sub: { info: TypeDefInfo.Tuple, @@ -145,7 +145,7 @@ describe('getTypeValue', (): void => { expect( getTypeDef('Vec<(PropIndex, Proposal, AccountId)>') ).toEqual({ - info: TypeDefInfo.Vector, + info: TypeDefInfo.Vec, type: 'Vec<(PropIndex, Proposal, AccountId)>', sub: { info: TypeDefInfo.Tuple, diff --git a/packages/types/src/codec/createType.ts b/packages/types/src/codec/createType.ts index 308de0eb73..812ba262b6 100644 --- a/packages/types/src/codec/createType.ts +++ b/packages/types/src/codec/createType.ts @@ -8,7 +8,6 @@ import { assert } from '@polkadot/util'; import { InterfaceRegistry } from '../interfaceRegistry'; import { Codec, Constructor } from '../types'; import Null from '../primitive/Null'; -import StorageData from '../primitive/StorageData'; import Text from '../primitive/Text'; import Compact from './Compact'; import Enum from './Enum'; @@ -19,8 +18,8 @@ import Struct from './Struct'; import Tuple from './Tuple'; import U8aFixed, { BitLength as U8aFixedBitLength } from './U8aFixed'; import UInt from './UInt'; -import Vector from './Vector'; -import VectorFixed from './VectorFixed'; +import Vec from './Vec'; +import VecFixed from './VecFixed'; import getRegistry from './typeRegistry'; export enum TypeDefInfo { @@ -33,8 +32,8 @@ export enum TypeDefInfo { Set, Struct, Tuple, - Vector, - VectorFixed, + Vec, + VecFixed, // anything not full supported (keep this as the last entry) Null } @@ -114,11 +113,10 @@ function _decodeEnum (value: TypeDef, details: string[] | Record name, type: 'Null' })) - : Object.entries(details).map(([name, type]): TypeDef => ({ - info: TypeDefInfo.Plain, - name, - type: type || 'Null' - })); + : Object.entries(details).map(([name, type]): TypeDef => + // eslint-disable-next-line @typescript-eslint/no-use-before-define + getTypeDef(type || 'Null', name) + ); return value; } @@ -169,7 +167,7 @@ export function getTypeDef (_type: Text | string, name?: string): TypeDef { // as a first round, only u8 via u8aFixed, we can add more support assert(vecLen <= 256, `${type}: Only support for [Type; ], where length <= 256`); - value.info = TypeDefInfo.VectorFixed; + value.info = TypeDefInfo.VecFixed; value.ext = { length: vecLen, type: vecType } as unknown as TypeDefExtVecFixed; } else if (startingWith(type, '{', '}')) { const parsed = JSON.parse(type); @@ -190,7 +188,7 @@ export function getTypeDef (_type: Text | string, name?: string): TypeDef { value.info = TypeDefInfo.Option; value.sub = getTypeDef(subType); } else if (startingWith(type, 'Vec<', '>')) { - value.info = TypeDefInfo.Vector; + value.info = TypeDefInfo.Vec; value.sub = getTypeDef(subType); } else if (startingWith(type, 'Linkage<', '>')) { value.info = TypeDefInfo.Linkage; @@ -284,13 +282,13 @@ export function getTypeClass (value: TypeDef, Fallback? (value.sub as TypeDef[]).map((Type): Constructor => getTypeClass(Type)) ) as unknown as Constructor; - case TypeDefInfo.Vector: - assert(value.sub && !Array.isArray(value.sub), 'Expected subtype for Vector'); - return Vector.with( + case TypeDefInfo.Vec: + assert(value.sub && !Array.isArray(value.sub), 'Expected subtype for Vec'); + return Vec.with( getTypeClass(value.sub as TypeDef) ) as unknown as Constructor; - case TypeDefInfo.VectorFixed: + case TypeDefInfo.VecFixed: assert(value.ext, 'Expected length & type information for fixed vector'); const ext = value.ext as TypeDefExtVecFixed; @@ -298,7 +296,7 @@ export function getTypeClass (value: TypeDef, Fallback? return ( ext.type === 'u8' ? U8aFixed.with((ext.length * 8) as U8aFixedBitLength) - : VectorFixed.with(createClass(ext.type), ext.length) + : VecFixed.with(createClass(ext.type), ext.length) ) as unknown as Constructor; case TypeDefInfo.Linkage: @@ -340,7 +338,7 @@ function initType': Option; - 'Vec': Vector; + 'Vec': Vec; AccountIndex: AccountIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Address: Address; 'Option
': Option
; - 'Vec
': Vector
; + 'Vec
': Vec
; Event: Event; 'Option': Option; - 'Vec': Vector; - EventIndex: EventIndex; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; - EventRecord: EventRecord; - 'Option': Option; - 'Vec': Vector; - EventRecord0to76: EventRecord0to76; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + Block: Block; + 'Option': Option; + 'Vec': Vec; Bool: Bool; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; bool: bool; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Bytes: Bytes; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + ConsensusEngineId: ConsensusEngineId; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; Data: Data; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + Digest: Digest; + 'Option': Option; + 'Vec': Vec; + DigestItem: DigestItem; + 'Option': Option; + 'Vec': Vec; H160: H160; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; H256: H256; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; H512: H512; 'Option': Option; - 'Vec': Vector; - I8: I8; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + Header: Header; + 'Option
': Option
; + 'Vec
': Vec
; i8: i8; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - I16: I16; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + I8: I8; + 'Option': Option; + 'Vec': Vec; i16: i16; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - I32: I32; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + I16: I16; + 'Option': Option; + 'Vec': Vec; i32: i32; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - I64: I64; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + I32: I32; + 'Option': Option; + 'Vec': Vec; i64: i64; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + I64: I64; + 'Option': Option; + 'Vec': Vec; Fixed64: Fixed64; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - I128: I128; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; i128: i128; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - I256: I256; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + I128: I128; + 'Option': Option; + 'Vec': Vec; i256: i256; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - KeyValue: KeyValue; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + I256: I256; + 'Option': Option; + 'Vec': Vec; Method: Method; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Moment: Moment; 'Option': Option; - 'Vec': Vector; - MomentOf: MomentOf; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Null: Null; 'Option': Option; - 'Vec': Vector; - Phantom: Phantom; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Origin: Origin; 'Option': Option; - 'Vec': Vector; - StorageData: StorageData; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; StorageHasher: StorageHasher; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; StorageKey: StorageKey; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Text: Text; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Type: Type; 'Option': Option; - 'Vec': Vector; - U8: U8; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; u8: u8; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - U16: U16; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + U8: U8; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; u16: u16; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - U32: U32; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + U16: U16; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; u32: u32; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - U64: U64; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + U32: U32; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; u64: u64; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - U128: U128; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + U64: U64; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; u128: u128; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - U256: U256; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + U128: U128; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; u256: u256; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; - USize: USize; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + U256: U256; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; usize: usize; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Vote: Vote; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Extrinsic: Extrinsic; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ExtrinsicEra: ExtrinsicEra; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; MortalEra: MortalEra; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ImmortalEra: ImmortalEra; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; SignaturePayload: SignaturePayload; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } diff --git a/packages/types/src/primitive/AccountId.spec.ts b/packages/types/src/primitive/AccountId.spec.ts index 717c53a161..4448376bd7 100644 --- a/packages/types/src/primitive/AccountId.spec.ts +++ b/packages/types/src/primitive/AccountId.spec.ts @@ -4,13 +4,18 @@ import { setAddressPrefix } from '@polkadot/util-crypto'; +import createType from '../codec/createType'; import U8a from '../codec/U8a'; -import Vector from '../codec/Vector'; +import Vec from '../codec/Vec'; import jsonVec from '../json/AccountIdVec.001.json'; +import { injectDefinitions } from '../srml'; import AccountId from './AccountId'; -import StorageData from './StorageData'; describe('AccountId', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + describe('defaults', (): void => { const id = new AccountId(); @@ -85,8 +90,8 @@ describe('AccountId', (): void => { it('has the correct entries', (): void => { setAddressPrefix(68); - const data = new StorageData(jsonVec.params.result.changes[0][1]); - const list = new Vector(AccountId, data).map((accountId): string => accountId.toString()); + const data = createType('StorageData', jsonVec.params.result.changes[0][1]); + const list = new Vec(AccountId, data).map((accountId): string => accountId.toString()); expect(list).toEqual([ '7qVJujLF3EDbZt5WfQXWvueFedMS4Vfk2Hb4GyR8jwksTLup', diff --git a/packages/types/src/rpc/Block.spec.ts b/packages/types/src/primitive/Block.spec.ts similarity index 93% rename from packages/types/src/rpc/Block.spec.ts rename to packages/types/src/primitive/Block.spec.ts index e94b24b1c2..ab44061771 100644 --- a/packages/types/src/rpc/Block.spec.ts +++ b/packages/types/src/primitive/Block.spec.ts @@ -5,11 +5,13 @@ import extrinsics from '@polkadot/api-metadata/extrinsics/static'; import block00300 from '../json/SignedBlock.003.00.json'; -import Method from '../primitive/Method'; +import { injectDefinitions } from '../srml'; +import Method from './Method'; import Block from './Block'; describe('Block', (): void => { beforeEach((): void => { + injectDefinitions(); Method.injectMethods(extrinsics); }); diff --git a/packages/types/src/rpc/Block.ts b/packages/types/src/primitive/Block.ts similarity index 83% rename from packages/types/src/rpc/Block.ts rename to packages/types/src/primitive/Block.ts index e938a6076e..d48134f321 100644 --- a/packages/types/src/rpc/Block.ts +++ b/packages/types/src/primitive/Block.ts @@ -8,9 +8,9 @@ import { AnyU8a } from '../types'; import { blake2AsU8a } from '@polkadot/util-crypto'; import createType, { ClassOf } from '../codec/createType'; -import Extrinsic from '../primitive/Extrinsic/Extrinsic'; +import Extrinsic from './Extrinsic/Extrinsic'; import Struct from '../codec/Struct'; -import Vector from '../codec/Vector'; +import Vec from '../codec/Vec'; import Header, { HeaderValue } from './Header'; export interface BlockValue { @@ -27,7 +27,7 @@ export default class Block extends Struct { public constructor (value?: BlockValue | Uint8Array) { super({ header: Header, - extrinsics: ClassOf>('Vec') + extrinsics: ClassOf('Vec') }, value); } @@ -41,8 +41,8 @@ export default class Block extends Struct { /** * @description The [[Extrinsic]] contained in the block */ - public get extrinsics (): Vector { - return this.get('extrinsics') as Vector; + public get extrinsics (): Vec { + return this.get('extrinsics') as Vec; } /** diff --git a/packages/types/src/primitive/Bytes.spec.ts b/packages/types/src/primitive/Bytes.spec.ts index 4b0cb3daac..4973fffea8 100644 --- a/packages/types/src/primitive/Bytes.spec.ts +++ b/packages/types/src/primitive/Bytes.spec.ts @@ -2,10 +2,15 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import createType from '../codec/createType'; +import { injectDefinitions } from '../srml'; import Bytes from './Bytes'; -import StorageData from './StorageData'; describe('Bytes', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + const CODE = new Uint8Array([0x14, 0x3a, 0x63, 0x6f, 0x64, 0x65]); describe('construction', (): void => { @@ -30,7 +35,7 @@ describe('Bytes', (): void => { it('creates via storagedata (no prefix)', (): void => { expect( new Bytes( - new StorageData('0x3a636f6465') + createType('StorageData', '0x3a636f6465') ).toU8a() ).toEqual(CODE); }); @@ -38,7 +43,7 @@ describe('Bytes', (): void => { it('creates via storagedata (with length prefix)', (): void => { expect( new Bytes( - new StorageData('0x143a636f6465') + createType('StorageData', '0x143a636f6465') ).toU8a() ).toEqual(CODE); }); diff --git a/packages/types/src/primitive/Bytes.ts b/packages/types/src/primitive/Bytes.ts index a0ba42c96e..bb38de4388 100644 --- a/packages/types/src/primitive/Bytes.ts +++ b/packages/types/src/primitive/Bytes.ts @@ -2,9 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { AnyU8a } from '../types'; + import { assert, isString, isU8a, u8aToU8a } from '@polkadot/util'; -import { AnyU8a } from '../types'; +import { ClassOf } from '../codec/createType'; import Compact from '../codec/Compact'; import U8a from '../codec/U8a'; @@ -13,7 +15,7 @@ import U8a from '../codec/U8a'; * @description * A Bytes wrapper for Vec. The significant difference between this and a normal Uint8Array * is that this version allows for length-encoding. (i.e. it is a variable-item codec, the same - * as what is found in [[Text]] and [[Vector]]) + * as what is found in [[Text]] and [[Vec]]) */ export default class Bytes extends U8a { public constructor (value?: AnyU8a) { @@ -21,18 +23,13 @@ export default class Bytes extends U8a { } private static decodeBytes (value?: AnyU8a): Uint8Array | undefined { - // FIXME Cyclic dependency, however needed for the StoreageData check below. In a perfect - // world, we should probably be checking Bytes - however as a first step, check against - // StorageData to cater for the _specific_ problematic case - const StorageData = require('./StorageData').default; - if (Array.isArray(value) || isString(value)) { const u8a = u8aToU8a(value); return Bytes.decodeBytes( Compact.addLengthPrefix(u8a) ); - } else if (value instanceof StorageData) { + } else if (value instanceof ClassOf('StorageData')) { // Here we cater for the actual StorageData that _could_ have a length prefix. In the // case of `:code` it is not added, for others it is const u8a = value as Uint8Array; diff --git a/packages/types/src/primitive/ConsensusEngineId.ts b/packages/types/src/primitive/ConsensusEngineId.ts new file mode 100644 index 0000000000..02feac9f65 --- /dev/null +++ b/packages/types/src/primitive/ConsensusEngineId.ts @@ -0,0 +1,77 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import BN from 'bn.js'; +import { assert, bnToBn } from '@polkadot/util'; + +import Bytes from './Bytes'; +import U32 from './U32'; +import U64 from './U64'; + +const CID_AURA = 0x61727561; // 'aura' +const CID_BABE = 0x65626162; // 'babe' +const CID_GRPA = 0x4b4e5246; // 'FRNK' (don't ask, used to be afg1) + +export { CID_AURA, CID_BABE, CID_GRPA }; + +/** + * @name ConsensusEngineId + * @description + * A 4-byte identifier (actually a [u8; 4]) identifying the engine, e.g. for Aura it would be [b'a', b'u', b'r', b'a'] + */ +export default class ConsensusEngineId extends U32 { + public static idToString (input: number | BN): string { + return bnToBn(input) + .toArray('le') + .map((code): string => String.fromCharCode(code)) + .join(''); + } + + public static stringToId (input: string): number { + return input + .split('') + .reverse() + .reduce((result, char): number => (result * 256) + char.charCodeAt(0), 0); + } + + /** + * @description `true` if the engine matches aura + */ + public get isAura (): boolean { + return this.eq(CID_AURA); + } + + /** + * @description `true` is the engine matches babe + */ + public get isBabe (): boolean { + return this.eq(CID_BABE); + } + + /** + * @description `true` is the engine matches grandpa + */ + public get isGrandpa (): boolean { + return this.eq(CID_GRPA); + } + + /** + * @description From the input bytes, decode into an aura-tuple + */ + public extractSlot (bytes: Bytes): U64 { + assert(this.isAura, 'Invalid engine for asAura conversion'); + + return new U64( + // no compact prefix, only use the correct number of supplied bytes + bytes.toU8a(true).subarray(0, 8) + ); + } + + /** + * @description Override the default toString to return a 4-byte string + */ + public toString (): string { + return ConsensusEngineId.idToString(this as BN); + } +} diff --git a/packages/types/src/rpc/Digest.spec.ts b/packages/types/src/primitive/Digest.spec.ts similarity index 93% rename from packages/types/src/rpc/Digest.spec.ts rename to packages/types/src/primitive/Digest.spec.ts index 78019d10a7..f5842dd0c0 100644 --- a/packages/types/src/rpc/Digest.spec.ts +++ b/packages/types/src/primitive/Digest.spec.ts @@ -5,7 +5,8 @@ import { injectDefinitions } from '../srml'; import json3 from '../json/Header.003.json'; import block1 from '../json/SignedBlock.003.00.json'; -import Digest, { ConsensusEngineId, CID_AURA, CID_BABE, CID_GRPA } from './Digest'; +import ConsensusEngineId, { CID_AURA, CID_BABE, CID_GRPA } from './ConsensusEngineId'; +import Digest from './Digest'; describe('Digest', (): void => { beforeEach((): void => { diff --git a/packages/types/src/primitive/Digest.ts b/packages/types/src/primitive/Digest.ts new file mode 100644 index 0000000000..1493833758 --- /dev/null +++ b/packages/types/src/primitive/Digest.ts @@ -0,0 +1,194 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { AuthorityId } from '../srml/consensus/types'; +import { Hash } from '../srml/runtime/types'; +import { Consensus, PreRuntime, Seal, SealV0 } from '../srml/rpc/types'; + +import { assert } from '@polkadot/util'; + +import { ClassOf } from '../codec/createType'; +import Enum from '../codec/Enum'; +import Struct from '../codec/Struct'; +import Vec from '../codec/Vec'; +import Bytes from './Bytes'; + +/** + * @name DigestItem + * @description + * A [[Enum]] the specifies the specific item in the logs of a [[Digest]] + */ +export class DigestItem extends Enum { + public constructor (value: any) { + super({ + Other: ClassOf('Bytes'), // 0 + AuthoritiesChange: ClassOf('Vec'), // 1 + ChangesTrieRoot: ClassOf('Hash'), // 2 + SealV0: ClassOf('SealV0'), // 3 + Consensus: ClassOf('Consensus'), // 4 + Seal: ClassOf('Seal'), // 5 + PreRuntime: ClassOf('PreRuntime') // 6 + }, value); + } + + /** + * @description Returns the item as a [[Vec]] + */ + public get asAuthoritiesChange (): Vec { + assert(this.isAuthoritiesChange, `Cannot convert '${this.type}' via asAuthoritiesChange`); + + return this.value as Vec; + } + + /** + * @description Returns the item as a [[ChangesTrieRoot]] + */ + public get asChangesTrieRoot (): Hash { + assert(this.isChangesTrieRoot, `Cannot convert '${this.type}' via asChangesTrieRoot`); + + return this.value as Hash; + } + + /** + * @desciption Retuns the item as a [[Consensus]] + */ + public get asConsensus (): Consensus { + assert(this.isConsensus, `Cannot convert '${this.type}' via asConsensus`); + + return this.value as Consensus; + } + + /** + * @description Returns the item as a [[Bytes]] + */ + public get asOther (): Bytes { + assert(this.isOther, `Cannot convert '${this.type}' via asOther`); + + return this.value as Bytes; + } + + /** + * @description Returns the item as a [[PreRuntime]] + */ + public get asPreRuntime (): PreRuntime { + assert(this.isPreRuntime, `Cannot convert '${this.type}' via asPreRuntime`); + + return this.value as PreRuntime; + } + + /** + * @description Returns the item as a [[Seal]] + */ + public get asSeal (): Seal { + assert(this.isSeal, `Cannot convert '${this.type}' via asSeal`); + + return this.value as Seal; + } + + /** + * @description Returns the item as a [[SealV0]] + */ + public get asSealV0 (): SealV0 { + assert(this.isSealV0, `Cannot convert '${this.type}' via asSealV0`); + + return this.value as SealV0; + } + + /** + * @description Returns true on [[AuthoritiesChange]] + */ + public get isAuthoritiesChange (): boolean { + return this.type === 'AuthoritiesChange'; + } + + /** + * @description Returns true on [[ChangesTrieRoot]] + */ + public get isChangesTrieRoot (): boolean { + return this.type === 'ChangesTrieRoot'; + } + + /** + * @description Returns true on [[Consensus]] + */ + public get isConsensus (): boolean { + return this.type === 'Consensus'; + } + + /** + * @description Returns true on [[Other]] + */ + public get isOther (): boolean { + return this.type === 'Other'; + } + + /** + * @description Returns true on [[PreRuntime]] + */ + public get isPreRuntime (): boolean { + return this.type === 'PreRuntime'; + } + + /** + * @description Returns true on [[Seal]] + */ + public get isSeal (): boolean { + return this.type === 'Seal'; + } + + /** + * @description Returns true on [[SealV0]] + */ + public get isSealV0 (): boolean { + return this.type === 'SealV0'; + } + + /** + * @description Converts the Object to JSON, typically used for RPC transfers. For logs, we overrides to produce the hex version (sligning with substrate gives in actual JSON responses) + */ + public toJSON (): string { + return this.toHex(); + } + + /** + * @description Returns the type of engine + */ + public get type (): string { + return super.type; + } +} + +/** + * @name Digest + * @description + * A [[Header]] Digest + */ +export default class Digest extends Struct { + public constructor (value: any) { + super({ + logs: Vec.with(DigestItem) + }, value); + } + + /** + * @description The [[DigestItem]] logs + */ + public get logs (): Vec { + return this.get('logs') as Vec; + } + + /** + * @description The [[DigestItem]] logs, filtered, filter items included. This is useful for derive functionality where only a certain type of log is to be returned. + */ + public logsWith (...include: string[]): Vec { + return this.logs.filter(({ type }): boolean => include.includes(type)) as Vec; + } + + /** + * @description The [[DigestItem]] logs, filtered, filter items exluded. This is useful for stripping headers for eg. WASM runtime execution. + */ + public logsWithout (...exclude: string[]): Vec { + return this.logs.filter(({ type }): boolean => !exclude.includes(type)) as Vec; + } +} diff --git a/packages/types/src/primitive/Event.ts b/packages/types/src/primitive/Event.ts index 4346bddc9e..63f38e04f1 100644 --- a/packages/types/src/primitive/Event.ts +++ b/packages/types/src/primitive/Event.ts @@ -2,30 +2,21 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { EventId } from '../srml/system/types'; import { Constructor, Codec } from '../types'; import { assert, isUndefined, stringCamelCase, u8aToHex } from '@polkadot/util'; +import { ClassOf, TypeDef, getTypeClass, getTypeDef } from '../codec/createType'; import Struct from '../codec/Struct'; import Tuple from '../codec/Tuple'; -import U8aFixed from '../codec/U8aFixed'; -import { TypeDef, getTypeClass, getTypeDef } from '../codec/createType'; import Metadata from '../Metadata'; import { EventMetadata as EventMetadataV7 } from '../Metadata/v7/Events'; import Null from './Null'; -import U32 from './U32'; import Unconstructable from './Unconstructable'; const EventTypes: Record> = {}; -/** - * @name EventIndex - * @description - * The Substrate EventIndex representation as a [[U32]]. - */ -export class EventIndex extends U32 { -} - /** * @name EventData * @description @@ -78,18 +69,6 @@ export class EventData extends Tuple { } } -/** - * @name EventId - * @description - * This follows the same approach as in [[Method]], we have the `[sectionIndex, methodIndex]` pairing - * that indicates the actual event fired - */ -export class EventId extends U8aFixed { - public constructor (value?: any) { - super(value, 16); - } -} - /** * @name Event * @description @@ -103,7 +82,7 @@ export default class Event extends Struct { const { DataType, value } = Event.decodeEvent(_value); super({ - index: EventId, + index: ClassOf('EventId'), data: DataType }, value); } diff --git a/packages/types/src/primitive/EventRecord.ts b/packages/types/src/primitive/EventRecord.ts index 851701a4f6..5154fa0fa2 100644 --- a/packages/types/src/primitive/EventRecord.ts +++ b/packages/types/src/primitive/EventRecord.ts @@ -3,114 +3,12 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Hash } from '../srml/runtime/types'; +import { Phase } from '../srml/system/types'; -import { assert } from '@polkadot/util'; - -import createType, { ClassOf } from '../codec/createType'; -import Enum from '../codec/Enum'; +import { ClassOf } from '../codec/createType'; import Struct from '../codec/Struct'; -import Vector from '../codec/Vector'; +import Vec from '../codec/Vec'; import Event from './Event'; -import Null from './Null'; -import U32 from './U32'; - -/** - * @name ApplyExtrinsic - * @description - * The [[Phase]] where the extrinsic is applied - */ -export class ApplyExtrinsic extends U32 { -} - -/** - * @name Finalization - * @description - * The [[Phase]] where the extrinsic is being Finalized - */ -export class Finalization extends Null { -} - -/** - * @name Phase - * @description - * An [[Enum]] that indicates the specific phase where the [[EventRecord]] was generated - */ -export class Phase extends Enum { - public constructor (value: any, index?: number) { - super({ - ApplyExtrinsic, - Finalization - }, value, index); - } - - /** - * @description Returns the item as a [[ApplyExtrinsic]] - */ - public get asApplyExtrinsic (): ApplyExtrinsic { - assert(this.isApplyExtrinsic, `Cannot convert '${this.type}' via asApplyExtrinsic`); - - return this.value as ApplyExtrinsic; - } - - /** - * @description Returns the item as a [[Finalization]] - */ - public get asFinalization (): Finalization { - assert(this.isFinalization, `Cannot convert '${this.type}' via asFinalization`); - - return this.value as Finalization; - } - - /** - * @description true when this is a ApplyExtrinsic - */ - public get isApplyExtrinsic (): boolean { - return this.type === 'ApplyExtrinsic'; - } - - /** - * @description true when this is a ApplyExtrinsic - */ - public get isFinalization (): boolean { - return this.type === 'Finalization'; - } -} - -/** - * @name EventRecord_0_76 - * @description - * A record for an [[Event]] (as specified by [[Metadata]]) with the specific [[Phase]] of - * application. - */ -export class EventRecord0to76 extends Struct { - public constructor (value: any) { - super({ - phase: Phase, - event: Event - }, value); - } - - /** - * @description The [[Event]] this record refers to - */ - public get event (): Event { - return this.get('event') as Event; - } - - /** - * @description The [[Phase]] where the event was generated - */ - public get phase (): Phase { - return this.get('phase') as Phase; - } - - /** - * @description The [[Hash]] topics for this event (empty, compat) - */ - public get topics (): Vector { - return createType('Vec', []); - } -} /** * @name EventRecord @@ -121,13 +19,14 @@ export class EventRecord0to76 extends Struct { export default class EventRecord extends Struct { public constructor (value: any) { super({ - phase: Phase, + phase: ClassOf('Phase'), event: Event, topics: ClassOf('Vec') }, value); } - public static Fallback = EventRecord0to76; + // TODO We want these injected by createType + public static Fallback = ClassOf('EventRecord0to76'); /** * @description The [[Event]] this record refers to @@ -146,7 +45,7 @@ export default class EventRecord extends Struct { /** * @description The [[Hash]] topics for this event */ - public get topics (): Vector { - return this.get('topics') as Vector; + public get topics (): Vec { + return this.get('topics') as Vec; } } diff --git a/packages/types/src/rpc/Header.spec.ts b/packages/types/src/primitive/Header.spec.ts similarity index 100% rename from packages/types/src/rpc/Header.spec.ts rename to packages/types/src/primitive/Header.spec.ts diff --git a/packages/types/src/rpc/Header.ts b/packages/types/src/primitive/Header.ts similarity index 98% rename from packages/types/src/rpc/Header.ts rename to packages/types/src/primitive/Header.ts index 28c7a894a2..4df6313ee9 100644 --- a/packages/types/src/rpc/Header.ts +++ b/packages/types/src/primitive/Header.ts @@ -32,7 +32,7 @@ export default class Header extends Struct { number: ClassOf('Compact'), stateRoot: ClassOf('Hash'), extrinsicsRoot: ClassOf('Hash'), - digest: Digest + digest: ClassOf('Digest') }, value || {}); } diff --git a/packages/types/src/primitive/KeyValue.spec.ts b/packages/types/src/primitive/KeyValue.spec.ts deleted file mode 100644 index aae1ed0ea6..0000000000 --- a/packages/types/src/primitive/KeyValue.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import KeyValue, { KeyValueOption } from './KeyValue'; - -describe('KeyValue', (): void => { - it('decodes KeyValue from u8a', (): void => { - expect( - new KeyValue( - Uint8Array.from([ - 4 << 2, - 0x11, 0x22, 0x33, 0x44, - 9 << 2, - 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 - ]) - ).toJSON() - ).toEqual(['0x11223344', '0x998877665544332211']); - }); - - it('encodes KeyValue from JSON', (): void => { - expect( - new KeyValue(['0x11223344', '0x998877665544332211']).toU8a() - ).toEqual( - new Uint8Array([ - 4 << 2, - 0x11, 0x22, 0x33, 0x44, - 9 << 2, - 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 - ]) - ); - }); - - it('exposes the properties for key/value', (): void => { - const kv = new KeyValue(['0x11223344', '0x998877665544332211']); - - expect(kv.key.toHex()).toEqual('0x11223344'); - expect(kv.value.toHex()).toEqual('0x998877665544332211'); - }); -}); - -describe('KeyValueOption', (): void => { - it('exposes the properties for key/value', (): void => { - const kv = new KeyValueOption([ - '0x11223344' - ]); - - expect(kv.key.toHex()).toEqual('0x11223344'); - expect(kv.value.isNone).toEqual(true); - }); -}); diff --git a/packages/types/src/primitive/KeyValue.ts b/packages/types/src/primitive/KeyValue.ts deleted file mode 100644 index 422d6d26ce..0000000000 --- a/packages/types/src/primitive/KeyValue.ts +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { AnyU8a } from '../types'; - -import Option from '../codec/Option'; -import Tuple from '../codec/Tuple'; -import StorageData from './StorageData'; -import StorageKey from './StorageKey'; - -type KeyValueValue = [AnyU8a, AnyU8a]; - -/** - * @name KeyValue - * @description - * KeyValue structure. Since most of the keys and resultant values in Subtrate are - * hashed and/or encoded, this does not wrap [[Text]], but rather a [[Bytes]] - * for the keys and values. (Not to be confused with the KeyValue in [[Metadata]], that - * is actually for Maps, whereas this is a representation of actual storage values) - */ -export default class KeyValue extends Tuple { - public constructor (value?: KeyValueValue | Uint8Array) { - super({ - key: StorageKey, - value: StorageData - }, value); - } - - /** - * @description The [[StorageKey]] - */ - public get key (): StorageKey { - return this[0] as StorageKey; - } - - /** - * @description The [[StorageData]] - */ - public get value (): StorageData { - return this[1] as StorageData; - } -} - -export type KeyValueOptionValue = [AnyU8a, AnyU8a?]; - -/** - * @name KeyValueOption - * @description - * A key/value change. This is similar to the [[KeyValue]] structure, - * however in this case the value could be optional. Here it extends - * from a [[Tuple]], indicating the use inside areas such as [[StorageChangeSet]] - */ -export class KeyValueOption extends Tuple { - public constructor (value?: KeyValueOptionValue | Uint8Array) { - super({ - StorageKey, - 'Option': Option.with(StorageData) - }, value); - } - - /** - * @description The [[StorageKey]] - */ - public get key (): StorageKey { - return this[0] as StorageKey; - } - - /** - * @description The [[Option]] [[StorageData]] - */ - public get value (): Option { - return this[1] as Option; - } -} diff --git a/packages/types/src/primitive/Moment.ts b/packages/types/src/primitive/Moment.ts index c86ed42f6f..8b9ad24346 100644 --- a/packages/types/src/primitive/Moment.ts +++ b/packages/types/src/primitive/Moment.ts @@ -131,11 +131,3 @@ export default class Moment extends Date implements Codec { return bnToU8a(this.toNumber(), BITLENGTH, true); } } - -/** - * @name MomentOf - * @description - * The Substrate MomentOf representation as a [[Moment]]. - */ -export class MomentOf extends Moment { -} diff --git a/packages/types/src/primitive/Null.ts b/packages/types/src/primitive/Null.ts index b9ccceb324..f6c7291330 100644 --- a/packages/types/src/primitive/Null.ts +++ b/packages/types/src/primitive/Null.ts @@ -69,14 +69,3 @@ export default class Null implements Codec { return new Uint8Array(); } } - -/** - * @name Phantom - * @description - * Implements a type that does not contain anything (apart from `null`) - */ -export class Phantom extends Null { - public toRawType (): string { - return 'Phantom'; - } -} diff --git a/packages/types/src/primitive/StorageData.ts b/packages/types/src/primitive/StorageData.ts deleted file mode 100644 index 21b45573c2..0000000000 --- a/packages/types/src/primitive/StorageData.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import Bytes from './Bytes'; - -/** - * @name StorageData - * @description - * Data retrieved via Storage queries and data for key-value pairs - */ -export default class StorageData extends Bytes { -} diff --git a/packages/types/src/primitive/index.ts b/packages/types/src/primitive/index.ts index b6efdd6ebc..0a411e7633 100644 --- a/packages/types/src/primitive/index.ts +++ b/packages/types/src/primitive/index.ts @@ -13,37 +13,38 @@ export { default as AccountId } from './AccountId'; export { default as AccountIndex } from './AccountIndex'; export { default as Address } from './Address'; -export { default as Event, EventIndex } from './Event'; -export { default as EventRecord, EventRecord0to76 } from './EventRecord'; +export { default as Event } from './Event'; +export { default as Block } from './Block'; export { default as Bool, default as bool } from './Bool'; export { default as Bytes } from './Bytes'; +export { default as ConsensusEngineId } from './ConsensusEngineId'; export { default as Data } from './Data'; +export { default as Digest, DigestItem } from './Digest'; export * from './Extrinsic'; export { default as H160 } from './H160'; export { default as H256 } from './H256'; export { default as H512 } from './H512'; -export { default as I8, default as i8 } from './I8'; -export { default as I16, default as i16 } from './I16'; -export { default as I32, default as i32 } from './I32'; -export { default as I64, default as i64 } from './I64'; +export { default as Header } from './Header'; +export { default as i8, default as I8 } from './I8'; +export { default as i16, default as I16 } from './I16'; +export { default as i32, default as I32 } from './I32'; +export { default as i64, default as I64 } from './I64'; export { default as Fixed64 } from './I64Fixed'; -export { default as I128, default as i128 } from './I128'; -export { default as I256, default as i256 } from './I256'; -export { default as KeyValue } from './KeyValue'; +export { default as i128, default as I128 } from './I128'; +export { default as i256, default as I256 } from './I256'; export { default as Method } from './Method'; -export { default as Moment, MomentOf } from './Moment'; -export { default as Null, Phantom } from './Null'; +export { default as Moment } from './Moment'; +export { default as Null } from './Null'; export { default as Origin } from './Origin'; -export { default as StorageData } from './StorageData'; export { default as StorageHasher } from './StorageHasher'; export { default as StorageKey } from './StorageKey'; export { default as Text } from './Text'; export { default as Type } from './Type'; -export { default as U8, default as u8 } from './U8'; -export { default as U16, default as u16 } from './U16'; -export { default as U32, default as u32 } from './U32'; -export { default as U64, default as u64 } from './U64'; -export { default as U128, default as u128 } from './U128'; -export { default as U256, default as u256 } from './U256'; -export { default as USize, default as usize } from './USize'; +export { default as u8, default as U8 } from './U8'; +export { default as u16, default as U16 } from './U16'; +export { default as u32, default as U32 } from './U32'; +export { default as u64, default as U64 } from './U64'; +export { default as u128, default as U128 } from './U128'; +export { default as u256, default as U256 } from './U256'; +export { default as usize } from './USize'; export { default as Vote } from './Vote'; diff --git a/packages/types/src/rpc/ChainProperties.spec.ts b/packages/types/src/rpc/ChainProperties.spec.ts deleted file mode 100644 index efde7d4f71..0000000000 --- a/packages/types/src/rpc/ChainProperties.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import ChainProperties from './ChainProperties'; - -describe('ChainProperties', (): void => { - it('decodes from a null value', (): void => { - expect( - [...new ChainProperties(null).entries()] - ).toEqual([]); - }); - - it('decodes from an actual object', (): void => { - expect( - [...new ChainProperties({ - decimals: 15, - tokenSymbol: 'BBQ' - }).entries()] - ).toEqual([['decimals', 15], ['tokenSymbol', 'BBQ']]); - }); - - it('checks equality', (): void => { - expect( - new ChainProperties({ - decimals: 15, - tokenSymbol: 'BBQ' - }).eq([['tokenSymbol', 'BBQ'], ['decimals', 15]]) - ).toBe(true); - }); -}); diff --git a/packages/types/src/rpc/ChainProperties.ts b/packages/types/src/rpc/ChainProperties.ts deleted file mode 100644 index abc44cc745..0000000000 --- a/packages/types/src/rpc/ChainProperties.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import StructAny from '../codec/StructAny'; - -/** - * @name ChainProperties - * @description - * Wraps the properties retrieved from the chain via the `system.properties` RPC call. - */ -export default class ChainProperties extends StructAny { - /** - * @description The token decimals, if defined (de-facto standard only) - */ - public get tokenDecimals (): number | undefined { - return this.get('tokenDecimals'); - } - - /** - * @description The token system, if defined (de-facto standard only) - */ - public get tokenSymbol (): string | undefined { - return this.get('tokenSymbol'); - } -} diff --git a/packages/types/src/rpc/Digest.ts b/packages/types/src/rpc/Digest.ts deleted file mode 100644 index cbf6159bf3..0000000000 --- a/packages/types/src/rpc/Digest.ts +++ /dev/null @@ -1,415 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { Hash, Signature } from '../srml/runtime/types'; - -import BN from 'bn.js'; -import { assert, bnToBn } from '@polkadot/util'; - -import Enum from '../codec/Enum'; -import Struct from '../codec/Struct'; -import Tuple from '../codec/Tuple'; -import Vector from '../codec/Vector'; -import Bytes from '../primitive/Bytes'; -import U32 from '../primitive/U32'; -import U64 from '../primitive/U64'; - -// Should import AuthorityId (however, move these to generated types) -import AuthorityId from '../primitive/AccountId'; -import { ClassOf } from '../codec'; - -const CID_AURA = 0x61727561; // 'aura' -const CID_BABE = 0x65626162; // 'babe' -const CID_GRPA = 0x4b4e5246; // 'FRNK' (don't ask, used to be afg1) - -export { CID_AURA, CID_BABE, CID_GRPA }; - -/** - * @name AuthoritiesChange - * @description - * Log for Authories changed - */ -export class AuthoritiesChange extends Vector.with(AuthorityId) { -} - -/** - * @name ConsensusEngineId - * @description - * A 4-byte identifier (actually a [u8; 4]) identifying the engine, e.g. for Aura it would be [b'a', b'u', b'r', b'a'] - */ -export class ConsensusEngineId extends U32 { - public static idToString (input: number | BN): string { - return bnToBn(input) - .toArray('le') - .map((code): string => String.fromCharCode(code)) - .join(''); - } - - public static stringToId (input: string): number { - return input - .split('') - .reverse() - .reduce((result, char): number => (result * 256) + char.charCodeAt(0), 0); - } - - /** - * @description `true` if the engine matches aura - */ - public get isAura (): boolean { - return this.eq(CID_AURA); - } - - /** - * @description `true` is the engine matches babe - */ - public get isBabe (): boolean { - return this.eq(CID_BABE); - } - - /** - * @description `true` is the engine matches grandpa - */ - public get isGrandpa (): boolean { - return this.eq(CID_GRPA); - } - - /** - * @description From the input bytes, decode into an aura-tuple - */ - public extractSlot (bytes: Bytes): U64 { - assert(this.isAura, 'Invalid engine for asAura conversion'); - - return new U64( - // no compact prefix, only use the correct number of supplied bytes - bytes.toU8a(true).subarray(0, 8) - ); - } - - /** - * @description Override the default toString to return a 4-byte string - */ - public toString (): string { - return ConsensusEngineId.idToString(this as BN); - } -} - -/** - * @name Consensus - * @description - * Log item indicating consensus - */ -export class Consensus extends Tuple { - public constructor (value: any) { - super({ - ConsensusEngineId, - Bytes - }, value); - } - - /** - * @description The wrapped engine [[ConsensusEngineId]] - */ - public get engine (): ConsensusEngineId { - return this[0] as ConsensusEngineId; - } - - /** - * @description The wrapped [[Bytes]] - */ - public get data (): Bytes { - return this[1] as Bytes; - } - - /** - * @description The slot extracted from the raw data (fails on non-Aura) - */ - public get slot (): U64 { - return this.engine.extractSlot(this.data); - } -} - -/** - * @name SealV0 - * @description - * Log item indicating a sealing event. This has been replaced in later versions with a renamed [[Seal]], we however have kept compatibility with the old version - */ -export class SealV0 extends Tuple { - public constructor (value: any) { - super({ - U64, - Signature: ClassOf('Signature') - }, value); - } - - /** - * @description The wrapped [[Signature]] - */ - public get signature (): Signature { - return this[1] as Signature; - } - - /** - * @description The wrapped [[U64]] slot - */ - public get slot (): U64 { - return this[0] as U64; - } -} - -/** - * @name Seal - * @description - * Log item indicating a sealing event. - */ -export class Seal extends Tuple { - public constructor (value: any) { - super({ - ConsensusEngineId, - Bytes - }, value); - } - - /** - * @description The wrapped [[Bytes]] - */ - public get data (): Bytes { - return this[1] as Bytes; - } - - /** - * @description The wrapped [[U64]] slot - */ - public get slot (): U64 { - return this[0] as U64; - } -} - -/** - * @name Other - * @description - * Log item that is just a stream of [[Bytes]] - */ -export class Other extends Bytes { -} - -/** - * @name PreRuntime - * @description - * These are messages from the consensus engine to the runtime, although the consensus engine the consensus engine can (and should) read them itself to avoid ode and state duplication. - */ -export class PreRuntime extends Tuple { - public constructor (value: any) { - super({ - ConsensusEngineId, - Bytes - }, value); - } - - /** - * @description The wrapped [[ConsensusEngineId]] - */ - public get engine (): ConsensusEngineId { - return this[0] as ConsensusEngineId; - } - - /** - * @description The wrapped [[Bytes]] - */ - public get data (): Bytes { - return this[1] as Bytes; - } - - /** - * @description The slot extracted from the raw data (fails on non-Aura) - */ - public get slot (): U64 { - return this.engine.extractSlot(this.data); - } -} - -/** - * @name DigestItem - * @description - * A [[Enum]] the specifies the specific item in the logs of a [[Digest]] - */ -export class DigestItem extends Enum { - public constructor (value: any) { - super({ - Other, // 0 - AuthoritiesChange, // 1 - ChangesTrieRoot: ClassOf('Hash'), // 2 - SealV0, // 3 - Consensus, // 4 - Seal, // 5 - PreRuntime // 6 - }, value); - } - - /** - * @description Returns the item as a [[AuthoritiesChange]] - */ - public get asAuthoritiesChange (): AuthoritiesChange { - assert(this.isAuthoritiesChange, `Cannot convert '${this.type}' via asAuthoritiesChange`); - - return this.value as AuthoritiesChange; - } - - /** - * @description Returns the item as a [[ChangesTrieRoot]] - */ - public get asChangesTrieRoot (): Hash { - assert(this.isChangesTrieRoot, `Cannot convert '${this.type}' via asChangesTrieRoot`); - - return this.value as Hash; - } - - /** - * @desciption Retuns the item as a [[Consensus]] - */ - public get asConsensus (): Consensus { - assert(this.isConsensus, `Cannot convert '${this.type}' via asConsensus`); - - return this.value as Consensus; - } - - /** - * @description Returns the item as a [[Other]] - */ - public get asOther (): Other { - assert(this.isOther, `Cannot convert '${this.type}' via asOther`); - - return this.value as Other; - } - - /** - * @description Returns the item as a [[PreRuntime]] - */ - public get asPreRuntime (): PreRuntime { - assert(this.isPreRuntime, `Cannot convert '${this.type}' via asPreRuntime`); - - return this.value as PreRuntime; - } - - /** - * @description Returns the item as a [[Seal]] - */ - public get asSeal (): Seal { - assert(this.isSeal, `Cannot convert '${this.type}' via asSeal`); - - return this.value as Seal; - } - - /** - * @description Returns the item as a [[SealV0]] - */ - public get asSealV0 (): SealV0 { - assert(this.isSealV0, `Cannot convert '${this.type}' via asSealV0`); - - return this.value as SealV0; - } - - /** - * @description Returns true on [[AuthoritiesChange]] - */ - public get isAuthoritiesChange (): boolean { - return this.type === 'AuthoritiesChange'; - } - - /** - * @description Returns true on [[ChangesTrieRoot]] - */ - public get isChangesTrieRoot (): boolean { - return this.type === 'ChangesTrieRoot'; - } - - /** - * @description Returns true on [[Consensus]] - */ - public get isConsensus (): boolean { - return this.type === 'Consensus'; - } - - /** - * @description Returns true on [[Other]] - */ - public get isOther (): boolean { - return this.type === 'Other'; - } - - /** - * @description Returns true on [[PreRuntime]] - */ - public get isPreRuntime (): boolean { - return this.type === 'PreRuntime'; - } - - /** - * @description Returns true on [[Seal]] - */ - public get isSeal (): boolean { - return this.type === 'Seal'; - } - - /** - * @description Returns true on [[SealV0]] - */ - public get isSealV0 (): boolean { - return this.type === 'SealV0'; - } - - /** - * @description Converts the Object to JSON, typically used for RPC transfers. For logs, we overrides to produce the hex version (sligning with substrate gives in actual JSON responses) - */ - public toJSON (): string { - return this.toHex(); - } - - /** - * @description Returns the type of engine - */ - public get type (): string { - return super.type; - } -} - -/** - * @name Digest - * @description - * A [[Header]] Digest - */ -export default class Digest extends Struct { - public constructor (value: any) { - super({ - logs: Vector.with(DigestItem) - }, value); - } - - /** - * @description The [[DigestItem]] logs - */ - public get logs (): Vector { - return this.get('logs') as Vector; - } - - /** - * @description The [[DigestItem]] logs, filtered, filter items included. This is useful for derive functionality where only a certain type of log is to be returned. - */ - public logsWith (...include: string[]): Vector { - return this.logs.filter(({ type }): boolean => include.includes(type)) as Vector; - } - - /** - * @description The [[DigestItem]] logs, filtered, filter items exluded. This is useful for stripping headers for eg. WASM runtime execution. - */ - public logsWithout (...exclude: string[]): Vector { - return this.logs.filter(({ type }): boolean => !exclude.includes(type)) as Vector; - } -} - -/** - * @name DigestOf - * @description - * A [[Header]] Digest - */ -export class DigestOf extends Digest { } diff --git a/packages/types/src/rpc/ExtrinsicStatus.ts b/packages/types/src/rpc/ExtrinsicStatus.ts deleted file mode 100644 index 136ef9a21c..0000000000 --- a/packages/types/src/rpc/ExtrinsicStatus.ts +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { Hash } from '../srml/types'; - -import { assert } from '@polkadot/util'; - -import { ClassOf } from '../codec/createType'; -import Enum from '../codec/Enum'; -import Vector from '../codec/Vector'; -import Null from '../primitive/Null'; -import Text from '../primitive/Text'; - -/** - * @name ExtrinsicStatus - * @description - * An [[Enum]] that indicates the status of the [[Extrinsic]] as been submitted - */ -export default class ExtrinsicStatus extends Enum { - public constructor (value: any, index?: number) { - super({ - Future: Null, - Ready: Null, - Finalized: ClassOf('Hash'), - Usurped: ClassOf('Hash'), - Broadcast: Vector.with(Text), - Dropped: Null, - Invalid: Null - }, value, index); - } - - /** - * @description Returns the item as a [[Broadcast]] - */ - public get asBroadcast (): Vector { - assert(this.isBroadcast, `Cannot convert '${this.type}' via asBroadcast`); - - return this.value as Vector; - } - - /** - * @description Returns the item as a [[Dropped]] - */ - public get asDropped (): Null { - assert(this.isDropped, `Cannot convert '${this.type}' via asDropped`); - - return this.value as Null; - } - - /** - * @description Returns the item as a [[Finalized]] - */ - public get asFinalized (): Hash { - assert(this.isFinalized, `Cannot convert '${this.type}' via asFinalized`); - - return this.value as Hash; - } - - /** - * @description Returns the item as a [[Future]] - */ - public get asFuture (): Null { - assert(this.isFuture, `Cannot convert '${this.type}' via asFuture`); - - return this.value as Null; - } - - /** - * @description Returns the item as a [[Invalid]] - */ - public get asInvalid (): Null { - assert(this.isInvalid, `Cannot convert '${this.type}' via asInvalid`); - - return this.value as Null; - } - - /** - * @description Returns the item as a [[Ready]] - */ - public get asReady (): Null { - assert(this.isReady, `Cannot convert '${this.type}' via asReady`); - - return this.value as Null; - } - - /** - * @description Returns the item as a [[Usurped]] - */ - public get asUsurped (): Hash { - assert(this.isUsurped, `Cannot convert '${this.type}' via asUsurped`); - - return this.value as Hash; - } - - /** - * @description Returns true if the status is boadcast - */ - public get isBroadcast (): boolean { - return this.type === 'Broadcast'; - } - - /** - * @description Returns true if the status is dropped - */ - public get isDropped (): boolean { - return this.type === 'Dropped'; - } - - /** - * @description Returns true if the status is finalized - */ - public get isFinalized (): boolean { - return this.type === 'Finalized'; - } - - /** - * @description Returns true if the status is future - */ - public get isFuture (): boolean { - return this.type === 'Future'; - } - - /** - * @description Returns true if the status is invalid - */ - public get isInvalid (): boolean { - return this.type === 'Invalid'; - } - - /** - * @description Returns true if the status is eady - */ - public get isReady (): boolean { - return this.type === 'Ready'; - } - - /** - * @description Returns true if the status is usurped - */ - public get isUsurped (): boolean { - return this.type === 'Usurped'; - } -} diff --git a/packages/types/src/rpc/Health.ts b/packages/types/src/rpc/Health.ts deleted file mode 100644 index b9739cd9a7..0000000000 --- a/packages/types/src/rpc/Health.ts +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import Struct from '../codec/Struct'; -import Bool from '../primitive/Bool'; -import U64 from '../primitive/U64'; - -/** - * @name Health - * @description - * A system health indicator, reported back over RPC - */ -export default class Health extends Struct { - public constructor (value?: any) { - super({ - peers: U64, - isSyncing: Bool, - shouldHavePeers: Bool - }, value); - } - - /** - * @description The sync status - */ - public get isSyncing (): Bool { - return this.get('isSyncing') as Bool; - } - - /** - * @description The numbers of peers as [[U64]] - */ - public get peers (): U64 { - return this.get('peers') as U64; - } - - /** - * @description Should this node have peers (not active on --dev) - */ - public get shouldHavePeers (): Bool { - return this.get('shouldHavePeers') as Bool; - } -} diff --git a/packages/types/src/rpc/NetworkState.ts b/packages/types/src/rpc/NetworkState.ts deleted file mode 100644 index 301f80457c..0000000000 --- a/packages/types/src/rpc/NetworkState.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import StructAny from '../codec/StructAny'; - -/** - * @name NetworkState - * @description - * Wraps the properties retrieved from the chain via the `system.network_state` RPC call. - */ -export default class NetworkState extends StructAny { -} diff --git a/packages/types/src/rpc/PeerInfo.ts b/packages/types/src/rpc/PeerInfo.ts deleted file mode 100644 index aaf31e37aa..0000000000 --- a/packages/types/src/rpc/PeerInfo.ts +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { BlockNumber, Hash } from '../srml/runtime/types'; - -import { ClassOf } from '../codec/createType'; -import Struct from '../codec/Struct'; -import Text from '../primitive/Text'; -import U32 from '../primitive/U32'; - -/** - * @name PeerInfo - * @description - * A system peer info indicator, reported back over RPC - */ -export default class PeerInfo extends Struct { - public constructor (value?: any) { - super({ - peerId: Text, - roles: Text, - protocolVersion: U32, - bestHash: ClassOf('Hash'), - bestNumber: ClassOf('BlockNumber') - }, value); - } - - /** - * @description The best block hash for the peer - */ - public get bestHash (): Hash { - return this.get('bestHash') as Hash; - } - - /** - * @description The best block hash for the peer - */ - public get bestNumber (): BlockNumber { - return this.get('bestNumber') as BlockNumber; - } - - /** - * @description The p2p network id for the peer - */ - public get peerId (): Text { - return this.get('peerId') as Text; - } - - /** - * @description The index of the peer in our list - */ - public get protocolVersion (): U32 { - return this.get('protocolVersion') as U32; - } - - /** - * @description The roles of the peer on the network - */ - public get roles (): Text { - return this.get('roles') as Text; - } -} diff --git a/packages/types/src/rpc/RuntimeVersion.ts b/packages/types/src/rpc/RuntimeVersion.ts deleted file mode 100644 index fe602f7979..0000000000 --- a/packages/types/src/rpc/RuntimeVersion.ts +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { AnyNumber, AnyU8a, RuntimeVersionInterface } from '../types'; - -import Struct from '../codec/Struct'; -import Tuple from '../codec/Tuple'; -import U8aFixed from '../codec/U8aFixed'; -import Vector from '../codec/Vector'; -import Text from '../primitive/Text'; -import U32 from '../primitive/U32'; - -/** - * @name ApiId - * @description - * An identifier for the runtime API - */ -export class ApiId extends U8aFixed { - public constructor (value?: AnyU8a) { - super(value, 64); - } -} - -interface RuntimeVersionApiValue { - id?: AnyU8a; - version?: AnyNumber; -} - -/** - * @name RuntimeVersionApi - * @description - * A [[Tuple]] that conatins the [[ApiId]] and [[U32]] version - */ -export class RuntimeVersionApi extends Tuple { - public constructor (value?: RuntimeVersionApiValue | Uint8Array) { - super({ - ApiId, - U32 - }, value); - } - - /** - * @description The [[ApiId]] - */ - public get id (): ApiId { - return this[0] as ApiId; - } - - /** - * @description The specific version as [[U32]] - */ - public get version (): U32 { - return this[1] as U32; - } -} - -interface RuntimeVersionValue { - specName?: string; - implName?: string; - authoringVersion?: AnyNumber; - specVersion?: AnyNumber; - implVersion?: AnyNumber; - apis?: RuntimeVersionApiValue[]; -} - -/** - * @name RuntimeVersion - * @description - * A defintion of the runtime and the associated versions thereof - */ -export default class RuntimeVersion extends Struct implements RuntimeVersionInterface { - public constructor (value?: RuntimeVersionValue | Uint8Array) { - super({ - specName: Text, - implName: Text, - authoringVersion: U32, - specVersion: U32, - implVersion: U32, - apis: Vector.with(RuntimeVersionApi) - }, value); - } - - /** - * @description The available APIs as [[RuntimeVersionApi]] - */ - public get apis (): Vector { - return this.get('apis') as Vector; - } - - /** - * @description The authoring version as [[U32]] - */ - public get authoringVersion (): U32 { - return this.get('authoringVersion') as U32; - } - - /** - * @description The implementation name - */ - public get implName (): Text { - return this.get('implName') as Text; - } - - /** - * @description The implementation version - */ - public get implVersion (): U32 { - return this.get('implVersion') as U32; - } - - /** - * @description The specification name - */ - public get specName (): Text { - return this.get('specName') as Text; - } - - /** - * @description The specification version - */ - public get specVersion (): U32 { - return this.get('specVersion') as U32; - } -} diff --git a/packages/types/src/rpc/SignedBlock.ts b/packages/types/src/rpc/SignedBlock.ts deleted file mode 100644 index 726d891f6e..0000000000 --- a/packages/types/src/rpc/SignedBlock.ts +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { Hash, Justification } from '../srml/runtime/types'; -import { AnyU8a } from '../types'; - -import { ClassOf } from '../codec/createType'; -import Struct from '../codec/Struct'; -import Block, { BlockValue } from './Block'; - -interface SignedBlockValue { - block?: BlockValue; - justification?: AnyU8a; -} - -/** - * @name SignedBlock - * @description - * A [[Block]] that has been signed and contains a [[Justification]] - */ -export default class SignedBlock extends Struct { - public constructor (value?: SignedBlockValue | Uint8Array) { - super({ - block: Block, - justification: ClassOf('Justification') - }, value); - } - - /** - * @description The wrapped [[Block]] - */ - public get block (): Block { - return this.get('block') as Block; - } - - /** - * @description Block/header [[Hash]] - */ - public get hash (): Hash { - return this.block.hash; - } - - /** - * @description The wrapped [[Justification]] - */ - public get justification (): Justification { - return this.get('justification') as Justification; - } -} diff --git a/packages/types/src/rpc/StorageChangeSet.ts b/packages/types/src/rpc/StorageChangeSet.ts deleted file mode 100644 index d9327d2d51..0000000000 --- a/packages/types/src/rpc/StorageChangeSet.ts +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { Hash } from '../srml/runtime/types'; -import { AnyU8a } from '../types'; - -import { ClassOf } from '../codec/createType'; -import Struct from '../codec/Struct'; -import Vector from '../codec/Vector'; -import { KeyValueOption, KeyValueOptionValue } from '../primitive/KeyValue'; - -interface StorageChangeSetValue { - block?: AnyU8a; - changes?: KeyValueOptionValue[]; -} - -/** - * @name StorageChangeSet - * @description - * A set of storage changes. It contains the [[Block]] hash and - * a list of the actual changes that took place as an array of - * [[KeyValueOption]] - */ -export default class StorageChangeSet extends Struct { - public constructor (value?: StorageChangeSetValue | Uint8Array) { - super({ - block: ClassOf('Hash'), - changes: Vector.with(KeyValueOption) - }, value); - } - - /** - * @description The applicable changes as [[KeyValueOption]] - */ - public get changes (): Vector { - return this.get('changes') as Vector; - } - - /** - * @description The block [[Hash]] - */ - public get block (): Hash { - return this.get('block') as Hash; - } -} diff --git a/packages/types/src/rpc/index.ts b/packages/types/src/rpc/index.ts deleted file mode 100644 index 4a935fc066..0000000000 --- a/packages/types/src/rpc/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -// NOTE When adding any types here, we need to update the coumentation links as -// well - /docs/SUMMARY.md as well as ../README.md - -/** - * @summary Type definitions that are used in the rpc - */ -export { default as Block } from './Block'; -export { default as ChainProperties } from './ChainProperties'; -export { default as Digest, DigestItem, DigestOf } from './Digest'; -export { default as ExtrinsicStatus } from './ExtrinsicStatus'; -export { default as Header } from './Header'; -export { default as Health } from './Health'; -export { default as NetworkState } from './NetworkState'; -export { default as PeerInfo } from './PeerInfo'; -export { default as RuntimeVersion } from './RuntimeVersion'; -export { default as SignedBlock } from './SignedBlock'; -export { default as StorageChangeSet } from './StorageChangeSet'; diff --git a/packages/types/src/scripts/MetadataMd.ts b/packages/types/src/scripts/MetadataMd.ts index 0b36232648..7bcc00944d 100644 --- a/packages/types/src/scripts/MetadataMd.ts +++ b/packages/types/src/scripts/MetadataMd.ts @@ -2,6 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import '../injector'; + import fs from 'fs'; import { stringCamelCase, stringLowerFirst } from '@polkadot/util'; diff --git a/packages/types/src/scripts/srmlTS.ts b/packages/types/src/scripts/srmlTS.ts index ececaab70e..ffb4808b56 100644 --- a/packages/types/src/scripts/srmlTS.ts +++ b/packages/types/src/scripts/srmlTS.ts @@ -27,7 +27,7 @@ interface TypeImports { primitiveTypes: TypeExist; } -const HEADER = '/* eslint-disable @typescript-eslint/no-empty-interface */\n// Auto-generated via `yarn build:srmlTs`, do not edit\n\n'; +const HEADER = '// Auto-generated via `yarn build:srmlTs`, do not edit\n\n'; const FOOTER = '\n'; // Maps the types as found to the source location. This is used to generate the @@ -68,14 +68,19 @@ function isCompactEncodable (Child: Constructor): boolean { return Object.values(COMPACT_ENCODABLE).some((CompactEncodable): boolean => isChildClass(CompactEncodable, Child)); } -// helper to generate a `export interface extends {} -function createInterface (name: string = '', base: string, body: string = ''): string { - return `export interface ${name} extends ${base} {${body.length ? '\n' : ''}${body}}`; +// helper to generate a `export interface extends {} +function exportInterface (name: string = '', base: string, body: string = ''): string { + return `/** ${base} */\nexport interface ${name} extends ${base} {${body.length ? '\n' : ''}${body}}`; +} + +// helper to create an `export = ` +function exportType (name: string = '', base: string): string { + return `/** ${base} */\nexport type ${name} = ${base};`; } // helper to generate a `readonly : ;` getter -function createGetter (name: string = '', type: string): string { - return ` readonly ${name}: ${type};\n`; +function createGetter (name: string = '', type: string, doc?: string): string { + return ` /** ${doc || type} */\n readonly ${name}: ${type};\n`; } // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -91,7 +96,7 @@ function tsCompact ({ name: compactName, sub }: TypeDef, imports: TypeImports): switch (def.info) { case TypeDefInfo.Plain: setImports(imports, [def.type]); - return createInterface(compactName, `Compact<${def.type}>`); + return exportType(compactName, `Compact<${def.type}>`); default: throw new Error(`Enum: ${compactName}: Unhandled type ${TypeDefInfo[def.info]}`); @@ -106,18 +111,19 @@ function tsEnum ({ name: enumName, sub }: TypeDef, imports: TypeImports): string const [enumType, asGetter] = type === 'Null' ? ['', ''] : [`(${type})`, createGetter(`as${getter}`, type)]; - const isGetter = createGetter(`is${getter}`, 'boolean'); + const isGetter = createGetter(`is${getter}`, 'boolean', `${index}:: ${name}${enumType}`); switch (info) { case TypeDefInfo.Plain: - return ` /**\n * @description ${index}:: ${name}${enumType}\n */\n${isGetter}${asGetter}`; + case TypeDefInfo.Vec: + return `${isGetter}${asGetter}`; default: throw new Error(`Enum: ${enumName}: Unhandled type ${TypeDefInfo[info]}`); } }); - return createInterface(enumName, 'Enum', keys.join('')); + return exportInterface(enumName, 'Enum', keys.join('')); } function tsOption ({ name: optionName, sub }: TypeDef, imports: TypeImports): string { @@ -128,7 +134,7 @@ function tsOption ({ name: optionName, sub }: TypeDef, imports: TypeImports): st switch (def.info) { case TypeDefInfo.Plain: setImports(imports, [def.type]); - return createInterface(optionName, `Option<${def.type}>`); + return exportType(optionName, `Option<${def.type}>`); default: throw new Error(`Enum: ${optionName}: Unhandled type ${TypeDefInfo[def.info]}`); @@ -138,7 +144,7 @@ function tsOption ({ name: optionName, sub }: TypeDef, imports: TypeImports): st function tsPlain ({ name: plainName, type }: TypeDef, imports: TypeImports): string { setImports(imports, [type]); - return createInterface(plainName, type); + return exportType(plainName, type); } function _tsStructGetterType (structName: string | undefined, { info, sub, type }: TypeDef, imports: TypeImports): [string, string] { @@ -162,12 +168,12 @@ function _tsStructGetterType (structName: string | undefined, { info, sub, type case TypeDefInfo.Plain: return [type, type]; - case TypeDefInfo.Vector: + case TypeDefInfo.Vec: _type = (sub as TypeDef).type; - setImports(imports, ['Vector']); + setImports(imports, ['Vec']); - return [_type, `Vector<${_type}>`]; + return [_type, `Vec<${_type}>`]; default: throw new Error(`Struct: ${structName}: Unhandled type ${TypeDefInfo[info]}`); @@ -181,7 +187,7 @@ function tsSet ({ name: setName, sub }: TypeDef, imports: TypeImports): string { createGetter(`is${name}`, 'boolean') ); - return createInterface(setName, 'Set', types.join('')); + return exportInterface(setName, 'Set', types.join('')); } function tsStruct ({ name: structName, sub }: TypeDef, imports: TypeImports): string { @@ -193,7 +199,7 @@ function tsStruct ({ name: structName, sub }: TypeDef, imports: TypeImports): st return createGetter(typedef.name, returnType); }); - return createInterface(structName, 'Struct', keys.join('')); + return exportInterface(structName, 'Struct', keys.join('')); } function _tsTupleGetterType (tupleName: string | undefined, { info, sub, type }: TypeDef, imports: TypeImports): string { @@ -219,20 +225,18 @@ function tsTuple ({ name: tupleName, sub }: TypeDef, imports: TypeImports): stri const types = (sub as TypeDef[]).map((typedef): string => _tsTupleGetterType(tupleName, typedef, imports) ); - const exp = createInterface(tupleName, `Codec, _${tupleName}`); - // TODO We need some way here of identifying the fields - return `type _${tupleName} = [${types.join(', ')}];\n${exp}`; + return exportType(tupleName, `[${types.join(', ')}] & Codec`); } -function tsVector ({ ext, info, name: vectorName, sub }: TypeDef, imports: TypeImports): string { - const type = info === TypeDefInfo.VectorFixed +function tsVec ({ ext, info, name: vectorName, sub }: TypeDef, imports: TypeImports): string { + const type = info === TypeDefInfo.VecFixed ? (ext as TypeDefExtVecFixed).type : (sub as TypeDef).type; - setImports(imports, ['Vector', type]); + setImports(imports, ['Vec', type]); - return createInterface(vectorName, `Vector<${type}>`); + return exportType(vectorName, `Vec<${type}>`); } // creates the import lines @@ -250,13 +254,13 @@ function createImportCode (header: string, checks: { file: string; types: string function getDerivedTypes (type: string, primitiveName: string, imports: TypeImports, indent: number = 2): string { // `primitiveName` represents the actual primitive type our type is mapped to const isCompact = isCompactEncodable((primitiveClasses as any)[primitiveName]); - setImports(imports, ['Option', 'Vector', isCompact ? 'Compact' : '']); + setImports(imports, ['Option', 'Vec', isCompact ? 'Compact' : '']); return [ `${type}: ${type};`, isCompact ? `'Compact<${type}>': Compact<${type}>;` : undefined, `'Option<${type}>': Option<${type}>;`, - `'Vec<${type}>': Vector<${type}>;` + `'Vec<${type}>': Vec<${type}>;` ] .filter((x): boolean => !!x) .map((line): string => `${' '.repeat(indent)}${line}`) // Add indentation @@ -289,8 +293,8 @@ function generateTsDef (srmlName: string, { types }: { types: Record]; -export interface Uncle extends Codec, _Uncle {} +/** [Hash, Option] & Codec */ +export type Uncle = [Hash, Option] & Codec; +/** Enum */ export interface UncleEntryItem extends Enum { - /** - * @description 0:: InclusionHeight(InclusionHeight) - */ + /** 0:: InclusionHeight(InclusionHeight) */ readonly isInclusionHeight: boolean; + /** InclusionHeight */ readonly asInclusionHeight: InclusionHeight; - /** - * @description 1:: Uncle(Uncle) - */ + /** 1:: Uncle(Uncle) */ readonly isUncle: boolean; + /** Uncle */ readonly asUncle: Uncle; } @@ -28,12 +27,12 @@ declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { InclusionHeight: InclusionHeight; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Uncle: Uncle; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; UncleEntryItem: UncleEntryItem; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/babe/types.ts b/packages/types/src/srml/babe/types.ts index 8bcc2347df..f97f308b0f 100644 --- a/packages/types/src/srml/babe/types.ts +++ b/packages/types/src/srml/babe/types.ts @@ -1,16 +1,16 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Option, Vector } from '../../codec'; +import { Compact, Option, Vec } from '../../codec'; import { u64 } from '../../primitive'; -export interface BabeWeight extends u64 {} +/** u64 */ +export type BabeWeight = u64; declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { BabeWeight: BabeWeight; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/balances/types.ts b/packages/types/src/srml/balances/types.ts index 3e17efe4bf..5217fb32d9 100644 --- a/packages/types/src/srml/balances/types.ts +++ b/packages/types/src/srml/balances/types.ts @@ -1,25 +1,37 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Option, Set, Struct, Vector } from '../../codec'; +import { Option, Set, Struct, Vec } from '../../codec'; import { Balance, BlockNumber, LockIdentifier } from '../runtime/types'; +/** Struct */ export interface BalanceLock extends Struct { + /** LockIdentifier */ readonly id: LockIdentifier; + /** Balance */ readonly amount: Balance; + /** BlockNumber */ readonly until: BlockNumber; + /** WithdrawReasons */ readonly reasons: WithdrawReasons; } +/** Struct */ export interface VestingSchedule extends Struct { + /** Balance */ readonly offset: Balance; + /** Balance */ readonly perBlock: Balance; } +/** Set */ export interface WithdrawReasons extends Set { + /** boolean */ readonly isTransactionPayment: boolean; + /** boolean */ readonly isTransfer: boolean; + /** boolean */ readonly isReserve: boolean; + /** boolean */ readonly isFee: boolean; } @@ -27,12 +39,12 @@ declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { VestingSchedule: VestingSchedule; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; WithdrawReasons: WithdrawReasons; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; BalanceLock: BalanceLock; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/collective/types.ts b/packages/types/src/srml/collective/types.ts index aba727fa43..2fe0e7a6a3 100644 --- a/packages/types/src/srml/collective/types.ts +++ b/packages/types/src/srml/collective/types.ts @@ -1,18 +1,24 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Option, Struct, Vector } from '../../codec'; +import { Compact, Option, Struct, Vec } from '../../codec'; import { AccountId, u32, u64 } from '../../primitive'; -export interface MemberCount extends u64 {} +/** u64 */ +export type MemberCount = u64; -export interface ProposalIndex extends u32 {} +/** u32 */ +export type ProposalIndex = u32; +/** Struct */ export interface Votes extends Struct { + /** ProposalIndex */ readonly index: ProposalIndex; + /** MemberCount */ readonly threshold: MemberCount; - readonly ayes: Vector; - readonly nays: Vector; + /** Vec */ + readonly ayes: Vec; + /** Vec */ + readonly nays: Vec; } declare module '@polkadot/types/interfaceRegistry' { @@ -20,13 +26,13 @@ declare module '@polkadot/types/interfaceRegistry' { MemberCount: MemberCount; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ProposalIndex: ProposalIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Votes: Votes; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/consensus/types.ts b/packages/types/src/srml/consensus/types.ts index 176419e531..a991314136 100644 --- a/packages/types/src/srml/consensus/types.ts +++ b/packages/types/src/srml/consensus/types.ts @@ -1,15 +1,15 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Option, Vector } from '../../codec'; +import { Option, Vec } from '../../codec'; import { AccountId } from '../../primitive'; -export interface AuthorityId extends AccountId {} +/** AccountId */ +export type AuthorityId = AccountId; declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { AuthorityId: AuthorityId; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/contracts/types.ts b/packages/types/src/srml/contracts/types.ts index 4a8f7003ad..c5c3d8eef6 100644 --- a/packages/types/src/srml/contracts/types.ts +++ b/packages/types/src/srml/contracts/types.ts @@ -1,107 +1,141 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Enum, Option, Struct, Vector } from '../../codec'; +import { Compact, Enum, Option, Struct, Vec } from '../../codec'; import { Bool, Bytes, Null, u32, u64, u8 } from '../../primitive'; import { Balance, BlockNumber, Hash } from '../runtime/types'; +/** Struct */ export interface AliveContractInfo extends Struct { + /** TrieId */ readonly trieId: TrieId; + /** u32 */ readonly storageSize: u32; + /** CodeHash */ readonly codeHash: CodeHash; + /** Balance */ readonly rentAllowance: Balance; + /** BlockNumber */ readonly deductBlock: BlockNumber; + /** Option */ readonly lastWrite: Option; } -export interface CodeHash extends Hash {} +/** Hash */ +export type CodeHash = Hash; +/** Enum */ export interface ContractInfo extends Enum { - /** - * @description 0:: Alive(AliveContractInfo) - */ + /** 0:: Alive(AliveContractInfo) */ readonly isAlive: boolean; + /** AliveContractInfo */ readonly asAlive: AliveContractInfo; - /** - * @description 1:: Tombstone(TombstoneContractInfo) - */ + /** 1:: Tombstone(TombstoneContractInfo) */ readonly isTombstone: boolean; + /** TombstoneContractInfo */ readonly asTombstone: TombstoneContractInfo; } -export interface ContractStorageKey extends Vector {} +/** Vec */ +export type ContractStorageKey = Vec; -export interface Gas extends u64 {} +/** u64 */ +export type Gas = u64; +/** Struct */ export interface PrefabWasmModule extends Struct { + /** Compact */ readonly scheduleVersion: Compact; + /** Compact */ readonly initial: Compact; + /** Compact */ readonly maximum: Compact; + /** PrefabWasmModuleReserved */ readonly _reserved: PrefabWasmModuleReserved; + /** Bytes */ readonly code: Bytes; } -export interface PrefabWasmModuleReserved extends Option {} +/** Option */ +export type PrefabWasmModuleReserved = Option; +/** Struct */ export interface Schedule extends Struct { + /** u32 */ readonly version: u32; + /** Gas */ readonly putCodePerByteCost: Gas; + /** Gas */ readonly growMemCost: Gas; + /** Gas */ readonly regularOpCost: Gas; + /** Gas */ readonly returnDataPerByteCost: Gas; + /** Gas */ readonly eventDataPerByteCost: Gas; + /** Gas */ readonly eventPerTopicCost: Gas; + /** Gas */ readonly eventBaseCost: Gas; + /** Gas */ readonly sandboxDataReadCost: Gas; + /** Gas */ readonly sandboxDataWriteCost: Gas; + /** u32 */ readonly maxEventTopics: u32; + /** u32 */ readonly maxStackHeight: u32; + /** u32 */ readonly maxMemoryPages: u32; + /** Bool */ readonly enablePrintln: Bool; + /** u32 */ readonly maxSubjectLen: u32; } -export interface SeedOf extends Hash {} +/** Hash */ +export type SeedOf = Hash; -export interface TombstoneContractInfo extends Hash {} +/** Hash */ +export type TombstoneContractInfo = Hash; -export interface TrieId extends Bytes {} +/** Bytes */ +export type TrieId = Bytes; declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { CodeHash: CodeHash; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; TrieId: TrieId; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; AliveContractInfo: AliveContractInfo; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; TombstoneContractInfo: TombstoneContractInfo; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ContractInfo: ContractInfo; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ContractStorageKey: ContractStorageKey; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Gas: Gas; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; PrefabWasmModuleReserved: PrefabWasmModuleReserved; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; PrefabWasmModule: PrefabWasmModule; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Schedule: Schedule; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; SeedOf: SeedOf; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/definitions.ts b/packages/types/src/srml/definitions.ts index aa4b74fcda..a531e724f0 100644 --- a/packages/types/src/srml/definitions.ts +++ b/packages/types/src/srml/definitions.ts @@ -34,3 +34,6 @@ export { default as parachains } from './parachains/definitions'; export { default as staking } from './staking/definitions'; export { default as system } from './system/definitions'; export { default as treasury } from './treasury/definitions'; + +// pull in rpc last, assuming that is uses info from above +export { default as rpc } from './rpc/definitions'; diff --git a/packages/types/src/srml/democracy/types.ts b/packages/types/src/srml/democracy/types.ts index 1ddb3a615f..221b93d59a 100644 --- a/packages/types/src/srml/democracy/types.ts +++ b/packages/types/src/srml/democracy/types.ts @@ -1,48 +1,44 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Enum, Option, Struct, Vector } from '../../codec'; +import { Compact, Enum, Option, Struct, Vec } from '../../codec'; import { Method, u32 } from '../../primitive'; import { BlockNumber } from '../runtime/types'; import { VoteThreshold } from '../elections/types'; +/** Enum */ export interface Conviction extends Enum { - /** - * @description 0:: None - */ + /** 0:: None */ readonly isNone: boolean; - /** - * @description 1:: Locked1x - */ + /** 1:: Locked1x */ readonly isLocked1X: boolean; - /** - * @description 2:: Locked2x - */ + /** 2:: Locked2x */ readonly isLocked2X: boolean; - /** - * @description 3:: Locked3x - */ + /** 3:: Locked3x */ readonly isLocked3X: boolean; - /** - * @description 4:: Locked4x - */ + /** 4:: Locked4x */ readonly isLocked4X: boolean; - /** - * @description 5:: Locked5x - */ + /** 5:: Locked5x */ readonly isLocked5X: boolean; } -export interface PropIndex extends u32 {} +/** u32 */ +export type PropIndex = u32; -export interface Proposal extends Method {} +/** Method */ +export type Proposal = Method; -export interface ReferendumIndex extends u32 {} +/** u32 */ +export type ReferendumIndex = u32; +/** Struct */ export interface ReferendumInfo extends Struct { + /** BlockNumber */ readonly end: BlockNumber; + /** Proposal */ readonly proposal: Proposal; + /** VoteThreshold */ readonly threshold: VoteThreshold; + /** BlockNumber */ readonly delay: BlockNumber; } @@ -50,20 +46,20 @@ declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { Conviction: Conviction; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; PropIndex: PropIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Proposal: Proposal; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ReferendumIndex: ReferendumIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ReferendumInfo: ReferendumInfo; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/deprecated/types.ts b/packages/types/src/srml/deprecated/types.ts index 720d130759..c7ab80f160 100644 --- a/packages/types/src/srml/deprecated/types.ts +++ b/packages/types/src/srml/deprecated/types.ts @@ -1,69 +1,71 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Enum, Option, Struct, Vector } from '../../codec'; +import { Compact, Enum, Option, Struct, Vec } from '../../codec'; import { AccountId, Bytes, Null, i8, u32, u64 } from '../../primitive'; import { Balance } from '../runtime/types'; +/** Struct */ export interface AccountInfo extends Struct { + /** Bytes */ readonly trieId: Bytes; + /** u64 */ readonly currentMemStored: u64; } -export interface Amount extends Balance {} +/** Balance */ +export type Amount = Balance; -export interface AssetOf extends u32 {} +/** u32 */ +export type AssetOf = u32; -export interface InherentOfflineReport extends Null {} +/** Null */ +export type InherentOfflineReport = Null; -export interface LockPeriods extends i8 {} +/** i8 */ +export type LockPeriods = i8; +/** Enum */ export interface NewAccountOutcome extends Enum { - /** - * @description 0:: NoHint - */ + /** 0:: NoHint */ readonly isNoHint: boolean; - /** - * @description 1:: GoodHint - */ + /** 1:: GoodHint */ readonly isGoodHint: boolean; - /** - * @description 2:: BadHint - */ + /** 2:: BadHint */ readonly isBadHint: boolean; } -export interface OpaqueKey extends Bytes {} +/** Bytes */ +export type OpaqueKey = Bytes; -export interface SessionKey extends AccountId {} +/** AccountId */ +export type SessionKey = AccountId; declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { NewAccountOutcome: NewAccountOutcome; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Amount: Amount; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; AssetOf: AssetOf; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; AccountInfo: AccountInfo; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; LockPeriods: LockPeriods; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; InherentOfflineReport: InherentOfflineReport; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; SessionKey: SessionKey; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; OpaqueKey: OpaqueKey; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/elections/types.ts b/packages/types/src/srml/elections/types.ts index 4ef1a380a3..be09161536 100644 --- a/packages/types/src/srml/elections/types.ts +++ b/packages/types/src/srml/elections/types.ts @@ -1,35 +1,37 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Enum, Option, Struct, Vector } from '../../codec'; +import { Compact, Enum, Option, Struct, Vec } from '../../codec'; import { u32 } from '../../primitive'; import { Balance } from '../runtime/types'; -export interface ApprovalFlag extends u32 {} +/** u32 */ +export type ApprovalFlag = u32; -export interface SetIndex extends u32 {} +/** u32 */ +export type SetIndex = u32; -export interface VoteIndex extends u32 {} +/** u32 */ +export type VoteIndex = u32; +/** Struct */ export interface VoterInfo extends Struct { + /** VoteIndex */ readonly lastActive: VoteIndex; + /** VoteIndex */ readonly lastWin: VoteIndex; + /** Balance */ readonly pot: Balance; + /** Balance */ readonly stake: Balance; } +/** Enum */ export interface VoteThreshold extends Enum { - /** - * @description 0:: Super majority approval - */ + /** 0:: Super majority approval */ readonly isSuperMajorityApproval: boolean; - /** - * @description 1:: Super majority rejection - */ + /** 1:: Super majority rejection */ readonly isSuperMajorityRejection: boolean; - /** - * @description 2:: Simple majority - */ + /** 2:: Simple majority */ readonly isSimpleMajority: boolean; } @@ -38,20 +40,20 @@ declare module '@polkadot/types/interfaceRegistry' { ApprovalFlag: ApprovalFlag; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; SetIndex: SetIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; VoteIndex: VoteIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; VoterInfo: VoterInfo; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; VoteThreshold: VoteThreshold; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/grandpa/types.ts b/packages/types/src/srml/grandpa/types.ts index 3f067847aa..746fea8d0e 100644 --- a/packages/types/src/srml/grandpa/types.ts +++ b/packages/types/src/srml/grandpa/types.ts @@ -1,51 +1,56 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit import { Codec } from '../../types'; -import { Compact, Enum, Option, Struct, Vector } from '../../codec'; +import { Compact, Enum, Option, Struct, Vec } from '../../codec'; import { u64 } from '../../primitive'; import { BlockNumber } from '../runtime/types'; import { AuthorityId } from '../consensus/types'; -export interface AuthorityWeight extends u64 {} +/** u64 */ +export type AuthorityWeight = u64; -type _NextAuthority = [AuthorityId, u64]; -export interface NextAuthority extends Codec, _NextAuthority {} +/** [AuthorityId, u64] & Codec */ +export type NextAuthority = [AuthorityId, u64] & Codec; +/** Struct */ export interface PendingPause extends Struct { + /** BlockNumber */ readonly scheduledAt: BlockNumber; + /** BlockNumber */ readonly delay: BlockNumber; } +/** Struct */ export interface PendingResume extends Struct { + /** BlockNumber */ readonly scheduledAt: BlockNumber; + /** BlockNumber */ readonly delay: BlockNumber; } +/** Struct */ export interface StoredPendingChange extends Struct { + /** BlockNumber */ readonly scheduledAt: BlockNumber; + /** BlockNumber */ readonly delay: BlockNumber; - readonly nextAuthorities: Vector; + /** Vec */ + readonly nextAuthorities: Vec; } +/** Enum */ export interface StoredState extends Enum { - /** - * @description 0:: Live - */ + /** 0:: Live */ readonly isLive: boolean; - /** - * @description 1:: PendingPause(PendingPause) - */ + /** 1:: PendingPause(PendingPause) */ readonly isPendingPause: boolean; + /** PendingPause */ readonly asPendingPause: PendingPause; - /** - * @description 2:: Paused - */ + /** 2:: Paused */ readonly isPaused: boolean; - /** - * @description 3:: PendingResume(PendingResume) - */ + /** 3:: PendingResume(PendingResume) */ readonly isPendingResume: boolean; + /** PendingResume */ readonly asPendingResume: PendingResume; } @@ -54,21 +59,21 @@ declare module '@polkadot/types/interfaceRegistry' { AuthorityWeight: AuthorityWeight; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; NextAuthority: NextAuthority; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; PendingPause: PendingPause; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; PendingResume: PendingResume; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; StoredPendingChange: StoredPendingChange; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; StoredState: StoredState; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/imOnline/types.ts b/packages/types/src/srml/imOnline/types.ts index 2454391905..54388c7174 100644 --- a/packages/types/src/srml/imOnline/types.ts +++ b/packages/types/src/srml/imOnline/types.ts @@ -1,41 +1,50 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Option, Struct, Vector } from '../../codec'; +import { Option, Struct, Vec } from '../../codec'; import { Bytes } from '../../primitive'; import { BlockNumber } from '../runtime/types'; import { AuthorityId } from '../consensus/types'; import { SessionIndex } from '../session/types'; +/** Struct */ export interface Heartbeat extends Struct { + /** BlockNumber */ readonly blockNumber: BlockNumber; + /** OpaqueNetworkState */ readonly networkState: OpaqueNetworkState; + /** SessionIndex */ readonly sessionIndex: SessionIndex; + /** AuthorityId */ readonly authorityId: AuthorityId; } -export interface OpaqueMultiaddr extends Bytes {} +/** Bytes */ +export type OpaqueMultiaddr = Bytes; +/** Struct */ export interface OpaqueNetworkState extends Struct { + /** OpaquePeerId */ readonly peerId: OpaquePeerId; - readonly externalAddresses: Vector; + /** Vec */ + readonly externalAddresses: Vec; } -export interface OpaquePeerId extends Bytes {} +/** Bytes */ +export type OpaquePeerId = Bytes; declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { OpaqueMultiaddr: OpaqueMultiaddr; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; OpaquePeerId: OpaquePeerId; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; OpaqueNetworkState: OpaqueNetworkState; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Heartbeat: Heartbeat; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/index.ts b/packages/types/src/srml/index.ts index 9e73fbd25e..6662ac5e12 100644 --- a/packages/types/src/srml/index.ts +++ b/packages/types/src/srml/index.ts @@ -2,6 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { ClassOf } from '../codec/createType'; import getTypeRegistry from '../codec/typeRegistry'; import * as srmlTypes from './definitions'; @@ -14,4 +15,7 @@ export function injectDefinitions (): void { Object.values(srmlTypes).forEach(({ types }): void => registry.register(types) ); + + // Here we setup the fallbacks + ClassOf('EventRecord').Fallback = ClassOf('EventRecord0to76'); } diff --git a/packages/types/src/srml/parachains/types.ts b/packages/types/src/srml/parachains/types.ts index d5076f4a30..77d6746a5e 100644 --- a/packages/types/src/srml/parachains/types.ts +++ b/packages/types/src/srml/parachains/types.ts @@ -1,261 +1,266 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit import { Codec } from '../../types'; -import { Compact, Enum, Option, Struct, Vector } from '../../codec'; +import { Compact, Enum, Option, Struct, Vec } from '../../codec'; import { AccountId, Bytes, u32, u64 } from '../../primitive'; import { BalanceOf, BlockNumber, Hash, Signature } from '../runtime/types'; +/** Struct */ export interface AttestedCandidate extends Struct { + /** CandidateReceipt */ readonly candidate: CandidateReceipt; - readonly validityVotes: Vector; + /** Vec */ + readonly validityVotes: Vec; } -export interface AuctionIndex extends u32 {} +/** u32 */ +export type AuctionIndex = u32; -type _BalanceUpload = [AccountId, u64]; -export interface BalanceUpload extends Codec, _BalanceUpload {} +/** [AccountId, u64] & Codec */ +export type BalanceUpload = [AccountId, u64] & Codec; +/** Enum */ export interface Bidder extends Enum { - /** - * @description 0:: New(NewBidder) - */ + /** 0:: New(NewBidder) */ readonly isNew: boolean; + /** NewBidder */ readonly asNew: NewBidder; - /** - * @description 1:: Existing(ParaId) - */ + /** 1:: Existing(ParaId) */ readonly isExisting: boolean; + /** ParaId */ readonly asExisting: ParaId; } +/** Struct */ export interface CandidateReceipt extends Struct { + /** ParaId */ readonly parachainIndex: ParaId; + /** AccountId */ readonly collator: AccountId; + /** CollatorSignature */ readonly signature: CollatorSignature; + /** HeadData */ readonly headData: HeadData; - readonly balanceUploads: Vector; - readonly egressQueueRoots: Vector; + /** Vec */ + readonly balanceUploads: Vec; + /** Vec */ + readonly egressQueueRoots: Vec; + /** u64 */ readonly fees: u64; + /** Hash */ readonly blockDataHash: Hash; } -export interface CollatorSignature extends Signature {} +/** Signature */ +export type CollatorSignature = Signature; -type _EgressQueueRoot = [ParaId, Hash]; -export interface EgressQueueRoot extends Codec, _EgressQueueRoot {} +/** [ParaId, Hash] & Codec */ +export type EgressQueueRoot = [ParaId, Hash] & Codec; -export interface HeadData extends Bytes {} +/** Bytes */ +export type HeadData = Bytes; +/** Enum */ export interface IncomingParachain extends Enum { - /** - * @description 0:: Unset(NewBidder) - */ + /** 0:: Unset(NewBidder) */ readonly isUnset: boolean; + /** NewBidder */ readonly asUnset: NewBidder; - /** - * @description 1:: Fixed(IncomingParachainFixed) - */ + /** 1:: Fixed(IncomingParachainFixed) */ readonly isFixed: boolean; + /** IncomingParachainFixed */ readonly asFixed: IncomingParachainFixed; - /** - * @description 2:: Deploy(IncomingParachainDeploy) - */ + /** 2:: Deploy(IncomingParachainDeploy) */ readonly isDeploy: boolean; + /** IncomingParachainDeploy */ readonly asDeploy: IncomingParachainDeploy; } +/** Struct */ export interface IncomingParachainDeploy extends Struct { + /** Bytes */ readonly code: Bytes; + /** Bytes */ readonly initialHeadData: Bytes; } +/** Struct */ export interface IncomingParachainFixed extends Struct { + /** Hash */ readonly codeHash: Hash; + /** Bytes */ readonly initialHeadData: Bytes; } -export interface LeasePeriod extends BlockNumber {} +/** BlockNumber */ +export type LeasePeriod = BlockNumber; -export interface LeasePeriodOf extends LeasePeriod {} +/** LeasePeriod */ +export type LeasePeriodOf = LeasePeriod; +/** Struct */ export interface NewBidder extends Struct { + /** AccountId */ readonly who: AccountId; + /** SubId */ readonly sub: SubId; } +/** Enum */ export interface ParachainDispatchOrigin extends Enum { - /** - * @description 0:: Signed - */ + /** 0:: Signed */ readonly isSigned: boolean; - /** - * @description 1:: Parachain - */ + /** 1:: Parachain */ readonly isParachain: boolean; } -export interface ParaId extends u32 {} +/** u32 */ +export type ParaId = u32; -export interface ParaIdOf extends ParaId {} +/** ParaId */ +export type ParaIdOf = ParaId; +/** Enum */ export interface SlotRange extends Enum { - /** - * @description 0:: ZeroZero - */ + /** 0:: ZeroZero */ readonly isZeroZero: boolean; - /** - * @description 1:: ZeroOne - */ + /** 1:: ZeroOne */ readonly isZeroOne: boolean; - /** - * @description 2:: ZeroTwo - */ + /** 2:: ZeroTwo */ readonly isZeroTwo: boolean; - /** - * @description 3:: ZeroThree - */ + /** 3:: ZeroThree */ readonly isZeroThree: boolean; - /** - * @description 4:: OneOne - */ + /** 4:: OneOne */ readonly isOneOne: boolean; - /** - * @description 5:: OneTwo - */ + /** 5:: OneTwo */ readonly isOneTwo: boolean; - /** - * @description 6:: OneThree - */ + /** 6:: OneThree */ readonly isOneThree: boolean; - /** - * @description 7:: TwoTwo - */ + /** 7:: TwoTwo */ readonly isTwoTwo: boolean; - /** - * @description 8:: TwoThree - */ + /** 8:: TwoThree */ readonly isTwoThree: boolean; - /** - * @description 9:: ThreeThree - */ + /** 9:: ThreeThree */ readonly isThreeThree: boolean; } -export interface SubId extends u32 {} +/** u32 */ +export type SubId = u32; +/** Struct */ export interface UpwardMessage extends Struct { + /** ParachainDispatchOrigin */ readonly origin: ParachainDispatchOrigin; + /** Bytes */ readonly data: Bytes; } -export interface ValidatorIndex extends u32 {} +/** u32 */ +export type ValidatorIndex = u32; +/** Enum */ export interface ValidityAttestation extends Enum { - /** - * @description 0:: None - */ + /** 0:: None */ readonly isNone: boolean; - /** - * @description 1:: Implicit(CollatorSignature) - */ + /** 1:: Implicit(CollatorSignature) */ readonly isImplicit: boolean; + /** CollatorSignature */ readonly asImplicit: CollatorSignature; - /** - * @description 2:: Explicit(CollatorSignature) - */ + /** 2:: Explicit(CollatorSignature) */ readonly isExplicit: boolean; + /** CollatorSignature */ readonly asExplicit: CollatorSignature; } -type _ValidityVote = [ValidatorIndex, ValidityAttestation]; -export interface ValidityVote extends Codec, _ValidityVote {} +/** [ValidatorIndex, ValidityAttestation] & Codec */ +export type ValidityVote = [ValidatorIndex, ValidityAttestation] & Codec; -export interface WinningData extends Vector {} +/** Vec */ +export type WinningData = Vec; -type _WinningDataEntry = [AccountId, ParaIdOf, BalanceOf]; -export interface WinningDataEntry extends Codec, _WinningDataEntry {} +/** [AccountId, ParaIdOf, BalanceOf] & Codec */ +export type WinningDataEntry = [AccountId, ParaIdOf, BalanceOf] & Codec; declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { AuctionIndex: AuctionIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; CollatorSignature: CollatorSignature; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ValidityAttestation: ValidityAttestation; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ParaId: ParaId; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ParaIdOf: ParaIdOf; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ValidatorIndex: ValidatorIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ValidityVote: ValidityVote; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; BalanceUpload: BalanceUpload; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; EgressQueueRoot: EgressQueueRoot; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; HeadData: HeadData; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; CandidateReceipt: CandidateReceipt; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; AttestedCandidate: AttestedCandidate; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; SubId: SubId; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; NewBidder: NewBidder; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Bidder: Bidder; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; IncomingParachainDeploy: IncomingParachainDeploy; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; IncomingParachainFixed: IncomingParachainFixed; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; IncomingParachain: IncomingParachain; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; LeasePeriod: LeasePeriod; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; LeasePeriodOf: LeasePeriodOf; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ParachainDispatchOrigin: ParachainDispatchOrigin; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; SlotRange: SlotRange; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; UpwardMessage: UpwardMessage; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; WinningDataEntry: WinningDataEntry; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; WinningData: WinningData; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/rpc/ChainProperties.spec.ts b/packages/types/src/srml/rpc/ChainProperties.spec.ts new file mode 100644 index 0000000000..3e9de60f02 --- /dev/null +++ b/packages/types/src/srml/rpc/ChainProperties.spec.ts @@ -0,0 +1,28 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import createType from '../../codec/createType'; +import { injectDefinitions } from '..'; + +describe('ChainProperties', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + + it('decodes from a null value', (): void => { + expect( + [...createType('ChainProperties', null).entries()] + ).toEqual([]); + }); + + it('decodes from an actual object', (): void => { + const { tokenDecimals, tokenSymbol } = createType('ChainProperties', { + tokenDecimals: 15, + tokenSymbol: 'BBQ' + }); + + expect(tokenDecimals.eq(15)).toBe(true); + expect(tokenSymbol.eq('BBQ')).toBe(true); + }); +}); diff --git a/packages/types/src/rpc/ExtrinsicStatus.spec.ts b/packages/types/src/srml/rpc/ExtrinsicStatus.spec.ts similarity index 71% rename from packages/types/src/rpc/ExtrinsicStatus.spec.ts rename to packages/types/src/srml/rpc/ExtrinsicStatus.spec.ts index 88812a0af4..3095d7ef8f 100644 --- a/packages/types/src/rpc/ExtrinsicStatus.spec.ts +++ b/packages/types/src/srml/rpc/ExtrinsicStatus.spec.ts @@ -2,9 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { injectDefinitions } from '../srml'; -import rpc from '../json/ExtrinsicStatus.001.json'; -import ExtrinsicStatus from './ExtrinsicStatus'; +import { ExtrinsicStatus } from './types'; + +import createType from '../../codec/createType'; +import rpc from '../../json/ExtrinsicStatus.001.json'; +import { injectDefinitions } from '..'; describe('ExtrinsicStatus', (): void => { let status: ExtrinsicStatus; @@ -12,7 +14,7 @@ describe('ExtrinsicStatus', (): void => { beforeEach((): void => { injectDefinitions(); - status = new ExtrinsicStatus(rpc.params.result); + status = createType('ExtrinsicStatus', rpc.params.result); }); it('has the correct type', (): void => { diff --git a/packages/types/src/srml/rpc/KeyValueOption.spec.ts b/packages/types/src/srml/rpc/KeyValueOption.spec.ts new file mode 100644 index 0000000000..18eff201aa --- /dev/null +++ b/packages/types/src/srml/rpc/KeyValueOption.spec.ts @@ -0,0 +1,21 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import createType from '../../codec/createType'; +import { injectDefinitions } from '..'; + +describe('KeyValueOption', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + + it('exposes the properties for key/value', (): void => { + const [key, value] = createType('KeyValueOption', [ + '0x11223344' + ]); + + expect(key.toHex()).toEqual('0x11223344'); + expect(value.isNone).toEqual(true); + }); +}); diff --git a/packages/types/src/rpc/RuntimeVersion.spec.ts b/packages/types/src/srml/rpc/RuntimeVersion.spec.ts similarity index 60% rename from packages/types/src/rpc/RuntimeVersion.spec.ts rename to packages/types/src/srml/rpc/RuntimeVersion.spec.ts index 0065f33063..7dffe20aa4 100644 --- a/packages/types/src/rpc/RuntimeVersion.spec.ts +++ b/packages/types/src/srml/rpc/RuntimeVersion.spec.ts @@ -2,21 +2,29 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import rpc from '../json/RuntimeVersion.002.json'; -import RuntimeVersion from './RuntimeVersion'; +import { RuntimeVersion } from './types'; + +import createType from '../../codec/createType'; +import rpc from '../../json/RuntimeVersion.002.json'; +import { injectDefinitions } from '..'; describe('RuntimeVersion', (): void => { - const version = new RuntimeVersion(rpc.result); + let version: RuntimeVersion; + + beforeEach((): void => { + injectDefinitions(); + version = createType('RuntimeVersion', rpc.result); + }); it('has the correct authoring', (): void => { expect(version.authoringVersion.toNumber()).toEqual(10); }); it('has the apis', (): void => { - const api = version.apis[0]; + const [apiId, apiVersion] = version.apis[0]; - expect(api.id.toHex()).toEqual('0xdf6acb689907609b'); - expect(api.version.toNumber()).toEqual(2); + expect(apiId.toHex()).toEqual('0xdf6acb689907609b'); + expect(apiVersion.toNumber()).toEqual(2); }); it('has the correct implementation', (): void => { diff --git a/packages/types/src/rpc/SignedBlock.spec.ts b/packages/types/src/srml/rpc/SignedBlock.spec.ts similarity index 77% rename from packages/types/src/rpc/SignedBlock.spec.ts rename to packages/types/src/srml/rpc/SignedBlock.spec.ts index 29e299b354..daffc45195 100644 --- a/packages/types/src/rpc/SignedBlock.spec.ts +++ b/packages/types/src/srml/rpc/SignedBlock.spec.ts @@ -4,12 +4,12 @@ import extrinsics from '@polkadot/api-metadata/extrinsics/static'; -import Method from '../primitive/Method'; -import events from '../json/SignedBlock.002.json'; -import immortalTxs from '../json/SignedBlock.004.immortal.json'; -import mortalTxs from '../json/SignedBlock.004.mortal.json'; -import { injectDefinitions } from '../srml'; -import SignedBlock from './SignedBlock'; +import createType from '../../codec/createType'; +import Method from '../../primitive/Method'; +import events from '../../json/SignedBlock.002.json'; +import immortalTxs from '../../json/SignedBlock.004.immortal.json'; +import mortalTxs from '../../json/SignedBlock.004.mortal.json'; +import { injectDefinitions } from '..'; describe('SignedBlock', (): void => { beforeEach((): void => { @@ -18,7 +18,7 @@ describe('SignedBlock', (): void => { }); it('decodes a full block', (): void => { - const s = new SignedBlock(events.result); + const s = createType('SignedBlock', events.result); expect( s.block.header.stateRoot.toString() @@ -38,7 +38,7 @@ describe('SignedBlock', (): void => { describe('extrinsics', (): void => { it('can decode immortals', (): void => { - const s = new SignedBlock(immortalTxs.result); + const s = createType('SignedBlock', immortalTxs.result); const immortalTx = s.block.extrinsics[2]; expect(immortalTx.method.methodName).toEqual('transfer'); @@ -46,7 +46,7 @@ describe('SignedBlock', (): void => { }); it('can decode mortals', (): void => { - const s = new SignedBlock(mortalTxs.result); + const s = createType('SignedBlock', mortalTxs.result); const mortalTx = s.block.extrinsics[2]; expect(mortalTx.method.methodName).toEqual('transfer'); diff --git a/packages/types/src/rpc/StorageChangeSet.spec.ts b/packages/types/src/srml/rpc/StorageChangeSet.spec.ts similarity index 70% rename from packages/types/src/rpc/StorageChangeSet.spec.ts rename to packages/types/src/srml/rpc/StorageChangeSet.spec.ts index d9e54bfebe..758494be70 100644 --- a/packages/types/src/rpc/StorageChangeSet.spec.ts +++ b/packages/types/src/srml/rpc/StorageChangeSet.spec.ts @@ -3,12 +3,17 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { createType } from '@polkadot/types'; -import json from '../json/StorageChangeSet.001.json'; -import StorageChangeSet from './StorageChangeSet'; + +import json from '../../json/StorageChangeSet.001.json'; +import { injectDefinitions } from '../'; describe('StorageChangeSet', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + describe('construction', (): void => { - const set = new StorageChangeSet({ + const set = createType('StorageChangeSet', { block: '0x1234', changes: [ ['0xab', '0xcd'] @@ -23,13 +28,13 @@ describe('StorageChangeSet', (): void => { it('wraps key/value', (): void => { expect( - set.changes[0].value.toString() + set.changes[0][1].toString() ).toEqual('0xcd'); }); }); describe('json', (): void => { - const set = new StorageChangeSet(json.params.result); + const set = createType('StorageChangeSet', json.params.result); it('has the correct hash', (): void => { expect( @@ -39,11 +44,11 @@ describe('StorageChangeSet', (): void => { it('has the changes', (): void => { expect(set.changes).toHaveLength(1); - expect(set.changes[0].key.toHex()).toEqual('0x54bdbdb5e438d574dd4da05ee6131cee'); + expect(set.changes[0][0].toHex()).toEqual('0x54bdbdb5e438d574dd4da05ee6131cee'); }); it('converts result data to Bytes', (): void => { - const bytes = createType('Bytes', set.changes[0].value.unwrap()); + const bytes = createType('Bytes', set.changes[0][1].unwrap()); expect(bytes).toHaveLength(4452); }); diff --git a/packages/types/src/srml/rpc/definitions.ts b/packages/types/src/srml/rpc/definitions.ts new file mode 100644 index 0000000000..64ccec93f2 --- /dev/null +++ b/packages/types/src/srml/rpc/definitions.ts @@ -0,0 +1,61 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +export default { + types: { + ApiId: '[u8; 8]', + ChainProperties: { + tokenDecimals: 'u32', + tokenSymbol: 'Text' + }, + Consensus: '(ConsensusEngineId, Bytes)', + ExtrinsicStatus: { + _enum: { + Future: 'Null', + Ready: 'Null', + Finalized: 'Hash', + Usurped: 'Hash', + Broadcast: 'Vec', + Dropped: 'Null', + Invalid: 'Null' + } + }, + Health: { + peers: 'u64', + isSyncing: 'bool', + shouldHavePeers: 'bool' + }, + KeyValueOption: '(StorageKey, Option)', + NetworkState: { + peerId: 'Text' + }, + PeerInfo: { + peerId: 'Text', + roles: 'Text', + protocolVersion: 'u32', + bestHash: 'Hash', + bestNumber: 'BlockNumber' + }, + PreRuntime: '(ConsensusEngineId, Bytes)', + RuntimeVersionApi: '(ApiId, u32)', + RuntimeVersion: { + specName: 'Text', + implName: 'Text', + authoringVersion: 'u32', + specVersion: 'u32', + implVersion: 'u32', + apis: 'Vec' + }, + SealV0: '(u64, Signature)', + Seal: '(ConsensusEngineId, Bytes)', + SignedBlock: { + block: 'Block', + justification: 'Justification' + }, + StorageChangeSet: { + block: 'Hash', + changes: 'Vec' + } + } +}; diff --git a/packages/types/src/srml/rpc/types.ts b/packages/types/src/srml/rpc/types.ts new file mode 100644 index 0000000000..4be6a8bdf1 --- /dev/null +++ b/packages/types/src/srml/rpc/types.ts @@ -0,0 +1,171 @@ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Codec } from '../../types'; +import { Enum, Option, Struct, Vec } from '../../codec'; +import { Block, Bytes, ConsensusEngineId, StorageKey, Text, bool, u32, u64, u8 } from '../../primitive'; +import { BlockNumber, Hash, Justification, Signature, StorageData } from '../runtime/types'; + +/** Vec */ +export type ApiId = Vec; + +/** Struct */ +export interface ChainProperties extends Struct { + /** u32 */ + readonly tokenDecimals: u32; + /** Text */ + readonly tokenSymbol: Text; +} + +/** [ConsensusEngineId, Bytes] & Codec */ +export type Consensus = [ConsensusEngineId, Bytes] & Codec; + +/** Enum */ +export interface ExtrinsicStatus extends Enum { + /** 0:: Future */ + readonly isFuture: boolean; + /** 1:: Ready */ + readonly isReady: boolean; + /** 2:: Finalized(Hash) */ + readonly isFinalized: boolean; + /** Hash */ + readonly asFinalized: Hash; + /** 3:: Usurped(Hash) */ + readonly isUsurped: boolean; + /** Hash */ + readonly asUsurped: Hash; + /** 4:: Broadcast(Vec) */ + readonly isBroadcast: boolean; + /** Vec */ + readonly asBroadcast: Vec; + /** 5:: Dropped */ + readonly isDropped: boolean; + /** 6:: Invalid */ + readonly isInvalid: boolean; +} + +/** Struct */ +export interface Health extends Struct { + /** u64 */ + readonly peers: u64; + /** bool */ + readonly isSyncing: bool; + /** bool */ + readonly shouldHavePeers: bool; +} + +/** [StorageKey, Option] & Codec */ +export type KeyValueOption = [StorageKey, Option] & Codec; + +/** Struct */ +export interface NetworkState extends Struct { + /** Text */ + readonly peerId: Text; +} + +/** Struct */ +export interface PeerInfo extends Struct { + /** Text */ + readonly peerId: Text; + /** Text */ + readonly roles: Text; + /** u32 */ + readonly protocolVersion: u32; + /** Hash */ + readonly bestHash: Hash; + /** BlockNumber */ + readonly bestNumber: BlockNumber; +} + +/** [ConsensusEngineId, Bytes] & Codec */ +export type PreRuntime = [ConsensusEngineId, Bytes] & Codec; + +/** Struct */ +export interface RuntimeVersion extends Struct { + /** Text */ + readonly specName: Text; + /** Text */ + readonly implName: Text; + /** u32 */ + readonly authoringVersion: u32; + /** u32 */ + readonly specVersion: u32; + /** u32 */ + readonly implVersion: u32; + /** Vec */ + readonly apis: Vec; +} + +/** [ApiId, u32] & Codec */ +export type RuntimeVersionApi = [ApiId, u32] & Codec; + +/** [ConsensusEngineId, Bytes] & Codec */ +export type Seal = [ConsensusEngineId, Bytes] & Codec; + +/** [u64, Signature] & Codec */ +export type SealV0 = [u64, Signature] & Codec; + +/** Struct */ +export interface SignedBlock extends Struct { + /** Block */ + readonly block: Block; + /** Justification */ + readonly justification: Justification; +} + +/** Struct */ +export interface StorageChangeSet extends Struct { + /** Hash */ + readonly block: Hash; + /** Vec */ + readonly changes: Vec; +} + +declare module '@polkadot/types/interfaceRegistry' { + export interface InterfaceRegistry { + ApiId: ApiId; + 'Option': Option; + 'Vec': Vec; + ChainProperties: ChainProperties; + 'Option': Option; + 'Vec': Vec; + Consensus: Consensus; + 'Option': Option; + 'Vec': Vec; + ExtrinsicStatus: ExtrinsicStatus; + 'Option': Option; + 'Vec': Vec; + Health: Health; + 'Option': Option; + 'Vec': Vec; + KeyValueOption: KeyValueOption; + 'Option': Option; + 'Vec': Vec; + NetworkState: NetworkState; + 'Option': Option; + 'Vec': Vec; + PeerInfo: PeerInfo; + 'Option': Option; + 'Vec': Vec; + PreRuntime: PreRuntime; + 'Option': Option; + 'Vec': Vec; + RuntimeVersionApi: RuntimeVersionApi; + 'Option': Option; + 'Vec': Vec; + RuntimeVersion: RuntimeVersion; + 'Option': Option; + 'Vec': Vec; + SealV0: SealV0; + 'Option': Option; + 'Vec': Vec; + Seal: Seal; + 'Option': Option; + 'Vec': Vec; + SignedBlock: SignedBlock; + 'Option': Option; + 'Vec': Vec; + StorageChangeSet: StorageChangeSet; + 'Option': Option; + 'Vec': Vec; + } +} diff --git a/packages/types/src/srml/runtime/KeyValue.spec.ts b/packages/types/src/srml/runtime/KeyValue.spec.ts new file mode 100644 index 0000000000..2b924ae2ce --- /dev/null +++ b/packages/types/src/srml/runtime/KeyValue.spec.ts @@ -0,0 +1,45 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { KeyValue } from './types'; + +import createType from '../../codec/createType'; +import { injectDefinitions } from '..'; + +describe('KeyValue', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + + it('decodes KeyValue from u8a', (): void => { + expect( + createType('KeyValue', Uint8Array.from([ + 4 << 2, + 0x11, 0x22, 0x33, 0x44, + 9 << 2, + 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 + ])).toJSON() + ).toEqual(['0x11223344', '0x998877665544332211']); + }); + + it('encodes KeyValue from JSON', (): void => { + expect( + createType('KeyValue', ['0x11223344', '0x998877665544332211']).toU8a() + ).toEqual( + new Uint8Array([ + 4 << 2, + 0x11, 0x22, 0x33, 0x44, + 9 << 2, + 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 + ]) + ); + }); + + it('exposes the properties for key/value', (): void => { + const [key, value] = createType('KeyValue', ['0x11223344', '0x998877665544332211']); + + expect(key.toHex()).toEqual('0x11223344'); + expect(value.toHex()).toEqual('0x998877665544332211'); + }); +}); diff --git a/packages/types/src/srml/runtime/definitions.ts b/packages/types/src/srml/runtime/definitions.ts index 8d32b56187..a7406d8eeb 100644 --- a/packages/types/src/srml/runtime/definitions.ts +++ b/packages/types/src/srml/runtime/definitions.ts @@ -15,12 +15,15 @@ export default { Index: 'u64', Perbill: 'u32', Permill: 'u32', + Phantom: 'Null', SessionKeys: { ed25519: 'AccountId' }, Signature: 'H512', Ed25519Signature: 'Signature', Sr25519Signature: 'Signature', + StorageData: 'Bytes', + KeyValue: '(StorageKey, StorageData)', ValidatorId: 'AccountId', Weight: 'u32', WeightMultiplier: 'Fixed64' diff --git a/packages/types/src/srml/runtime/types.ts b/packages/types/src/srml/runtime/types.ts index 80f561e783..40bbec0ace 100644 --- a/packages/types/src/srml/runtime/types.ts +++ b/packages/types/src/srml/runtime/types.ts @@ -1,110 +1,146 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Option, Struct, Vector } from '../../codec'; -import { AccountId, Bytes, Fixed64, H256, H512, u128, u32, u64, u8 } from '../../primitive'; +import { Codec } from '../../types'; +import { Compact, Option, Struct, Vec } from '../../codec'; +import { AccountId, Bytes, Fixed64, H256, H512, Null, StorageKey, u128, u32, u64, u8 } from '../../primitive'; -export interface AccountIdOf extends AccountId {} +/** AccountId */ +export type AccountIdOf = AccountId; -export interface Balance extends u128 {} +/** u128 */ +export type Balance = u128; -export interface BalanceOf extends Balance {} +/** Balance */ +export type BalanceOf = Balance; -export interface BlockNumber extends u64 {} +/** u64 */ +export type BlockNumber = u64; -export interface Ed25519Signature extends Signature {} +/** Signature */ +export type Ed25519Signature = Signature; -export interface Hash extends H256 {} +/** H256 */ +export type Hash = H256; -export interface Index extends u64 {} +/** u64 */ +export type Index = u64; -export interface Justification extends Bytes {} +/** Bytes */ +export type Justification = Bytes; -export interface KeyTypeId extends u32 {} +/** u32 */ +export type KeyTypeId = u32; -export interface LockIdentifier extends Vector {} +/** [StorageKey, StorageData] & Codec */ +export type KeyValue = [StorageKey, StorageData] & Codec; -export interface Perbill extends u32 {} +/** Vec */ +export type LockIdentifier = Vec; -export interface Permill extends u32 {} +/** u32 */ +export type Perbill = u32; +/** u32 */ +export type Permill = u32; + +/** Null */ +export type Phantom = Null; + +/** Struct */ export interface SessionKeys extends Struct { + /** AccountId */ readonly ed25519: AccountId; } -export interface Signature extends H512 {} +/** H512 */ +export type Signature = H512; -export interface Sr25519Signature extends Signature {} +/** Signature */ +export type Sr25519Signature = Signature; -export interface ValidatorId extends AccountId {} +/** Bytes */ +export type StorageData = Bytes; -export interface Weight extends u32 {} +/** AccountId */ +export type ValidatorId = AccountId; -export interface WeightMultiplier extends Fixed64 {} +/** u32 */ +export type Weight = u32; + +/** Fixed64 */ +export type WeightMultiplier = Fixed64; declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { AccountIdOf: AccountIdOf; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Balance: Balance; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; BalanceOf: BalanceOf; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; BlockNumber: BlockNumber; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Hash: Hash; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Justification: Justification; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; KeyTypeId: KeyTypeId; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; LockIdentifier: LockIdentifier; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Index: Index; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Perbill: Perbill; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Permill: Permill; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + Phantom: Phantom; + 'Option': Option; + 'Vec': Vec; SessionKeys: SessionKeys; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Signature: Signature; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Ed25519Signature: Ed25519Signature; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Sr25519Signature: Sr25519Signature; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + StorageData: StorageData; + 'Option': Option; + 'Vec': Vec; + KeyValue: KeyValue; + 'Option': Option; + 'Vec': Vec; ValidatorId: ValidatorId; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Weight: Weight; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; WeightMultiplier: WeightMultiplier; - 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/session/types.ts b/packages/types/src/srml/session/types.ts index 63d464894e..88e043b7a0 100644 --- a/packages/types/src/srml/session/types.ts +++ b/packages/types/src/srml/session/types.ts @@ -1,22 +1,23 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Option, Vector } from '../../codec'; +import { Compact, Option, Vec } from '../../codec'; import { u32 } from '../../primitive'; import { SessionKeys } from '../runtime/types'; -export interface Keys extends SessionKeys {} +/** SessionKeys */ +export type Keys = SessionKeys; -export interface SessionIndex extends u32 {} +/** u32 */ +export type SessionIndex = u32; declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { SessionIndex: SessionIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Keys: Keys; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/staking/definitions.ts b/packages/types/src/srml/staking/definitions.ts index ae87dc2d6a..bb5cd3dd77 100644 --- a/packages/types/src/srml/staking/definitions.ts +++ b/packages/types/src/srml/staking/definitions.ts @@ -18,6 +18,7 @@ export default { own: 'Compact', others: 'Vec' }, + MomentOf: 'Moment', RewardDestination: { _enum: [ 'Staked', diff --git a/packages/types/src/srml/staking/types.ts b/packages/types/src/srml/staking/types.ts index a3c3500fa9..3ea4986333 100644 --- a/packages/types/src/srml/staking/types.ts +++ b/packages/types/src/srml/staking/types.ts @@ -1,57 +1,76 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Compact, Enum, Option, Struct, Vector } from '../../codec'; -import { AccountId, u32 } from '../../primitive'; +import { Compact, Enum, Option, Struct, Vec } from '../../codec'; +import { AccountId, Moment, u32 } from '../../primitive'; import { Balance, BlockNumber } from '../runtime/types'; -export interface EraIndex extends u32 {} +/** u32 */ +export type EraIndex = u32; +/** Struct */ export interface EraRewards extends Struct { + /** u32 */ readonly total: u32; - readonly rewards: Vector; + /** Vec */ + readonly rewards: Vec; } +/** Struct */ export interface Exposure extends Struct { + /** Compact */ readonly total: Compact; + /** Compact */ readonly own: Compact; - readonly others: Vector; + /** Vec */ + readonly others: Vec; } +/** Struct */ export interface IndividualExposure extends Struct { + /** AccountId */ readonly who: AccountId; + /** Compact */ readonly value: Compact; } +/** Moment */ +export type MomentOf = Moment; + +/** Enum */ export interface RewardDestination extends Enum { - /** - * @description 0:: Staked - */ + /** 0:: Staked */ readonly isStaked: boolean; - /** - * @description 1:: Stash - */ + /** 1:: Stash */ readonly isStash: boolean; - /** - * @description 2:: Controller - */ + /** 2:: Controller */ readonly isController: boolean; } +/** Struct */ export interface StakingLedger extends Struct { + /** AccountId */ readonly stash: AccountId; + /** Compact */ readonly total: Compact; + /** Compact */ readonly active: Compact; - readonly unlocking: Vector; + /** Vec */ + readonly unlocking: Vec; } +/** Struct */ export interface UnlockChunk extends Struct { + /** Compact */ readonly value: Compact; + /** Compact */ readonly era: Compact; } +/** Struct */ export interface ValidatorPrefs extends Struct { + /** Compact */ readonly unstakeThreshold: Compact; + /** Compact */ readonly validatorPayment: Compact; } @@ -60,27 +79,30 @@ declare module '@polkadot/types/interfaceRegistry' { EraIndex: EraIndex; 'Compact': Compact; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; EraRewards: EraRewards; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; IndividualExposure: IndividualExposure; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; Exposure: Exposure; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + MomentOf: MomentOf; + 'Option': Option; + 'Vec': Vec; RewardDestination: RewardDestination; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; UnlockChunk: UnlockChunk; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; StakingLedger: StakingLedger; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; ValidatorPrefs: ValidatorPrefs; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/primitive/EventRecord.spec.ts b/packages/types/src/srml/system/EventRecord.spec.ts similarity index 57% rename from packages/types/src/primitive/EventRecord.spec.ts rename to packages/types/src/srml/system/EventRecord.spec.ts index 7872aa2569..60d1ef64e2 100644 --- a/packages/types/src/primitive/EventRecord.spec.ts +++ b/packages/types/src/srml/system/EventRecord.spec.ts @@ -2,29 +2,32 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import createType from '../codec/createType'; -import Vector from '../codec/Vector'; -import json1 from '../json/EventRecord.001.json'; -import json3 from '../json/EventRecord.003.json'; -import { injectDefinitions } from '../srml'; -import Metadata from '../Metadata'; -import metadataV0 from '../Metadata/v0/static'; -import metadata from '../Metadata/static'; -import Event from './Event'; -import EventRecord from './EventRecord'; +import { EventRecord } from './types'; + +import createType from '../../codec/createType'; +import Vec from '../../codec/Vec'; +import json1 from '../../json/EventRecord.001.json'; +import json3 from '../../json/EventRecord.003.json'; +import { injectDefinitions } from '..'; +import Metadata from '../../Metadata'; +import metadataV0 from '../../Metadata/v0/static'; +import metadata from '../../Metadata/static'; +import Event from '../../primitive/Event'; describe('EventRecord', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + describe('EventRecord_0_76', (): void => { beforeEach((): void => { - injectDefinitions(); - Event.injectMetadata( new Metadata(metadataV0) ); }); it('decodes correctly', (): void => { - const records: Vector = createType('Vec', json1.params.result.changes[0][1]) as any; + const records: Vec = createType('Vec', json1.params.result.changes[0][1]) as any; const er = records[0]; expect(er.phase.type).toEqual('ApplyExtrinsic'); @@ -41,7 +44,7 @@ describe('EventRecord', (): void => { }); it('decodes older eventrecord correctly', (): void => { - const records: Vector = createType('Vec', json1.params.result.changes[0][1], true) as any; + const records: Vec = createType('Vec', json1.params.result.changes[0][1], true) as any; const er = records[0]; expect(er.phase.type).toEqual('ApplyExtrinsic'); @@ -49,7 +52,7 @@ describe('EventRecord', (): void => { it('decodes eventrecord with topics correctly', (): void => { const hex = json3.params.result.changes[0][1]; - const records: Vector = createType('Vec', hex, true) as any; + const records: Vec = createType('Vec', hex, true) as any; const er = records[0]; expect(er.phase.type).toEqual('ApplyExtrinsic'); diff --git a/packages/types/src/srml/system/definitions.ts b/packages/types/src/srml/system/definitions.ts index 42e4b87244..673aeb5505 100644 --- a/packages/types/src/srml/system/definitions.ts +++ b/packages/types/src/srml/system/definitions.ts @@ -4,6 +4,25 @@ export default { types: { - Key: 'Bytes' + DigestOf: 'Digest', + EventId: '[u8; 2]', + EventIndex: 'u32', + Key: 'Bytes', + Phase: { + _enum: { + ApplyExtrinsic: 'u32', + Finalization: 'Null' + } + }, + EventRecord0to76: { + phase: 'Phase', + event: 'Event' + }, + // Fallback in injectDefinitions + EventRecord: { + phase: 'Phase', + event: 'Event', + topics: 'Vec' + } } }; diff --git a/packages/types/src/srml/system/types.ts b/packages/types/src/srml/system/types.ts index 74271159c5..9581dc7f79 100644 --- a/packages/types/src/srml/system/types.ts +++ b/packages/types/src/srml/system/types.ts @@ -1,15 +1,72 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Option, Vector } from '../../codec'; -import { Bytes } from '../../primitive'; +import { Compact, Enum, Option, Struct, Vec } from '../../codec'; +import { Bytes, Digest, Event, u32, u8 } from '../../primitive'; +import { Hash } from '../runtime/types'; -export interface Key extends Bytes {} +/** Digest */ +export type DigestOf = Digest; + +/** Vec */ +export type EventId = Vec; + +/** u32 */ +export type EventIndex = u32; + +/** Struct */ +export interface EventRecord extends Struct { + /** Phase */ + readonly phase: Phase; + /** Event */ + readonly event: Event; + /** Vec */ + readonly topics: Vec; +} + +/** Struct */ +export interface EventRecord0to76 extends Struct { + /** Phase */ + readonly phase: Phase; + /** Event */ + readonly event: Event; +} + +/** Bytes */ +export type Key = Bytes; + +/** Enum */ +export interface Phase extends Enum { + /** 0:: ApplyExtrinsic(u32) */ + readonly isApplyExtrinsic: boolean; + /** u32 */ + readonly asApplyExtrinsic: u32; + /** 1:: Finalization */ + readonly isFinalization: boolean; +} declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { + DigestOf: DigestOf; + 'Option': Option; + 'Vec': Vec; + EventId: EventId; + 'Option': Option; + 'Vec': Vec; + EventIndex: EventIndex; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; Key: Key; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; + Phase: Phase; + 'Option': Option; + 'Vec': Vec; + EventRecord0to76: EventRecord0to76; + 'Option': Option; + 'Vec': Vec; + EventRecord: EventRecord; + 'Option': Option; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/treasury/types.ts b/packages/types/src/srml/treasury/types.ts index c28f57681f..e68d0f1f1d 100644 --- a/packages/types/src/srml/treasury/types.ts +++ b/packages/types/src/srml/treasury/types.ts @@ -1,14 +1,18 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Option, Struct, Vector } from '../../codec'; +import { Option, Struct, Vec } from '../../codec'; import { AccountId } from '../../primitive'; import { Balance } from '../runtime/types'; +/** Struct */ export interface TreasuryProposal extends Struct { + /** AccountId */ readonly proposer: AccountId; + /** Balance */ readonly value: Balance; + /** AccountId */ readonly beneficiary: AccountId; + /** Balance */ readonly bond: Balance; } @@ -16,6 +20,6 @@ declare module '@polkadot/types/interfaceRegistry' { export interface InterfaceRegistry { TreasuryProposal: TreasuryProposal; 'Option': Option; - 'Vec': Vector; + 'Vec': Vec; } } diff --git a/packages/types/src/srml/types.ts b/packages/types/src/srml/types.ts index ea27849d1f..c6e4a2824b 100644 --- a/packages/types/src/srml/types.ts +++ b/packages/types/src/srml/types.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit export * from './runtime/types'; @@ -18,3 +17,4 @@ export * from './parachains/types'; export * from './staking/types'; export * from './system/types'; export * from './treasury/types'; +export * from './rpc/types'; diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index 14607b36f7..209e578624 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -8,7 +8,7 @@ import BN from 'bn.js'; import Compact from './codec/Compact'; import U8a from './codec/U8a'; -import { FunctionMetadata } from './Metadata/v6/Calls'; +import { FunctionMetadata } from './Metadata/v7/Calls'; import Method from './primitive/Method'; import Address from './primitive/Address';