Make Block, Header & Digest generic (#1196)
* Make Block, Header & Digest generic * It lints * Linting passes, tests passes
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Compact, Option, Vec } from './codec';
|
||||
import { AccountId, AccountIndex, Address, Block, Bool, Bytes, ConsensusEngineId, Data, Digest, DigestItem, Event, Extrinsic, ExtrinsicEra, Fixed64, H160, H256, H512, Header, I128, I16, I256, I32, I64, I8, ImmortalEra, Method, Moment, MortalEra, Null, Origin, SignaturePayload, StorageHasher, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, Vote, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive';
|
||||
import { AccountIdOf, Balance, BalanceOf, BlockNumber, Ed25519Signature, Hash, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Perbill, Permill, Phantom, SessionKeys, Signature, Sr25519Signature, StorageData, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime';
|
||||
import { AccountId, AccountIndex, Address, Bool, Bytes, Data, Event, Extrinsic, ExtrinsicEra, Fixed64, GenericBlock, GenericConsensusEngineId, GenericDigest, GenericDigestItem, H160, H256, H512, I128, I16, I256, I32, I64, I8, ImmortalEra, Method, Moment, MortalEra, Null, Origin, SignaturePayload, StorageHasher, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, Vote, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive';
|
||||
import { AccountIdOf, Balance, BalanceOf, Block, BlockNumber, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Perbill, Permill, Phantom, PreRuntime, Seal, SealV0, SessionKeys, Signature, SignedBlock, Sr25519Signature, StorageData, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime';
|
||||
import { AuthorityId } from './interfaces/consensus';
|
||||
import { Keys, SessionIndex } from './interfaces/session';
|
||||
import { AuthorityWeight, NextAuthority, PendingPause, PendingResume, StoredPendingChange, StoredState } from './interfaces/grandpa';
|
||||
@@ -19,7 +19,7 @@ import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceip
|
||||
import { EraIndex, EraRewards, Exposure, IndividualExposure, MomentOf, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from './interfaces/staking';
|
||||
import { DigestOf, EventId, EventIndex, EventRecord, EventRecord0to76, Key, Phase } from './interfaces/system';
|
||||
import { TreasuryProposal } from './interfaces/treasury';
|
||||
import { ApiId, ChainProperties, Consensus, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, PreRuntime, RuntimeVersion, RuntimeVersionApi, Seal, SealV0, SignedBlock, StorageChangeSet } from './interfaces/rpc';
|
||||
import { ApiId, ChainProperties, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from './interfaces/rpc';
|
||||
|
||||
export interface InterfaceRegistry {
|
||||
AccountId: AccountId;
|
||||
@@ -35,9 +35,6 @@ export interface InterfaceRegistry {
|
||||
Event: Event;
|
||||
'Option<Event>': Option<Event>;
|
||||
'Vec<Event>': Vec<Event>;
|
||||
Block: Block;
|
||||
'Option<Block>': Option<Block>;
|
||||
'Vec<Block>': Vec<Block>;
|
||||
Bool: Bool;
|
||||
'Option<Bool>': Option<Bool>;
|
||||
'Vec<Bool>': Vec<Bool>;
|
||||
@@ -47,19 +44,9 @@ export interface InterfaceRegistry {
|
||||
Bytes: Bytes;
|
||||
'Option<Bytes>': Option<Bytes>;
|
||||
'Vec<Bytes>': Vec<Bytes>;
|
||||
ConsensusEngineId: ConsensusEngineId;
|
||||
'Compact<ConsensusEngineId>': Compact<ConsensusEngineId>;
|
||||
'Option<ConsensusEngineId>': Option<ConsensusEngineId>;
|
||||
'Vec<ConsensusEngineId>': Vec<ConsensusEngineId>;
|
||||
Data: Data;
|
||||
'Option<Data>': Option<Data>;
|
||||
'Vec<Data>': Vec<Data>;
|
||||
Digest: Digest;
|
||||
'Option<Digest>': Option<Digest>;
|
||||
'Vec<Digest>': Vec<Digest>;
|
||||
DigestItem: DigestItem;
|
||||
'Option<DigestItem>': Option<DigestItem>;
|
||||
'Vec<DigestItem>': Vec<DigestItem>;
|
||||
H160: H160;
|
||||
'Option<H160>': Option<H160>;
|
||||
'Vec<H160>': Vec<H160>;
|
||||
@@ -69,9 +56,6 @@ export interface InterfaceRegistry {
|
||||
H512: H512;
|
||||
'Option<H512>': Option<H512>;
|
||||
'Vec<H512>': Vec<H512>;
|
||||
Header: Header;
|
||||
'Option<Header>': Option<Header>;
|
||||
'Vec<Header>': Vec<Header>;
|
||||
i8: i8;
|
||||
'Option<i8>': Option<i8>;
|
||||
'Vec<i8>': Vec<i8>;
|
||||
@@ -205,6 +189,19 @@ export interface InterfaceRegistry {
|
||||
SignaturePayload: SignaturePayload;
|
||||
'Option<SignaturePayload>': Option<SignaturePayload>;
|
||||
'Vec<SignaturePayload>': Vec<SignaturePayload>;
|
||||
GenericBlock: GenericBlock;
|
||||
'Option<GenericBlock>': Option<GenericBlock>;
|
||||
'Vec<GenericBlock>': Vec<GenericBlock>;
|
||||
GenericConsensusEngineId: GenericConsensusEngineId;
|
||||
'Compact<GenericConsensusEngineId>': Compact<GenericConsensusEngineId>;
|
||||
'Option<GenericConsensusEngineId>': Option<GenericConsensusEngineId>;
|
||||
'Vec<GenericConsensusEngineId>': Vec<GenericConsensusEngineId>;
|
||||
GenericDigest: GenericDigest;
|
||||
'Option<GenericDigest>': Option<GenericDigest>;
|
||||
'Vec<GenericDigest>': Vec<GenericDigest>;
|
||||
GenericDigestItem: GenericDigestItem;
|
||||
'Option<GenericDigestItem>': Option<GenericDigestItem>;
|
||||
'Vec<GenericDigestItem>': Vec<GenericDigestItem>;
|
||||
AccountIdOf: AccountIdOf;
|
||||
'Option<AccountIdOf>': Option<AccountIdOf>;
|
||||
'Vec<AccountIdOf>': Vec<AccountIdOf>;
|
||||
@@ -219,12 +216,52 @@ export interface InterfaceRegistry {
|
||||
'Compact<BlockNumber>': Compact<BlockNumber>;
|
||||
'Option<BlockNumber>': Option<BlockNumber>;
|
||||
'Vec<BlockNumber>': Vec<BlockNumber>;
|
||||
Signature: Signature;
|
||||
'Option<Signature>': Option<Signature>;
|
||||
'Vec<Signature>': Vec<Signature>;
|
||||
Ed25519Signature: Ed25519Signature;
|
||||
'Option<Ed25519Signature>': Option<Ed25519Signature>;
|
||||
'Vec<Ed25519Signature>': Vec<Ed25519Signature>;
|
||||
Sr25519Signature: Sr25519Signature;
|
||||
'Option<Sr25519Signature>': Option<Sr25519Signature>;
|
||||
'Vec<Sr25519Signature>': Vec<Sr25519Signature>;
|
||||
ConsensusEngineId: ConsensusEngineId;
|
||||
'Compact<ConsensusEngineId>': Compact<ConsensusEngineId>;
|
||||
'Option<ConsensusEngineId>': Option<ConsensusEngineId>;
|
||||
'Vec<ConsensusEngineId>': Vec<ConsensusEngineId>;
|
||||
PreRuntime: PreRuntime;
|
||||
'Option<PreRuntime>': Option<PreRuntime>;
|
||||
'Vec<PreRuntime>': Vec<PreRuntime>;
|
||||
SealV0: SealV0;
|
||||
'Option<SealV0>': Option<SealV0>;
|
||||
'Vec<SealV0>': Vec<SealV0>;
|
||||
Seal: Seal;
|
||||
'Option<Seal>': Option<Seal>;
|
||||
'Vec<Seal>': Vec<Seal>;
|
||||
Consensus: Consensus;
|
||||
'Option<Consensus>': Option<Consensus>;
|
||||
'Vec<Consensus>': Vec<Consensus>;
|
||||
DigestItem: DigestItem;
|
||||
'Option<DigestItem>': Option<DigestItem>;
|
||||
'Vec<DigestItem>': Vec<DigestItem>;
|
||||
Digest: Digest;
|
||||
'Option<Digest>': Option<Digest>;
|
||||
'Vec<Digest>': Vec<Digest>;
|
||||
Hash: Hash;
|
||||
'Option<Hash>': Option<Hash>;
|
||||
'Vec<Hash>': Vec<Hash>;
|
||||
Header: Header;
|
||||
'Option<Header>': Option<Header>;
|
||||
'Vec<Header>': Vec<Header>;
|
||||
Justification: Justification;
|
||||
'Option<Justification>': Option<Justification>;
|
||||
'Vec<Justification>': Vec<Justification>;
|
||||
Block: Block;
|
||||
'Option<Block>': Option<Block>;
|
||||
'Vec<Block>': Vec<Block>;
|
||||
SignedBlock: SignedBlock;
|
||||
'Option<SignedBlock>': Option<SignedBlock>;
|
||||
'Vec<SignedBlock>': Vec<SignedBlock>;
|
||||
KeyTypeId: KeyTypeId;
|
||||
'Compact<KeyTypeId>': Compact<KeyTypeId>;
|
||||
'Option<KeyTypeId>': Option<KeyTypeId>;
|
||||
@@ -250,15 +287,6 @@ export interface InterfaceRegistry {
|
||||
SessionKeys: SessionKeys;
|
||||
'Option<SessionKeys>': Option<SessionKeys>;
|
||||
'Vec<SessionKeys>': Vec<SessionKeys>;
|
||||
Signature: Signature;
|
||||
'Option<Signature>': Option<Signature>;
|
||||
'Vec<Signature>': Vec<Signature>;
|
||||
Ed25519Signature: Ed25519Signature;
|
||||
'Option<Ed25519Signature>': Option<Ed25519Signature>;
|
||||
'Vec<Ed25519Signature>': Vec<Ed25519Signature>;
|
||||
Sr25519Signature: Sr25519Signature;
|
||||
'Option<Sr25519Signature>': Option<Sr25519Signature>;
|
||||
'Vec<Sr25519Signature>': Vec<Sr25519Signature>;
|
||||
StorageData: StorageData;
|
||||
'Option<StorageData>': Option<StorageData>;
|
||||
'Vec<StorageData>': Vec<StorageData>;
|
||||
@@ -581,9 +609,6 @@ export interface InterfaceRegistry {
|
||||
ChainProperties: ChainProperties;
|
||||
'Option<ChainProperties>': Option<ChainProperties>;
|
||||
'Vec<ChainProperties>': Vec<ChainProperties>;
|
||||
Consensus: Consensus;
|
||||
'Option<Consensus>': Option<Consensus>;
|
||||
'Vec<Consensus>': Vec<Consensus>;
|
||||
ExtrinsicStatus: ExtrinsicStatus;
|
||||
'Option<ExtrinsicStatus>': Option<ExtrinsicStatus>;
|
||||
'Vec<ExtrinsicStatus>': Vec<ExtrinsicStatus>;
|
||||
@@ -599,24 +624,12 @@ export interface InterfaceRegistry {
|
||||
PeerInfo: PeerInfo;
|
||||
'Option<PeerInfo>': Option<PeerInfo>;
|
||||
'Vec<PeerInfo>': Vec<PeerInfo>;
|
||||
PreRuntime: PreRuntime;
|
||||
'Option<PreRuntime>': Option<PreRuntime>;
|
||||
'Vec<PreRuntime>': Vec<PreRuntime>;
|
||||
RuntimeVersionApi: RuntimeVersionApi;
|
||||
'Option<RuntimeVersionApi>': Option<RuntimeVersionApi>;
|
||||
'Vec<RuntimeVersionApi>': Vec<RuntimeVersionApi>;
|
||||
RuntimeVersion: RuntimeVersion;
|
||||
'Option<RuntimeVersion>': Option<RuntimeVersion>;
|
||||
'Vec<RuntimeVersion>': Vec<RuntimeVersion>;
|
||||
SealV0: SealV0;
|
||||
'Option<SealV0>': Option<SealV0>;
|
||||
'Vec<SealV0>': Vec<SealV0>;
|
||||
Seal: Seal;
|
||||
'Option<Seal>': Option<Seal>;
|
||||
'Vec<Seal>': Vec<Seal>;
|
||||
SignedBlock: SignedBlock;
|
||||
'Option<SignedBlock>': Option<SignedBlock>;
|
||||
'Vec<SignedBlock>': Vec<SignedBlock>;
|
||||
StorageChangeSet: StorageChangeSet;
|
||||
'Option<StorageChangeSet>': Option<StorageChangeSet>;
|
||||
'Vec<StorageChangeSet>': Vec<StorageChangeSet>;
|
||||
|
||||
@@ -9,7 +9,6 @@ export default {
|
||||
tokenDecimals: 'u32',
|
||||
tokenSymbol: 'Text'
|
||||
},
|
||||
Consensus: '(ConsensusEngineId, Bytes)',
|
||||
ExtrinsicStatus: {
|
||||
_enum: {
|
||||
Future: 'Null',
|
||||
@@ -37,7 +36,6 @@ export default {
|
||||
bestHash: 'Hash',
|
||||
bestNumber: 'BlockNumber'
|
||||
},
|
||||
PreRuntime: '(ConsensusEngineId, Bytes)',
|
||||
RuntimeVersionApi: '(ApiId, u32)',
|
||||
RuntimeVersion: {
|
||||
specName: 'Text',
|
||||
@@ -47,12 +45,6 @@ export default {
|
||||
implVersion: 'u32',
|
||||
apis: 'Vec<RuntimeVersionApi>'
|
||||
},
|
||||
SealV0: '(u64, Signature)',
|
||||
Seal: '(ConsensusEngineId, Bytes)',
|
||||
SignedBlock: {
|
||||
block: 'Block',
|
||||
justification: 'Justification'
|
||||
},
|
||||
StorageChangeSet: {
|
||||
block: 'Hash',
|
||||
changes: 'Vec<KeyValueOption>'
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
import { Codec } from '../../types';
|
||||
import { Enum, Option, Struct, Vec } from '../../codec';
|
||||
import { Block, Bytes, ConsensusEngineId, StorageKey, Text, bool, u32, u64, u8 } from '../../primitive';
|
||||
import { BlockNumber, Hash, Justification, Signature, StorageData } from '../runtime';
|
||||
import { StorageKey, Text, bool, u32, u64, u8 } from '../../primitive';
|
||||
import { BlockNumber, Hash, StorageData } from '../runtime';
|
||||
|
||||
/** Vec<u8> */
|
||||
export type ApiId = Vec<u8>;
|
||||
@@ -16,9 +16,6 @@ export interface ChainProperties extends Struct {
|
||||
readonly tokenSymbol: Text;
|
||||
}
|
||||
|
||||
/** [ConsensusEngineId, Bytes] & Codec */
|
||||
export type Consensus = [ConsensusEngineId, Bytes] & Codec;
|
||||
|
||||
/** Enum */
|
||||
export interface ExtrinsicStatus extends Enum {
|
||||
/** 0:: Future */
|
||||
@@ -76,9 +73,6 @@ export interface PeerInfo extends Struct {
|
||||
readonly bestNumber: BlockNumber;
|
||||
}
|
||||
|
||||
/** [ConsensusEngineId, Bytes] & Codec */
|
||||
export type PreRuntime = [ConsensusEngineId, Bytes] & Codec;
|
||||
|
||||
/** Struct */
|
||||
export interface RuntimeVersion extends Struct {
|
||||
/** Text */
|
||||
@@ -98,20 +92,6 @@ export interface RuntimeVersion extends Struct {
|
||||
/** [ApiId, u32] & Codec */
|
||||
export type RuntimeVersionApi = [ApiId, u32] & Codec;
|
||||
|
||||
/** [ConsensusEngineId, Bytes] & Codec */
|
||||
export type Seal = [ConsensusEngineId, Bytes] & Codec;
|
||||
|
||||
/** [u64, Signature] & Codec */
|
||||
export type SealV0 = [u64, Signature] & Codec;
|
||||
|
||||
/** Struct */
|
||||
export interface SignedBlock extends Struct {
|
||||
/** Block */
|
||||
readonly block: Block;
|
||||
/** Justification */
|
||||
readonly justification: Justification;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface StorageChangeSet extends Struct {
|
||||
/** Hash */
|
||||
|
||||
+13
-13
@@ -2,23 +2,23 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import '../injector';
|
||||
import '../../injector';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import json1 from '../json/Header.001.json';
|
||||
import json2 from '../json/Header.002.json';
|
||||
import json3 from '../json/Header.003.json';
|
||||
import block00300 from '../json/SignedBlock.003.00.json';
|
||||
import block00301 from '../json/SignedBlock.003.01.json';
|
||||
import Header from './Header';
|
||||
import createType from '../../codec/createType';
|
||||
import json1 from '../../json/Header.001.json';
|
||||
import json2 from '../../json/Header.002.json';
|
||||
import json3 from '../../json/Header.003.json';
|
||||
import block00300 from '../../json/SignedBlock.003.00.json';
|
||||
import block00301 from '../../json/SignedBlock.003.01.json';
|
||||
|
||||
describe('Header', (): void => {
|
||||
it('decodes an actual JSON response', (): void => {
|
||||
const header = new Header(json1.result);
|
||||
const header = createType('Header', json1.result);
|
||||
|
||||
expect(
|
||||
header.blockNumber.toNumber()
|
||||
header.number.toNumber()
|
||||
).toEqual(0);
|
||||
expect(
|
||||
header.extrinsicsRoot.toString()
|
||||
@@ -35,7 +35,7 @@ describe('Header', (): void => {
|
||||
});
|
||||
|
||||
it('parses old-style JSON headers (deprecated)', (): void => {
|
||||
const header = new Header(json2.result);
|
||||
const header = createType('Header', json2.result);
|
||||
|
||||
expect(
|
||||
header.digest.logs
|
||||
@@ -43,18 +43,18 @@ describe('Header', (): void => {
|
||||
});
|
||||
|
||||
it('creates a valid hash (incl. digest & compact)', (): void => {
|
||||
const header = new Header(json3.result);
|
||||
const header = createType('Header', json3.result);
|
||||
|
||||
expect(
|
||||
header.hash.toHex()
|
||||
).toEqual('0x464692ad0e225a74274a7ef411e045f1fc7c2639b5f780c7c18f91f4100f5e54');
|
||||
expect(
|
||||
header.blockNumber.eq(new BN(1650758))
|
||||
header.number.eq(new BN(1650758))
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('calculates correct hash, matching with parentHash', (): void => {
|
||||
const blockHash = new Header(block00300.result.block.header).hash.toHex();
|
||||
const blockHash = createType('Header', block00300.result.block.header).hash.toHex();
|
||||
|
||||
expect(blockHash).toEqual(block00301.result.block.header.parentHash);
|
||||
});
|
||||
@@ -8,8 +8,37 @@ export default {
|
||||
Balance: 'u128',
|
||||
BalanceOf: 'Balance',
|
||||
BlockNumber: 'u64',
|
||||
|
||||
// block
|
||||
// :: signature
|
||||
Signature: 'H512',
|
||||
Ed25519Signature: 'Signature',
|
||||
Sr25519Signature: 'Signature',
|
||||
// :: digest
|
||||
ConsensusEngineId: 'GenericConsensusEngineId',
|
||||
PreRuntime: '(ConsensusEngineId, Bytes)',
|
||||
SealV0: '(u64, Signature)',
|
||||
Seal: '(ConsensusEngineId, Bytes)',
|
||||
Consensus: '(ConsensusEngineId, Bytes)',
|
||||
DigestItem: 'GenericDigestItem',
|
||||
Digest: 'GenericDigest',
|
||||
Hash: 'H256',
|
||||
// :: parts
|
||||
Header: {
|
||||
parentHash: 'Hash',
|
||||
number: 'Compact<BlockNumber>',
|
||||
stateRoot: 'Hash',
|
||||
extrinsicsRoot: 'Hash',
|
||||
digest: 'Digest'
|
||||
},
|
||||
Justification: 'Bytes',
|
||||
// :: definitions
|
||||
Block: 'GenericBlock',
|
||||
SignedBlock: {
|
||||
block: 'Block',
|
||||
justification: 'Justification'
|
||||
},
|
||||
|
||||
KeyTypeId: 'u32',
|
||||
LockIdentifier: '[u8; 8]',
|
||||
Index: 'u64',
|
||||
@@ -19,9 +48,6 @@ export default {
|
||||
SessionKeys: {
|
||||
ed25519: 'AccountId'
|
||||
},
|
||||
Signature: 'H512',
|
||||
Ed25519Signature: 'Signature',
|
||||
Sr25519Signature: 'Signature',
|
||||
StorageData: 'Bytes',
|
||||
KeyValue: '(StorageKey, StorageData)',
|
||||
ValidatorId: 'AccountId',
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Codec } from '../../types';
|
||||
import { Struct, Vec } from '../../codec';
|
||||
import { AccountId, Bytes, Fixed64, H256, H512, Null, StorageKey, u128, u32, u64, u8 } from '../../primitive';
|
||||
import { Compact, Struct, Vec } from '../../codec';
|
||||
import { AccountId, Bytes, Fixed64, GenericBlock, GenericConsensusEngineId, GenericDigest, GenericDigestItem, H256, H512, Null, StorageKey, u128, u32, u64, u8 } from '../../primitive';
|
||||
|
||||
/** AccountId */
|
||||
export type AccountIdOf = AccountId;
|
||||
@@ -13,15 +13,44 @@ export type Balance = u128;
|
||||
/** Balance */
|
||||
export type BalanceOf = Balance;
|
||||
|
||||
/** GenericBlock */
|
||||
export type Block = GenericBlock;
|
||||
|
||||
/** u64 */
|
||||
export type BlockNumber = u64;
|
||||
|
||||
/** [ConsensusEngineId, Bytes] & Codec */
|
||||
export type Consensus = [ConsensusEngineId, Bytes] & Codec;
|
||||
|
||||
/** GenericConsensusEngineId */
|
||||
export type ConsensusEngineId = GenericConsensusEngineId;
|
||||
|
||||
/** GenericDigest */
|
||||
export type Digest = GenericDigest;
|
||||
|
||||
/** GenericDigestItem */
|
||||
export type DigestItem = GenericDigestItem;
|
||||
|
||||
/** Signature */
|
||||
export type Ed25519Signature = Signature;
|
||||
|
||||
/** H256 */
|
||||
export type Hash = H256;
|
||||
|
||||
/** Struct */
|
||||
export interface Header extends Struct {
|
||||
/** Hash */
|
||||
readonly parentHash: Hash;
|
||||
/** Compact<BlockNumber> */
|
||||
readonly number: Compact<BlockNumber>;
|
||||
/** Hash */
|
||||
readonly stateRoot: Hash;
|
||||
/** Hash */
|
||||
readonly extrinsicsRoot: Hash;
|
||||
/** Digest */
|
||||
readonly digest: Digest;
|
||||
}
|
||||
|
||||
/** u64 */
|
||||
export type Index = u64;
|
||||
|
||||
@@ -46,6 +75,15 @@ export type Permill = u32;
|
||||
/** Null */
|
||||
export type Phantom = Null;
|
||||
|
||||
/** [ConsensusEngineId, Bytes] & Codec */
|
||||
export type PreRuntime = [ConsensusEngineId, Bytes] & Codec;
|
||||
|
||||
/** [ConsensusEngineId, Bytes] & Codec */
|
||||
export type Seal = [ConsensusEngineId, Bytes] & Codec;
|
||||
|
||||
/** [u64, Signature] & Codec */
|
||||
export type SealV0 = [u64, Signature] & Codec;
|
||||
|
||||
/** Struct */
|
||||
export interface SessionKeys extends Struct {
|
||||
/** AccountId */
|
||||
@@ -55,6 +93,14 @@ export interface SessionKeys extends Struct {
|
||||
/** H512 */
|
||||
export type Signature = H512;
|
||||
|
||||
/** Struct */
|
||||
export interface SignedBlock extends Struct {
|
||||
/** Block */
|
||||
readonly block: Block;
|
||||
/** Justification */
|
||||
readonly justification: Justification;
|
||||
}
|
||||
|
||||
/** Signature */
|
||||
export type Sr25519Signature = Signature;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
|
||||
import { Enum, Struct, Vec } from '../../codec';
|
||||
import { Bytes, Digest, Event, u32, u8 } from '../../primitive';
|
||||
import { Hash } from '../runtime';
|
||||
import { Bytes, Event, u32, u8 } from '../../primitive';
|
||||
import { Digest, Hash } from '../runtime';
|
||||
|
||||
/** Digest */
|
||||
export type DigestOf = Digest;
|
||||
|
||||
+3
-3
@@ -2,12 +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 '../injector';
|
||||
import '../../injector';
|
||||
|
||||
import extrinsics from '@polkadot/api-metadata/extrinsics/static';
|
||||
|
||||
import block00300 from '../json/SignedBlock.003.00.json';
|
||||
import Method from './Method';
|
||||
import block00300 from '../../json/SignedBlock.003.00.json';
|
||||
import Method from '../Method';
|
||||
import Block from './Block';
|
||||
|
||||
describe('Block', (): void => {
|
||||
+15
-8
@@ -2,16 +2,23 @@
|
||||
// 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 '../interfaces/runtime';
|
||||
import { AnyU8a } from '../types';
|
||||
import { Digest, DigestItem, Hash, Header } from '../../interfaces/runtime';
|
||||
import { AnyNumber, AnyU8a } from '../../types';
|
||||
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import createType, { ClassOf } from '../codec/createType';
|
||||
import Extrinsic from './Extrinsic/Extrinsic';
|
||||
import Struct from '../codec/Struct';
|
||||
import Vec from '../codec/Vec';
|
||||
import Header, { HeaderValue } from './Header';
|
||||
import createType, { ClassOf } from '../../codec/createType';
|
||||
import Extrinsic from '../Extrinsic/Extrinsic';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vec from '../../codec/Vec';
|
||||
|
||||
export interface HeaderValue {
|
||||
digest?: Digest | { logs: DigestItem[] };
|
||||
extrinsicsRoot?: AnyU8a;
|
||||
number?: AnyNumber;
|
||||
parentHash?: AnyU8a;
|
||||
stateRoot?: AnyU8a;
|
||||
}
|
||||
|
||||
export interface BlockValue {
|
||||
extrinsics?: AnyU8a[];
|
||||
@@ -26,7 +33,7 @@ export interface BlockValue {
|
||||
export default class Block extends Struct {
|
||||
public constructor (value?: BlockValue | Uint8Array) {
|
||||
super({
|
||||
header: Header,
|
||||
header: ClassOf('Header'),
|
||||
extrinsics: ClassOf('Vec<Extrinsic>')
|
||||
}, value);
|
||||
}
|
||||
+3
-3
@@ -5,9 +5,9 @@
|
||||
import BN from 'bn.js';
|
||||
import { assert, bnToBn } from '@polkadot/util';
|
||||
|
||||
import Bytes from './Bytes';
|
||||
import U32 from './U32';
|
||||
import U64 from './U64';
|
||||
import Bytes from '../Bytes';
|
||||
import U32 from '../U32';
|
||||
import U64 from '../U64';
|
||||
|
||||
const CID_AURA = 0x61727561; // 'aura'
|
||||
const CID_BABE = 0x65626162; // 'babe'
|
||||
+3
-3
@@ -2,10 +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 '../injector';
|
||||
import '../../injector';
|
||||
|
||||
import json3 from '../json/Header.003.json';
|
||||
import block1 from '../json/SignedBlock.003.00.json';
|
||||
import json3 from '../../json/Header.003.json';
|
||||
import block1 from '../../json/SignedBlock.003.00.json';
|
||||
import ConsensusEngineId, { CID_AURA, CID_BABE, CID_GRPA } from './ConsensusEngineId';
|
||||
import Digest from './Digest';
|
||||
|
||||
+7
-8
@@ -2,17 +2,16 @@
|
||||
// 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 '../interfaces/consensus';
|
||||
import { Hash } from '../interfaces/runtime';
|
||||
import { Consensus, PreRuntime, Seal, SealV0 } from '../interfaces/rpc';
|
||||
import { AuthorityId } from '../../interfaces/consensus';
|
||||
import { Consensus, Hash, PreRuntime, Seal, SealV0 } from '../../interfaces/runtime';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { ClassOf } from '../codec/createType';
|
||||
import Enum from '../codec/Enum';
|
||||
import Struct from '../codec/Struct';
|
||||
import Vec from '../codec/Vec';
|
||||
import Bytes from './Bytes';
|
||||
import { ClassOf } from '../../codec/createType';
|
||||
import Enum from '../../codec/Enum';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Bytes from '../Bytes';
|
||||
|
||||
/**
|
||||
* @name DigestItem
|
||||
@@ -0,0 +1,7 @@
|
||||
// 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 as GenericBlock } from './Block';
|
||||
export { default as GenericConsensusEngineId } from './ConsensusEngineId';
|
||||
export { default as GenericDigest, DigestItem as GenericDigestItem } from './Digest';
|
||||
@@ -1,78 +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, Hash } from '../interfaces/runtime';
|
||||
import { AnyNumber, AnyU8a } from '../types';
|
||||
|
||||
import { ClassOf } from '../codec/createType';
|
||||
import Compact from '../codec/Compact';
|
||||
import Struct from '../codec/Struct';
|
||||
import Digest, { DigestItem } from './Digest';
|
||||
|
||||
export interface HeaderValue {
|
||||
digest?: Digest | { logs: DigestItem[] };
|
||||
extrinsicsRoot?: AnyU8a;
|
||||
number?: AnyNumber;
|
||||
parentHash?: AnyU8a;
|
||||
stateRoot?: AnyU8a;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Header
|
||||
* @description
|
||||
* A [[Block]] header
|
||||
*/
|
||||
export default class Header extends Struct {
|
||||
public constructor (value?: HeaderValue | Uint8Array | null) {
|
||||
super({
|
||||
parentHash: ClassOf('Hash'),
|
||||
number: ClassOf('Compact<BlockNumber>'),
|
||||
stateRoot: ClassOf('Hash'),
|
||||
extrinsicsRoot: ClassOf('Hash'),
|
||||
digest: ClassOf('Digest')
|
||||
}, value || {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[BlockNumber]]
|
||||
*/
|
||||
public get blockNumber (): BlockNumber {
|
||||
return (this.get('number') as Compact<BlockNumber>).unwrap();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[Digest]]
|
||||
*/
|
||||
public get digest (): Digest {
|
||||
return this.get('digest') as Digest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped extrisics root as a [[Hash]]
|
||||
*/
|
||||
public get extrinsicsRoot (): Hash {
|
||||
return this.get('extrinsicsRoot') as Hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Alias for `blockNumber` (this is displayed in JSON)
|
||||
*/
|
||||
public get number (): BlockNumber {
|
||||
return this.blockNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped parent as a [[Hash]]
|
||||
*/
|
||||
public get parentHash (): Hash {
|
||||
return this.get('parentHash') as Hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped state root as a [[Hash]]
|
||||
*/
|
||||
public get stateRoot (): Hash {
|
||||
return this.get('stateRoot') as Hash;
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,14 @@ export { default as AccountId } from './AccountId';
|
||||
export { default as AccountIndex } from './AccountIndex';
|
||||
export { default as Address } from './Address';
|
||||
export { default as Event } from './Event';
|
||||
export { default as Block } from './Block';
|
||||
export { default as Bool, default as bool } from './Bool';
|
||||
export { default as Bytes } from './Bytes';
|
||||
export { default as ConsensusEngineId } from './ConsensusEngineId';
|
||||
export { default as Data } from './Data';
|
||||
export { default as Digest, DigestItem } from './Digest';
|
||||
export * from './Extrinsic';
|
||||
export * from './Generic';
|
||||
export { default as H160 } from './H160';
|
||||
export { default as H256 } from './H256';
|
||||
export { default as H512 } from './H512';
|
||||
export { default as Header } from './Header';
|
||||
export { default as i8, default as I8 } from './I8';
|
||||
export { default as i16, default as I16 } from './I16';
|
||||
export { default as i32, default as I32 } from './I32';
|
||||
|
||||
Reference in New Issue
Block a user