Move contracts classes to srml/contracts (now as types-only) (#1153)
* Move contracts classes to srml/contracts (now as types-only) * Exclude srml generated files from codeclimate * Alos excluse types/src/scripts * Replace Compact<T>.toBn() with unwrap() * Fic compact type (#1156) * Remove as unknown as T (T typing is working) * Move interfaces back to the relevant types.ts
This commit is contained in:
@@ -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)
|
||||
);
|
||||
|
||||
@@ -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<UInt | Moment> implements Codec {
|
||||
public constructor (Type: Constructor<UInt | Moment>, value: Compact | AnyNumber = 0) {
|
||||
super(Compact.decodeCompact(Type, value));
|
||||
export default class Compact<T extends UInt | Moment> extends Base<T> implements Codec {
|
||||
public constructor (Type: Constructor<T>, value: Compact<T> | AnyNumber = 0) {
|
||||
super(Compact.decodeCompact<T>(Type, value));
|
||||
}
|
||||
|
||||
public static with (Type: Constructor<UInt | Moment>): Constructor<Compact> {
|
||||
return class extends Compact {
|
||||
public static with<T extends UInt | Moment> (Type: Constructor<T>): Constructor<Compact<T>> {
|
||||
return class extends Compact<T> {
|
||||
public constructor (value?: any) {
|
||||
super(Type, value);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export default class Compact extends Base<UInt | Moment> implements Codec {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static decodeCompact (Type: Constructor<UInt | Moment>, value: Compact | AnyNumber): Moment | UInt {
|
||||
public static decodeCompact<T extends UInt | Moment> (Type: Constructor<T>, value: Compact<T> | 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<UInt | Moment> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BlockNumber>).unwrap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<string, any
|
||||
// `generators[typedef.info](...)` TS will show any unhandled types. Rather
|
||||
// we are being explicit in having no handlers where we do not support (yet)
|
||||
const generators = {
|
||||
[TypeDefInfo.Compact]: errorUnhandled,
|
||||
[TypeDefInfo.Compact]: tsCompact,
|
||||
[TypeDefInfo.DoubleMap]: errorUnhandled,
|
||||
[TypeDefInfo.Enum]: tsEnum,
|
||||
[TypeDefInfo.Linkage]: errorUnhandled,
|
||||
[TypeDefInfo.Null]: errorUnhandled,
|
||||
[TypeDefInfo.Option]: errorUnhandled,
|
||||
[TypeDefInfo.Option]: tsOption,
|
||||
[TypeDefInfo.Plain]: tsPlain,
|
||||
[TypeDefInfo.Struct]: tsStruct,
|
||||
[TypeDefInfo.Tuple]: tsTuple,
|
||||
@@ -168,7 +215,7 @@ function generateTsDef (srmlName: string, { types }: { types: Record<string, any
|
||||
header = header.concat(`import { ${substrateImports.join(', ')} } from '../../type';\n`);
|
||||
}
|
||||
|
||||
fs.writeFileSync(`packages/types/src/srml/${srmlName}/types.ts`, header.concat('\n').concat(sortedDefs.join('\n\n')).concat(FOOTER), { flag: 'w' });
|
||||
fs.writeFileSync(`packages/types/src/srml/${srmlName}/${OUTPUT_FILE}`, header.concat('\n').concat(sortedDefs.join('\n\n')).concat(FOOTER), { flag: 'w' });
|
||||
}
|
||||
|
||||
Object.entries(definitions).forEach(([name, obj]): void =>
|
||||
|
||||
@@ -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<BlockNumber>'
|
||||
},
|
||||
TombstoneContractInfo: 'Hash',
|
||||
ContractInfo: {
|
||||
_enum: {
|
||||
Alive: 'AliveContractInfo',
|
||||
Tombstone: 'TombstoneContractInfo'
|
||||
}
|
||||
},
|
||||
ContractStorageKey: '[u8; 32]',
|
||||
Gas: 'u64',
|
||||
PrefabWasmModuleReserved: 'Option<Null>',
|
||||
PrefabWasmModule: {
|
||||
scheduleVersion: 'Compact<u32>',
|
||||
initial: 'Compact<u32>',
|
||||
maximum: 'Compact<u32>',
|
||||
_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'
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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<BlockNumber>;
|
||||
}
|
||||
|
||||
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<u8> {}
|
||||
|
||||
export interface Gas extends u64 {}
|
||||
|
||||
export interface PrefabWasmModule extends Struct {
|
||||
readonly scheduleVersion: Compact<u32>;
|
||||
readonly initial: Compact<u32>;
|
||||
readonly maximum: Compact<u32>;
|
||||
readonly _reserved: PrefabWasmModuleReserved;
|
||||
readonly code: Bytes;
|
||||
}
|
||||
|
||||
export interface PrefabWasmModuleReserved extends Option<Null> {}
|
||||
|
||||
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 {}
|
||||
@@ -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';
|
||||
|
||||
@@ -63,6 +63,8 @@ export default {
|
||||
Deploy: 'IncomingParachainDeploy'
|
||||
}
|
||||
},
|
||||
LeasePeriod: 'BlockNumber',
|
||||
LeasePeriodOf: 'LeasePeriod',
|
||||
ParachainDispatchOrigin: {
|
||||
_enum: [
|
||||
'Signed',
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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<BlockNumber> {
|
||||
return this.get('lastWrite') as Option<BlockNumber>;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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]';
|
||||
}
|
||||
}
|
||||
@@ -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<Balance>).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<Balance>).unwrap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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<Balance>).unwrap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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<Null> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<BlockNumber>).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<Balance>).unwrap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Balance>).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<Balance>).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<U32> {
|
||||
return this.get('unstakeThreshold') as Compact<U32>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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<Balance> {
|
||||
return this.get('validatorPayment') as Compact<Balance>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user