From 438c02def5ccf12dfef2394dfb2f71ea72893925 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 7 Aug 2019 18:08:38 +0200 Subject: [PATCH] Add types for Polkadot claims module (#1277) * Add types for Polkadot claims module * ' instead of ` * Adjust types, `[u8; x]` workarounds * One less import * Map [u8; x] -> Uint8Array * Fix Codec imports --- packages/types/src/interfaceRegistry.ts | 121 +++++++++--------- .../src/interfaces/claims/definitions.ts | 10 ++ packages/types/src/interfaces/claims/index.ts | 3 + packages/types/src/interfaces/claims/types.ts | 10 ++ .../types/src/interfaces/contracts/types.ts | 9 +- packages/types/src/interfaces/definitions.ts | 5 +- packages/types/src/interfaces/rpc/types.ts | 6 +- .../types/src/interfaces/runtime/types.ts | 8 +- packages/types/src/interfaces/system/types.ts | 7 +- packages/types/src/interfaces/types.ts | 3 +- packages/types/src/scripts/interfacesTs.ts | 12 +- 11 files changed, 119 insertions(+), 75 deletions(-) create mode 100644 packages/types/src/interfaces/claims/definitions.ts create mode 100644 packages/types/src/interfaces/claims/index.ts create mode 100644 packages/types/src/interfaces/claims/types.ts diff --git a/packages/types/src/interfaceRegistry.ts b/packages/types/src/interfaceRegistry.ts index f309dbf45d..fcc2154de4 100644 --- a/packages/types/src/interfaceRegistry.ts +++ b/packages/types/src/interfaceRegistry.ts @@ -16,10 +16,11 @@ import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from import { AccountInfo, Amount, AssetOf, InherentOfflineReport, LockPeriods, NewAccountOutcome, OpaqueKey, SessionKey } from './interfaces/deprecated'; import { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from './interfaces/genericAsset'; import { Heartbeat, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from './interfaces/imOnline'; -import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParachainDispatchOrigin, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from './interfaces/parachains'; import { EraIndex, EraRewards, Exposure, IndividualExposure, MomentOf, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from './interfaces/staking'; import { DigestOf, Event, EventId, EventIndex, EventRecord, EventRecord0to76, Key, Phase } from './interfaces/system'; import { TreasuryProposal } from './interfaces/treasury'; +import { EcdsaSignature, EthereumAddress } from './interfaces/claims'; +import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParachainDispatchOrigin, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from './interfaces/parachains'; import { ApiId, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from './interfaces/rpc'; export interface InterfaceRegistry { @@ -435,6 +436,68 @@ export interface InterfaceRegistry { Heartbeat: Heartbeat; 'Option': Option; 'Vec': Vec; + EraIndex: EraIndex; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; + EraRewards: EraRewards; + 'Option': Option; + 'Vec': Vec; + IndividualExposure: IndividualExposure; + 'Option': Option; + 'Vec': Vec; + Exposure: Exposure; + 'Option': Option; + 'Vec': Vec; + MomentOf: MomentOf; + 'Option': Option; + 'Vec': Vec; + RewardDestination: RewardDestination; + 'Option': Option; + 'Vec': Vec; + UnlockChunk: UnlockChunk; + 'Option': Option; + 'Vec': Vec; + StakingLedger: StakingLedger; + 'Option': Option; + 'Vec': Vec; + ValidatorPrefs: ValidatorPrefs; + 'Option': Option; + 'Vec': Vec; + DigestOf: DigestOf; + 'Option': Option; + 'Vec': Vec; + EventId: EventId; + 'Option': Option; + 'Vec': Vec; + EventIndex: EventIndex; + 'Compact': Compact; + 'Option': Option; + 'Vec': Vec; + Key: Key; + 'Option': Option; + 'Vec': Vec; + Phase: Phase; + 'Option': Option; + 'Vec': Vec; + Event: Event; + 'Option': Option; + 'Vec': Vec; + EventRecord0to76: EventRecord0to76; + 'Option': Option; + 'Vec': Vec; + EventRecord: EventRecord; + 'Option': Option; + 'Vec': Vec; + TreasuryProposal: TreasuryProposal; + 'Option': Option; + 'Vec': Vec; + EcdsaSignature: EcdsaSignature; + 'Option': Option; + 'Vec': Vec; + EthereumAddress: EthereumAddress; + 'Option': Option; + 'Vec': Vec; AuctionIndex: AuctionIndex; 'Compact': Compact; 'Option': Option; @@ -514,62 +577,6 @@ export interface InterfaceRegistry { WinningData: WinningData; 'Option': Option; 'Vec': Vec; - EraIndex: EraIndex; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vec; - EraRewards: EraRewards; - 'Option': Option; - 'Vec': Vec; - IndividualExposure: IndividualExposure; - 'Option': Option; - 'Vec': Vec; - Exposure: Exposure; - 'Option': Option; - 'Vec': Vec; - MomentOf: MomentOf; - 'Option': Option; - 'Vec': Vec; - RewardDestination: RewardDestination; - 'Option': Option; - 'Vec': Vec; - UnlockChunk: UnlockChunk; - 'Option': Option; - 'Vec': Vec; - StakingLedger: StakingLedger; - 'Option': Option; - 'Vec': Vec; - ValidatorPrefs: ValidatorPrefs; - 'Option': Option; - 'Vec': Vec; - DigestOf: DigestOf; - 'Option': Option; - 'Vec': Vec; - EventId: EventId; - 'Option': Option; - 'Vec': Vec; - EventIndex: EventIndex; - 'Compact': Compact; - 'Option': Option; - 'Vec': Vec; - Key: Key; - 'Option': Option; - 'Vec': Vec; - Phase: Phase; - 'Option': Option; - 'Vec': Vec; - Event: Event; - 'Option': Option; - 'Vec': Vec; - EventRecord0to76: EventRecord0to76; - 'Option': Option; - 'Vec': Vec; - EventRecord: EventRecord; - 'Option': Option; - 'Vec': Vec; - TreasuryProposal: TreasuryProposal; - 'Option': Option; - 'Vec': Vec; ApiId: ApiId; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/interfaces/claims/definitions.ts b/packages/types/src/interfaces/claims/definitions.ts new file mode 100644 index 0000000000..4b91924ad0 --- /dev/null +++ b/packages/types/src/interfaces/claims/definitions.ts @@ -0,0 +1,10 @@ +// 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: { + EcdsaSignature: '[u8; 65]', + EthereumAddress: 'H160' + } +}; diff --git a/packages/types/src/interfaces/claims/index.ts b/packages/types/src/interfaces/claims/index.ts new file mode 100644 index 0000000000..f94c8a0ae8 --- /dev/null +++ b/packages/types/src/interfaces/claims/index.ts @@ -0,0 +1,3 @@ +// Auto-generated via `yarn build:interfaces`, do not edit + +export * from './types'; diff --git a/packages/types/src/interfaces/claims/types.ts b/packages/types/src/interfaces/claims/types.ts new file mode 100644 index 0000000000..13d563c08b --- /dev/null +++ b/packages/types/src/interfaces/claims/types.ts @@ -0,0 +1,10 @@ +// Auto-generated via `yarn build:interfaces`, do not edit + +import { Codec } from '../../types'; +import { H160 } from '../../primitive'; + +/** Uint8Array & Codec */ +export type EcdsaSignature = Uint8Array & Codec; + +/** H160 */ +export type EthereumAddress = H160; diff --git a/packages/types/src/interfaces/contracts/types.ts b/packages/types/src/interfaces/contracts/types.ts index 037d1f6a93..c7a83ad1c7 100644 --- a/packages/types/src/interfaces/contracts/types.ts +++ b/packages/types/src/interfaces/contracts/types.ts @@ -1,7 +1,8 @@ // Auto-generated via `yarn build:interfaces`, do not edit -import { Compact, Enum, Option, Struct, Vec } from '../../codec'; -import { Bytes, Null, bool, u32, u64, u8 } from '../../primitive'; +import { Codec } from '../../types'; +import { Compact, Enum, Option, Struct } from '../../codec'; +import { Bytes, Null, bool, u32, u64 } from '../../primitive'; import { Balance, BlockNumber, Hash } from '../runtime'; /** Struct */ @@ -35,8 +36,8 @@ export interface ContractInfo extends Enum { readonly asTombstone: TombstoneContractInfo; } -/** Vec */ -export type ContractStorageKey = Vec; +/** Uint8Array & Codec */ +export type ContractStorageKey = Uint8Array & Codec; /** u64 */ export type Gas = u64; diff --git a/packages/types/src/interfaces/definitions.ts b/packages/types/src/interfaces/definitions.ts index d26d96dccd..c5829e4fed 100644 --- a/packages/types/src/interfaces/definitions.ts +++ b/packages/types/src/interfaces/definitions.ts @@ -31,10 +31,13 @@ export { default as democracy } from './democracy/definitions'; export { default as deprecated } from './deprecated/definitions'; export { default as genericAsset } from './genericAsset/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 system } from './system/definitions'; export { default as treasury } from './treasury/definitions'; +// polkadot-specific types +export { default as claims } from './claims/definitions'; +export { default as parachains } from './parachains/definitions'; + // pull in rpc last, assuming that is uses info from above export { default as rpc } from './rpc/definitions'; diff --git a/packages/types/src/interfaces/rpc/types.ts b/packages/types/src/interfaces/rpc/types.ts index 898003dfa2..26caec712e 100644 --- a/packages/types/src/interfaces/rpc/types.ts +++ b/packages/types/src/interfaces/rpc/types.ts @@ -2,11 +2,11 @@ import { Codec } from '../../types'; import { Enum, Option, Struct, Vec } from '../../codec'; -import { Bytes, StorageData, StorageKey, Text, bool, u32, u64, u8 } from '../../primitive'; +import { Bytes, StorageData, StorageKey, Text, bool, u32, u64 } from '../../primitive'; import { BlockNumber, Hash } from '../runtime'; -/** Vec */ -export type ApiId = Vec; +/** Uint8Array & Codec */ +export type ApiId = Uint8Array & Codec; /** Struct */ export interface ChainProperties extends Struct { diff --git a/packages/types/src/interfaces/runtime/types.ts b/packages/types/src/interfaces/runtime/types.ts index 8c0273c527..85877875c7 100644 --- a/packages/types/src/interfaces/runtime/types.ts +++ b/packages/types/src/interfaces/runtime/types.ts @@ -1,8 +1,8 @@ // Auto-generated via `yarn build:interfaces`, do not edit import { Codec } from '../../types'; -import { Compact, Struct, Vec } from '../../codec'; -import { Bytes, Fixed64, GenericAccountId, GenericAccountIndex, GenericAddress, GenericBlock, GenericCall, GenericConsensusEngineId, GenericDigest, GenericDigestItem, GenericExtrinsic, GenericExtrinsicEra, GenericExtrinsicPayload, GenericImmortalEra, GenericMortalEra, GenericOrigin, H256, H512, Null, StorageData, StorageKey, u128, u32, u64, u8 } from '../../primitive'; +import { Compact, Struct } from '../../codec'; +import { Bytes, Fixed64, GenericAccountId, GenericAccountIndex, GenericAddress, GenericBlock, GenericCall, GenericConsensusEngineId, GenericDigest, GenericDigestItem, GenericExtrinsic, GenericExtrinsicEra, GenericExtrinsicPayload, GenericImmortalEra, GenericMortalEra, GenericOrigin, H256, H512, Null, StorageData, StorageKey, u128, u32, u64 } from '../../primitive'; /** GenericAccountId */ export type AccountId = GenericAccountId; @@ -90,8 +90,8 @@ export type KeyTypeId = u32; /** [StorageKey, StorageData] & Codec */ export type KeyValue = [StorageKey, StorageData] & Codec; -/** Vec */ -export type LockIdentifier = Vec; +/** Uint8Array & Codec */ +export type LockIdentifier = Uint8Array & Codec; /** u64 */ export type Moment = u64; diff --git a/packages/types/src/interfaces/system/types.ts b/packages/types/src/interfaces/system/types.ts index f0c381427b..1b53db0bcc 100644 --- a/packages/types/src/interfaces/system/types.ts +++ b/packages/types/src/interfaces/system/types.ts @@ -1,7 +1,8 @@ // Auto-generated via `yarn build:interfaces`, do not edit +import { Codec } from '../../types'; import { Enum, Struct, Vec } from '../../codec'; -import { Bytes, GenericEvent, u32, u8 } from '../../primitive'; +import { Bytes, GenericEvent, u32 } from '../../primitive'; import { Digest, Hash } from '../runtime'; /** Digest */ @@ -10,8 +11,8 @@ export type DigestOf = Digest; /** GenericEvent */ export type Event = GenericEvent; -/** Vec */ -export type EventId = Vec; +/** Uint8Array & Codec */ +export type EventId = Uint8Array & Codec; /** u32 */ export type EventIndex = u32; diff --git a/packages/types/src/interfaces/types.ts b/packages/types/src/interfaces/types.ts index 0a6a1828d1..0641821293 100644 --- a/packages/types/src/interfaces/types.ts +++ b/packages/types/src/interfaces/types.ts @@ -14,8 +14,9 @@ export * from './democracy/types'; export * from './deprecated/types'; export * from './genericAsset/types'; export * from './imOnline/types'; -export * from './parachains/types'; export * from './staking/types'; export * from './system/types'; export * from './treasury/types'; +export * from './claims/types'; +export * from './parachains/types'; export * from './rpc/types'; diff --git a/packages/types/src/scripts/interfacesTs.ts b/packages/types/src/scripts/interfacesTs.ts index 2ea1a9c281..6faf1dd9ea 100644 --- a/packages/types/src/scripts/interfacesTs.ts +++ b/packages/types/src/scripts/interfacesTs.ts @@ -229,7 +229,7 @@ function _tsTupleGetterType (tupleName: string | undefined, { info, sub, type }: } function tsTuple ({ name: tupleName, sub }: TypeDef, imports: TypeImports): string { - setImports(imports, ['Tuple']); + setImports(imports, ['Codec', 'Tuple']); const types = (sub as TypeDef[]).map((typedef): string => _tsTupleGetterType(tupleName, typedef, imports) @@ -243,6 +243,14 @@ function tsVec ({ ext, info, name: vectorName, sub }: TypeDef, imports: TypeImpo ? (ext as TypeDefExtVecFixed).type : (sub as TypeDef).type; + // FIXME This should be a VecFixed + // FIXME Technically Vec has length prefix, so for others this is not 100% + if (info === TypeDefInfo.VecFixed && type === 'u8') { + setImports(imports, ['Codec']); + + return exportType(vectorName, 'Uint8Array & Codec'); + } + setImports(imports, ['Vec', type]); return exportType(vectorName, `Vec<${type}>`); @@ -331,7 +339,7 @@ function generateTsDef (defName: string, { types }: { types: Record const header = createImportCode(HEADER, [ { file: '../../types', - types: imports.codecTypes['Tuple'] ? ['Codec'] : [] + types: Object.keys(imports.typesTypes) }, { file: '../../codec',