From 9955c3c082b1c34d068167cfbfe5479fdc62f60b Mon Sep 17 00:00:00 2001 From: junderw Date: Sat, 29 Dec 2018 10:35:57 +0900 Subject: [PATCH] Add strictPropertyInitialization --- src/block.ts | 22 +++++++++++++--------- tsconfig.json | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/block.ts b/src/block.ts index 03ff901..6440d8a 100644 --- a/src/block.ts +++ b/src/block.ts @@ -24,19 +24,23 @@ function txesHaveWitness (transactions: Array): boolean { export class Block { version: number - prevHash: Buffer - merkleRoot: Buffer + prevHash?: Buffer + merkleRoot?: Buffer timestamp: number - witnessCommit: Buffer + witnessCommit?: Buffer bits: number nonce: number - transactions: Array + transactions?: Array constructor () { this.version = 1 this.timestamp = 0 this.bits = 0 this.nonce = 0 + this.prevHash = undefined + this.merkleRoot = undefined + this.witnessCommit = undefined + this.transactions = undefined } static fromBuffer (buffer: Buffer): Block { @@ -134,7 +138,7 @@ export class Block { } hasWitnessCommit (): boolean { - return txesHaveWitness(this.transactions) + return txesHaveWitness(>this.transactions) } byteLength (headersOnly: boolean): number { @@ -179,8 +183,8 @@ export class Block { } writeInt32(this.version) - writeSlice(this.prevHash) - writeSlice(this.merkleRoot) + writeSlice(this.prevHash) + writeSlice(this.merkleRoot) writeUInt32(this.timestamp) writeUInt32(this.bits) writeUInt32(this.nonce) @@ -207,7 +211,7 @@ export class Block { if (!this.transactions) throw errorMerkleNoTxes const actualMerkleRoot = Block.calculateMerkleRoot(this.transactions) - return this.merkleRoot.compare(actualMerkleRoot) === 0 + return (this.merkleRoot).compare(actualMerkleRoot) === 0 } checkWitnessCommit (): boolean { @@ -215,7 +219,7 @@ export class Block { if (!this.hasWitnessCommit()) throw errorWitnessNotSegwit const actualWitnessCommit = Block.calculateMerkleRoot(this.transactions, true) - return this.witnessCommit.compare(actualWitnessCommit) === 0 + return (this.witnessCommit).compare(actualWitnessCommit) === 0 } checkProofOfWork (): boolean { diff --git a/tsconfig.json b/tsconfig.json index cfc286a..fd2d954 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "strictBindCallApply": true, - "strictPropertyInitialization": false, + "strictPropertyInitialization": true, "noImplicitThis": true, "alwaysStrict": true, "esModuleInterop": true