diff --git a/.codeclimate.yml b/.codeclimate.yml index dd0a3cdb69..146cac3fbd 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -4,3 +4,5 @@ exclude_patterns: - "**/*.test.js" - "**/*.test.ts" - "docs/**/*.js" +- "packages/types/src/scripts/" +- "packages/types/src/srml/" diff --git a/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts b/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts index 5039086cd9..fbd90fc459 100644 --- a/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts +++ b/packages/api-metadata/src/consts/fromMetadata/fromMetadata.spec.ts @@ -4,9 +4,12 @@ import { Metadata, BlockNumber } from '@polkadot/types'; import json from '@polkadot/types/Metadata/v6/static'; +import { injectDefinitions } from '@polkadot/types/Metadata/util/testUtil'; import fromMetadata from '../fromMetadata'; +injectDefinitions(); + // Use the pre-generated metadata const metadata = new Metadata(json); const consts = fromMetadata(metadata); diff --git a/packages/rpc-core/src/formatting.spec.ts b/packages/rpc-core/src/formatting.spec.ts index 5c1d3364fd..9b2f7aefbc 100644 --- a/packages/rpc-core/src/formatting.spec.ts +++ b/packages/rpc-core/src/formatting.spec.ts @@ -7,6 +7,7 @@ import BN from 'bn.js'; import fromMetadata from '@polkadot/api-metadata/storage/fromMetadata'; import { Storage } from '@polkadot/api-metadata/storage/types'; import Metadata from '@polkadot/types/Metadata'; +import { injectDefinitions } from '@polkadot/types/Metadata/util/testUtil'; import rpcMetadataV3 from '@polkadot/types/Metadata/v3/static'; import rpcMetadataV4 from '@polkadot/types/Metadata/v4/static'; import rpcMetadataV5 from '@polkadot/types/Metadata/v5/static'; @@ -30,6 +31,8 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str let provider: any; beforeEach((): void => { + injectDefinitions(); + provider = { send: jest.fn((method, [key]): Promise => Promise.resolve( diff --git a/packages/types/src/Metadata/util/testUtil.ts b/packages/types/src/Metadata/util/testUtil.ts index bfe429fd35..d4bce81d51 100644 --- a/packages/types/src/Metadata/util/testUtil.ts +++ b/packages/types/src/Metadata/util/testUtil.ts @@ -12,7 +12,7 @@ import Method from '../../primitive/Method'; import { MetadataInterface } from '../types'; import { Codec } from '../../types'; -function injectDefinitions (): void { +export function injectDefinitions (): void { Object.values(srmlTypes).forEach(({ types }): void => getTypeRegistry().register(types) ); diff --git a/packages/types/src/codec/Compact.ts b/packages/types/src/codec/Compact.ts index f6852d7d94..97492a0cd8 100644 --- a/packages/types/src/codec/Compact.ts +++ b/packages/types/src/codec/Compact.ts @@ -20,13 +20,13 @@ import UInt from './UInt'; * used by other types to add length-prefixed encoding, or in the case of wrapped types, taking * a number and making the compact representation thereof */ -export default class Compact extends Base implements Codec { - public constructor (Type: Constructor, value: Compact | AnyNumber = 0) { - super(Compact.decodeCompact(Type, value)); +export default class Compact extends Base implements Codec { + public constructor (Type: Constructor, value: Compact | AnyNumber = 0) { + super(Compact.decodeCompact(Type, value)); } - public static with (Type: Constructor): Constructor { - return class extends Compact { + public static with (Type: Constructor): Constructor> { + return class extends Compact { public constructor (value?: any) { super(Type, value); } @@ -50,7 +50,7 @@ export default class Compact extends Base implements Codec { return value; } - public static decodeCompact (Type: Constructor, value: Compact | AnyNumber): Moment | UInt { + public static decodeCompact (Type: Constructor, value: Compact | AnyNumber): Moment | UInt { if (value instanceof Compact) { return new Type(value.raw); } else if (isString(value)) { @@ -154,7 +154,7 @@ export default class Compact extends Base implements Codec { /** * @description Returns the embedded [[UInt]] or [[Moment]] value */ - public unwrap (): UInt | Moment { - return this.raw; + public unwrap (): T { + return this.raw as T; } } diff --git a/packages/types/src/rpc/Header.ts b/packages/types/src/rpc/Header.ts index 7fd56dc461..cdb40d6049 100644 --- a/packages/types/src/rpc/Header.ts +++ b/packages/types/src/rpc/Header.ts @@ -40,7 +40,7 @@ export default class Header extends Struct { * @description The wrapped [[BlockNumber]] */ public get blockNumber (): BlockNumber { - return (this.get('number') as Compact).toBn() as BlockNumber; + return (this.get('number') as Compact).unwrap(); } /** diff --git a/packages/types/src/scripts/srmlTS.ts b/packages/types/src/scripts/srmlTS.ts index 6ca6297890..0062908399 100644 --- a/packages/types/src/scripts/srmlTS.ts +++ b/packages/types/src/scripts/srmlTS.ts @@ -22,6 +22,7 @@ interface TypeImports { const HEADER = '/* eslint-disable @typescript-eslint/no-empty-interface */\n// Auto-generated, do not edit\n\n'; const FOOTER = '\n'; +const OUTPUT_FILE = 'types.ts'; function setImports ({ codecTypes, ownTypes, primitiveTypes, substrateTypes }: TypeImports, type: string | null, codecType: string | null): void { if (type && !ownTypes.includes(type)) { @@ -42,6 +43,21 @@ function errorUnhandled (def: TypeDef, imports: TypeImports): string { throw new Error(`Generate: ${name}: Unhandled type ${TypeDefInfo[def.info]}`); } +function tsCompact ({ name: compactName, sub }: TypeDef, imports: TypeImports): string { + const def = (sub as TypeDef); + + setImports(imports, null, 'Compact'); + + switch (def.info) { + case TypeDefInfo.Plain: + setImports(imports, def.type, null); + return `export interface ${compactName} extends Compact<${def.type}> {}`; + + default: + throw new Error(`Enum: ${compactName}: Unhandled type ${TypeDefInfo[def.info]}`); + } +} + function tsEnum ({ name: enumName, sub }: TypeDef, imports: TypeImports): string { setImports(imports, null, 'Enum'); @@ -62,6 +78,21 @@ function tsEnum ({ name: enumName, sub }: TypeDef, imports: TypeImports): string return `export interface ${enumName} extends Enum {\n${keys.join('')}}`; } +function tsOption ({ name: optionName, sub }: TypeDef, imports: TypeImports): string { + const def = (sub as TypeDef); + + setImports(imports, null, 'Option'); + + switch (def.info) { + case TypeDefInfo.Plain: + setImports(imports, def.type, null); + return `export interface ${optionName} extends Option<${def.type}> {}`; + + default: + throw new Error(`Enum: ${optionName}: Unhandled type ${TypeDefInfo[def.info]}`); + } +} + function tsPlain ({ name: plainName, type }: TypeDef, imports: TypeImports): string { setImports(imports, type, null); @@ -69,12 +100,28 @@ function tsPlain ({ name: plainName, type }: TypeDef, imports: TypeImports): str } function _tsStructGetterType (structName: string | undefined, { info, sub, type }: TypeDef, imports: TypeImports): [string, string] { + let _type; + switch (info) { + case TypeDefInfo.Compact: + _type = (sub as TypeDef).type; + + setImports(imports, null, 'Compact'); + + return [_type, `Compact<${_type}>`]; + + case TypeDefInfo.Option: + _type = (sub as TypeDef).type; + + setImports(imports, null, 'Option'); + + return [_type, `Option<${_type}>`]; + case TypeDefInfo.Plain: return [type, type]; case TypeDefInfo.Vector: - const _type = (sub as TypeDef).type; + _type = (sub as TypeDef).type; setImports(imports, null, 'Vector'); @@ -123,12 +170,12 @@ function generateTsDef (srmlName: string, { types }: { types: Record diff --git a/packages/types/src/srml/contracts/definitions.ts b/packages/types/src/srml/contracts/definitions.ts new file mode 100644 index 0000000000..4def409b02 --- /dev/null +++ b/packages/types/src/srml/contracts/definitions.ts @@ -0,0 +1,52 @@ +// 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: { + CodeHash: 'Hash', + TrieId: 'Bytes', + AliveContractInfo: { + trieId: 'TrieId', + storageSize: 'u32', + codeHash: 'CodeHash', + rentAllowance: 'Balance', + deductBlock: 'BlockNumber', + lastWrite: 'Option' + }, + TombstoneContractInfo: 'Hash', + ContractInfo: { + _enum: { + Alive: 'AliveContractInfo', + Tombstone: 'TombstoneContractInfo' + } + }, + ContractStorageKey: '[u8; 32]', + Gas: 'u64', + PrefabWasmModuleReserved: 'Option', + PrefabWasmModule: { + scheduleVersion: 'Compact', + initial: 'Compact', + maximum: 'Compact', + _reserved: 'PrefabWasmModuleReserved', + code: 'Bytes' + }, + Schedule: { + version: 'u32', + putCodePerByteCost: 'Gas', + growMemCost: 'Gas', + regularOpCost: 'Gas', + returnDataPerByteCost: 'Gas', + eventDataPerByteCost: 'Gas', + eventPerTopicCost: 'Gas', + eventBaseCost: 'Gas', + sandboxDataReadCost: 'Gas', + sandboxDataWriteCost: 'Gas', + maxEventTopics: 'u32', + maxStackHeight: 'u32', + maxMemoryPages: 'u32', + enablePrintln: 'Bool', + maxSubjectLen: 'u32' + } + } +}; diff --git a/packages/types/src/srml/contracts/types.ts b/packages/types/src/srml/contracts/types.ts new file mode 100644 index 0000000000..9aff4344a1 --- /dev/null +++ b/packages/types/src/srml/contracts/types.ts @@ -0,0 +1,66 @@ +/* eslint-disable @typescript-eslint/no-empty-interface */ +// Auto-generated, do not edit + +import { Compact, Enum, Option, Struct, Vector } from '../../codec'; +import { Balance, Bool, Bytes, Hash, Null, u32, u64, u8 } from '../../primitive'; +import { BlockNumber } from '../../type'; + +export interface AliveContractInfo extends Struct { + readonly trieId: TrieId; + readonly storageSize: u32; + readonly codeHash: CodeHash; + readonly rentAllowance: Balance; + readonly deductBlock: BlockNumber; + readonly lastWrite: Option; +} + +export interface CodeHash extends Hash {} + +export interface ContractInfo extends Enum { + /** + * @description 0:: Alive(AliveContractInfo) + */ + readonly isAlive: boolean; + readonly asAlive: AliveContractInfo; + /** + * @description 1:: Tombstone(TombstoneContractInfo) + */ + readonly isTombstone: boolean; + readonly asTombstone: TombstoneContractInfo; +} + +export interface ContractStorageKey extends Vector {} + +export interface Gas extends u64 {} + +export interface PrefabWasmModule extends Struct { + readonly scheduleVersion: Compact; + readonly initial: Compact; + readonly maximum: Compact; + readonly _reserved: PrefabWasmModuleReserved; + readonly code: Bytes; +} + +export interface PrefabWasmModuleReserved extends Option {} + +export interface Schedule extends Struct { + readonly version: u32; + readonly putCodePerByteCost: Gas; + readonly growMemCost: Gas; + readonly regularOpCost: Gas; + readonly returnDataPerByteCost: Gas; + readonly eventDataPerByteCost: Gas; + readonly eventPerTopicCost: Gas; + readonly eventBaseCost: Gas; + readonly sandboxDataReadCost: Gas; + readonly sandboxDataWriteCost: Gas; + readonly maxEventTopics: u32; + readonly maxStackHeight: u32; + readonly maxMemoryPages: u32; + readonly enablePrintln: Bool; + readonly maxSubjectLen: u32; +} + +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 2da4f5a6db..b2ccb74d8e 100644 --- a/packages/types/src/srml/definitions.ts +++ b/packages/types/src/srml/definitions.ts @@ -7,5 +7,6 @@ // injection order is critical. export { default as grandpa } from './grandpa/definitions'; +export { default as contracts } from './contracts/definitions'; export { default as imOnline } from './imOnline/definitions'; export { default as parachains } from './parachains/definitions'; diff --git a/packages/types/src/srml/parachains/definitions.ts b/packages/types/src/srml/parachains/definitions.ts index 29d520618a..fc17a783d9 100644 --- a/packages/types/src/srml/parachains/definitions.ts +++ b/packages/types/src/srml/parachains/definitions.ts @@ -63,6 +63,8 @@ export default { Deploy: 'IncomingParachainDeploy' } }, + LeasePeriod: 'BlockNumber', + LeasePeriodOf: 'LeasePeriod', ParachainDispatchOrigin: { _enum: [ 'Signed', diff --git a/packages/types/src/srml/parachains/types.ts b/packages/types/src/srml/parachains/types.ts index 44a2c735b0..e285f2e395 100644 --- a/packages/types/src/srml/parachains/types.ts +++ b/packages/types/src/srml/parachains/types.ts @@ -4,7 +4,7 @@ import { Codec } from '../../types'; import { Enum, Struct, Vector } from '../../codec'; import { AccountId, BalanceOf, Bytes, Hash, Signature, u32, u64 } from '../../primitive'; -import { SessionKey } from '../../type'; +import { BlockNumber, SessionKey } from '../../type'; export interface AttestedCandidate extends Struct { readonly candidate: CandidateReceipt; @@ -79,6 +79,10 @@ export interface IncomingParachainFixed extends Struct { readonly initialHeadData: Bytes; } +export interface LeasePeriod extends BlockNumber {} + +export interface LeasePeriodOf extends LeasePeriod {} + export interface NewBidder extends Struct { readonly who: AccountId; readonly sub: SubId; diff --git a/packages/types/src/srml/types.ts b/packages/types/src/srml/types.ts index 8955bc0f40..ca495383a6 100644 --- a/packages/types/src/srml/types.ts +++ b/packages/types/src/srml/types.ts @@ -3,5 +3,6 @@ // of the Apache-2.0 license. See the LICENSE file for details. export * from './grandpa/types'; +export * from './contracts/types'; export * from './imOnline/types'; export * from './parachains/types'; diff --git a/packages/types/src/type/CodeHash.ts b/packages/types/src/type/CodeHash.ts deleted file mode 100644 index e46837033e..0000000000 --- a/packages/types/src/type/CodeHash.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 Hash from '../primitive/Hash'; - -/** - * @name CodeHash - * @description - * The default contract code hash that is used accross the system. It is a - * wrapper around [[Hash]], representing a 32-byte blake2b (Substrate) value - */ -export default class CodeHash extends Hash { -} diff --git a/packages/types/src/type/ContractInfo.ts b/packages/types/src/type/ContractInfo.ts deleted file mode 100644 index d7745c0ec8..0000000000 --- a/packages/types/src/type/ContractInfo.ts +++ /dev/null @@ -1,110 +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 { assert } from '@polkadot/util'; - -import Option from '../codec/Option'; -import Bytes from '../primitive/Bytes'; -import Enum from '../codec/Enum'; -import Struct from '../codec/Struct'; -import Balance from '../primitive/Balance'; -import Hash from '../primitive/Hash'; -import U32 from '../primitive/U32'; -import BlockNumber from './BlockNumber'; -import CodeHash from './CodeHash'; - -export class TrieId extends Bytes { -} - -export class AliveContractInfo extends Struct { - public constructor (value?: any) { - super({ - trieId: TrieId, - storageSize: U32, - codeHash: CodeHash, - rentAllowance: Balance, - deductBlock: BlockNumber, - lastWrite: Option.with(BlockNumber) - }, value); - } - - public get codeHash (): CodeHash { - return this.get('codeHash') as CodeHash; - } - - public get deductBlock (): BlockNumber { - return this.get('deductBlock') as BlockNumber; - } - - public get lastWrite (): Option { - return this.get('lastWrite') as Option; - } - - public get rentAllowance (): Balance { - return this.get('rentAllowance') as Balance; - } - - public get storageSize (): U32 { - return this.get('storageSize') as U32; - } - - public get trieId (): TrieId { - return this.get('trieId') as TrieId; - } -} - -export class Alive extends AliveContractInfo { -} - -export class TombstoneContractInfo extends Hash { -} - -export class Tombstone extends TombstoneContractInfo { -} - -/** - * @name ContractInfo - * @description - * The contract information for a given contract - */ -export default class ContractInfo extends Enum { - public constructor (value?: any) { - super({ - Alive, - Tombstone - }, value); - } - - /** - * @description Returns the item as an [[Alive]] - */ - public get asAlive (): Alive { - assert(this.isAlive, `Cannot convert '${this.type}' via asAlive`); - - return this.value as Alive; - } - - /** - * @description Returns the item as an [[Tombstone]] - */ - public get asTombstone (): Tombstone { - assert(this.isTombstone, `Cannot convert '${this.type}' via asTombstone`); - - return this.value as Tombstone; - } - - /** - * @description value is an [[Alive]] - */ - public get isAlive (): boolean { - return this.toNumber() === 0; - } - - /** - * @description value is an [[Tombstone]] - */ - public get isTombstone (): boolean { - return this.toNumber() === 1; - } -} diff --git a/packages/types/src/type/ContractStorageKey.ts b/packages/types/src/type/ContractStorageKey.ts deleted file mode 100644 index fcfad9ae58..0000000000 --- a/packages/types/src/type/ContractStorageKey.ts +++ /dev/null @@ -1,25 +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 U8aFixed from '../codec/U8aFixed'; - -/** - * @name ContractStorageKey - * @description - * A [u8; 32] representing a storeage key in contracts - */ -export default class ContractStorageKey extends U8aFixed { - public constructor (value?: AnyU8a) { - super(value, 256); - } - - /** - * @description Returns the base runtime type name for this instance - */ - public toRawType (): string { - return '[u8; 32]'; - } -} diff --git a/packages/types/src/type/Exposure.ts b/packages/types/src/type/Exposure.ts index e6386f7608..7ecef6c24d 100644 --- a/packages/types/src/type/Exposure.ts +++ b/packages/types/src/type/Exposure.ts @@ -26,14 +26,14 @@ export default class Exposure extends Struct { * @description The validator's own stash that is exposed */ public get own (): Balance { - return (this.get('own') as Compact).toBn() as 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).toBn() as Balance; + return (this.get('total') as Compact).unwrap(); } /** diff --git a/packages/types/src/type/Gas.ts b/packages/types/src/type/Gas.ts deleted file mode 100644 index 4b8ab772be..0000000000 --- a/packages/types/src/type/Gas.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 U64 from '../primitive/U64'; - -/** - * @name Gas - * @description - * A gas number type for Substrate, extending [[U64]] - */ -export default class Gas extends U64 { -} diff --git a/packages/types/src/type/IndividualExposure.ts b/packages/types/src/type/IndividualExposure.ts index 6f69be56a1..e367c4dd0f 100644 --- a/packages/types/src/type/IndividualExposure.ts +++ b/packages/types/src/type/IndividualExposure.ts @@ -24,7 +24,7 @@ export default class IndividualExposure extends Struct { * @description The value */ public get value (): Balance { - return (this.get('value') as Compact).toBn() as Balance; + return (this.get('value') as Compact).unwrap(); } /** diff --git a/packages/types/src/type/LeasePeriod.ts b/packages/types/src/type/LeasePeriod.ts deleted file mode 100644 index 3780357528..0000000000 --- a/packages/types/src/type/LeasePeriod.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 BlockNumber from './BlockNumber'; - -/** - * @name LeasePeriod - * @description - * The length of the parachain lease - */ -export default class LeasePeriod extends BlockNumber { -} - -/** - * @name LeasePeriodOf - * @description - * The length of the parachain lease - */ -export class LeasePeriodOf extends LeasePeriod { -} diff --git a/packages/types/src/type/PrefabWasmModule.ts b/packages/types/src/type/PrefabWasmModule.ts deleted file mode 100644 index 20ef3b8713..0000000000 --- a/packages/types/src/type/PrefabWasmModule.ts +++ /dev/null @@ -1,57 +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 Option from '../codec/Option'; -import Struct from '../codec/Struct'; -import Bytes from '../primitive/Bytes'; -import Null from '../primitive/Null'; -import U32 from '../primitive/U32'; - -class PrefabWasmModuleReserved extends Option { -} - -/** - * @name PrefabWasmModule - * @description Struct to encode the vesting schedule of an individual account - */ -export default class PrefabWasmModule extends Struct { - public constructor (value?: any) { - super({ - scheduleVersion: Compact.with(U32), - initial: Compact.with(U32), - maximum: Compact.with(U32), - _reserved: PrefabWasmModuleReserved, - code: Bytes - }, value); - } - - /** - * @description The code as [[Bytes]] - */ - public get code (): Bytes { - return this.get('code') as Bytes; - } - - /** - * @description The initial as [[Compact]] - */ - public get initial (): Compact { - return this.get('initial') as Compact; - } - - /** - * @description The maximum as [[Compact]] - */ - public get maximum (): Compact { - return this.get('maximum') as Compact; - } - - /** - * @description The scheduleVersion value as [[Compact]] - */ - public get scheduleVersion (): Compact { - return this.get('scheduleVersion') as Compact; - } -} diff --git a/packages/types/src/type/Schedule.ts b/packages/types/src/type/Schedule.ts deleted file mode 100644 index 79c9d45995..0000000000 --- a/packages/types/src/type/Schedule.ts +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2017-2019 @polkadot/types authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import Struct from '../codec/Struct'; -import Bool from '../primitive/Bool'; -import U32 from '../primitive/U32'; -import Gas from './Gas'; - -/** - * @name Schedule - * @description - * Definition of the cost schedule and other parameterizations for wasm vm - */ -export default class Schedule extends Struct { - public constructor (value?: any) { - super({ - version: U32, - putCodePerByteCost: Gas, - growMemCost: Gas, - regularOpCost: Gas, - returnDataPerByteCost: Gas, - eventDataPerByteCost: Gas, - eventPerTopicCost: Gas, - eventBaseCost: Gas, - sandboxDataReadCost: Gas, - sandboxDataWriteCost: Gas, - maxEventTopics: U32, - maxStackHeight: U32, - maxMemoryPages: U32, - enablePrintln: Bool, - maxSubjectLen: U32 - }, value); - } - - /** - * @description Whether the `ext_println` function is allowed to be used contracts. MUST only be enabled for `dev` chains, NOT for production chains - */ - public get enablePrintln (): Bool { - return this.get('enablePrintln') as Bool; - } - - /** - * @description Gas cost to deposit an event; the base. - */ - public get eventBaseCost (): Gas { - return this.get('eventBaseCost') as Gas; - } - - /** - * @description Gas cost to deposit an event; the per-byte portion. - */ - public get eventDataPerByteCost (): Gas { - return this.get('eventDataPerByteCost') as Gas; - } - - /** - * @description Gas cost to deposit an event; the cost per topic. - */ - public get eventPerTopicCost (): Gas { - return this.get('eventPerTopicCost') as Gas; - } - - /** - * @description Gas cost of a growing memory by single page. - */ - public get growMemCost (): Gas { - return this.get('growMemCost') as Gas; - } - - /** - * @description The maximum number of topics supported by an event. - */ - public get maxEventTopics (): U32 { - return this.get('maxEventTopics') as U32; - } - - /** - * @description What is the maximal memory pages amount is allowed to have for a contract. - */ - public get maxMemoryPages (): U32 { - return this.get('maxMemoryPages') as U32; - } - - /** - * @description How tall the stack is allowed to grow? - */ - public get maxStackHeight (): U32 { - return this.get('maxStackHeight') as U32; - } - - /** - * @description The maximum length of a subject used for PRNG generation. - */ - public get maxSubjectLen (): U32 { - return this.get('maxSubjectLen') as U32; - } - - /** - * @description Cost of putting a byte of code into the storage. - */ - public get putCodePerByteCost (): Gas { - return this.get('putCodePerByteCost') as Gas; - } - - /** - * @description Gas cost of a regular operation. - */ - public get regularOpCost (): Gas { - return this.get('regularOpCost') as Gas; - } - - /** - * @description Gas cost per one byte returned. - */ - public get returnDataPerByteCost (): Gas { - return this.get('returnDataPerByteCost') as Gas; - } - - /** - * @description Gas cost per one byte read from the sandbox memory. - */ - public get sandboxDataReadCost (): Gas { - return this.get('sandboxDataReadCost') as Gas; - } - - /** - * @description Gas cost per one byte written to the sandbox memory. - */ - public get sandboxDataWriteCost (): Gas { - return this.get('sandboxDataWriteCost') as Gas; - } - - /** - * @description Version of the schedule. - */ - public get version (): U32 { - return this.get('version') as U32; - } -} diff --git a/packages/types/src/type/StakingLedger.ts b/packages/types/src/type/StakingLedger.ts index b3b2f5d24e..4e0be406e4 100644 --- a/packages/types/src/type/StakingLedger.ts +++ b/packages/types/src/type/StakingLedger.ts @@ -29,7 +29,7 @@ export default class StakingLedger extends Struct { * @description The total amount of the stash's balance that will be at stake in any forthcoming rounds */ public get active (): Balance { - return (this.get('active') as Compact).toBn() as BlockNumber; + return (this.get('active') as Compact).unwrap(); } /** @@ -43,7 +43,7 @@ export default class StakingLedger extends Struct { * @description The total amount of the stash's balance that we are currently accounting for. It's just `active` plus all the `unlocking` balances */ public get total (): Balance { - return (this.get('total') as Compact).toBn() as Balance; + return (this.get('total') as Compact).unwrap(); } /** diff --git a/packages/types/src/type/UnlockChunk.ts b/packages/types/src/type/UnlockChunk.ts index 5d5c2c604c..92283481c4 100644 --- a/packages/types/src/type/UnlockChunk.ts +++ b/packages/types/src/type/UnlockChunk.ts @@ -24,13 +24,13 @@ export default class UnlockChunk extends Struct { * @description Era number at which point it'll be unlocked */ public get era (): BlockNumber { - return (this.get('era') as Compact).toBn() as BlockNumber; + return (this.get('era') as Compact).unwrap(); } /** * @description Amount of funds to be unlocked */ public get value (): Balance { - return (this.get('value') as Compact).toBn() as Balance; + return (this.get('value') as Compact).unwrap(); } } diff --git a/packages/types/src/type/ValidatorPrefs.ts b/packages/types/src/type/ValidatorPrefs.ts index f4ddd0b6b0..c7025acd86 100644 --- a/packages/types/src/type/ValidatorPrefs.ts +++ b/packages/types/src/type/ValidatorPrefs.ts @@ -30,14 +30,14 @@ export default class ValidatorPrefs extends Struct { /** * @description The unstake threshold as [[U32]] */ - public get unstakeThreshold (): U32 { - return this.get('unstakeThreshold') 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; + public get validatorPayment (): Compact { + return this.get('validatorPayment') as Compact; } } diff --git a/packages/types/src/type/index.ts b/packages/types/src/type/index.ts index 58a6466495..c23ad8c2ac 100644 --- a/packages/types/src/type/index.ts +++ b/packages/types/src/type/index.ts @@ -16,10 +16,7 @@ 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 CodeHash } from './CodeHash'; export { default as Conviction } from './Conviction'; -export { default as ContractInfo } from './ContractInfo'; -export { default as ContractStorageKey } from './ContractStorageKey'; export { default as EraIndex } from './EraIndex'; export { default as Exposure } from './Exposure'; export { default as Extrinsic } from './Extrinsic'; @@ -27,13 +24,11 @@ export { default as ExtrinsicEra, MortalEra, ImmortalEra } from './ExtrinsicEra' export { default as ExtrinsicSignature } from './ExtrinsicSignature'; // NOTE Only used internally, exported as PendingExtrinsics // export { default as Extrinsics } from './Extrinsics'; -export { default as Gas } from './Gas'; export { default as IndividualExposure } from './IndividualExposure'; export { default as InherentOfflineReport } from './InherentOfflineReport'; export { default as Key } from './Key'; export { default as Keys } from './Keys'; export { default as KeyValue } from './KeyValue'; -export { default as LeasePeriod, LeasePeriodOf } from './LeasePeriod'; export { default as LockIdentifier } from './LockIdentifier'; export { default as LockPeriods } from './LockPeriods'; // NOTE Nonce is renamed to Index @@ -46,14 +41,12 @@ 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 PrefabWasmModule } from './PrefabWasmModule'; 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 Schedule } from './Schedule'; export { default as SeedOf } from './SeedOf'; export { default as SessionIndex } from './SessionIndex'; export { default as SessionKey } from './SessionKey';