1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const client_common_1 = require("@neo-one/client-common");
|
4 | const node_core_1 = require("@neo-one/node-core");
|
5 | const Context_1 = require("./Context");
|
6 | class HeaderContext extends Context_1.Context {
|
7 | constructor({ type, viewNumber, myIndex, primaryIndex, expectedView, validators, blockReceivedTimeSeconds, transactions, signatures, header, }) {
|
8 | const previousHash = header.type === 'existing' ? header.block.previousHash : header.previousHash;
|
9 | const transactionHashes = header.transactionHashes;
|
10 | const blockIndex = header.type === 'existing' ? header.block.index : header.blockIndex;
|
11 | const nonce = header.type === 'existing' ? header.block.consensusData : header.nonce;
|
12 | const timestamp = header.type === 'existing' ? header.block.timestamp : header.timestamp;
|
13 | const nextConsensus = header.type === 'existing' ? header.block.nextConsensus : header.nextConsensus;
|
14 | super({
|
15 | type,
|
16 | previousHash,
|
17 | blockIndex,
|
18 | viewNumber,
|
19 | myIndex,
|
20 | primaryIndex,
|
21 | expectedView,
|
22 | validators,
|
23 | blockReceivedTimeSeconds,
|
24 | });
|
25 | this.transactions = transactions;
|
26 | this.transactionHashes = transactionHashes;
|
27 | this.transactionHashesSet = new Set(transactionHashes);
|
28 | this.signatures = signatures;
|
29 | if (header.type === 'existing') {
|
30 | this.header = header.block;
|
31 | }
|
32 | else {
|
33 | this.header = new node_core_1.Block({
|
34 | version: this.version,
|
35 | previousHash: this.previousHash,
|
36 | merkleRoot: node_core_1.MerkleTree.computeRoot(this.transactionHashes.map((hash) => client_common_1.common.hexToUInt256(hash))),
|
37 | timestamp,
|
38 | index: this.blockIndex,
|
39 | consensusData: nonce,
|
40 | nextConsensus,
|
41 | transactions: [],
|
42 | });
|
43 | }
|
44 | }
|
45 | cloneSignatures(_options) {
|
46 | throw new Error('Not Implemented');
|
47 | }
|
48 | toJSON() {
|
49 | return Object.assign({}, super.toJSON(), { transactionHashes: this.transactionHashes.map((hash) => client_common_1.common.uInt256ToString(hash)), signatures: this.signatures.map((signature) => signature === undefined ? 'undefined' : signature.toString('hex')) });
|
50 | }
|
51 | }
|
52 | exports.HeaderContext = HeaderContext;
|
53 |
|
54 | //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkhlYWRlckNvbnRleHQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwREFBdUY7QUFDdkYsa0RBQXVEO0FBRXZELHVDQUFvQztBQStCcEMsTUFBYSxhQUErRCxTQUFRLGlCQUFVO0lBTzVGLFlBQW1CLEVBQ2pCLElBQUksRUFDSixVQUFVLEVBQ1YsT0FBTyxFQUNQLFlBQVksRUFDWixZQUFZLEVBQ1osVUFBVSxFQUNWLHdCQUF3QixFQUN4QixZQUFZLEVBQ1osVUFBVSxFQUNWLE1BQU0sR0FDVztRQUNqQixNQUFNLFlBQVksR0FBRyxNQUFNLENBQUMsSUFBSSxLQUFLLFVBQVUsQ0FBQyxDQUFDLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxZQUFZLENBQUM7UUFDbEcsTUFBTSxpQkFBaUIsR0FBRyxNQUFNLENBQUMsaUJBQWlCLENBQUM7UUFDbkQsTUFBTSxVQUFVLEdBQUcsTUFBTSxDQUFDLElBQUksS0FBSyxVQUFVLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxNQUFNLENBQUMsVUFBVSxDQUFDO1FBQ3ZGLE1BQU0sS0FBSyxHQUFHLE1BQU0sQ0FBQyxJQUFJLEtBQUssVUFBVSxDQUFDLENBQUMsQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLGFBQWEsQ0FBQyxDQUFDLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQztRQUNyRixNQUFNLFNBQVMsR0FBRyxNQUFNLENBQUMsSUFBSSxLQUFLLFVBQVUsQ0FBQyxDQUFD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