Expand types & tests (#166)
* RegEx for alias * Expand tests * Cleanup naming * Options & Struct tests * Cleanup Length with tests * Enum tests * TODO... expand/question assumption * Remove extra line * Hashin tests (commented, encoding change) * Export Type on Vector & Struct * Test Type & Base * Address FIXME & additional test * Cleanup TODOs * Add MisbehaviorReport * Add index.ts combinators * typo in export * Comment typo * Update index.ts * Update MisbehaviorReport.ts * Update MisbehaviorReport.spec.js * Extract Bft, add SignedBlock (allow anonymous structures) * <foo>Struct -> <foo>Value (for constructor args) * AnyNumber/U8a types for inputs (PR comment) * Comment struct generics * Typo in comment * Simplify StorageFunctionType construction * Fix liniting (wtf?) * Fix linting & tests, make more robust
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { AnyNumber, AnyU8a } from './types';
|
||||
|
||||
import blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a';
|
||||
|
||||
import UInt from './codec/UInt';
|
||||
import Struct from './codec/Struct';
|
||||
import Vector from './codec/Vector';
|
||||
|
||||
@@ -13,21 +13,21 @@ import BlockNumber from './BlockNumber';
|
||||
import Bytes from './Bytes';
|
||||
import Hash from './Hash';
|
||||
|
||||
type DigestStruct = {
|
||||
logs?: Array<Uint8Array | string>
|
||||
type DigestValue = {
|
||||
logs?: Array<AnyU8a>
|
||||
};
|
||||
|
||||
type HeaderStruct = {
|
||||
digest?: DigestStruct,
|
||||
extrinsicsRoot?: Hash | Uint8Array | string,
|
||||
number?: UInt | BN | number | string,
|
||||
parentHash?: Hash | Uint8Array | string,
|
||||
stateRoot?: Hash | Uint8Array | string
|
||||
export type HeaderValue = {
|
||||
digest?: DigestValue,
|
||||
extrinsicsRoot?: AnyU8a,
|
||||
number?: AnyNumber,
|
||||
parentHash?: AnyU8a,
|
||||
stateRoot?: AnyU8a
|
||||
};
|
||||
|
||||
// A block header digest.
|
||||
export class Digest extends Struct {
|
||||
constructor (value: DigestStruct = {}) {
|
||||
constructor (value: DigestValue = {}) {
|
||||
super({
|
||||
logs: Vector.with(Bytes)
|
||||
}, value);
|
||||
@@ -40,7 +40,7 @@ export class Digest extends Struct {
|
||||
|
||||
// A block header.
|
||||
export default class Header extends Struct {
|
||||
constructor (value: HeaderStruct = {}) {
|
||||
constructor (value: HeaderValue = {}) {
|
||||
super({
|
||||
parentHash: Hash,
|
||||
number: BlockNumber,
|
||||
@@ -62,7 +62,7 @@ export default class Header extends Struct {
|
||||
return this.raw.extrinsicsRoot as Hash;
|
||||
}
|
||||
|
||||
// convernience, encodes the header and returns the actual hash
|
||||
// convenience, encodes the header and returns the actual hash
|
||||
get hash (): Hash {
|
||||
return new Hash(
|
||||
blake2Asu8a(this.toU8a(), 256)
|
||||
|
||||
Reference in New Issue
Block a user