* 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
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
// Copyright 2017-2018 @polkadot/api-codec authors & contributors
|
|
// This software may be modified and distributed under the terms
|
|
// of the ISC license. See the LICENSE file for details.
|
|
|
|
import { AnyU8a } from './types';
|
|
|
|
import blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a';
|
|
|
|
import Struct from './codec/Struct';
|
|
import Vector from './codec/Vector';
|
|
import Extrinsic from './Extrinsic';
|
|
import Hash from './Hash';
|
|
import Header, { HeaderValue } from './Header';
|
|
|
|
export type BlockValue = {
|
|
extrinsics?: Array<AnyU8a>
|
|
header?: HeaderValue
|
|
};
|
|
|
|
// A block encoded with header and extrinsics
|
|
export default class Block extends Struct {
|
|
constructor (value: BlockValue = {}) {
|
|
super({
|
|
header: Header,
|
|
extrinsics: Vector.with(Extrinsic)
|
|
}, value);
|
|
}
|
|
|
|
get extrinsics (): Vector<Extrinsic> {
|
|
return this.raw.extrinsics as Vector<Extrinsic>;
|
|
}
|
|
|
|
// convenience, encodes the header and returns the actual hash
|
|
get hash (): Hash {
|
|
return new Hash(
|
|
blake2Asu8a(this.toU8a(), 256)
|
|
);
|
|
}
|
|
|
|
get header (): Header {
|
|
return this.raw.header as Header;
|
|
}
|
|
}
|