diff --git a/CHANGELOG.md b/CHANGELOG.md index e33334eab0..50728c989a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,20 @@ # 0.82.0-beta.x -- **Breaking change** The `ContractsAbi` type has been moved from `@polkadot/types` to `import { Abi } from '@polkadot/api-contract`. This paves the way for an enhanced contracts interface, instead of dealing with low-level API calls. -- **Breaking change** `api.derive.contract` is now `api.derive.contracts` to align with the substrate 2.x rename. (Feture detection is used so it supports both 1.x and 2.x chains) -- **Breaking change** The api now uses the module name instead of the prefix to generate the storage methods. The methods of the grandpa module changed from `api.query.grandpaFinality` to `api.query.grandpa`. -- **Breaking Change** StorageFunction has been renamed to StorageEntry. -- **Breaking Change** `@polkadot/extrinsics` and `@polkadot/storage` have been moved to `@polkadot/api-metadata` and are now accessible as `@polkadot/api-metadata/extrinsics` and `@polkadot/api-metadata/storage`, respectively. -- **Breaking Change** Vote interface extends U8a instead of I8. Vote properties can be accessed via the `isAye`, `isNay`, and `conviction` getters. Votes can still be constructed as before with a raw JS boolean, a SCALE encoded Boolean, an i8 number, or a JS object with properties `aye` and `conviction` defined. -- Support latest substrate 2.x v6 metadata with module constants using `api.consts`. -- Support V2 Extrinsics in addition to V1 -- Addition of `api.derive.elections` -- `usize` is now a blacklisted type that will throw on construction. Since it is platform-specific, it creates incompatibilities between native (generally u64) and WASM (always u32) code. Use one of the `u32` or `u64` types explicitly. +- Support for substrate 2.x (master) has been extended, + - Additional types have been addedd for the modules + - `api.derive.contract` is now `api.derive.contracts` to align with the substrate 2.x rename. (Feture detection is used so it supports both 1.x and 2.x chains) + - Addition of `api.derive.elections` +- Support latest substrate 2.x v6 & v7 metadata with module constants using `api.consts`. + - The api now uses the module name for the storage methods, aligning module names for consistency with transactions. The methods of the grandpa module moved from `api.query.grandpaFinality` to `api.query.grandpa`. + - Internally the `@polkadot/extrinsics` and `@polkadot/storage` have been moved to `@polkadot/api-metadata` and are now accessible as `@polkadot/api-metadata/extrinsics` and `@polkadot/api-metadata/storage`, respectively. +- Support V2 Extrinsics in addition to V1, v2 includes an optional `tip` + - An additon to this support, the `Signer` interface has deprecated the `sign` method and replaced it with `signPayload`. Support for the former will be removed in subsequent versions. +- Types have been extended an has been moved to definitions instead of classes for a large number of these type - + - **Breaking Change** For creation of types, it is recommended to use `createType(, )` instead of e.g. `new Proposal(...)`. When passing these to methods, construction should not be neededd, the raw value can be passed. + - **Breaking Change** Vote interface extends U8a instead of I8. Vote properties can be accessed via the `isAye`, `isNay`, and `conviction` getters. Votes can still be constructed as before with a raw JS boolean, a SCALE encoded Boolean, an i8 number, or a JS object with properties `aye` and `conviction` defined. + - **Breaking Change** For moved types, a previous import would have been from `@polkadot/types`, i.e. `import { SetIndex } from '@polkaot/types`, not just the definitions are available via `import { SetIndex } from '@polkadot/srml/types` + - The `ContractsAbi` type has been moved from `@polkadot/types` to `import { Abi } from '@polkadot/api-contract`. This paves the way for an enhanced contracts interface, instead of dealing with low-level API calls. + - `usize` is now a blacklisted type that will throw on construction. Since it is platform-specific, it creates incompatibilities between native (generally u64) and WASM (always u32) code. Use one of the `u32` or `u64` types explicitly. # 0.81.1 diff --git a/packages/api-derive/src/balances/all.ts b/packages/api-derive/src/balances/all.ts index 83229f6746..8c79550e74 100644 --- a/packages/api-derive/src/balances/all.ts +++ b/packages/api-derive/src/balances/all.ts @@ -2,11 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { BalanceLock, VestingSchedule } from '@polkadot/types/srml/balances/types'; + import BN from 'bn.js'; import { combineLatest, of, Observable } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId, AccountIndex, Address, Balance, BalanceLock, BlockNumber, Index, Option, VestingSchedule } from '@polkadot/types'; +import { AccountId, AccountIndex, Address, Balance, BlockNumber, ClassOf, Index, Option, createType } from '@polkadot/types'; import { bnMax } from '@polkadot/util'; import { idAndIndex } from '../accounts/idAndIndex'; @@ -19,7 +21,7 @@ type Result = [AccountId | undefined, BlockNumber | undefined, [Balance?, Balanc const EMPTY_ACCOUNT = new AccountId(); const ZERO = new Balance(0); -function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalance = ZERO, reservedBalance = ZERO, locks = [], vesting = new Option(VestingSchedule, null), accountNonce = ZERO]]: Result): DerivedBalances { +function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalance = ZERO, reservedBalance = ZERO, locks = [], vesting = new Option(ClassOf('VestingSchedule'), null), accountNonce = ZERO]]: Result): DerivedBalances { let lockedBalance = ZERO; if (Array.isArray(locks)) { @@ -32,7 +34,7 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan } // offset = balance locked at genesis, perBlock is the unlock amount - const { offset, perBlock } = vesting.unwrapOr(new VestingSchedule()); + const { offset, perBlock } = vesting.unwrapOr(createType('VestingSchedule')); const vestedNow: BN = perBlock.mul(bestNumber); const vestedBalance: BN = vestedNow.gt(offset) ? freeBalance diff --git a/packages/api-derive/src/democracy/referendumInfo.ts b/packages/api-derive/src/democracy/referendumInfo.ts index 2a8564b083..8c3e7be882 100644 --- a/packages/api-derive/src/democracy/referendumInfo.ts +++ b/packages/api-derive/src/democracy/referendumInfo.ts @@ -2,11 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { ReferendumInfo } from '@polkadot/types/srml/democracy/types'; + import BN from 'bn.js'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { Option, ReferendumInfo } from '@polkadot/types'; +import { Option } from '@polkadot/types'; import { isNull } from '@polkadot/util'; import { ReferendumInfoExtended } from '../type'; diff --git a/packages/api-derive/src/democracy/referendumInfos.ts b/packages/api-derive/src/democracy/referendumInfos.ts index 5799f5be80..f2cb47e547 100644 --- a/packages/api-derive/src/democracy/referendumInfos.ts +++ b/packages/api-derive/src/democracy/referendumInfos.ts @@ -2,11 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { ReferendumInfo } from '@polkadot/types/srml/democracy/types'; + import BN from 'bn.js'; import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { Option, ReferendumInfo, Vector } from '@polkadot/types'; +import { Option, Vector } from '@polkadot/types'; import { ReferendumInfoExtended } from '../type'; import { drr } from '../util/drr'; diff --git a/packages/api-derive/src/democracy/referendums.ts b/packages/api-derive/src/democracy/referendums.ts index a91794a8bf..108fd258c3 100644 --- a/packages/api-derive/src/democracy/referendums.ts +++ b/packages/api-derive/src/democracy/referendums.ts @@ -2,11 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { ReferendumIndex } from '@polkadot/types/srml/democracy/types'; + import BN from 'bn.js'; import { Observable, of } from 'rxjs'; import { switchMap } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { Option, ReferendumIndex } from '@polkadot/types'; +import { Option } from '@polkadot/types'; import { ReferendumInfoExtended } from '../type'; import { drr } from '../util/drr'; diff --git a/packages/api-derive/src/elections/approvalsOf.ts b/packages/api-derive/src/elections/approvalsOf.ts index 607aae2eb5..8c7827dfe6 100644 --- a/packages/api-derive/src/elections/approvalsOf.ts +++ b/packages/api-derive/src/elections/approvalsOf.ts @@ -2,11 +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 { SetIndex } from '@polkadot/types/srml/elections/types'; +import { ApprovalFlag, SetIndex } from '@polkadot/types/srml/elections/types'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Observable } from 'rxjs'; -import { AccountId, Vector, ApprovalFlag } from '@polkadot/types'; +import { AccountId, Vector } from '@polkadot/types'; import { switchMap, map } from 'rxjs/operators'; import { approvalFlagsToBools } from '../util/approvalFlagsToBools'; import { drr } from '../util/drr'; diff --git a/packages/api-derive/src/elections/approvalsOfAt.ts b/packages/api-derive/src/elections/approvalsOfAt.ts index 93245cacd3..7127d224d4 100644 --- a/packages/api-derive/src/elections/approvalsOfAt.ts +++ b/packages/api-derive/src/elections/approvalsOfAt.ts @@ -2,11 +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 { SetIndex } from '@polkadot/types/srml/elections/types'; +import { ApprovalFlag, SetIndex } from '@polkadot/types/srml/elections/types'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { Observable } from 'rxjs'; -import { AccountId, Vector, ApprovalFlag } from '@polkadot/types'; +import { AccountId, Vector } from '@polkadot/types'; import { map } from 'rxjs/operators'; import { approvalFlagsToBools } from '../util/approvalFlagsToBools'; import { drr } from '../util/drr'; diff --git a/packages/api-derive/src/elections/info.ts b/packages/api-derive/src/elections/info.ts index 5f52123c93..909bbe6175 100644 --- a/packages/api-derive/src/elections/info.ts +++ b/packages/api-derive/src/elections/info.ts @@ -2,13 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { SetIndex } from '@polkadot/types/srml/elections/types'; +import { SetIndex, VoteIndex } from '@polkadot/types/srml/elections/types'; import BN from 'bn.js'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId, BlockNumber, VoteIndex } from '@polkadot/types'; +import { AccountId, BlockNumber } from '@polkadot/types'; import { DerivedElectionsInfo } from '../types'; import { drr } from '../util/drr'; diff --git a/packages/api-derive/src/staking/info.ts b/packages/api-derive/src/staking/info.ts index ee6afcc893..9afc42ad65 100644 --- a/packages/api-derive/src/staking/info.ts +++ b/packages/api-derive/src/staking/info.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 { SessionKey, Keys } from '@polkadot/types/srml/session/types'; +import { Keys } from '@polkadot/types/srml/session/types'; +import { Exposure, RewardDestination, ValidatorPrefs } from '@polkadot/types/srml/staking/types'; import { ApiInterfaceRx } from '@polkadot/api/types'; import { DerivedStaking, DerivedUnlocking } from '../types'; @@ -10,7 +11,7 @@ import { DerivedStaking, DerivedUnlocking } from '../types'; import BN from 'bn.js'; import { combineLatest, Observable, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; -import { AccountId, BlockNumber, Exposure, Option, RewardDestination, StakingLedger, Tuple, ValidatorPrefs, Vector, UnlockChunk } from '@polkadot/types'; +import { AccountId, BlockNumber, Option, StakingLedger, Tuple, Vector, UnlockChunk } from '@polkadot/types'; import { isUndefined } from '@polkadot/util'; @@ -74,7 +75,7 @@ function redeemableSum (stakingLedger: StakingLedger | undefined, eraLength: BN, }, 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 | Vector): { 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); @@ -124,7 +125,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 | Vector, 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; @@ -171,7 +172,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 | Vector, 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/ReferendumInfoExtended.ts b/packages/api-derive/src/type/ReferendumInfoExtended.ts index 299494d6e0..551e40a43c 100644 --- a/packages/api-derive/src/type/ReferendumInfoExtended.ts +++ b/packages/api-derive/src/type/ReferendumInfoExtended.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 { ReferendumIndex, ReferendumInfo } from '@polkadot/types/srml/democracy/types'; + import BN from 'bn.js'; -import { ReferendumInfo, ReferendumIndex } from '@polkadot/types'; +import { ClassOf, createType } from '@polkadot/types'; import { AnyJsonObject } from '@polkadot/types/types'; /** @@ -11,7 +13,7 @@ import { AnyJsonObject } from '@polkadot/types/types'; * @description * A [[ReferendumInfo]] with an additional `index` field */ -export default class ReferendumInfoExtended extends ReferendumInfo { +export default class ReferendumInfoExtended extends ClassOf('ReferendumInfo') { private _index: ReferendumIndex; public constructor (value: ReferendumInfo | ReferendumInfoExtended, index?: BN | number) { @@ -19,7 +21,7 @@ export default class ReferendumInfoExtended extends ReferendumInfo { this._index = value instanceof ReferendumInfoExtended ? value.index - : new ReferendumIndex(index); + : createType('ReferendumIndex', index); } /** diff --git a/packages/api-derive/src/types.ts b/packages/api-derive/src/types.ts index 34f4e21050..63494e459b 100644 --- a/packages/api-derive/src/types.ts +++ b/packages/api-derive/src/types.ts @@ -2,10 +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 { SetIndex } from '@polkadot/types/srml/elections/types'; +import { SetIndex, VoteIndex } from '@polkadot/types/srml/elections/types'; +import { Exposure, RewardDestination, ValidatorPrefs } from '@polkadot/types/srml/staking/types'; import BN from 'bn.js'; -import { AccountId, Balance, BlockNumber, Exposure, Index, RewardDestination, StakingLedger, ValidatorPrefs, Vote, VoteIndex } from '@polkadot/types'; +import { AccountId, Balance, BlockNumber, Index, StakingLedger, Vote } from '@polkadot/types'; export interface DerivedBalances { accountId: AccountId; diff --git a/packages/api-derive/src/util/approvalFlagToBool.ts b/packages/api-derive/src/util/approvalFlagToBool.ts index b17e5dd4b8..99d4628297 100644 --- a/packages/api-derive/src/util/approvalFlagToBool.ts +++ b/packages/api-derive/src/util/approvalFlagToBool.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 { ApprovalFlag } from '@polkadot/types/srml/elections/types'; + import BN from 'bn.js'; -import { Vector, ApprovalFlag } from '@polkadot/types'; +import { Vector } from '@polkadot/types'; export function approvalFlagToBool (flags: Vector): boolean[] { const bools: boolean[] = []; @@ -12,6 +14,8 @@ export function approvalFlagToBool (flags: Vector): boolean[] { bools.push(!flag.toBn().uand((new BN(1)).shln(bit)).isZero()); } } + const lastApproval: number = bools.lastIndexOf(true); + return lastApproval >= 0 ? bools.slice(0, lastApproval + 1) : []; } diff --git a/packages/api-derive/src/util/approvalFlagsToBools.ts b/packages/api-derive/src/util/approvalFlagsToBools.ts index b187781f5c..88fed43c04 100644 --- a/packages/api-derive/src/util/approvalFlagsToBools.ts +++ b/packages/api-derive/src/util/approvalFlagsToBools.ts @@ -2,15 +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 { Vector, ApprovalFlag } from '@polkadot/types'; +import { ApprovalFlag } from '@polkadot/types/srml/elections/types'; + +import { Vector } from '@polkadot/types'; export function approvalFlagsToBools (flags: Vector): boolean[] { const bools: boolean[] = []; + flags.forEach((flag: ApprovalFlag): void => { const str = flag.toString(2); + for (const bit of str) { bools.push(!!parseInt(bit, 10)); } }); + return bools; } diff --git a/packages/api-metadata/src/extrinsics/fromMetadata/fromMetadata.spec.ts b/packages/api-metadata/src/extrinsics/fromMetadata/fromMetadata.spec.ts index d701bd84e1..1f26e97122 100644 --- a/packages/api-metadata/src/extrinsics/fromMetadata/fromMetadata.spec.ts +++ b/packages/api-metadata/src/extrinsics/fromMetadata/fromMetadata.spec.ts @@ -3,10 +3,13 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Extrinsic, Metadata } from '@polkadot/types'; +import { injectDefinitions } from '@polkadot/types/srml'; import json from '@polkadot/types/Metadata/v7/static'; import fromMetadata from '.'; +injectDefinitions(); + // Use the pre-generated metadata const metadata = new Metadata(json); const newExtrinsics = fromMetadata(metadata); diff --git a/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts b/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts index d6ab998a70..74db73c494 100644 --- a/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts +++ b/packages/api-metadata/src/storage/fromMetadata/fromMetadata.spec.ts @@ -5,11 +5,15 @@ import testingPairs from '@polkadot/keyring/testingPairs'; import { Metadata } from '@polkadot/types'; import json from '@polkadot/types/Metadata/v6/static'; +import { injectDefinitions } from '@polkadot/types/srml'; import { u8aToHex } from '@polkadot/util'; import fromMetadata from '../fromMetadata'; +injectDefinitions(); + const keyring = testingPairs({ type: 'ed25519' }); + // Use the pre-generated metadata const metadata = new Metadata(json); const storage = fromMetadata(metadata); diff --git a/packages/api/src/promise/Api.spec.ts b/packages/api/src/promise/Api.spec.ts index fc90e201e7..24de69d2dd 100644 --- a/packages/api/src/promise/Api.spec.ts +++ b/packages/api/src/promise/Api.spec.ts @@ -5,8 +5,8 @@ import { Hash } from '@polkadot/types'; import Mock from '@polkadot/rpc-provider/mock/index'; -import { ApiPromise } from './..'; -import { ApiOptions } from './../types'; +import { ApiPromise } from '..'; +import { ApiOptions } from '../types'; describe('Metadata queries', (): void => { let mock: Mock; diff --git a/packages/api/test/e2e/api-derive/promise.spec.ts b/packages/api/test/e2e/api-derive/promise.spec.ts index 5c83644f28..c45fa79c4c 100644 --- a/packages/api/test/e2e/api-derive/promise.spec.ts +++ b/packages/api/test/e2e/api-derive/promise.spec.ts @@ -5,7 +5,6 @@ import ApiPromise from '@polkadot/api/promise/Api'; import testingPairs from '@polkadot/keyring/testingPairs'; import { WsProvider } from '@polkadot/rpc-provider'; -import { RewardDestination } from '@polkadot/types'; import { SubmittableResult } from '@polkadot/api'; import { HeaderExtended } from '@polkadot/api-derive/type'; @@ -185,7 +184,7 @@ describe.skip('derive e2e', (): void => { // start by setting the reqred to Staked, so we have a common starting point await api.tx.staking - .setPayee(new RewardDestination('Staked')) + .setPayee('Staked') .signAndSend(testingPairs().alice, ({ status }): void => { if (status.isFinalized) { console.error('setPayee(Staked) isFinalized'); @@ -208,7 +207,7 @@ describe.skip('derive e2e', (): void => { // Wait a bit, and change reward destination setTimeout(async (): Promise => { await api.tx.staking - .setPayee(new RewardDestination('Stash')) + .setPayee('Stash') .signAndSend(testingPairs().alice, ({ status }): void => { if (status.isFinalized) { console.error('setPayee(Stash) isFinalized'); diff --git a/packages/api/test/e2e/rpc-core/basics.spec.ts b/packages/api/test/e2e/rpc-core/basics.spec.ts index ee5453e44c..2f7d2022ce 100644 --- a/packages/api/test/e2e/rpc-core/basics.spec.ts +++ b/packages/api/test/e2e/rpc-core/basics.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 { ChainProperties, PendingExtrinsics } from '@polkadot/types'; +import { ChainProperties, Extrinsic, Vector } from '@polkadot/types'; import WsProvider from '@polkadot/rpc-provider/ws'; import Rpc from '@polkadot/rpc-core'; @@ -18,8 +18,8 @@ describe.skip('e2e basics', (): void => { it('retrieves the pending extrinsics', (done): void => { rpc.author .pendingExtrinsics() - .subscribe((extrinsics: PendingExtrinsics): void => { - expect(extrinsics).toBeInstanceOf(PendingExtrinsics); + .subscribe((extrinsics: Vector): void => { + expect(extrinsics).toBeInstanceOf(Vector); done(); }); }); diff --git a/packages/type-jsonrpc/src/author.ts b/packages/type-jsonrpc/src/author.ts index 3706168e4d..b097be39fc 100644 --- a/packages/type-jsonrpc/src/author.ts +++ b/packages/type-jsonrpc/src/author.ts @@ -10,7 +10,8 @@ import createParam from './create/param'; const pendingExtrinsics: RpcMethodOpt = { description: 'Returns all pending extrinsics, potentially grouped by sender', params: [], - type: 'PendingExtrinsics' + // @ts-ignore Yeap, the Vec here is fine + type: 'Vec' }; const submitExtrinsic: RpcMethodOpt = { diff --git a/packages/types/README.md b/packages/types/README.md index 7d9f6ef022..5b1fff4e46 100644 --- a/packages/types/README.md +++ b/packages/types/README.md @@ -91,10 +91,6 @@ These custom types implement specific types that are found as part of the Substr | [[Balance]] | The Substrate Balance representation as a [[U128]] | | [[BalanceLock]] | The Substrate BalanceLock for staking | | [[BalanceOf]] | The Substrate BalanceOf representation as a [[Balance]] | -| [[BftAtReport]] | A report of a/b hash-signature pairs for a specific index | -| [[BftAuthoritySignature]] | Represents a Bft Hash and Signature pairing, typically used in reporting network behaviour | -| [[BftHashSignature]] | Represents a Bft Hash and Signature pairing, typically used in reporting network behaviour | -| [[BftProposeOutOfTurn]] | A report for out-of-turn proposals | | [[BlockNumber]] | A representation of a Substrate BlockNumber, implemented as a [[U64]] | | [[CodeHash]] | The default contract code hash that is used accross the system | | [[Conviction]] | A value denoting the strength of conviction of a vote. | @@ -103,7 +99,6 @@ These custom types implement specific types that are found as part of the Substr | [[ContractStorageKey]] | A representation of a storage key for contracts | | [[EraIndex]] | A representation for the era count | | [[Exposure]] | A snapshot of the stake backing a single validator in the system | -| [[Extrinsics]] | A [[Vector]] of [[Extrinsic]] | | [[Gas]] | A gas number type for Substrate, extending [[U64]] | | [[Heartbeat]] | Heartbeat which is send/received. | | [[IndividualExposure]] | The Substrate IndividualExposure for staking | @@ -196,7 +191,6 @@ These types are not used in the runtime, but are rather used in RPC results: | [[NetworkState]] | Wraps the properties retrieved from the chain via the `system.network_state` RPC call | | [[Metadata]] | The versioned runtime metadata as a decoded structure | | [[PeerInfo]] | A system peer info indicator, reported back over RPC | -| [[PendingExtrinsics]] | A list of pending [[Extrinsics]] | | [[RuntimeVersion]] | A [[Tuple]] that conatins the [[ApiId]] and [[U32]] version | | [[SignedBlock]] | A [[Block]] that has been signed and contains a [[Justification]] | | [[StorageChangeSet]] | A set of storage changes. It contains the [[Block]] hash and a list of the actual changes | diff --git a/packages/types/src/codec/EnumType.spec.ts b/packages/types/src/codec/EnumType.spec.ts index f8e9bccd3e..663017ad31 100644 --- a/packages/types/src/codec/EnumType.spec.ts +++ b/packages/types/src/codec/EnumType.spec.ts @@ -68,7 +68,7 @@ describe('Enum', (): void => { expect(test.isSecond).toEqual(true); expect(test.asSecond.toNumber()).toEqual(42); - expect((): never => test.asThird).toThrow(/Cannot convert Second via asThird/); + expect((): never => test.asThird).toThrow(/Cannot convert 'Second' via asThird/); }); it('stringifies with custom types', (): void => { diff --git a/packages/types/src/codec/EnumType.ts b/packages/types/src/codec/EnumType.ts index df266335ed..8b9ebee434 100644 --- a/packages/types/src/codec/EnumType.ts +++ b/packages/types/src/codec/EnumType.ts @@ -4,7 +4,7 @@ import { AnyJson, Codec, Constructor } from '../types'; -import { assert, hexToU8a, isHex, isNumber, isObject, isString, isU8a, isUndefined, u8aConcat, u8aToHex } from '@polkadot/util'; +import { assert, hexToU8a, isHex, isNumber, isObject, isString, isU8a, isUndefined, stringCamelCase, stringUpperFirst, u8aConcat, u8aToHex } from '@polkadot/util'; import Null from '../primitive/Null'; import Base from './Base'; @@ -132,8 +132,9 @@ export default class Enum extends Base { super(Types, value, index); Object.keys(this._def).forEach((_key): void => { - const askey = `as${_key}`; - const iskey = `is${_key}`; + const name = stringUpperFirst(stringCamelCase(_key.replace(' ', '_'))); + const askey = `as${name}`; + const iskey = `is${name}`; // do not clobber existing properties on the object if (isUndefined((this as any)[iskey])) { @@ -147,7 +148,7 @@ export default class Enum extends Base { Object.defineProperty(this, askey, { enumerable: true, get: (): Codec => { - assert((this as any)[iskey], `Cannot convert ${this.type} via ${askey}`); + assert((this as any)[iskey], `Cannot convert '${this.type}' via ${askey}`); return this.value; } diff --git a/packages/types/src/codec/Tuple.spec.ts b/packages/types/src/codec/Tuple.spec.ts index 41383f9b88..63b50d5d47 100644 --- a/packages/types/src/codec/Tuple.spec.ts +++ b/packages/types/src/codec/Tuple.spec.ts @@ -2,21 +2,25 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { Proposal } from '../srml/democracy/types'; +import { VoteThreshold } from '../srml/elections/types'; +import { CodecTo } from '../types'; + import extrinsics from '@polkadot/api-metadata/extrinsics/static'; -import { CodecTo } from '../types'; +import { ClassOf } from '../codec/createType'; import Method from '../primitive/Method'; import Text from '../primitive/Text'; import U32 from '../primitive/U32'; +import { injectDefinitions } from '../srml'; import BlockNumber from '../type/BlockNumber'; -import Proposal from '../type/Proposal'; -import VoteThreshold from '../type/VoteThreshold'; import Tuple from './Tuple'; describe('Tuple', (): void => { let tuple: Tuple; beforeEach((): void => { + injectDefinitions(); tuple = new Tuple( [Text, U32], ['bazzing', 69] @@ -56,7 +60,7 @@ describe('Tuple', (): void => { Method.injectMethods(extrinsics); const test = new (Tuple.with([ - BlockNumber, Proposal, VoteThreshold + BlockNumber, ClassOf('Proposal'), ClassOf('VoteThreshold') ] ))('0x62190000000000000003507b0a092230783432223a202230783433220a7d0a01'); @@ -71,7 +75,7 @@ describe('Tuple', (): void => { it('exposes the Types (object creation)', (): void => { const test = new Tuple({ - BlockNumber, VoteThreshold + BlockNumber, VoteThreshold: ClassOf('VoteThreshold') }, []); expect(test.Types).toEqual(['BlockNumber', 'VoteThreshold']); diff --git a/packages/types/src/codec/Tuple.ts b/packages/types/src/codec/Tuple.ts index f84c6cfc65..12f9963d92 100644 --- a/packages/types/src/codec/Tuple.ts +++ b/packages/types/src/codec/Tuple.ts @@ -2,9 +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 { AnyNumber, AnyU8a, AnyString, Codec, Constructor } from '../types'; + import { isU8a, u8aConcat, isHex, hexToU8a } from '@polkadot/util'; -import { AnyNumber, AnyU8a, AnyString, Codec, Constructor } from '../types'; import { decodeU8a } from './utils'; import AbstractArray from './AbstractArray'; diff --git a/packages/types/src/codec/Vector.spec.ts b/packages/types/src/codec/Vector.spec.ts index 54a159414b..22d93fa2cd 100644 --- a/packages/types/src/codec/Vector.spec.ts +++ b/packages/types/src/codec/Vector.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 { Proposal, PropIndex } from '../srml/democracy/types'; import { Codec, CodecTo } from '../types'; import extrinsics from '@polkadot/api-metadata/extrinsics/static'; @@ -9,8 +10,6 @@ import extrinsics from '@polkadot/api-metadata/extrinsics/static'; import AccountId from '../primitive/AccountId'; import Method from '../primitive/Method'; import Text from '../primitive/Text'; -import PropIndex from '../type/PropIndex'; -import Proposal from '../type/Proposal'; import createType from './createType'; import Vector from './Vector'; import Tuple from './Tuple'; diff --git a/packages/types/src/codec/createType.ts b/packages/types/src/codec/createType.ts index 64b33d55ba..da10bb11f9 100644 --- a/packages/types/src/codec/createType.ts +++ b/packages/types/src/codec/createType.ts @@ -276,7 +276,7 @@ export function getTypeClass (value: TypeDef, Fallback? return Fallback; } - throw new Error(`Unable to determine type from '${value.type}'`); + throw new Error(`Unable to determine type from ${JSON.stringify(value)}`); } // alias for createClass diff --git a/packages/types/src/index.spec.ts b/packages/types/src/index.spec.ts index 604bb3237a..cc54ca1e7b 100644 --- a/packages/types/src/index.spec.ts +++ b/packages/types/src/index.spec.ts @@ -6,11 +6,16 @@ import extrinsics from '@polkadot/api-metadata/extrinsics/static'; import { Codec, Constructor } from './types'; import * as Classes from './index.types'; +import { injectDefinitions } from './srml'; const Types = Classes as Record; const UNCONSTRUCTABLE = ['origin', 'usize', 'vote']; describe('types', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + describe('default creation', (): void => { Object.keys(Types).forEach((name): void => { it(`creates an empty ${name}`, (): void => { diff --git a/packages/types/src/rpc/Block.ts b/packages/types/src/rpc/Block.ts index 541fe0e3ac..3ca7e1e55e 100644 --- a/packages/types/src/rpc/Block.ts +++ b/packages/types/src/rpc/Block.ts @@ -6,9 +6,11 @@ import { AnyU8a } from '../types'; import { blake2AsU8a } from '@polkadot/util-crypto'; +import { ClassOf } from '../codec/createType'; +import Extrinsic from '../primitive/Extrinsic/Extrinsic'; import Struct from '../codec/Struct'; +import Vector from '../codec/Vector'; import Hash from '../primitive/Hash'; -import Extrinsics from '../type/Extrinsics'; import Header, { HeaderValue } from './Header'; export interface BlockValue { @@ -25,7 +27,7 @@ export default class Block extends Struct { public constructor (value?: BlockValue | Uint8Array) { super({ header: Header, - extrinsics: Extrinsics + extrinsics: ClassOf>('Vec') }, value); } @@ -39,10 +41,10 @@ export default class Block extends Struct { } /** - * @description The [[Extrinsics]] contained in the block + * @description The [[Extrinsic]] contained in the block */ - public get extrinsics (): Extrinsics { - return this.get('extrinsics') as Extrinsics; + public get extrinsics (): Vector { + return this.get('extrinsics') as Vector; } /** diff --git a/packages/types/src/rpc/Digest.ts b/packages/types/src/rpc/Digest.ts index 2b154fd614..44783d29c2 100644 --- a/packages/types/src/rpc/Digest.ts +++ b/packages/types/src/rpc/Digest.ts @@ -14,7 +14,9 @@ import Hash from '../primitive/Hash'; import Signature from '../primitive/Signature'; import U32 from '../primitive/U32'; import U64 from '../primitive/U64'; -import AuthorityId from '../type/AuthorityId'; + +// Should import AuthorityId (however, move these to generated types) +import AuthorityId from '../primitive/AccountId'; const CID_AURA = 0x61727561; // 'aura' const CID_BABE = 0x65626162; // 'babe' diff --git a/packages/types/src/rpc/PendingExtrinsics.ts b/packages/types/src/rpc/PendingExtrinsics.ts deleted file mode 100644 index a6d02e046e..0000000000 --- a/packages/types/src/rpc/PendingExtrinsics.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 Extrinsics from '../type/Extrinsics'; - -/** - * @name PendingExtrinsics - * @description - * A list of pending [[Extrinsics]] - */ -export default class PendingExtrinsics extends Extrinsics { -} diff --git a/packages/types/src/rpc/SignedBlock.spec.ts b/packages/types/src/rpc/SignedBlock.spec.ts index 15ebaa45b0..29e299b354 100644 --- a/packages/types/src/rpc/SignedBlock.spec.ts +++ b/packages/types/src/rpc/SignedBlock.spec.ts @@ -8,10 +8,12 @@ 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'; describe('SignedBlock', (): void => { beforeEach((): void => { + injectDefinitions(); Method.injectMethods(extrinsics); }); diff --git a/packages/types/src/rpc/SignedBlock.ts b/packages/types/src/rpc/SignedBlock.ts index 852d4bcc53..0be131869e 100644 --- a/packages/types/src/rpc/SignedBlock.ts +++ b/packages/types/src/rpc/SignedBlock.ts @@ -2,11 +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 { Justification } from '../srml/runtime/types'; import { AnyU8a } from '../types'; +import { ClassOf } from '../codec/createType'; import Struct from '../codec/Struct'; import Hash from '../primitive/Hash'; -import Justification from '../type/Justification'; import Block, { BlockValue } from './Block'; interface SignedBlockValue { @@ -23,7 +24,7 @@ export default class SignedBlock extends Struct { public constructor (value?: SignedBlockValue | Uint8Array) { super({ block: Block, - justification: Justification + justification: ClassOf('Justification') }, value); } diff --git a/packages/types/src/rpc/index.ts b/packages/types/src/rpc/index.ts index ef805975f0..4a935fc066 100644 --- a/packages/types/src/rpc/index.ts +++ b/packages/types/src/rpc/index.ts @@ -16,7 +16,6 @@ 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 PendingExtrinsics } from './PendingExtrinsics'; 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/srmlTS.ts b/packages/types/src/scripts/srmlTS.ts index e4af0ab629..f2ed8d3231 100644 --- a/packages/types/src/scripts/srmlTS.ts +++ b/packages/types/src/scripts/srmlTS.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import fs from 'fs'; -import { isString } from '@polkadot/util'; +import { isString, stringCamelCase, stringUpperFirst } from '@polkadot/util'; import { getTypeDef, TypeDef, TypeDefInfo, TypeDefExtVecFixed } from '../codec/createType'; import * as codecClasses from '../codec'; @@ -29,7 +29,6 @@ interface TypeImports { const HEADER = '/* eslint-disable @typescript-eslint/no-empty-interface */\n// Auto-generated via `yarn build:srmlTs`, do not edit\n\n'; const FOOTER = '\n'; -const OUTPUT_FILE = 'types.ts'; // Maps the types as found to the source location. This is used to generate the // imports in the output file, dep-duped and sorted @@ -58,6 +57,16 @@ function setImports ({ codecTypes, localTypes, ownTypes, primitiveTypes, substra }); } +// 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 `readonly : ;` getter +function createGetter (name: string = '', type: string): string { + return ` readonly ${name}: ${type};\n`; +} + // eslint-disable-next-line @typescript-eslint/no-unused-vars function errorUnhandled (def: TypeDef, imports: TypeImports): string { throw new Error(`Generate: ${name}: Unhandled type ${TypeDefInfo[def.info]}`); @@ -71,7 +80,7 @@ function tsCompact ({ name: compactName, sub }: TypeDef, imports: TypeImports): switch (def.info) { case TypeDefInfo.Plain: setImports(imports, [def.type]); - return `export interface ${compactName} extends Compact<${def.type}> {}`; + return createInterface(compactName, `Compact<${def.type}>`); default: throw new Error(`Enum: ${compactName}: Unhandled type ${TypeDefInfo[def.info]}`); @@ -81,21 +90,23 @@ function tsCompact ({ name: compactName, sub }: TypeDef, imports: TypeImports): function tsEnum ({ name: enumName, sub }: TypeDef, imports: TypeImports): string { setImports(imports, ['Enum']); - const keys = (sub as TypeDef[]).map(({ info, name, type }, index): string => { + const keys = (sub as TypeDef[]).map(({ info, name = '', type }, index): string => { + const getter = stringUpperFirst(stringCamelCase(name.replace(' ', '_'))); const [enumType, asGetter] = type === 'Null' ? ['', ''] - : [`(${type})`, ` readonly as${name}: ${type};\n`]; + : [`(${type})`, createGetter(`as${getter}`, type)]; + const isGetter = createGetter(`is${getter}`, 'boolean'); switch (info) { case TypeDefInfo.Plain: - return ` /**\n * @description ${index}:: ${name}${enumType}\n */\n readonly is${name}: boolean;\n${asGetter}`; + return ` /**\n * @description ${index}:: ${name}${enumType}\n */\n${isGetter}${asGetter}`; default: throw new Error(`Enum: ${enumName}: Unhandled type ${TypeDefInfo[info]}`); } }); - return `export interface ${enumName} extends Enum {\n${keys.join('')}}`; + return createInterface(enumName, 'Enum', keys.join('')); } function tsOption ({ name: optionName, sub }: TypeDef, imports: TypeImports): string { @@ -106,7 +117,7 @@ function tsOption ({ name: optionName, sub }: TypeDef, imports: TypeImports): st switch (def.info) { case TypeDefInfo.Plain: setImports(imports, [def.type]); - return `export interface ${optionName} extends Option<${def.type}> {}`; + return createInterface(optionName, `Option<${def.type}>`); default: throw new Error(`Enum: ${optionName}: Unhandled type ${TypeDefInfo[def.info]}`); @@ -116,7 +127,7 @@ function tsOption ({ name: optionName, sub }: TypeDef, imports: TypeImports): st function tsPlain ({ name: plainName, type }: TypeDef, imports: TypeImports): string { setImports(imports, [type]); - return `export interface ${plainName} extends ${type} {}`; + return createInterface(plainName, type); } function _tsStructGetterType (structName: string | undefined, { info, sub, type }: TypeDef, imports: TypeImports): [string, string] { @@ -158,21 +169,39 @@ function tsStruct ({ name: structName, sub }: TypeDef, imports: TypeImports): st setImports(imports, ['Struct', embedType]); - return ` readonly ${typedef.name}: ${returnType};\n`; + return createGetter(typedef.name, returnType); }); - return `export interface ${structName} extends Struct {\n${keys.join('')}}`; + return createInterface(structName, 'Struct', keys.join('')); +} + +function _tsTupleGetterType (tupleName: string | undefined, { info, sub, type }: TypeDef, imports: TypeImports): string { + switch (info) { + case TypeDefInfo.Option: + setImports(imports, ['Option', (sub as TypeDef).type]); + + return type; + + case TypeDefInfo.Plain: + setImports(imports, [type]); + + return type; + + default: + throw new Error(`Struct: ${tupleName}: Unhandled type ${TypeDefInfo[info]}`); + } } function tsTuple ({ name: tupleName, sub }: TypeDef, imports: TypeImports): string { - const types = (sub as TypeDef[]).map(({ type }): string => { - setImports(imports, ['Tuple', type]); + setImports(imports, ['Tuple']); - return type; - }); + 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(', ')}];\nexport interface ${tupleName} extends Codec, _${tupleName} {}`; + return `type _${tupleName} = [${types.join(', ')}];\n${exp}`; } function tsVector ({ ext, info, name: vectorName, sub }: TypeDef, imports: TypeImports): string { @@ -182,7 +211,7 @@ function tsVector ({ ext, info, name: vectorName, sub }: TypeDef, imports: TypeI setImports(imports, ['Vector', type]); - return `export interface ${vectorName} extends Vector<${type}> {}`; + return createInterface(vectorName, `Vector<${type}>`); } // creates the import lines @@ -253,7 +282,7 @@ function generateTsDef (srmlName: string, { types }: { types: Record { @@ -261,3 +290,7 @@ Object.entries(definitions).forEach(([srmlName, obj]): void => { generateTsDef(srmlName, obj); }); + +console.log(`Writing srml/types.ts`); + +fs.writeFileSync(`packages/types/src/srml/types.ts`, HEADER.concat(Object.keys(definitions).map((moduleName): string => `export * from './${moduleName}/types';`).join('\n')).concat(FOOTER), { flag: 'w' }); diff --git a/packages/types/src/srml/authorship/definitions.ts b/packages/types/src/srml/authorship/definitions.ts new file mode 100644 index 0000000000..f4f5f5a8fd --- /dev/null +++ b/packages/types/src/srml/authorship/definitions.ts @@ -0,0 +1,16 @@ +// 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: { + InclusionHeight: 'BlockNumber', + Uncle: '(Hash, Option)', + UncleEntryItem: { + _enum: { + InclusionHeight: 'InclusionHeight', + Uncle: 'Uncle' + } + } + } +}; diff --git a/packages/types/src/srml/authorship/types.ts b/packages/types/src/srml/authorship/types.ts new file mode 100644 index 0000000000..70d788de23 --- /dev/null +++ b/packages/types/src/srml/authorship/types.ts @@ -0,0 +1,25 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Codec } from '../../types'; +import { Enum, Option } from '../../codec'; +import { AccountId, Hash } from '../../primitive'; +import { BlockNumber } from '../../type'; + +export interface InclusionHeight extends BlockNumber {} + +type _Uncle = [Hash, Option]; +export interface Uncle extends Codec, _Uncle {} + +export interface UncleEntryItem extends Enum { + /** + * @description 0:: InclusionHeight(InclusionHeight) + */ + readonly isInclusionHeight: boolean; + readonly asInclusionHeight: InclusionHeight; + /** + * @description 1:: Uncle(Uncle) + */ + readonly isUncle: boolean; + readonly asUncle: Uncle; +} diff --git a/packages/types/src/srml/balances/definitions.ts b/packages/types/src/srml/balances/definitions.ts new file mode 100644 index 0000000000..498ecb7cc5 --- /dev/null +++ b/packages/types/src/srml/balances/definitions.ts @@ -0,0 +1,18 @@ +// 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: { + BalanceLock: { + id: 'LockIdentifier', + amount: 'Balance', + until: 'BlockNumber', + reasons: 'WithdrawReasons' + }, + VestingSchedule: { + offset: 'Balance', + perBlock: 'Balance' + } + } +}; diff --git a/packages/types/src/srml/balances/types.ts b/packages/types/src/srml/balances/types.ts new file mode 100644 index 0000000000..a037a1c900 --- /dev/null +++ b/packages/types/src/srml/balances/types.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Struct } from '../../codec'; +import { Balance } from '../../primitive'; +import { BlockNumber, WithdrawReasons } from '../../type'; +import { LockIdentifier } from '../runtime/types'; + +export interface BalanceLock extends Struct { + readonly id: LockIdentifier; + readonly amount: Balance; + readonly until: BlockNumber; + readonly reasons: WithdrawReasons; +} + +export interface VestingSchedule extends Struct { + readonly offset: Balance; + readonly perBlock: Balance; +} diff --git a/packages/types/src/srml/collective/definitions.ts b/packages/types/src/srml/collective/definitions.ts new file mode 100644 index 0000000000..494dfeb9b4 --- /dev/null +++ b/packages/types/src/srml/collective/definitions.ts @@ -0,0 +1,16 @@ +// 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: { + MemberCount: 'u64', + ProposalIndex: 'u32', + Votes: { + index: 'ProposalIndex', + threshold: 'MemberCount', + ayes: 'Vec', + nays: 'Vec' + } + } +}; diff --git a/packages/types/src/srml/collective/types.ts b/packages/types/src/srml/collective/types.ts new file mode 100644 index 0000000000..54437a9a65 --- /dev/null +++ b/packages/types/src/srml/collective/types.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Struct, Vector } from '../../codec'; +import { AccountId, u32, u64 } from '../../primitive'; + +export interface MemberCount extends u64 {} + +export interface ProposalIndex extends u32 {} + +export interface Votes extends Struct { + readonly index: ProposalIndex; + readonly threshold: MemberCount; + readonly ayes: Vector; + readonly nays: Vector; +} diff --git a/packages/types/src/type/EraIndex.ts b/packages/types/src/srml/consensus/definitions.ts similarity index 56% rename from packages/types/src/type/EraIndex.ts rename to packages/types/src/srml/consensus/definitions.ts index eade93ca50..cde145513d 100644 --- a/packages/types/src/type/EraIndex.ts +++ b/packages/types/src/srml/consensus/definitions.ts @@ -2,12 +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 U32 from '../primitive/U32'; - -/** - * @name EraIndex - * @description - * Index type of eras - */ -export default class EraIndex extends U32 { -} +export default { + types: { + AuthorityId: 'AccountId' + } +}; diff --git a/packages/types/src/srml/consensus/types.ts b/packages/types/src/srml/consensus/types.ts new file mode 100644 index 0000000000..15a3d68aba --- /dev/null +++ b/packages/types/src/srml/consensus/types.ts @@ -0,0 +1,6 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { AccountId } from '../../primitive'; + +export interface AuthorityId extends AccountId {} diff --git a/packages/types/src/srml/contracts/definitions.ts b/packages/types/src/srml/contracts/definitions.ts index 4def409b02..270c85a3cd 100644 --- a/packages/types/src/srml/contracts/definitions.ts +++ b/packages/types/src/srml/contracts/definitions.ts @@ -47,6 +47,7 @@ export default { maxMemoryPages: 'u32', enablePrintln: 'Bool', maxSubjectLen: 'u32' - } + }, + SeedOf: 'Hash' } }; diff --git a/packages/types/src/srml/contracts/types.ts b/packages/types/src/srml/contracts/types.ts index 684e46f419..128e10e2a5 100644 --- a/packages/types/src/srml/contracts/types.ts +++ b/packages/types/src/srml/contracts/types.ts @@ -61,6 +61,8 @@ export interface Schedule extends Struct { readonly maxSubjectLen: u32; } +export interface SeedOf extends Hash {} + export interface TombstoneContractInfo extends Hash {} export interface TrieId extends Bytes {} diff --git a/packages/types/src/srml/definitions.ts b/packages/types/src/srml/definitions.ts index eb6350af44..f30a37319c 100644 --- a/packages/types/src/srml/definitions.ts +++ b/packages/types/src/srml/definitions.ts @@ -6,15 +6,32 @@ // layers can re-use types from higher layers as this is being injected. The // injection order is critical. -// session before grandpa, ImOnline +// first do the deprecated types, these should be self-standing +export { default as deprecated } from './deprecated/definitions'; + +// runtime before balances, session +export { default as runtime } from './runtime/definitions'; + +// consensus before grandpa, imOnline +export { default as consensus } from './consensus/definitions'; + +// session before imOnline export { default as session } from './session/definitions'; // grandpa before parachains export { default as grandpa } from './grandpa/definitions'; -// remaining, alphabetical odering -export { default as babe } from './babe/definitions'; -export { default as contracts } from './contracts/definitions'; +// elections before democracy export { default as elections } from './elections/definitions'; + +// remaining, alphabetical odering +export { default as authorship } from './authorship/definitions'; +export { default as babe } from './babe/definitions'; +export { default as balances } from './balances/definitions'; +export { default as collective } from './collective/definitions'; +export { default as contracts } from './contracts/definitions'; +export { default as democracy } from './democracy/definitions'; export { default as imOnline } from './imOnline/definitions'; export { default as parachains } from './parachains/definitions'; +export { default as staking } from './staking/definitions'; +export { default as treasury } from './treasury/definitions'; diff --git a/packages/types/src/srml/democracy/definitions.ts b/packages/types/src/srml/democracy/definitions.ts new file mode 100644 index 0000000000..d95ebb0693 --- /dev/null +++ b/packages/types/src/srml/democracy/definitions.ts @@ -0,0 +1,33 @@ +// 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: { + Conviction: { + _enum: [ + // 0.1x votes, unlocked. + 'None', + // 1x votes, locked for an enactment period following a successful vote. + 'Locked1x', + // 2x votes, locked for 2x enactment periods following a successful vote. + 'Locked2x', + // 3x votes, locked for 4x... + 'Locked3x', + // 4x votes, locked for 8x... + 'Locked4x', + // 5x votes, locked for 16x... + 'Locked5x' + ] + }, + PropIndex: 'u32', + Proposal: 'Method', + ReferendumIndex: 'u32', + ReferendumInfo: { + end: 'BlockNumber', + proposal: 'Proposal', + threshold: 'VoteThreshold', + delay: 'BlockNumber' + } + } +}; diff --git a/packages/types/src/srml/democracy/types.ts b/packages/types/src/srml/democracy/types.ts new file mode 100644 index 0000000000..f0c723ea15 --- /dev/null +++ b/packages/types/src/srml/democracy/types.ts @@ -0,0 +1,47 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Enum, Struct } from '../../codec'; +import { Method, u32 } from '../../primitive'; +import { BlockNumber } from '../../type'; +import { VoteThreshold } from '../elections/types'; + +export interface Conviction extends Enum { + /** + * @description 0:: None + */ + readonly isNone: boolean; + /** + * @description 1:: Locked1x + */ + readonly isLocked1X: boolean; + /** + * @description 2:: Locked2x + */ + readonly isLocked2X: boolean; + /** + * @description 3:: Locked3x + */ + readonly isLocked3X: boolean; + /** + * @description 4:: Locked4x + */ + readonly isLocked4X: boolean; + /** + * @description 5:: Locked5x + */ + readonly isLocked5X: boolean; +} + +export interface PropIndex extends u32 {} + +export interface Proposal extends Method {} + +export interface ReferendumIndex extends u32 {} + +export interface ReferendumInfo extends Struct { + readonly end: BlockNumber; + readonly proposal: Proposal; + readonly threshold: VoteThreshold; + readonly delay: BlockNumber; +} diff --git a/packages/types/src/srml/deprecated/definitions.ts b/packages/types/src/srml/deprecated/definitions.ts new file mode 100644 index 0000000000..1f1c243c4d --- /dev/null +++ b/packages/types/src/srml/deprecated/definitions.ts @@ -0,0 +1,30 @@ +// 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: { + // Metadata v0 + NewAccountOutcome: { + _enum: ['NoHint', 'GoodHint', 'BadHint'] + }, + + // Metadata v1 + // :: fees + Amount: 'Balance', + AssetOf: 'u32', + + // Metadata v3 + // :: democracy + LockPeriods: 'i8', + + // Metadata v4 + // :: consensus + InherentOfflineReport: 'Null', // this is '()' originally (we don't handle that) + SessionKey: 'AccountId', + + // Metadata v5 + // :: session + OpaqueKey: 'Bytes' + } +}; diff --git a/packages/types/src/srml/deprecated/types.ts b/packages/types/src/srml/deprecated/types.ts new file mode 100644 index 0000000000..7684d1f0f5 --- /dev/null +++ b/packages/types/src/srml/deprecated/types.ts @@ -0,0 +1,32 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Enum } from '../../codec'; +import { AccountId, Balance, Bytes, Null, i8, u32 } from '../../primitive'; + +export interface Amount extends Balance {} + +export interface AssetOf extends u32 {} + +export interface InherentOfflineReport extends Null {} + +export interface LockPeriods extends i8 {} + +export interface NewAccountOutcome extends Enum { + /** + * @description 0:: NoHint + */ + readonly isNoHint: boolean; + /** + * @description 1:: GoodHint + */ + readonly isGoodHint: boolean; + /** + * @description 2:: BadHint + */ + readonly isBadHint: boolean; +} + +export interface OpaqueKey extends Bytes {} + +export interface SessionKey extends AccountId {} diff --git a/packages/types/src/srml/elections/definitions.ts b/packages/types/src/srml/elections/definitions.ts index 012052d447..be8dc92adf 100644 --- a/packages/types/src/srml/elections/definitions.ts +++ b/packages/types/src/srml/elections/definitions.ts @@ -4,6 +4,21 @@ export default { types: { - SetIndex: 'u32' + ApprovalFlag: 'u32', + SetIndex: 'u32', + VoteIndex: 'u32', + VoterInfo: { + lastActive: 'VoteIndex', + lastWin: 'VoteIndex', + pot: 'Balance', + stake: 'Balance' + }, + VoteThreshold: { + _enum: [ + 'Super majority approval', + 'Super majority rejection', + 'Simple majority' + ] + } } }; diff --git a/packages/types/src/srml/elections/types.ts b/packages/types/src/srml/elections/types.ts index 2b9768f35f..e283a54502 100644 --- a/packages/types/src/srml/elections/types.ts +++ b/packages/types/src/srml/elections/types.ts @@ -1,6 +1,33 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { u32 } from '../../primitive'; +import { Enum, Struct } from '../../codec'; +import { Balance, u32 } from '../../primitive'; + +export interface ApprovalFlag extends u32 {} export interface SetIndex extends u32 {} + +export interface VoteIndex extends u32 {} + +export interface VoterInfo extends Struct { + readonly lastActive: VoteIndex; + readonly lastWin: VoteIndex; + readonly pot: Balance; + readonly stake: Balance; +} + +export interface VoteThreshold extends Enum { + /** + * @description 0:: Super majority approval + */ + readonly isSuperMajorityApproval: boolean; + /** + * @description 1:: Super majority rejection + */ + readonly isSuperMajorityRejection: boolean; + /** + * @description 2:: Simple majority + */ + readonly isSimpleMajority: boolean; +} diff --git a/packages/types/src/srml/grandpa/definitions.ts b/packages/types/src/srml/grandpa/definitions.ts index 6bc8d2f344..69340898ae 100644 --- a/packages/types/src/srml/grandpa/definitions.ts +++ b/packages/types/src/srml/grandpa/definitions.ts @@ -5,7 +5,7 @@ export default { types: { AuthorityWeight: 'u64', - NextAuthority: '(SessionKey, u64)', + NextAuthority: '(AuthorityId, u64)', PendingPause: { /// Block at which the intention to pause was scheduled. scheduledAt: 'BlockNumber', diff --git a/packages/types/src/srml/grandpa/types.ts b/packages/types/src/srml/grandpa/types.ts index 161437329d..bfd491c48b 100644 --- a/packages/types/src/srml/grandpa/types.ts +++ b/packages/types/src/srml/grandpa/types.ts @@ -5,11 +5,11 @@ import { Codec } from '../../types'; import { Enum, Struct, Vector } from '../../codec'; import { u64 } from '../../primitive'; import { BlockNumber } from '../../type'; -import { SessionKey } from '../session/types'; +import { AuthorityId } from '../consensus/types'; export interface AuthorityWeight extends u64 {} -type _NextAuthority = [SessionKey, u64]; +type _NextAuthority = [AuthorityId, u64]; export interface NextAuthority extends Codec, _NextAuthority {} export interface PendingPause extends Struct { diff --git a/packages/types/src/srml/imOnline/types.ts b/packages/types/src/srml/imOnline/types.ts index c1ee9094a2..5b52852201 100644 --- a/packages/types/src/srml/imOnline/types.ts +++ b/packages/types/src/srml/imOnline/types.ts @@ -3,7 +3,8 @@ import { Struct, Vector } from '../../codec'; import { Bytes } from '../../primitive'; -import { AuthorityId, BlockNumber } from '../../type'; +import { BlockNumber } from '../../type'; +import { AuthorityId } from '../consensus/types'; import { SessionIndex } from '../session/types'; export interface Heartbeat extends Struct { diff --git a/packages/types/src/srml/parachains/definitions.ts b/packages/types/src/srml/parachains/definitions.ts index fc17a783d9..0d4d18dbd7 100644 --- a/packages/types/src/srml/parachains/definitions.ts +++ b/packages/types/src/srml/parachains/definitions.ts @@ -6,7 +6,6 @@ export default { types: { AuctionIndex: 'u32', CollatorSignature: 'Signature', - AvailabilityVote: '(SessionKey, CollatorSignature)', ValidityAttestation: { _enum: { // This Null is not in the original, however indexes start at 1, so add a @@ -18,7 +17,8 @@ export default { }, ParaId: 'u32', ParaIdOf: 'ParaId', - ValidityVote: '(AccountId, ValidityAttestation)', + ValidatorIndex: 'u32', + ValidityVote: '(ValidatorIndex, ValidityAttestation)', BalanceUpload: '(AccountId, u64)', EgressQueueRoot: '(ParaId, Hash)', HeadData: 'Bytes', @@ -34,8 +34,7 @@ export default { }, AttestedCandidate: { candidate: 'CandidateReceipt', - validityVotes: 'Vec', - availabilityVotes: 'Vec' + validityVotes: 'Vec' }, SubId: 'u32', NewBidder: { diff --git a/packages/types/src/srml/parachains/types.ts b/packages/types/src/srml/parachains/types.ts index f362db3cb9..a023f61207 100644 --- a/packages/types/src/srml/parachains/types.ts +++ b/packages/types/src/srml/parachains/types.ts @@ -5,19 +5,14 @@ import { Codec } from '../../types'; import { Enum, Struct, Vector } from '../../codec'; import { AccountId, BalanceOf, Bytes, Hash, Signature, u32, u64 } from '../../primitive'; import { BlockNumber } from '../../type'; -import { SessionKey } from '../session/types'; export interface AttestedCandidate extends Struct { readonly candidate: CandidateReceipt; readonly validityVotes: Vector; - readonly availabilityVotes: Vector; } export interface AuctionIndex extends u32 {} -type _AvailabilityVote = [SessionKey, CollatorSignature]; -export interface AvailabilityVote extends Codec, _AvailabilityVote {} - type _BalanceUpload = [AccountId, u64]; export interface BalanceUpload extends Codec, _BalanceUpload {} @@ -154,6 +149,8 @@ export interface UpwardMessage extends Struct { readonly data: Bytes; } +export interface ValidatorIndex extends u32 {} + export interface ValidityAttestation extends Enum { /** * @description 0:: None @@ -171,7 +168,7 @@ export interface ValidityAttestation extends Enum { readonly asExplicit: CollatorSignature; } -type _ValidityVote = [AccountId, ValidityAttestation]; +type _ValidityVote = [ValidatorIndex, ValidityAttestation]; export interface ValidityVote extends Codec, _ValidityVote {} export interface WinningData extends Vector {} diff --git a/packages/types/src/srml/runtime/definitions.ts b/packages/types/src/srml/runtime/definitions.ts new file mode 100644 index 0000000000..a8f052e548 --- /dev/null +++ b/packages/types/src/srml/runtime/definitions.ts @@ -0,0 +1,15 @@ +// 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: { + Justification: 'Bytes', + KeyTypeId: 'u32', + LockIdentifier: '[u8; 8]', + SessionKeys: { + ed25519: 'AccountId' + }, + ValidatorId: 'AccountId' + } +}; diff --git a/packages/types/src/srml/runtime/types.ts b/packages/types/src/srml/runtime/types.ts new file mode 100644 index 0000000000..e29c73cb9c --- /dev/null +++ b/packages/types/src/srml/runtime/types.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Struct, Vector } from '../../codec'; +import { AccountId, Bytes, u32, u8 } from '../../primitive'; + +export interface Justification extends Bytes {} + +export interface KeyTypeId extends u32 {} + +export interface LockIdentifier extends Vector {} + +export interface SessionKeys extends Struct { + readonly ed25519: AccountId; +} + +export interface ValidatorId extends AccountId {} diff --git a/packages/types/src/srml/session/definitions.ts b/packages/types/src/srml/session/definitions.ts index a8415cf3dd..c7ae5bcf46 100644 --- a/packages/types/src/srml/session/definitions.ts +++ b/packages/types/src/srml/session/definitions.ts @@ -5,21 +5,6 @@ export default { types: { SessionIndex: 'u32', - SessionKey: 'AuthorityId', - SessionKeys: { - ed25519: 'SessionKey' - }, - Keys: 'SessionKeys', - - // this needs to be moved to primitives (runtime, support) - KeyTypeId: 'u32', - - // this needs to be in staking - EraRewards: { - // Total number of points. Equals the sum of reward points for each validator. - total: 'u32', - // Reward at one index correspond to reward for validator in current_elected of this index. This this reward vec is only valid for one elected set. - rewards: 'Vec' - } + Keys: 'SessionKeys' } }; diff --git a/packages/types/src/srml/session/types.ts b/packages/types/src/srml/session/types.ts index 1bc21a2726..4d9928f360 100644 --- a/packages/types/src/srml/session/types.ts +++ b/packages/types/src/srml/session/types.ts @@ -1,23 +1,9 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ // Auto-generated via `yarn build:srmlTs`, do not edit -import { Struct, Vector } from '../../codec'; import { u32 } from '../../primitive'; -import { AuthorityId } from '../../type'; - -export interface EraRewards extends Struct { - readonly total: u32; - readonly rewards: Vector; -} +import { SessionKeys } from '../runtime/types'; export interface Keys extends SessionKeys {} -export interface KeyTypeId extends u32 {} - export interface SessionIndex extends u32 {} - -export interface SessionKey extends AuthorityId {} - -export interface SessionKeys extends Struct { - readonly ed25519: SessionKey; -} diff --git a/packages/types/src/srml/staking/definitions.ts b/packages/types/src/srml/staking/definitions.ts new file mode 100644 index 0000000000..1d06d9a1e1 --- /dev/null +++ b/packages/types/src/srml/staking/definitions.ts @@ -0,0 +1,38 @@ +// 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: { + EraIndex: 'u32', + EraRewards: { + // Total number of points. Equals the sum of reward points for each validator. + total: 'u32', + // Reward at one index correspond to reward for validator in current_elected of this index. This this reward vec is only valid for one elected set. + rewards: 'Vec' + }, + IndividualExposure: { + who: 'AccountId', + value: 'Compact' + }, + Exposure: { + total: 'Compact', + own: 'Compact', + others: 'Vec' + }, + RewardDestination: { + _enum: [ + // Pay into the stash account, increasing the amount at stake accordingly. + 'Staked', + // Pay into the stash account, not increasing the amount at stake. + 'Stash', + // Pay into the controller account. + 'Controller' + ] + }, + ValidatorPrefs: { + unstakeThreshold: 'Compact', + validatorPayment: 'Compact' + } + } +}; diff --git a/packages/types/src/srml/staking/types.ts b/packages/types/src/srml/staking/types.ts new file mode 100644 index 0000000000..357783a5f3 --- /dev/null +++ b/packages/types/src/srml/staking/types.ts @@ -0,0 +1,43 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Compact, Enum, Struct, Vector } from '../../codec'; +import { AccountId, Balance, u32 } from '../../primitive'; + +export interface EraIndex extends u32 {} + +export interface EraRewards extends Struct { + readonly total: u32; + readonly rewards: Vector; +} + +export interface Exposure extends Struct { + readonly total: Compact; + readonly own: Compact; + readonly others: Vector; +} + +export interface IndividualExposure extends Struct { + readonly who: AccountId; + readonly value: Compact; +} + +export interface RewardDestination extends Enum { + /** + * @description 0:: Staked + */ + readonly isStaked: boolean; + /** + * @description 1:: Stash + */ + readonly isStash: boolean; + /** + * @description 2:: Controller + */ + readonly isController: boolean; +} + +export interface ValidatorPrefs extends Struct { + readonly unstakeThreshold: Compact; + readonly validatorPayment: Compact; +} diff --git a/packages/types/src/type/VoteIndex.ts b/packages/types/src/srml/treasury/definitions.ts similarity index 52% rename from packages/types/src/type/VoteIndex.ts rename to packages/types/src/srml/treasury/definitions.ts index 580554baf9..0c12ca0b91 100644 --- a/packages/types/src/type/VoteIndex.ts +++ b/packages/types/src/srml/treasury/definitions.ts @@ -2,12 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import U32 from '../primitive/U32'; - -/** - * @name VoteIndex - * @description - * Voting index, implemented as a [[U32]] - */ -export default class VoteIndex extends U32 { -} +export default { + types: { + TreasuryProposal: { + proposer: 'AccountId', + value: 'Balance', + beneficiary: 'AccountId', + bond: 'Balance' + } + } +}; diff --git a/packages/types/src/srml/treasury/types.ts b/packages/types/src/srml/treasury/types.ts new file mode 100644 index 0000000000..89a8faa668 --- /dev/null +++ b/packages/types/src/srml/treasury/types.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit + +import { Struct } from '../../codec'; +import { AccountId, Balance } from '../../primitive'; + +export interface TreasuryProposal extends Struct { + readonly proposer: AccountId; + readonly value: Balance; + readonly beneficiary: AccountId; + readonly bond: Balance; +} diff --git a/packages/types/src/srml/types.ts b/packages/types/src/srml/types.ts index 81bca109e1..68a7e60eea 100644 --- a/packages/types/src/srml/types.ts +++ b/packages/types/src/srml/types.ts @@ -1,13 +1,19 @@ -// 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. +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated via `yarn build:srmlTs`, do not edit -// keep ordering here exactly the same as definitions +export * from './deprecated/types'; +export * from './runtime/types'; +export * from './consensus/types'; export * from './session/types'; export * from './grandpa/types'; - -export * from './babe/types'; -export * from './contracts/types'; export * from './elections/types'; +export * from './authorship/types'; +export * from './babe/types'; +export * from './balances/types'; +export * from './collective/types'; +export * from './contracts/types'; +export * from './democracy/types'; export * from './imOnline/types'; export * from './parachains/types'; +export * from './staking/types'; +export * from './treasury/types'; diff --git a/packages/types/src/type/Amount.ts b/packages/types/src/type/Amount.ts deleted file mode 100644 index ab2f394231..0000000000 --- a/packages/types/src/type/Amount.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 Balance from '../primitive/Balance'; - -/** - * @name Amount - * @description - * The Substrate Amount representation as a [[Balance]]. - */ -export default class Amount extends Balance { -} diff --git a/packages/types/src/type/ApprovalFlag.ts b/packages/types/src/type/ApprovalFlag.ts deleted file mode 100644 index 7b51d54253..0000000000 --- a/packages/types/src/type/ApprovalFlag.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 U32 from '../primitive/U32'; - -/** - * @name ApprovalFlag - * @description - * Approval Flag, implemented as a [[U32]] - */ -export default class ApprovalFlag extends U32 { -} diff --git a/packages/types/src/type/AssetOf.ts b/packages/types/src/type/AssetOf.ts deleted file mode 100644 index 6eb28b9923..0000000000 --- a/packages/types/src/type/AssetOf.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 Balance from '../primitive/Balance'; - -/** - * @name AssetOf - * @description - * The Substrate AssetOf representation as a [[Balance]]. - */ -export default class AssetOf extends Balance { -} diff --git a/packages/types/src/type/AuthorityId.ts b/packages/types/src/type/AuthorityId.ts deleted file mode 100644 index bdbbeb5fbe..0000000000 --- a/packages/types/src/type/AuthorityId.ts +++ /dev/null @@ -1,11 +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 AccountId from '../primitive/AccountId'; - -// Wrapper for a AuthorityId. Same as an normal AccountId, i.e. a wrapper -// around publicKey, however specialized since it specifically points to -// an authority. -export default class AuthorityId extends AccountId { -} diff --git a/packages/types/src/type/BalanceLock.ts b/packages/types/src/type/BalanceLock.ts deleted file mode 100644 index 8944e55ba5..0000000000 --- a/packages/types/src/type/BalanceLock.ts +++ /dev/null @@ -1,53 +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 Balance from '../primitive/Balance'; -import BlockNumber from './BlockNumber'; -import LockIdentifier from './LockIdentifier'; -import WithdrawReasons from './WithdrawReasons'; - -/** - * @name BalanceLock - * @description - * The Substrate BalanceLock for staking - */ -export default class BalanceLock extends Struct { - public constructor (value?: any) { - super({ - id: LockIdentifier, - amount: Balance, - until: BlockNumber, - reasons: WithdrawReasons - }, value); - } - - /** - * @description The amount - */ - public get amount (): Balance { - return this.get('amount') as Balance; - } - - /** - * @description The lock id - */ - public get id (): LockIdentifier { - return this.get('id') as LockIdentifier; - } - - /** - * @description The reasons - */ - public get reasons (): WithdrawReasons { - return this.get('reasons') as WithdrawReasons; - } - - /** - * @description Until when this is available - */ - public get until (): BlockNumber { - return this.get('until') as BlockNumber; - } -} diff --git a/packages/types/src/type/Bft.spec.ts b/packages/types/src/type/Bft.spec.ts deleted file mode 100644 index 58992c0786..0000000000 --- a/packages/types/src/type/Bft.spec.ts +++ /dev/null @@ -1,35 +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 { BftAuthoritySignature, BftHashSignature } from './Bft'; - -describe('BftAuthoritySignature', (): void => { - const sig = new BftAuthoritySignature([ - '0x12344321', - '0x567890098765' - ]); - - it('has the correct authorityId', (): void => { - expect(sig.authorityId.toHex()).toEqual('0x1234432100000000000000000000000000000000000000000000000000000000'); - }); - - it('has the correct signature', (): void => { - expect(sig.signature.toHex()).toEqual('0x56789009876500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'); - }); -}); - -describe('BftHashSignature', (): void => { - const sig = new BftHashSignature([ - '0x12344321', - '0x567890098765' - ]); - - it('has the correct hash', (): void => { - expect(sig.hash.toHex()).toEqual('0x1234432100000000000000000000000000000000000000000000000000000000'); - }); - - it('has the correct signature', (): void => { - expect(sig.signature.toHex()).toEqual('0x56789009876500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'); - }); -}); diff --git a/packages/types/src/type/Bft.ts b/packages/types/src/type/Bft.ts deleted file mode 100644 index 92bf6d9131..0000000000 --- a/packages/types/src/type/Bft.ts +++ /dev/null @@ -1,72 +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 Tuple from '../codec/Tuple'; -import Hash from '../primitive/Hash'; -import Signature from '../primitive/Signature'; -import AuthorityId from './AuthorityId'; - -export type BftAuthoritySignatureValue = [AnyU8a, AnyU8a]; - -/** - * @name BftAuthoritySignature - * @description - * Represents a Bft Hash and Signature pairing, typically used in reporting - * network behaviour. - */ -export class BftAuthoritySignature extends Tuple { - public constructor (value?: BftAuthoritySignatureValue | Uint8Array) { - super({ - AuthorityId, - Signature - }, value); - } - - /** - * @description The wrapped [[AuthoriyId]] - */ - public get authorityId (): AuthorityId { - return this[0] as AuthorityId; - } - - /** - * @description The wrapped [[Signature]] value - */ - public get signature (): Signature { - return this[1] as Signature; - } -} - -export type BftHashSignatureValue = [AnyU8a, AnyU8a]; - -/** - * @name BftHashSignature - * @description - * Represents a Bft Hash and Signature pairing, typically used in reporting - * network behaviour. - */ -export class BftHashSignature extends Tuple { - public constructor (value?: BftHashSignatureValue | Uint8Array) { - super({ - Hash, - Signature - }, value); - } - - /** - * @description The wrapped [[Hash]] - */ - public get hash (): Hash { - return this[0] as Hash; - } - - /** - * @description The wrapped [[Signature]] - */ - public get signature (): Signature { - return this[1] as Signature; - } -} diff --git a/packages/types/src/type/Conviction.ts b/packages/types/src/type/Conviction.ts deleted file mode 100644 index 564aeeb890..0000000000 --- a/packages/types/src/type/Conviction.ts +++ /dev/null @@ -1,29 +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 Enum from '../codec/Enum'; - -/** - * @name Conviction - * @description - * A value denoting the strength of conviction of a vote. - */ -export default class Conviction extends Enum { - public constructor (value: any) { - super([ - // 0.1x votes, unlocked. - 'None', - // 1x votes, locked for an enactment period following a successful vote. - 'Locked1x', - // 2x votes, locked for 2x enactment periods following a successful vote. - 'Locked2x', - // 3x votes, locked for 4x... - 'Locked3x', - // 4x votes, locked for 8x... - 'Locked4x', - // 5x votes, locked for 16x... - 'Locked5x' - ], value); - } -} diff --git a/packages/types/src/type/Exposure.ts b/packages/types/src/type/Exposure.ts deleted file mode 100644 index 7ecef6c24d..0000000000 --- a/packages/types/src/type/Exposure.ts +++ /dev/null @@ -1,45 +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 Compact from '../codec/Compact'; -import Struct from '../codec/Struct'; -import Vector from '../codec/Vector'; -import Balance from '../primitive/Balance'; -import IndividualExposure from './IndividualExposure'; - -/** - * @name Exposure - * @description - * A snapshot of the stake backing a single validator in the system - */ -export default class Exposure extends Struct { - public constructor (value?: any) { - super({ - total: Compact.with(Balance), - own: Compact.with(Balance), - others: Vector.with(IndividualExposure) - }, value); - } - - /** - * @description The validator's own stash that is exposed - */ - public get own (): Balance { - return (this.get('own') as Compact).unwrap(); - } - - /** - * @description The total balance backing this validator - */ - public get total (): Balance { - return (this.get('total') as Compact).unwrap(); - } - - /** - * @description The portions of nominators stashes that are exposed - */ - public get others (): Vector { - return this.get('others') as Vector; - } -} diff --git a/packages/types/src/type/Extrinsics.ts b/packages/types/src/type/Extrinsics.ts deleted file mode 100644 index dbcad7c1c8..0000000000 --- a/packages/types/src/type/Extrinsics.ts +++ /dev/null @@ -1,14 +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 Vector from '../codec/Vector'; -import Extrinsic from '../primitive/Extrinsic/Extrinsic'; - -/** - * @name Extrinsics - * @description - * A [[Vector]] of [[Extrinsic]] - */ -export default class Extrinsics extends Vector.with(Extrinsic) { -} diff --git a/packages/types/src/type/IndividualExposure.ts b/packages/types/src/type/IndividualExposure.ts deleted file mode 100644 index e367c4dd0f..0000000000 --- a/packages/types/src/type/IndividualExposure.ts +++ /dev/null @@ -1,36 +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 Compact from '../codec/Compact'; -import Struct from '../codec/Struct'; -import AccountId from '../primitive/AccountId'; -import Balance from '../primitive/Balance'; - -/** - * @name IndividualExposure - * @description - * The Substrate IndividualExposure for staking - */ -export default class IndividualExposure extends Struct { - public constructor (value?: any) { - super({ - who: AccountId, - value: Compact.with(Balance) - }, value); - } - - /** - * @description The value - */ - public get value (): Balance { - return (this.get('value') as Compact).unwrap(); - } - - /** - * @description The AccountId - */ - public get who (): AccountId { - return this.get('who') as AccountId; - } -} diff --git a/packages/types/src/type/InherentOfflineReport.ts b/packages/types/src/type/InherentOfflineReport.ts deleted file mode 100644 index d80c2de7b8..0000000000 --- a/packages/types/src/type/InherentOfflineReport.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 Tuple from '../codec/Tuple'; - -/** - * @name InherentOfflineReport - * @description - * Describes the offline-reporting extrinsic - */ -export default class InherentOfflineReport extends Tuple.with({}) { -} diff --git a/packages/types/src/type/Justification.spec.ts b/packages/types/src/type/Justification.spec.ts deleted file mode 100644 index 4f2c485ae0..0000000000 --- a/packages/types/src/type/Justification.spec.ts +++ /dev/null @@ -1,39 +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 rpc from '../json/SignedBlock.001.json'; -import { RhdJustification } from './Justification'; - -describe('RhdJustification', (): void => { - const just = new RhdJustification({ - roundNumber: 32, - hash: '0xabcd', - signatures: [ - ['0x1234', '0x5678'], - ['0x9876', '0x5432'] - ] - }); - - it('has the correct hash', (): void => { - expect(just.hash.toHex()).toEqual('0xabcd000000000000000000000000000000000000000000000000000000000000'); - }); - - it('has the correct round', (): void => { - expect(just.roundNumber.toNumber()).toEqual(32); - }); - - it('has the correct signatures', (): void => { - const sig = just.signatures[1]; - - expect(sig.authorityId.toHex()).toEqual('0x9876000000000000000000000000000000000000000000000000000000000000'); - }); - - it('creates from a JSON strusture', (): void => { - const viaRpc = new RhdJustification(rpc.result.justification); - - expect( - viaRpc.hash.toHex() - ).toEqual('0xfab4bb3a8b0a072d3d09858dc865ad2750b2e708536b6dacc89fad369eba781a'); - }); -}); diff --git a/packages/types/src/type/Justification.ts b/packages/types/src/type/Justification.ts deleted file mode 100644 index acd7afc9e6..0000000000 --- a/packages/types/src/type/Justification.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 { AnyNumber, AnyU8a } from '../types'; - -import Struct from '../codec/Struct'; -import Vector from '../codec/Vector'; -import Bytes from '../primitive/Bytes'; -import Hash from '../primitive/Hash'; -import U32 from '../primitive/U32'; -import { BftAuthoritySignature, BftAuthoritySignatureValue } from './Bft'; - -export interface RhdJustificationValue { - roundNumber?: AnyNumber; - hash?: AnyU8a; - signatures?: BftAuthoritySignatureValue[]; -} - -/** - * @name Justification - * @description - * A generic justification as a stream of [[Bytes]], this is specific per consensus implementation - */ -export default class Justification extends Bytes { -} - -/** - * @name RhdJustification - * @description - * [[Justification]] for the Rhododendron consensus algorithm - */ -export class RhdJustification extends Struct { - public constructor (value?: RhdJustificationValue | Uint8Array) { - super({ - roundNumber: U32, - hash: Hash, - signatures: Vector.with(BftAuthoritySignature) - }, value); - } - - /** - * @description The justification [[Hash]] - */ - public get hash (): Hash { - return this.get('hash') as Hash; - } - - /** - * @description The round this justification wraps as a [[U32]] - */ - public get roundNumber (): U32 { - return this.get('roundNumber') as U32; - } - - /** - * @description The [[BftAuthoritySignature]] array - */ - public get signatures (): Vector { - return this.get('signatures') as Vector; - } -} diff --git a/packages/types/src/type/LockIdentifier.ts b/packages/types/src/type/LockIdentifier.ts deleted file mode 100644 index 2629b56ecc..0000000000 --- a/packages/types/src/type/LockIdentifier.ts +++ /dev/null @@ -1,16 +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 U8aFixed from '../codec/U8aFixed'; - -/** - * @name LockIdentifier - * @description - * The Substrate LockIdentifier for staking - */ -export default class LockIdentifier extends U8aFixed { - public constructor (value?: any) { - super(value, 64); // [u8; 8] - } -} diff --git a/packages/types/src/type/LockPeriods.ts b/packages/types/src/type/LockPeriods.ts deleted file mode 100644 index 36eaaf0c3f..0000000000 --- a/packages/types/src/type/LockPeriods.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 I8 from '../primitive/I8'; - -/** - * @name LockPeriods - * @description - * A number of lock periods. - */ -export default class LockPeriods extends I8 { -} diff --git a/packages/types/src/type/MemberCount.ts b/packages/types/src/type/MemberCount.ts deleted file mode 100644 index 815c2b8349..0000000000 --- a/packages/types/src/type/MemberCount.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 U32 from '../primitive/U32'; - -/** - * @name MemberCount - * @description - * A number of council members as a [[U32]]. This also serves as a number of voting members, and since for motions, each council member may vote exactly once, therefore also the number of votes for any given motion.v - */ -export default class MemberCount extends U32 { -} diff --git a/packages/types/src/type/MisbehaviorReport.spec.ts b/packages/types/src/type/MisbehaviorReport.spec.ts deleted file mode 100644 index 32aef81ed1..0000000000 --- a/packages/types/src/type/MisbehaviorReport.spec.ts +++ /dev/null @@ -1,47 +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 MisbehaviorReport, { BftAtReport } from './MisbehaviorReport'; - -describe('BftAtReport', (): void => { - const report = new BftAtReport({ - round: 16, - a: ['0x1234', '0x5678'], - b: ['0x8765', '0x4321'] - }); - - it('has the correct round', (): void => { - expect(report.round.toNumber()).toEqual(16); - }); - - it('has the correct hash (a)', (): void => { - expect(report.a.hash.toHex()).toEqual('0x1234000000000000000000000000000000000000000000000000000000000000'); - }); - - it('has the correct signature (b)', (): void => { - expect(report.b.signature.toHex()).toEqual('0x43210000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'); - }); -}); - -describe('MisbehaviorReport', (): void => { - const report = new MisbehaviorReport({ - parentHash: '0x01020304', - parentNumber: 78, - target: '0x11112222', - misbehavior: 3 - }); - - it('has the correct misbehavior type', (): void => { - expect(report.misbehavior.type).toEqual('BftDoubleCommit'); - }); - - it('has the correct parent block', (): void => { - expect(report.parentHash.toHex()).toEqual('0x0102030400000000000000000000000000000000000000000000000000000000'); - expect(report.parentNumber.toNumber()).toEqual(78); - }); - - it('identifies the misbehaving authority', (): void => { - expect(report.target.toHex()).toEqual('0x1111222200000000000000000000000000000000000000000000000000000000'); - }); -}); diff --git a/packages/types/src/type/MisbehaviorReport.ts b/packages/types/src/type/MisbehaviorReport.ts deleted file mode 100644 index db2d84a9c3..0000000000 --- a/packages/types/src/type/MisbehaviorReport.ts +++ /dev/null @@ -1,247 +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 } from '../types'; - -import { assert } from '@polkadot/util'; - -import Enum from '../codec/Enum'; -import Struct from '../codec/Struct'; -import Hash from '../primitive/Hash'; -import U32 from '../primitive/U32'; -import AuthorityId from './AuthorityId'; -import { BftHashSignature, BftHashSignatureValue } from './Bft'; -import BlockNumber from './BlockNumber'; - -interface BftAtReportValueSingle { - round?: AnyNumber; - a?: BftHashSignatureValue; -} - -interface BftAtReportValue extends BftAtReportValueSingle { - b?: BftHashSignatureValue; -} - -/** - * @name BftAtReport - * @description - * A report of a/b hash-signature pairs for a specific index. This is the same - * structure as is used in BftDoublePrepare & BftDoubleCommit - */ -// FIXME It is not entirely obvious from the actual Rust code what the specific -// items in the structure is called, except a & b (one should be expected, the -// other actual) -export class BftAtReport extends Struct { - public constructor (value?: BftAtReportValue | Uint8Array) { - super({ - round: U32, - a: BftHashSignature, - b: BftHashSignature - }, value); - } - - /** - * @description The first report [[BftHashSignature]] - */ - public get a (): BftHashSignature { - return this.get('a') as BftHashSignature; - } - - /** - * @description The second report [[BftHashSignature]] - */ - public get b (): BftHashSignature { - return this.get('b') as BftHashSignature; - } - - /** - * @description The round this report applies to as [[U32]] - */ - public get round (): U32 { - return this.get('round') as U32; - } -} - -/** - * @name BftProposeOutOfTurn - * @description - * A report for out-of-turn proposals - */ -export class BftProposeOutOfTurn extends Struct { - public constructor (value?: BftAtReportValue | Uint8Array) { - super({ - round: U32, - a: BftHashSignature - }, value); - } - - /** - * @description The [[BftHashSignature]] the report applies to - */ - public get a (): BftHashSignature { - return this.get('a') as BftHashSignature; - } - - /** - * @description The round as [[u32]] - */ - public get round (): U32 { - return this.get('round') as U32; - } -} - -/** - * @name BftDoublePropose - * @description - * Report of a double-propose - */ -export class BftDoublePropose extends BftAtReport { -} - -/** - * @name BftDoublePrepare - * @description - * Report of a double-prepare - */ -export class BftDoublePrepare extends BftAtReport { -} - -/** - * @name BftDoubleCommit - * @description - * Report of a double-commit - */ -export class BftDoubleCommit extends BftAtReport { -} - -/** - * @name MisbehaviorKind - * @description - * An [[Enum]] containing a Bft misbehaviour - */ -export class MisbehaviorKind extends Enum { - public constructor (value?: BftAtReportValue | Uint8Array, index?: number) { - super({ - BftProposeOutOfTurn, - BftDoublePropose, - BftDoublePrepare, - BftDoubleCommit - }, value, index); - } - - /** - * @description Returns the item as a [[BftDoubleCommit]] - */ - public get asBftDoubleCommit (): BftDoubleCommit { - assert(this.isBftDoubleCommit, `Cannot convert '${this.type}' via asBftDoubleCommit`); - - return this.value as BftDoubleCommit; - } - - /** - * @description Returns the item as a [[BftDoublePrepare]] - */ - public get asBftDoublePrepare (): BftDoublePrepare { - assert(this.isBftDoublePrepare, `Cannot convert '${this.type}' via asBftDoublePrepare`); - - return this.value as BftDoublePrepare; - } - - /** - * @description Returns the item as a [[BftDoublePropose]] - */ - public get asBftDoublePropose (): BftDoublePropose { - assert(this.isBftDoublePropose, `Cannot convert '${this.type}' via asBftDoublePropose`); - - return this.value as BftDoublePropose; - } - - /** - * @description Returns the item as a [[BftProposeOutOfTurn]] - */ - public get asBftProposeOutOfTurn (): BftProposeOutOfTurn { - assert(this.isBftProposeOutOfTurn, `Cannot convert '${this.type}' via asBftProposeOutOfTurn`); - - return this.value as BftProposeOutOfTurn; - } - - /** - * @description true when this is a BftDoubleCommit - */ - public get isBftDoubleCommit (): boolean { - return this.type === 'BftDoubleCommit'; - } - - /** - * @description true when this is a BftDoublePrepare - */ - public get isBftDoublePrepare (): boolean { - return this.type === 'BftDoublePrepare'; - } - - /** - * @description true when this is a BftDoublePropose - */ - public get isBftDoublePropose (): boolean { - return this.type === 'BftDoublePropose'; - } - - /** - * @description true when this is a BftProposeOutOfTurn - */ - public get isBftProposeOutOfTurn (): boolean { - return this.type === 'BftProposeOutOfTurn'; - } -} - -interface MisbehaviorReportValue { - misbehavior?: MisbehaviorKind | number; - parentHash?: Hash | Uint8Array | string; - parentNumber?: AnyNumber; - target?: AuthorityId | string; -} - -/** - * @name MisbehaviorReport - * @description - * A Misbehaviour report of [[MisbehavioirKind]] against a specific [[AuthorityId]] - */ -export default class MisbehaviorReport extends Struct { - public constructor (value?: MisbehaviorReportValue | Uint8Array) { - super({ - parentHash: Hash, - parentNumber: BlockNumber, - target: AuthorityId, - misbehavior: MisbehaviorKind - }, value); - } - - /** - * @description The [[MisbehaviorKind]] - */ - public get misbehavior (): MisbehaviorKind { - return this.get('misbehavior') as MisbehaviorKind; - } - - /** - * @description The [[Hash]] of the parent block - */ - public get parentHash (): Hash { - return this.get('parentHash') as Hash; - } - - /** - * @description The [[BlockNumber]] of the parent - */ - public get parentNumber (): BlockNumber { - return this.get('parentNumber') as BlockNumber; - } - - /** - * @description The [[authorityId]] the report applies to - */ - public get target (): AuthorityId { - return this.get('target') as AuthorityId; - } -} diff --git a/packages/types/src/type/NewAccountOutcome.spec.ts b/packages/types/src/type/NewAccountOutcome.spec.ts deleted file mode 100644 index c6f4cf399b..0000000000 --- a/packages/types/src/type/NewAccountOutcome.spec.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 NewAccountOutcome from './NewAccountOutcome'; - -describe('NewAccountOutcome', (): void => { - it('allows setting value in constructor', (): void => { - expect( - new NewAccountOutcome(2).toNumber() - ).toEqual(2); - }); -}); diff --git a/packages/types/src/type/NewAccountOutcome.ts b/packages/types/src/type/NewAccountOutcome.ts deleted file mode 100644 index 74bc1eda31..0000000000 --- a/packages/types/src/type/NewAccountOutcome.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. - -import Enum from '../codec/Enum'; -import U8a from '../codec/U8a'; - -/** - * @name NewAccountOutcome - * @description - * Enum to track the outcome for creation of an [[AccountId]] - */ -export default class NewAccountOutcome extends Enum { - public constructor (index?: U8a | Uint8Array | number) { - super([ - 'NoHint', - 'GoodHint', - 'BadHint' - ], index); - } -} diff --git a/packages/types/src/type/PropIndex.ts b/packages/types/src/type/PropIndex.ts deleted file mode 100644 index 70dae78a67..0000000000 --- a/packages/types/src/type/PropIndex.ts +++ /dev/null @@ -1,14 +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 U32 from '../primitive/U32'; - -/** - * @name PropIndex - * @description - * An increasing number that represents a specific public proposal index in the - * system, implemented as a [[U32]] - */ -export default class PropIndex extends U32 { -} diff --git a/packages/types/src/type/Proposal.ts b/packages/types/src/type/Proposal.ts deleted file mode 100644 index f5fc52b1be..0000000000 --- a/packages/types/src/type/Proposal.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 Method from '../primitive/Method'; - -/** - * @name Proposal - * @description - * A proposal in the system. It just extends [[Method]] (Proposal = Call in Rust) - */ -export default class Proposal extends Method { -} diff --git a/packages/types/src/type/ProposalIndex.ts b/packages/types/src/type/ProposalIndex.ts deleted file mode 100644 index af6b3cb65e..0000000000 --- a/packages/types/src/type/ProposalIndex.ts +++ /dev/null @@ -1,14 +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 U32 from '../primitive/U32'; - -/** - * @name ProposalIndex - * @description - * An increasing number that represents a specific council proposal index in - * the system, implemented as [[U32]] - */ -export default class ProposalIndex extends U32 { -} diff --git a/packages/types/src/type/ReferendumIndex.ts b/packages/types/src/type/ReferendumIndex.ts deleted file mode 100644 index 264303104f..0000000000 --- a/packages/types/src/type/ReferendumIndex.ts +++ /dev/null @@ -1,14 +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 U32 from '../primitive/U32'; - -/** - * @name ReferendumIndex - * @description - * An increasing number that represents a specific referendum in the system. It - * is unique per chain. Implemented as [[U32]] - */ -export default class ReferendumIndex extends U32 { -} diff --git a/packages/types/src/type/ReferendumInfo.ts b/packages/types/src/type/ReferendumInfo.ts deleted file mode 100644 index 019dcce125..0000000000 --- a/packages/types/src/type/ReferendumInfo.ts +++ /dev/null @@ -1,61 +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 { Codec } from '../types'; - -import Struct from '../codec/Struct'; -import BlockNumber from './BlockNumber'; -import Proposal from './Proposal'; -import VoteThreshold from './VoteThreshold'; - -interface ReferendumInfoValue { - end?: BlockNumber; - proposal?: Proposal; - threshold?: VoteThreshold; - delay?: BlockNumber; -} - -/** - * @name ReferendumInfo - * @description - * Info regarding an ongoing referendum - */ -export default class ReferendumInfo extends Struct { - public constructor (value?: ReferendumInfoValue | Uint8Array | Map) { - super({ - end: BlockNumber, - proposal: Proposal, - threshold: VoteThreshold, - delay: BlockNumber - }, value); - } - - /** - * @description When voting on this referendum will end - */ - public get end (): BlockNumber { - return this.get('end') as BlockNumber; - } - - /** - * @description The proposal being voted on - */ - public get proposal (): Proposal { - return this.get('proposal') as Proposal; - } - - /** - * @description The thresholding mechanism to determine whether it passed - */ - public get threshold (): VoteThreshold { - return this.get('threshold') as VoteThreshold; - } - - /** - * @description The delay (in blocks) to wait after a successful referendum before deploying - */ - public get delay (): BlockNumber { - return this.get('delay') as BlockNumber; - } -} diff --git a/packages/types/src/type/RewardDestination.ts b/packages/types/src/type/RewardDestination.ts deleted file mode 100644 index 37138f6a43..0000000000 --- a/packages/types/src/type/RewardDestination.ts +++ /dev/null @@ -1,23 +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 Enum from '../codec/Enum'; - -/** - * @name RewardDestination - * @description - * A destination account for payment - */ -export default class RewardDestination extends Enum { - public constructor (value?: any) { - super([ - // Pay into the stash account, increasing the amount at stake accordingly. - 'Staked', - // Pay into the stash account, not increasing the amount at stake. - 'Stash', - // Pay into the controller account. - 'Controller' - ], value); - } -} diff --git a/packages/types/src/type/SeedOf.ts b/packages/types/src/type/SeedOf.ts deleted file mode 100644 index c724fbc7f4..0000000000 --- a/packages/types/src/type/SeedOf.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 Hash from '../primitive/Hash'; - -/** - * @name SeedOf - * @description - * The Substrate SeedOf representation as a [[Hash]]. - */ -export default class SeedOf extends Hash { -} diff --git a/packages/types/src/type/SessionKey.ts b/packages/types/src/type/SessionKey.ts deleted file mode 100644 index a8234dcf66..0000000000 --- a/packages/types/src/type/SessionKey.ts +++ /dev/null @@ -1,14 +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 AuthorityId from './AuthorityId'; - -/** - * @name SessionKey - * @description - * Wrapper for a SessionKey. Same as an normal [[AuthorityId]], i.e. a wrapper - * around publicKey. - */ -export default class SessionKey extends AuthorityId { -} diff --git a/packages/types/src/type/SessionKeys.ts b/packages/types/src/type/SessionKeys.ts deleted file mode 100644 index 70d2e6f70b..0000000000 --- a/packages/types/src/type/SessionKeys.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 Struct from '../codec/Struct'; -import SessionKey from './SessionKey'; - -/** - * @name SessionKeys - * @description - * Wrapper for the session and authority ids - */ -export default class SessionKeys extends Struct { - public constructor (value?: any) { - super({ - ed25519: SessionKey - }, value); - } - - /** - * @description The Aura session - */ - public get ed25519 (): SessionKey { - return this.get('ed25519') as SessionKey; - } -} diff --git a/packages/types/src/type/TreasuryProposal.ts b/packages/types/src/type/TreasuryProposal.ts deleted file mode 100644 index 32989cca5c..0000000000 --- a/packages/types/src/type/TreasuryProposal.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 Struct from '../codec/Struct'; -import AccountId from '../primitive/AccountId'; -import Balance from '../primitive/Balance'; - -/** - * @name TreasuryProposal - * @description - * A Proposal made for Treasury - */ -export default class TreasuryProposal extends Struct { - public constructor (value: any) { - super({ - proposer: AccountId, - value: Balance, - beneficiary: AccountId, - bond: Balance - }, value); - } - - /** - * @description The beneficiary - */ - public get beneficiary (): AccountId { - return this.get('beneficiary') as AccountId; - } - - /** - * @description The bond - */ - public get bond (): Balance { - return this.get('bond') as Balance; - } - - /** - * @description The proposer - */ - public get proposer (): AccountId { - return this.get('proposer') as AccountId; - } - - /** - * @description The bond - */ - public get value (): Balance { - return this.get('value') as Balance; - } -} diff --git a/packages/types/src/type/UncleEntryItem.ts b/packages/types/src/type/UncleEntryItem.ts deleted file mode 100644 index 03e11e147c..0000000000 --- a/packages/types/src/type/UncleEntryItem.ts +++ /dev/null @@ -1,42 +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 from './BlockNumber'; -import Enum from '../codec/Enum'; -import Tuple from '../codec/Tuple'; -import Option from '../codec/Option'; -import AccountId from '../primitive/AccountId'; -import Hash from '../primitive/Hash'; - -/** - * @name InclusionHeight - */ -export class InclusionHeight extends BlockNumber { -} - -/** - * @name Uncle - */ -export class Uncle extends Tuple { - public constructor (value: any) { - super({ - hash: Hash, - author: Option.with(AccountId) - }, value); - } -} - -/** - * @name UncleEntryItem - * - * @description Information about an uncle to include - */ -export default class UncleEntryItem extends Enum { - public constructor (value?: any) { - super({ - InclusionHeight, - Uncle - }, value); - } -} diff --git a/packages/types/src/type/ValidatorId.ts b/packages/types/src/type/ValidatorId.ts deleted file mode 100644 index d0d1d20bcc..0000000000 --- a/packages/types/src/type/ValidatorId.ts +++ /dev/null @@ -1,14 +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 AccountId from '../primitive/AccountId'; - -/** - * @name ValidatorId - * @description Wrapper for a ValidatorId. Same as an normal AccountId, i.e. a wrapper - * around publicKey, however specialized since it specifically points to - * an authority. - */ -export default class ValidatorId extends AccountId { -} diff --git a/packages/types/src/type/ValidatorPrefs.spec.ts b/packages/types/src/type/ValidatorPrefs.spec.ts deleted file mode 100644 index 73b2f35ac2..0000000000 --- a/packages/types/src/type/ValidatorPrefs.spec.ts +++ /dev/null @@ -1,23 +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 ValidatorPrefs from './ValidatorPrefs'; - -describe('ValidatorPrefs', (): void => { - it('starts with empty values', (): void => { - expect( - new ValidatorPrefs().validatorPayment.toNumber() - ).toEqual(0); - }); - - it('exposes the internal values via get', (): void => { - const prefs = new ValidatorPrefs({ - unstakeThreshold: 3, - validatorPayment: 12345 - }); - - expect(prefs.unstakeThreshold.toNumber()).toEqual(3); - expect(prefs.validatorPayment.toNumber()).toEqual(12345); - }); -}); diff --git a/packages/types/src/type/ValidatorPrefs.ts b/packages/types/src/type/ValidatorPrefs.ts deleted file mode 100644 index c7025acd86..0000000000 --- a/packages/types/src/type/ValidatorPrefs.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 { AnyNumber } from '../types'; - -import Compact from '../codec/Compact'; -import Struct from '../codec/Struct'; -import Balance from '../primitive/Balance'; -import U32 from '../primitive/U32'; - -interface ValidatorPrefsValue { - unstakeThreshold?: AnyNumber; - validatorPayment?: AnyNumber; -} - -/** - * @name ValidatorPrefs - * @description - * Validator preferences - */ -export default class ValidatorPrefs extends Struct { - public constructor (value?: ValidatorPrefsValue | Uint8Array) { - super({ - unstakeThreshold: Compact.with(U32), - validatorPayment: Compact.with(Balance) - }, value); - } - - /** - * @description The unstake threshold as [[U32]] - */ - public get unstakeThreshold (): Compact { - return this.get('unstakeThreshold') as Compact; - } - - /** - * @description The payment config for the validator as a [[Compact]] [[Balance]] - */ - public get validatorPayment (): Compact { - return this.get('validatorPayment') as Compact; - } -} diff --git a/packages/types/src/type/Vote.spec.ts b/packages/types/src/type/Vote.spec.ts index c9b7de7ef0..f6c2b55928 100644 --- a/packages/types/src/type/Vote.spec.ts +++ b/packages/types/src/type/Vote.spec.ts @@ -2,11 +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 Bool from '../primitive/Bool'; -import Conviction from './Conviction'; +import { injectDefinitions } from '../srml'; import Vote from './Vote'; describe('Vote', (): void => { + beforeEach((): void => { + injectDefinitions(); + }); + it('constructs via boolean true', (): void => { expect(new Vote(true).toU8a()).toEqual(new Uint8Array([128])); expect(new Vote(true).isAye).toBe(true); @@ -21,12 +24,12 @@ describe('Vote', (): void => { it('has isYay for positive', (): void => { // eslint-disable-next-line no-new-wrappers - expect(new Vote(new Bool(true)).isAye).toBe(true); + expect(new Vote(true).isAye).toBe(true); }); it('has isNay for negative', (): void => { // eslint-disable-next-line no-new-wrappers - expect(new Vote(new Bool(false)).isNay).toBe(true); + expect(new Vote(false).isNay).toBe(true); }); it('is Aye for negative numbers', (): void => { @@ -41,7 +44,7 @@ describe('Vote', (): void => { expect( new Vote({ aye: true, - conviction: new Conviction('Locked1x') + conviction: 'Locked1x' }).toU8a() ).toEqual(new Uint8Array([0b10000001])); }); @@ -49,8 +52,8 @@ describe('Vote', (): void => { it('constructs with V2 Vote aye is false, conviction is None', (): void => { expect( new Vote({ - aye: new Bool(false), - conviction: new Conviction('None') + aye: false, + conviction: 'None' }).toU8a() ).toEqual(new Uint8Array([0b00000000])); }); @@ -58,8 +61,8 @@ describe('Vote', (): void => { it('constructs with Vote aye is true, conviction is Locked4x', (): void => { expect( new Vote({ - aye: new Bool(true), - conviction: new Conviction('Locked4x') + aye: true, + conviction: 'Locked4x' }).toU8a() ).toEqual(new Uint8Array([0b10000100])); }); @@ -67,8 +70,8 @@ describe('Vote', (): void => { it('Conviction getter works', (): void => { expect( new Vote({ - aye: new Bool(true), - conviction: new Conviction('Locked2x') + aye: true, + conviction: 'Locked2x' }).conviction.toString() ).toEqual('Locked2x'); }); @@ -93,8 +96,8 @@ describe('Vote', (): void => { it('isAye getter works', (): void => { expect( new Vote({ - aye: new Bool(true), - conviction: new Conviction('None') + aye: true, + conviction: 'None' }).isAye) .toEqual(true); }); @@ -102,8 +105,8 @@ describe('Vote', (): void => { it('isNay getter works', (): void => { expect( new Vote({ - aye: new Bool(true), - conviction: new Conviction('None') + aye: true, + conviction: 'None' }).isNay) .toEqual(false); }); diff --git a/packages/types/src/type/Vote.ts b/packages/types/src/type/Vote.ts index 75ccb524c7..c556cdbe85 100644 --- a/packages/types/src/type/Vote.ts +++ b/packages/types/src/type/Vote.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 { Conviction } from '../srml/democracy/types'; + import { isBoolean, isNumber, isObject, isU8a, isUndefined } from '@polkadot/util'; -import Conviction from './Conviction'; +import createType from '../codec/createType'; import U8a from '../codec/U8a'; import Bool from '../primitive/Bool'; @@ -30,7 +32,7 @@ export default class Vote extends U8a { const conviction = decoded[0] & 0b01111111; this._aye = new Bool(msb); - this._conviction = new Conviction(conviction); + this._conviction = createType('Conviction', conviction); } private static decodeVote (value?: any): Uint8Array { @@ -46,7 +48,7 @@ export default class Vote extends U8a { : new Uint8Array([0b0]); } else if (isObject(value) && !isUndefined(value.aye) && !isUndefined(value.conviction)) { const aye = new Bool(value.aye); - const convictionIndex = new Conviction(value.conviction).index; + const convictionIndex = createType('Conviction', value.conviction).index; const result = convictionIndex | (aye.eq(true) ? 0b1 << 7 : 0b0); diff --git a/packages/types/src/type/VoteThreshold.spec.ts b/packages/types/src/type/VoteThreshold.spec.ts deleted file mode 100644 index b6e577c0d0..0000000000 --- a/packages/types/src/type/VoteThreshold.spec.ts +++ /dev/null @@ -1,19 +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 VoteThreshold from './VoteThreshold'; - -describe('VoteThreshold', (): void => { - it('starts with default value', (): void => { - expect( - new VoteThreshold().toString() - ).toEqual('Super majority approval'); - }); - - it('allows setting value in constructor', (): void => { - expect( - new VoteThreshold(2).toNumber() - ).toEqual(2); - }); -}); diff --git a/packages/types/src/type/VoteThreshold.ts b/packages/types/src/type/VoteThreshold.ts deleted file mode 100644 index 10e6659c26..0000000000 --- a/packages/types/src/type/VoteThreshold.ts +++ /dev/null @@ -1,20 +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 Enum from '../codec/Enum'; - -/** - * @name VoteThreshold - * @description - * Voting threshold, used inside proposals to set change the voting tally - */ -export default class VoteThreshold extends Enum { - public constructor (index?: number | Uint8Array) { - super([ - 'Super majority approval', - 'Super majority rejection', - 'Simple majority' - ], index); - } -} diff --git a/packages/types/src/type/VoterInfo.ts b/packages/types/src/type/VoterInfo.ts deleted file mode 100644 index c976c2e9b0..0000000000 --- a/packages/types/src/type/VoterInfo.ts +++ /dev/null @@ -1,53 +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 Balance from '../primitive/Balance'; -import VoteIndex from './VoteIndex'; - -/** - * @name VoterInfo - * @description - * The activity status of a voter. - */ - -export default class VoterInfo extends Struct { - public constructor (value?: any) { - super({ - lastActive: VoteIndex, - lastWin: VoteIndex, - pot: Balance, - stake: Balance - }, value); - } - - /** - * @description Last VoteIndex in which this voter assigned (or initialized) approvals. - */ - public get lastActive (): VoteIndex { - return this.get('lastActive') as VoteIndex; - } - - /** - * @description Last VoteIndex in which one of this voter's approvals won. - * Note that `last_win = N` indicates a last win at index `N-1`, hence `last_win = 0` means no win ever. - */ - public get lastWin (): VoteIndex { - return this.get('lastWin') as VoteIndex; - } - - /** - * @description The amount of stored weight as a result of not winning but changing approvals. - */ - public get pot (): Balance { - return this.get('pot') as Balance; - } - - /** - * @description Current staked amount. A lock equal to this value always exists. - */ - public get stake (): Balance { - return this.get('stake') as Balance; - } -} diff --git a/packages/types/src/type/Votes.ts b/packages/types/src/type/Votes.ts deleted file mode 100644 index 6ef05e9694..0000000000 --- a/packages/types/src/type/Votes.ts +++ /dev/null @@ -1,48 +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 Vector from '../codec/Vector'; -import AccountId from '../primitive/AccountId'; -import MemberCount from './MemberCount'; -import ProposalIndex from './ProposalIndex'; - -export default class Votes extends Struct { - public constructor (value: any) { - super({ - index: ProposalIndex, - threshold: MemberCount, - ayes: Vector.with(AccountId), - nays: Vector.with(AccountId) - }, value); - } - - /** - * @description The current set of voters that approved it. - */ - public get ayes (): Vector { - return this.get('ayes') as Vector; - } - - /** - * @description The proposal's unique index. - */ - public get index (): ProposalIndex { - return this.get('index') as ProposalIndex; - } - - /** - * @description The current set of voters that rejected it. - */ - public get nays (): Vector { - return this.get('nays') as Vector; - } - - /** - * @description The number of approval votes that are needed to pass the motion. - */ - public get threshold (): MemberCount { - return this.get('threshold') as MemberCount; - } -} diff --git a/packages/types/src/type/index.ts b/packages/types/src/type/index.ts index d2a471877e..db28a3e535 100644 --- a/packages/types/src/type/index.ts +++ b/packages/types/src/type/index.ts @@ -8,52 +8,15 @@ /** * @summary Type definitions that are used in the system */ -export { default as Amount } from './Amount'; -export { default as ApprovalFlag } from './ApprovalFlag'; -export { default as AssetOf } from './AssetOf'; -export { default as AuthorityId } from './AuthorityId'; -export { default as BalanceLock } from './BalanceLock'; -// NOTE Bft items are only used in internal structures -// export * from './Bft; export { default as BlockNumber } from './BlockNumber'; -export { default as Conviction } from './Conviction'; -export { default as EraIndex } from './EraIndex'; -export { default as Exposure } from './Exposure'; -// NOTE Only used internally, exported as PendingExtrinsics -// export { default as Extrinsics } from './Extrinsics'; -export { default as IndividualExposure } from './IndividualExposure'; -export { default as InherentOfflineReport } from './InherentOfflineReport'; export { default as Key } from './Key'; export { default as KeyValue } from './KeyValue'; -export { default as LockIdentifier } from './LockIdentifier'; -export { default as LockPeriods } from './LockPeriods'; // NOTE Nonce is renamed to Index export { default as Index, default as Nonce } from './Nonce'; export { default as IndexCompact } from './NonceCompact'; -export { default as Justification } from './Justification'; -export { default as MemberCount } from './MemberCount'; -export { default as MisbehaviorReport } from './MisbehaviorReport'; -export { default as NewAccountOutcome } from './NewAccountOutcome'; -export { default as OpaqueKey } from './OpaqueKey'; export { default as Permill } from './Permill'; export { default as Perbill } from './Perbill'; -export { default as PropIndex } from './PropIndex'; -export { default as Proposal } from './Proposal'; -export { default as ProposalIndex } from './ProposalIndex'; -export { default as ReferendumIndex } from './ReferendumIndex'; -export { default as ReferendumInfo } from './ReferendumInfo'; -export { default as RewardDestination } from './RewardDestination'; -export { default as SeedOf } from './SeedOf'; export { default as StakingLedger } from './StakingLedger'; -export { default as TreasuryProposal } from './TreasuryProposal'; -export { default as UncleEntryItem } from './UncleEntryItem'; export { default as UnlockChunk } from './UnlockChunk'; -export { default as ValidatorId } from './ValidatorId'; -export { default as ValidatorPrefs } from './ValidatorPrefs'; -export { default as VestingSchedule } from './VestingSchedule'; export { default as Vote } from './Vote'; -export { default as Votes } from './Votes'; -export { default as VoteThreshold } from './VoteThreshold'; -export { default as VoteIndex } from './VoteIndex'; -export { default as VoterInfo } from './VoterInfo'; export { default as WithdrawReasons } from './WithdrawReasons';