Update with Grandpa types (#411)
* Update with Grandpa types * JSON rename for input/output * JSON -> latest * Revert rpc update * Remove U8a | Uint8Array (equivalent) * Justification is Bytes * Update MisbehaviourReport * Fix JSON
This commit is contained in:
@@ -11,7 +11,7 @@ import StorageData from './StorageData';
|
||||
|
||||
describe('AccountId', () => {
|
||||
describe('decoding', () => {
|
||||
const testDecode = (type: string, input: Uint8Array | string | AccountId | U8a, expected: string) =>
|
||||
const testDecode = (type: string, input: Uint8Array | string | AccountId, expected: string) =>
|
||||
it(`can decode from ${type}`, () => {
|
||||
const a = new AccountId(input);
|
||||
expect(a.toString()).toBe(expected);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BftAuthoritySignature, BftHashSignature, Justification } from './Bft';
|
||||
import { BftAuthoritySignature, BftHashSignature } from './Bft';
|
||||
|
||||
describe('BftAuthoritySignature', () => {
|
||||
const sig = new BftAuthoritySignature({
|
||||
@@ -33,28 +33,3 @@ describe('BftHashSignature', () => {
|
||||
expect(sig.signature.toHex()).toEqual('0x567890098765');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Justification', () => {
|
||||
const just = new Justification({
|
||||
round: 32, // We get `round_number` from JSON, but both `round` and `round_number` works
|
||||
hash: '0xabcd',
|
||||
signatures: [
|
||||
{ authorityId: '0x1234', signature: '0x5678' },
|
||||
{ authorityId: '0x9876', signature: '0x5432' }
|
||||
]
|
||||
});
|
||||
|
||||
it('has the correct hash', () => {
|
||||
expect(just.hash.toHex()).toEqual('0xabcd');
|
||||
});
|
||||
|
||||
it('has the correct round', () => {
|
||||
expect(just.round.toNumber()).toEqual(32);
|
||||
});
|
||||
|
||||
it('has the correct signatures', () => {
|
||||
const sig = just.signatures[1];
|
||||
|
||||
expect(sig.authorityId.toHex()).toEqual('0x9876');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,16 +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 { AnyNumber, AnyU8a } from './types';
|
||||
import { AnyU8a } from './types';
|
||||
|
||||
import U8a from './codec/U8a';
|
||||
import Struct from './codec/Struct';
|
||||
import Tuple from './codec/Tuple';
|
||||
import Vector from './codec/Vector';
|
||||
import AuthorityId from './AuthorityId';
|
||||
import Hash from './Hash';
|
||||
import Signature from './Signature';
|
||||
import U32 from './U32';
|
||||
|
||||
export type BftAuthoritySignatureValue = {
|
||||
authorityId?: AnyU8a,
|
||||
@@ -21,7 +17,7 @@ export type BftAuthoritySignatureValue = {
|
||||
// Represents a Bft Hash and Signature pairing, typically used in reporting
|
||||
// network behaviour.
|
||||
export class BftAuthoritySignature extends Tuple {
|
||||
constructor (value?: BftAuthoritySignatureValue | U8a | Uint8Array) {
|
||||
constructor (value?: BftAuthoritySignatureValue | Uint8Array) {
|
||||
super({
|
||||
authorityId: AuthorityId,
|
||||
signature: Signature
|
||||
@@ -45,7 +41,7 @@ export type BftHashSignatureValue = {
|
||||
// Represents a Bft Hash and Signature pairing, typically used in reporting
|
||||
// network behaviour.
|
||||
export class BftHashSignature extends Tuple {
|
||||
constructor (value?: BftHashSignatureValue | U8a | Uint8Array) {
|
||||
constructor (value?: BftHashSignatureValue | Uint8Array) {
|
||||
super({
|
||||
hash: Hash,
|
||||
signature: Signature
|
||||
@@ -60,33 +56,3 @@ export class BftHashSignature extends Tuple {
|
||||
return this.getAtIndex(1) as Signature;
|
||||
}
|
||||
}
|
||||
|
||||
export type JustificationValue = {
|
||||
round?: AnyNumber,
|
||||
hash?: AnyU8a,
|
||||
signatures?: Array<BftAuthoritySignatureValue>
|
||||
};
|
||||
|
||||
export class Justification extends Struct {
|
||||
constructor (value?: JustificationValue | U8a | Uint8Array) {
|
||||
super({
|
||||
// FIXME Rust returns this as "round_number", we actually want a JSON alias
|
||||
// in the structure to take care of these renames...
|
||||
round: U32,
|
||||
hash: Hash,
|
||||
signatures: Vector.with(BftAuthoritySignature)
|
||||
}, value, new Map([['round', 'round_number']]));
|
||||
}
|
||||
|
||||
get hash (): Hash {
|
||||
return this.get('hash') as Hash;
|
||||
}
|
||||
|
||||
get round (): U32 {
|
||||
return this.get('round') as U32;
|
||||
}
|
||||
|
||||
get signatures (): Vector<BftAuthoritySignature> {
|
||||
return this.get('signatures') as Vector<BftAuthoritySignature>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import { AnyU8a } from './types';
|
||||
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import U8a from './codec/U8a';
|
||||
import Struct from './codec/Struct';
|
||||
import Extrinsics from './Extrinsics';
|
||||
import Hash from './Hash';
|
||||
@@ -19,7 +18,7 @@ export type BlockValue = {
|
||||
|
||||
// A block encoded with header and extrinsics
|
||||
export default class Block extends Struct {
|
||||
constructor (value?: BlockValue | U8a | Uint8Array) {
|
||||
constructor (value?: BlockValue | Uint8Array) {
|
||||
super({
|
||||
header: Header,
|
||||
extrinsics: Extrinsics
|
||||
|
||||
@@ -8,7 +8,6 @@ import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from './codec/Compact';
|
||||
import Struct from './codec/Struct';
|
||||
import U8a from './codec/U8a';
|
||||
|
||||
import BlockNumber from './BlockNumber';
|
||||
import Digest, { DigestItem } from './Digest';
|
||||
@@ -24,7 +23,7 @@ export type HeaderValue = {
|
||||
|
||||
// A block header.
|
||||
export default class Header extends Struct {
|
||||
constructor (value?: HeaderValue | U8a | Uint8Array) {
|
||||
constructor (value?: HeaderValue | Uint8Array) {
|
||||
super({
|
||||
parentHash: Hash,
|
||||
number: Compact.with(BlockNumber),
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright 2017-2018 @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', () => {
|
||||
const just = new RhdJustification({
|
||||
roundNumber: 32,
|
||||
hash: '0xabcd',
|
||||
signatures: [
|
||||
{ authorityId: '0x1234', signature: '0x5678' },
|
||||
{ authorityId: '0x9876', signature: '0x5432' }
|
||||
]
|
||||
});
|
||||
|
||||
it('has the correct hash', () => {
|
||||
expect(just.hash.toHex()).toEqual('0xabcd');
|
||||
});
|
||||
|
||||
it('has the correct round', () => {
|
||||
expect(just.roundNumber.toNumber()).toEqual(32);
|
||||
});
|
||||
|
||||
it('has the correct signatures', () => {
|
||||
const sig = just.signatures[1];
|
||||
|
||||
expect(sig.authorityId.toHex()).toEqual('0x9876');
|
||||
});
|
||||
|
||||
it('creates from a JSON strusture', () => {
|
||||
const viaRpc = new RhdJustification(rpc.result.justification);
|
||||
|
||||
expect(
|
||||
viaRpc.hash.toHex()
|
||||
).toEqual('0xfab4bb3a8b0a072d3d09858dc865ad2750b2e708536b6dacc89fad369eba781a');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2017-2018 @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 { BftAuthoritySignature, BftAuthoritySignatureValue } from './Bft';
|
||||
import Bytes from './Bytes';
|
||||
import Hash from './Hash';
|
||||
import U32 from './U32';
|
||||
|
||||
export type RhdJustificationValue = {
|
||||
roundNumber?: AnyNumber,
|
||||
hash?: AnyU8a,
|
||||
signatures?: Array<BftAuthoritySignatureValue>
|
||||
};
|
||||
|
||||
// generic justification, this is specific per consensus implementation
|
||||
export default class Justification extends Bytes {
|
||||
}
|
||||
|
||||
// justification for Rhododendron
|
||||
export class RhdJustification extends Struct {
|
||||
constructor (value?: RhdJustificationValue | Uint8Array) {
|
||||
super({
|
||||
roundNumber: U32,
|
||||
hash: Hash,
|
||||
signatures: Vector.with(BftAuthoritySignature)
|
||||
}, value, new Map([
|
||||
['roundNumber', 'round_number']
|
||||
]));
|
||||
}
|
||||
|
||||
get hash (): Hash {
|
||||
return this.get('hash') as Hash;
|
||||
}
|
||||
|
||||
get roundNumber (): U32 {
|
||||
return this.get('roundNumber') as U32;
|
||||
}
|
||||
|
||||
get signatures (): Vector<BftAuthoritySignature> {
|
||||
return this.get('signatures') as Vector<BftAuthoritySignature>;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import { AnyU8a } from './types';
|
||||
import Option from './codec/Option';
|
||||
import Struct from './codec/Struct';
|
||||
import Tuple from './codec/Tuple';
|
||||
import U8a from './codec/U8a';
|
||||
import StorageData from './StorageData';
|
||||
import StorageKey from './StorageKey';
|
||||
|
||||
@@ -21,7 +20,7 @@ type KeyValueValue = {
|
||||
// for the keys and values. (Not to be confused with the KeyValue in Metadata, that
|
||||
// is actually for Maps, whereas this is a representation of actaul storage values)
|
||||
export default class KeyValue extends Struct {
|
||||
constructor (value?: KeyValueValue | U8a | Uint8Array) {
|
||||
constructor (value?: KeyValueValue | Uint8Array) {
|
||||
super({
|
||||
key: StorageKey,
|
||||
value: StorageData
|
||||
@@ -46,7 +45,7 @@ export type KeyValueOptionValue = {
|
||||
// however in this case the value could be optional. Here it extends
|
||||
// from a Tuple, indicating the use inside areas such as StorageChangeSet
|
||||
export class KeyValueOption extends Tuple {
|
||||
constructor (value?: KeyValueOptionValue | U8a | Uint8Array) {
|
||||
constructor (value?: KeyValueOptionValue | Uint8Array) {
|
||||
super({
|
||||
key: StorageKey,
|
||||
value: Option.with(StorageData)
|
||||
|
||||
+433
-157
File diff suppressed because it is too large
Load Diff
@@ -2,18 +2,15 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import bbqBirch from './json/Metadata.bbq.json';
|
||||
import compacted from './json/Metadata.latest.json';
|
||||
import Metadata from './Metadata';
|
||||
import rpcdata from './Metadata.rpc';
|
||||
import bbqBirch from './json/Metadata.001.json';
|
||||
import compacted from './json/Metadata.002.json';
|
||||
import latestParsed from './Metadata.latest.json';
|
||||
|
||||
describe('Metadata', () => {
|
||||
it('decodes properly', () => {
|
||||
const decoded = new Metadata(rpcdata);
|
||||
const str = JSON.stringify(decoded.toJSON());
|
||||
|
||||
console.error(str);
|
||||
console.error(decoded.getUniqTypes());
|
||||
|
||||
expect(decoded.events.length).not.toBe(0);
|
||||
});
|
||||
@@ -24,9 +21,14 @@ describe('Metadata', () => {
|
||||
expect(decoded.events.length).not.toBe(0);
|
||||
});
|
||||
|
||||
it('decodes Compacted properly', () => {
|
||||
it('decodes latest properly', () => {
|
||||
const decoded = new Metadata(compacted.result);
|
||||
const str = JSON.stringify(decoded.toJSON());
|
||||
|
||||
console.error(str);
|
||||
console.error(decoded.getUniqTypes());
|
||||
|
||||
expect(decoded.events.length).not.toBe(0);
|
||||
expect(str).toEqual(JSON.stringify(latestParsed));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
import { AnyNumber } from './types';
|
||||
|
||||
import { hexToU8a, isHex, isU8a } from '@polkadot/util';
|
||||
import { assert, hexToU8a, isHex, isU8a, isUndefined } from '@polkadot/util';
|
||||
|
||||
import { getTypeDef, TypeDef, TypeDefInfo } from './codec/createType';
|
||||
import Compact from './codec/Compact';
|
||||
import Enum from './codec/Enum';
|
||||
import EnumType from './codec/EnumType';
|
||||
@@ -16,11 +17,27 @@ import Vector from './codec/Vector';
|
||||
import Text from './Text';
|
||||
import Type from './Type';
|
||||
import U16 from './U16';
|
||||
import * as allTypes from './index';
|
||||
|
||||
// Decodes the runtime metadata as passed through from the `state_getMetadata` call. This
|
||||
// file is probably best understood from the bottom-up, i.e. start reading right at the
|
||||
// end and work up. (Just so we don't use before definition)
|
||||
|
||||
// Quick and dirty flatten (.flat() not available)
|
||||
function flattenUniq (list: Array<any>): Array<any> {
|
||||
const flat = list.reduce((result, entry) => {
|
||||
return result.concat(
|
||||
Array.isArray(entry)
|
||||
? flattenUniq(entry)
|
||||
: entry
|
||||
);
|
||||
}, []);
|
||||
|
||||
return [...new Set(flat)]
|
||||
.filter((value: any) => value)
|
||||
.sort();
|
||||
}
|
||||
|
||||
export class OuterDispatchCall extends Struct {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
@@ -348,14 +365,6 @@ export default class RuntimeMetadata extends Struct {
|
||||
return value;
|
||||
}
|
||||
|
||||
// FIXME Currently toJSON creates a struct, so it is not a one-to-one mapping
|
||||
// with what is actually found on the RPC layer. This needs to be adjusted to
|
||||
// match the constructor with JSON. (However for now, it is useful in
|
||||
// debugging).
|
||||
toJSON (): any {
|
||||
return super.toJSON();
|
||||
}
|
||||
|
||||
get calls (): Vector<OuterDispatchCall> {
|
||||
return (this.get('outerDispatch') as OuterDispatchMetadata).calls;
|
||||
}
|
||||
@@ -370,16 +379,6 @@ export default class RuntimeMetadata extends Struct {
|
||||
|
||||
// Helper to retrieve a list of all type that are found, sorted and de-deuplicated
|
||||
getUniqTypes (): Array<string> {
|
||||
// Quick and dirty flatten (.flat() not available)
|
||||
const flatten = (list: Array<any>): Array<any> =>
|
||||
list.reduce((result, entry) => {
|
||||
return result.concat(
|
||||
Array.isArray(entry)
|
||||
? flatten(entry)
|
||||
: entry
|
||||
);
|
||||
}, []);
|
||||
|
||||
const events = this.events.map((module) =>
|
||||
module.events.map((event) =>
|
||||
event.arguments.map((argument) =>
|
||||
@@ -406,8 +405,41 @@ export default class RuntimeMetadata extends Struct {
|
||||
)
|
||||
);
|
||||
|
||||
return [...new Set(
|
||||
flatten([events, storages, args]).filter((value) => value)
|
||||
)].sort();
|
||||
const types = flattenUniq([events, storages, args]);
|
||||
|
||||
this.validateTypes(types);
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
private validateTypes (types: Array<string>): void {
|
||||
const extractTypes = (types: Array<string>): Array<any> => {
|
||||
return types.map((type) => {
|
||||
const decoded = getTypeDef(type);
|
||||
|
||||
switch (decoded.info) {
|
||||
case TypeDefInfo.Plain:
|
||||
return decoded.type;
|
||||
|
||||
case TypeDefInfo.Compact:
|
||||
case TypeDefInfo.Vector:
|
||||
return extractTypes([(decoded.sub as TypeDef).type]);
|
||||
|
||||
case TypeDefInfo.Tuple:
|
||||
return extractTypes(
|
||||
(decoded.sub as Array<TypeDef>).map((sub) => sub.type)
|
||||
);
|
||||
|
||||
default:
|
||||
throw new Error('Unreachable');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const missing = flattenUniq(extractTypes(types)).filter((type) =>
|
||||
isUndefined((allTypes as any)[type])
|
||||
);
|
||||
|
||||
assert(missing.length === 0, `Unknown types found, no types for ${missing}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ describe('MisbehaviorReport', () => {
|
||||
parentHash: '0x01020304',
|
||||
parentNumber: 78,
|
||||
target: '0x11112222',
|
||||
misbehavior: 0x12
|
||||
misbehavior: 3
|
||||
});
|
||||
|
||||
it('has the correct misbehavior type', () => {
|
||||
|
||||
@@ -6,16 +6,18 @@ import { AnyNumber } from './types';
|
||||
|
||||
import EnumType from './codec/EnumType';
|
||||
import Struct from './codec/Struct';
|
||||
import U8a from './codec/U8a';
|
||||
import AuthorityId from './AuthorityId';
|
||||
import { BftHashSignature, BftHashSignatureValue } from './Bft';
|
||||
import BlockNumber from './BlockNumber';
|
||||
import Hash from './Hash';
|
||||
import U32 from './U32';
|
||||
|
||||
type BftAtReportValue = {
|
||||
type BftAtReportValueSingle = {
|
||||
round?: AnyNumber,
|
||||
a?: BftHashSignatureValue,
|
||||
a?: BftHashSignatureValue
|
||||
};
|
||||
|
||||
type BftAtReportValue = BftAtReportValueSingle & {
|
||||
b?: BftHashSignatureValue
|
||||
};
|
||||
|
||||
@@ -26,7 +28,7 @@ type BftAtReportValue = {
|
||||
// items in the structure is called, except a & b (one should be expected, the
|
||||
// other actual)
|
||||
export class BftAtReport extends Struct {
|
||||
constructor (value?: BftAtReportValue | U8a | Uint8Array) {
|
||||
constructor (value?: BftAtReportValue | Uint8Array) {
|
||||
super({
|
||||
round: U32,
|
||||
a: BftHashSignature,
|
||||
@@ -47,6 +49,27 @@ export class BftAtReport extends Struct {
|
||||
}
|
||||
}
|
||||
|
||||
export class BftProposeOutOfTurn extends Struct {
|
||||
constructor (value?: BftAtReportValue | Uint8Array) {
|
||||
super({
|
||||
round: U32,
|
||||
a: BftHashSignature
|
||||
}, value);
|
||||
}
|
||||
|
||||
get a (): BftHashSignature {
|
||||
return this.get('a') as BftHashSignature;
|
||||
}
|
||||
|
||||
get round (): U32 {
|
||||
return this.get('round') as U32;
|
||||
}
|
||||
}
|
||||
|
||||
// Report of a double-propose
|
||||
export class BftDoublePropose extends BftAtReport {
|
||||
}
|
||||
|
||||
// Report of a double-prepare
|
||||
export class BftDoublePrepare extends BftAtReport {
|
||||
}
|
||||
@@ -55,12 +78,14 @@ export class BftDoublePrepare extends BftAtReport {
|
||||
export class BftDoubleCommit extends BftAtReport {
|
||||
}
|
||||
|
||||
export class MisbehaviorKind extends EnumType<BftDoublePrepare | BftDoubleCommit> {
|
||||
constructor (value?: BftAtReportValue | U8a | Uint8Array, index?: number) {
|
||||
super({
|
||||
0x11: BftDoublePrepare,
|
||||
0x12: BftDoubleCommit
|
||||
}, value, index);
|
||||
export class MisbehaviorKind extends EnumType<BftProposeOutOfTurn | BftDoublePropose | BftDoublePrepare | BftDoubleCommit> {
|
||||
constructor (value?: BftAtReportValue | Uint8Array, index?: number) {
|
||||
super([
|
||||
BftProposeOutOfTurn,
|
||||
BftDoublePropose,
|
||||
BftDoublePrepare,
|
||||
BftDoubleCommit
|
||||
], value, index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +98,7 @@ type MisbehaviorReportValue = {
|
||||
|
||||
// A Misbehaviour report against a specific AuthorityId
|
||||
export default class MisbehaviorReport extends Struct {
|
||||
constructor (value?: MisbehaviorReportValue | U8a | Uint8Array) {
|
||||
constructor (value?: MisbehaviorReportValue | Uint8Array) {
|
||||
super({
|
||||
parentHash: Hash,
|
||||
parentNumber: BlockNumber,
|
||||
|
||||
@@ -6,7 +6,6 @@ import { AnyNumber, AnyU8a } from './types';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import Tuple from './codec/Tuple';
|
||||
import U8a from './codec/U8a';
|
||||
import U8aFixed from './codec/U8aFixed';
|
||||
import Vector from './codec/Vector';
|
||||
import Text from './Text';
|
||||
@@ -24,7 +23,7 @@ type RuntimeVersionApiValue = {
|
||||
};
|
||||
|
||||
class RuntimeVersionApi extends Tuple {
|
||||
constructor (value?: RuntimeVersionApiValue | U8a | Uint8Array) {
|
||||
constructor (value?: RuntimeVersionApiValue | Uint8Array) {
|
||||
super({
|
||||
id: ApiId,
|
||||
version: U32
|
||||
@@ -50,7 +49,7 @@ type RuntimeVersionValue = {
|
||||
};
|
||||
|
||||
export default class RuntimeVersion extends Struct {
|
||||
constructor (value?: RuntimeVersionValue | U8a | Uint8Array) {
|
||||
constructor (value?: RuntimeVersionValue | Uint8Array) {
|
||||
super({
|
||||
specName: Text,
|
||||
implName: Text,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2018 @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';
|
||||
|
||||
// Wrapper for a SessionKey. Same as an normal AuthorityId, i.e. a wrapper
|
||||
// around publicKey.
|
||||
export default class SessionKey extends AuthorityId {
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { AnyNumber, AnyU8a } from './types';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import U8a from './codec/U8a';
|
||||
import Method from './Method';
|
||||
import Hash from './Hash';
|
||||
import Nonce from './Nonce';
|
||||
@@ -27,7 +26,7 @@ type SignaturePayloadValue = {
|
||||
export default class SignaturePayload extends Struct {
|
||||
protected _signature?: Uint8Array;
|
||||
|
||||
constructor (value?: SignaturePayloadValue | U8a | Uint8Array) {
|
||||
constructor (value?: SignaturePayloadValue | Uint8Array) {
|
||||
super({
|
||||
nonce: Nonce,
|
||||
method: Method,
|
||||
|
||||
@@ -25,12 +25,6 @@ describe('SignedBlock', () => {
|
||||
).toEqual('0xbfe02f7c26e5dad1226eccb1f4ef5306312602f7e1edbb9be50e8b87d9c7840b');
|
||||
});
|
||||
|
||||
it('has the justification', () => {
|
||||
expect(
|
||||
block.justification.hash.toHex()
|
||||
).toEqual('0xfab4bb3a8b0a072d3d09858dc865ad2750b2e708536b6dacc89fad369eba781a');
|
||||
});
|
||||
|
||||
it('decodes a block with logs', () => {
|
||||
const s = new SignedBlock(events.result);
|
||||
|
||||
|
||||
@@ -2,18 +2,19 @@
|
||||
// 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 Struct from './codec/Struct';
|
||||
import U8a from './codec/U8a';
|
||||
import { Justification, JustificationValue } from './Bft';
|
||||
import Block, { BlockValue } from './Block';
|
||||
import Justification from './Justification';
|
||||
|
||||
type SignedBlockValue = {
|
||||
block?: BlockValue,
|
||||
justification?: JustificationValue
|
||||
justification?: AnyU8a
|
||||
};
|
||||
|
||||
export default class SignedBlock extends Struct {
|
||||
constructor (value?: SignedBlockValue | U8a | Uint8Array) {
|
||||
constructor (value?: SignedBlockValue | Uint8Array) {
|
||||
super({
|
||||
block: Block,
|
||||
justification: Justification
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import { AnyU8a } from './types';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import U8a from './codec/U8a';
|
||||
import Vector from './codec/Vector';
|
||||
import Hash from './Hash';
|
||||
import { KeyValueOption, KeyValueOptionValue } from './KeyValue';
|
||||
@@ -18,7 +17,7 @@ type StorageChangeSetValue = {
|
||||
// A set of storage changes. It contains the hash/block and
|
||||
// a list of the actual changes that took place
|
||||
export default class StorageChangeSet extends Struct {
|
||||
constructor (value?: StorageChangeSetValue | Uint8Array | U8a) {
|
||||
constructor (value?: StorageChangeSetValue | Uint8Array) {
|
||||
super({
|
||||
hash: Hash,
|
||||
changes: Vector.with(KeyValueOption)
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright 2017-2018 @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 Tuple from './codec/Tuple';
|
||||
import Vector from './codec/Vector';
|
||||
|
||||
import BlockNumber from './BlockNumber';
|
||||
import SessionKey from './SessionKey';
|
||||
import U64 from './U64';
|
||||
|
||||
export type NextAuthorityValue = {
|
||||
index?: AnyNumber,
|
||||
sessionKey?: AnyU8a
|
||||
};
|
||||
|
||||
export type StoredPendingChangeValue = {
|
||||
scheduledAt: AnyNumber,
|
||||
delay: AnyNumber,
|
||||
nextAuthorities?: Array<Uint8Array | NextAuthorityValue>
|
||||
};
|
||||
|
||||
class NextAuthority extends Tuple {
|
||||
constructor (value?: Uint8Array | NextAuthorityValue) {
|
||||
super({
|
||||
sessionKey: SessionKey,
|
||||
index: U64
|
||||
}, value);
|
||||
}
|
||||
|
||||
get index (): U64 {
|
||||
return this.get('index') as U64;
|
||||
}
|
||||
|
||||
get sessionKey (): SessionKey {
|
||||
return this.get('sessionKey') as SessionKey;
|
||||
}
|
||||
}
|
||||
|
||||
// Stored pending change for a Grandpa events
|
||||
export default class StoredPendingChange extends Struct {
|
||||
constructor (value?: Uint8Array | StoredPendingChangeValue) {
|
||||
super({
|
||||
scheduledAt: BlockNumber,
|
||||
delay: BlockNumber,
|
||||
nextAuthorities: Vector.with(NextAuthority)
|
||||
}, value, new Map([
|
||||
['scheduledAt', 'scheduled_at'],
|
||||
['nextAuthorities', 'next_authorities']
|
||||
]));
|
||||
}
|
||||
|
||||
get delay (): BlockNumber {
|
||||
return this.get('delay') as BlockNumber;
|
||||
}
|
||||
|
||||
get nextAuthorities (): Vector<NextAuthority> {
|
||||
return this.get('nextAuthorities') as Vector<NextAuthority>;
|
||||
}
|
||||
|
||||
get scheduledAt (): BlockNumber {
|
||||
return this.get('scheduledAt') as BlockNumber;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import U8a from './codec/U8a';
|
||||
|
||||
describe('Text', () => {
|
||||
describe('decode', () => {
|
||||
const testDecode = (type: string, input: string | U8a | Uint8Array | { toString: () => string }, expected: string) =>
|
||||
const testDecode = (type: string, input: string | Uint8Array | { toString: () => string }, expected: string) =>
|
||||
it(`can decode from ${type}`, () => {
|
||||
expect(new Text(input).toString()).toBe(expected);
|
||||
});
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Compact from './codec/Compact';
|
||||
import U8a from './codec/U8a';
|
||||
import Text from './Text';
|
||||
|
||||
type Mapper = (value: string) => string;
|
||||
@@ -16,7 +15,7 @@ const ALLOWED_BOXES = ['Compact', 'Option', 'Vec'];
|
||||
export default class Type extends Text {
|
||||
private _originalLength: number;
|
||||
|
||||
constructor (value: Text | U8a | Uint8Array | string = '') {
|
||||
constructor (value: Text | Uint8Array | string = '') {
|
||||
// First decode it with Text
|
||||
const textValue = new Text(value).toString();
|
||||
// Then cleanup the textValue to get the @polkadot/types type, and pass the
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import { AnyNumber } from './types';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import U8a from './codec/U8a';
|
||||
import Balance from './Balance';
|
||||
import U32 from './U32';
|
||||
|
||||
@@ -15,7 +14,7 @@ type ValidatorPrefsValue = {
|
||||
};
|
||||
|
||||
export default class ValidatorPrefs extends Struct {
|
||||
constructor (value?: ValidatorPrefsValue | U8a | Uint8Array) {
|
||||
constructor (value?: ValidatorPrefsValue | Uint8Array) {
|
||||
super({
|
||||
unstakeThreshold: U32,
|
||||
validatorPayment: Balance
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Enum from './codec/Enum';
|
||||
import U8a from './codec/U8a';
|
||||
|
||||
// Voting threshold, used inside proposals to set change the voting tally
|
||||
export default class VoteThreshold extends Enum {
|
||||
constructor (index?: number | Uint8Array | U8a) {
|
||||
constructor (index?: number | Uint8Array) {
|
||||
super([
|
||||
'Super majority approval',
|
||||
'Super majority rejection',
|
||||
|
||||
@@ -63,7 +63,7 @@ export default class Option<T extends Codec> extends Base<T> implements Codec {
|
||||
}
|
||||
|
||||
toJSON (): any {
|
||||
this.raw.toJSON();
|
||||
return this.raw.toJSON();
|
||||
}
|
||||
|
||||
toU8a (isBare?: boolean): Uint8Array {
|
||||
|
||||
@@ -44,6 +44,7 @@ export { default as NewAccountOutcome } from './NewAccountOutcome';
|
||||
export { default as Null } from './Null';
|
||||
// NOTE Nonce is renamed to Index
|
||||
export { default as Index } from './Nonce';
|
||||
export { default as Justification } from './Justification';
|
||||
export { default as Origin } from './Origin';
|
||||
export { default as ParachainId } from './ParachainId';
|
||||
export { default as PendingExtrinsics } from './PendingExtrinsics';
|
||||
@@ -54,11 +55,13 @@ export { default as Proposal } from './Proposal';
|
||||
export { default as ProposalIndex } from './ProposalIndex';
|
||||
export { default as ReferendumIndex } from './ReferendumIndex';
|
||||
export { default as RuntimeVersion } from './RuntimeVersion';
|
||||
export { default as SessionKey } from './SessionKey';
|
||||
export { default as Signature } from './Signature';
|
||||
export { default as SignedBlock } from './SignedBlock';
|
||||
export { default as StorageChangeSet } from './StorageChangeSet';
|
||||
export { default as StorageData } from './StorageData';
|
||||
export { default as StorageKey } from './StorageKey';
|
||||
export { default as StoredPendingChange } from './StoredPendingChange';
|
||||
export { default as Text } from './Text';
|
||||
export { default as Type } from './Type';
|
||||
// NOTE We are exporting the U* classes as lowercase, matching with Rust
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user