import { BinaryWriter, HeaderJSON, InvalidFormatError, IOHelper, UInt256 } from '@neo-one/client-common-esnext-esm'; import { BlockBase, BlockBaseAdd } from './BlockBase'; import { DeserializeWireBaseOptions, DeserializeWireOptions, SerializableJSON, SerializableWire, SerializeJSONContext, } from './Serializable'; import { BinaryReader, utils } from './utils'; export type HeaderAdd = BlockBaseAdd; export interface HeaderKey { readonly hashOrIndex: UInt256 | number; } export class Header extends BlockBase implements SerializableWire
, SerializableJSON { public static deserializeWireBase(options: DeserializeWireBaseOptions): Header { const { reader } = options; const blockBase = super.deserializeBlockBaseWireBase(options); if (reader.readUInt8() !== 0) { throw new InvalidFormatError(); } return new this({ version: blockBase.version, previousHash: blockBase.previousHash, merkleRoot: blockBase.merkleRoot, timestamp: blockBase.timestamp, index: blockBase.index, consensusData: blockBase.consensusData, nextConsensus: blockBase.nextConsensus, script: blockBase.script, }); } public static deserializeWire(options: DeserializeWireOptions): Header { return this.deserializeWireBase({ context: options.context, reader: new BinaryReader(options.buffer), }); } protected readonly sizeExclusive: () => number = utils.lazy(() => IOHelper.sizeOfUInt8); public serializeWireBase(writer: BinaryWriter): void { super.serializeWireBase(writer); writer.writeUInt8(0); } public async serializeJSON(context: SerializeJSONContext): Promise { return super.serializeBlockBaseJSON(context); } }