Move additional classes to definition-only (#1165)

* Move additional classes to definition-only

* Move some additional quick-hit types

* Last of the easier type/* conversions

* Remove rhd files

* Remove commented line

* Add injector to types loading

* typo

* Update comment

* Merge master

* Rework & organize CHANGELOG

* Some small helper cleanups
This commit is contained in:
Jaco Greeff
2019-07-25 10:32:26 +02:00
committed by GitHub
parent 9ef7ee4a67
commit a25110b281
107 changed files with 682 additions and 1558 deletions
+1 -1
View File
@@ -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 => {
+5 -4
View File
@@ -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<Codec> {
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<Codec> {
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;
}
+9 -5
View File
@@ -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>('Proposal'), ClassOf<VoteThreshold>('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>('VoteThreshold')
}, []);
expect(test.Types).toEqual(['BlockNumber', 'VoteThreshold']);
+2 -1
View File
@@ -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';
+1 -2
View File
@@ -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';
+1 -1
View File
@@ -276,7 +276,7 @@ export function getTypeClass<T extends Codec = Codec> (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
+5
View File
@@ -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<string, Constructor>;
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 => {
+7 -5
View File
@@ -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<Vector<Extrinsic>>('Vec<Extrinsic>')
}, 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<Extrinsic> {
return this.get('extrinsics') as Vector<Extrinsic>;
}
/**
+3 -1
View File
@@ -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'
@@ -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 {
}
@@ -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);
});
+3 -2
View File
@@ -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>('Justification')
}, value);
}
-1
View File
@@ -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';
+51 -18
View File
@@ -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<Name> extends <Base> {<Body>}
function createInterface (name: string = '', base: string, body: string = ''): string {
return `export interface ${name} extends ${base} {${body.length ? '\n' : ''}${body}}`;
}
// helper to generate a `readonly <Name>: <Type>;` 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<string, any
}))
]);
fs.writeFileSync(`packages/types/src/srml/${srmlName}/${OUTPUT_FILE}`, header.concat(sortedDefs).concat(FOOTER), { flag: 'w' });
fs.writeFileSync(`packages/types/src/srml/${srmlName}/types.ts`, header.concat(sortedDefs).concat(FOOTER), { flag: 'w' });
}
Object.entries(definitions).forEach(([srmlName, obj]): void => {
@@ -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' });
@@ -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<AccountId>)',
UncleEntryItem: {
_enum: {
InclusionHeight: 'InclusionHeight',
Uncle: 'Uncle'
}
}
}
};
@@ -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<AccountId>];
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;
}
@@ -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'
}
}
};
+19
View File
@@ -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;
}
@@ -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<AccountId>',
nays: 'Vec<AccountId>'
}
}
};
@@ -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<AccountId>;
readonly nays: Vector<AccountId>;
}
@@ -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'
}
};
@@ -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 {}
@@ -47,6 +47,7 @@ export default {
maxMemoryPages: 'u32',
enablePrintln: 'Bool',
maxSubjectLen: 'u32'
}
},
SeedOf: 'Hash'
}
};
@@ -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 {}
+21 -4
View File
@@ -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';
@@ -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'
}
}
};
@@ -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;
}
@@ -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'
}
};
@@ -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 {}
@@ -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'
]
}
}
};
+28 -1
View File
@@ -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;
}
@@ -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',
+2 -2
View File
@@ -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 {
+2 -1
View File
@@ -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 {
@@ -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<ValidityVote>',
availabilityVotes: 'Vec<AvailabilityVote>'
validityVotes: 'Vec<ValidityVote>'
},
SubId: 'u32',
NewBidder: {
+3 -6
View File
@@ -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<ValidityVote>;
readonly availabilityVotes: Vector<AvailabilityVote>;
}
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<WinningDataEntry> {}
@@ -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'
}
};
+17
View File
@@ -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<u8> {}
export interface SessionKeys extends Struct {
readonly ed25519: AccountId;
}
export interface ValidatorId extends AccountId {}
+1 -16
View File
@@ -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<u32>'
}
Keys: 'SessionKeys'
}
};
+1 -15
View File
@@ -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<u32>;
}
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;
}
@@ -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<u32>'
},
IndividualExposure: {
who: 'AccountId',
value: 'Compact<Balance>'
},
Exposure: {
total: 'Compact<Balance>',
own: 'Compact<Balance>',
others: 'Vec<IndividualExposure>'
},
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<u32>',
validatorPayment: 'Compact<Balance>'
}
}
};
+43
View File
@@ -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<u32>;
}
export interface Exposure extends Struct {
readonly total: Compact<Balance>;
readonly own: Compact<Balance>;
readonly others: Vector<IndividualExposure>;
}
export interface IndividualExposure extends Struct {
readonly who: AccountId;
readonly value: Compact<Balance>;
}
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<u32>;
readonly validatorPayment: Compact<Balance>;
}
@@ -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'
}
}
};
+12
View File
@@ -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;
}
+13 -7
View File
@@ -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';
-13
View File
@@ -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 {
}
-13
View File
@@ -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 {
}
-13
View File
@@ -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 {
}
-11
View File
@@ -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 {
}
-53
View File
@@ -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;
}
}
-35
View File
@@ -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');
});
});
-72
View File
@@ -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;
}
}
-29
View File
@@ -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);
}
}
-45
View File
@@ -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<Balance>).unwrap();
}
/**
* @description The total balance backing this validator
*/
public get total (): Balance {
return (this.get('total') as Compact<Balance>).unwrap();
}
/**
* @description The portions of nominators stashes that are exposed
*/
public get others (): Vector<IndividualExposure> {
return this.get('others') as Vector<IndividualExposure>;
}
}
-14
View File
@@ -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) {
}
@@ -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<Balance>).unwrap();
}
/**
* @description The AccountId
*/
public get who (): AccountId {
return this.get('who') as AccountId;
}
}
@@ -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({}) {
}
@@ -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');
});
});
-62
View File
@@ -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<BftAuthoritySignature> {
return this.get('signatures') as Vector<BftAuthoritySignature>;
}
}
-16
View File
@@ -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]
}
}
-13
View File
@@ -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 {
}
-13
View File
@@ -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 {
}
@@ -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');
});
});
@@ -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;
}
}
@@ -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);
});
});
@@ -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);
}
}
-14
View File
@@ -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 {
}
-13
View File
@@ -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 {
}
-14
View File
@@ -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 {
}
@@ -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 {
}
-61
View File
@@ -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<string, Codec>) {
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;
}
}
@@ -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);
}
}
-13
View File
@@ -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 {
}
-14
View File
@@ -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 {
}
-26
View File
@@ -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;
}
}
@@ -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;
}
}
-42
View File
@@ -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);
}
}
-14
View File
@@ -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 {
}
@@ -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);
});
});
-43
View File
@@ -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<U32> {
return this.get('unstakeThreshold') as Compact<U32>;
}
/**
* @description The payment config for the validator as a [[Compact]] [[Balance]]
*/
public get validatorPayment (): Compact<Balance> {
return this.get('validatorPayment') as Compact<Balance>;
}
}
+18 -15
View File
@@ -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);
});
+5 -3
View File
@@ -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', 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>('Conviction', value.conviction).index;
const result = convictionIndex | (aye.eq(true) ? 0b1 << 7 : 0b0);
@@ -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);
});
});
-20
View File
@@ -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);
}
}
-53
View File
@@ -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;
}
}
-48
View File
@@ -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<AccountId> {
return this.get('ayes') as Vector<AccountId>;
}
/**
* @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<AccountId> {
return this.get('nays') as Vector<AccountId>;
}
/**
* @description The number of approval votes that are needed to pass the motion.
*/
public get threshold (): MemberCount {
return this.get('threshold') as MemberCount;
}
}
-37
View File
@@ -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';