Move HeaderExtended type to api-derive (#923)

* Move HeaderExtended type to api-derive

* Really remove HeaderExt from Header this time around
This commit is contained in:
Jaco Greeff
2019-05-17 11:44:14 +02:00
committed by Amaury Martiny
parent 43a1d95809
commit 36d7a85ed2
9 changed files with 81 additions and 69 deletions
-62
View File
@@ -8,8 +8,6 @@ import { blake2AsU8a } from '@polkadot/util-crypto';
import Compact from '../codec/Compact';
import Struct from '../codec/Struct';
import U64 from '../primitive/U64';
import AccountId from '../primitive/AccountId';
import Hash from '../primitive/Hash';
import BlockNumber from '../type/BlockNumber';
import Digest, { DigestItem } from './Digest';
@@ -89,63 +87,3 @@ export default class Header extends Struct {
return this.get('stateRoot') as Hash;
}
}
/**
* @name HeaderExtended
* @description
* A [[Block]] header with an additional `author` field that indicates the block author
*/
export class HeaderExtended extends Header {
private _author?: AccountId;
constructor (header: Header | null = null, sessionValidators: Array<AccountId> = []) {
super(header);
if (!header || !header.digest || !sessionValidators.length) {
return;
}
let item = header.digest.logs.find((log) => log.isConsensus);
let slot: U64 | undefined;
// extract author from the consensus (substrate 1.0, digest)
if (item) {
const consensus = item.asConsensus;
if (consensus.isAura) {
slot = consensus.asAura[0];
}
} else {
item = header.digest.logs.find((log) => log.isSeal);
// extract author from the seal (pre substrate 1.0, backwards compat)
if (item) {
slot = item.asSeal.slot;
}
}
// found a slot? Great, extract the validator
if (slot) {
this._author = sessionValidators[slot.toNumber() % sessionValidators.length];
}
}
/**
* @description Convenience method, returns the author for the block
*/
get author (): AccountId | undefined {
return this._author;
}
/**
* @description Creates the JSON representation
*/
toJSON (): any {
return {
...super.toJSON(),
author: this.author
? this.author.toJSON()
: undefined
};
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ export { default as Block } from './Block';
export { default as ChainProperties } from './ChainProperties';
export { default as Digest, DigestItem } from './Digest';
export { default as ExtrinsicStatus } from './ExtrinsicStatus';
export { default as Header, HeaderExtended } from './Header';
export { default as Header } from './Header';
export { default as Health } from './Health';
export { default as Json } from './Json';
export { default as NetworkState } from './NetworkState';