@neo-one/node-protocol
Version:
NEO•ONE NEO node and consensus protocol.
63 lines (61 loc) • 2.31 kB
JavaScript
import { IOHelper } from '@neo-one/client-common';
import { BinaryReader, BlockBase, utils, } from '@neo-one/node-core';
export class MerkleBlockPayload extends BlockBase {
constructor({ version, previousHash, merkleRoot, timestamp, index, consensusData, nextConsensus, script, transactionCount, hashes, flags, }) {
super({
version,
previousHash,
merkleRoot,
timestamp,
index,
consensusData,
nextConsensus,
script,
});
this.transactionCount = transactionCount;
this.hashes = hashes;
this.flags = flags;
this.merkleBlockPayloadSizeInternal = utils.lazy(() => super.size +
IOHelper.sizeOfUInt32LE +
IOHelper.sizeOfArray(this.hashes, () => IOHelper.sizeOfUInt256) +
IOHelper.sizeOfVarBytesLE(this.flags));
}
static deserializeWireBase(options) {
const { reader } = options;
const blockBase = super.deserializeBlockBaseWireBase(options);
const transactionCount = reader.readVarUIntLE(utils.INT_MAX_VALUE).toNumber();
const hashes = reader.readArray(() => reader.readUInt256());
const flags = reader.readVarBytesLE();
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,
transactionCount,
hashes,
flags,
});
}
static deserializeWire(options) {
return this.deserializeWireBase({
context: options.context,
reader: new BinaryReader(options.buffer),
});
}
get size() {
return this.merkleBlockPayloadSizeInternal();
}
serializeWireBase(writer) {
super.serializeWireBase(writer);
writer.writeVarUIntLE(this.transactionCount);
writer.writeArray(this.hashes, (hash) => {
writer.writeUInt256(hash);
});
writer.writeVarBytesLE(this.flags);
}
}
//# sourceMappingURL=MerkleBlockPayload.js.map