Browse Source

Add strictPropertyInitialization

fixTypes
junderw 6 years ago
parent
commit
9955c3c082
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 22
      src/block.ts
  2. 2
      tsconfig.json

22
src/block.ts

@ -24,19 +24,23 @@ function txesHaveWitness (transactions: Array<Transaction>): boolean {
export class Block { export class Block {
version: number version: number
prevHash: Buffer prevHash?: Buffer
merkleRoot: Buffer merkleRoot?: Buffer
timestamp: number timestamp: number
witnessCommit: Buffer witnessCommit?: Buffer
bits: number bits: number
nonce: number nonce: number
transactions: Array<Transaction> transactions?: Array<Transaction>
constructor () { constructor () {
this.version = 1 this.version = 1
this.timestamp = 0 this.timestamp = 0
this.bits = 0 this.bits = 0
this.nonce = 0 this.nonce = 0
this.prevHash = undefined
this.merkleRoot = undefined
this.witnessCommit = undefined
this.transactions = undefined
} }
static fromBuffer (buffer: Buffer): Block { static fromBuffer (buffer: Buffer): Block {
@ -134,7 +138,7 @@ export class Block {
} }
hasWitnessCommit (): boolean { hasWitnessCommit (): boolean {
return txesHaveWitness(this.transactions) return txesHaveWitness(<Array<Transaction>>this.transactions)
} }
byteLength (headersOnly: boolean): number { byteLength (headersOnly: boolean): number {
@ -179,8 +183,8 @@ export class Block {
} }
writeInt32(this.version) writeInt32(this.version)
writeSlice(this.prevHash) writeSlice(<Buffer>this.prevHash)
writeSlice(this.merkleRoot) writeSlice(<Buffer>this.merkleRoot)
writeUInt32(this.timestamp) writeUInt32(this.timestamp)
writeUInt32(this.bits) writeUInt32(this.bits)
writeUInt32(this.nonce) writeUInt32(this.nonce)
@ -207,7 +211,7 @@ export class Block {
if (!this.transactions) throw errorMerkleNoTxes if (!this.transactions) throw errorMerkleNoTxes
const actualMerkleRoot = Block.calculateMerkleRoot(this.transactions) const actualMerkleRoot = Block.calculateMerkleRoot(this.transactions)
return this.merkleRoot.compare(actualMerkleRoot) === 0 return (<Buffer>this.merkleRoot).compare(actualMerkleRoot) === 0
} }
checkWitnessCommit (): boolean { checkWitnessCommit (): boolean {
@ -215,7 +219,7 @@ export class Block {
if (!this.hasWitnessCommit()) throw errorWitnessNotSegwit if (!this.hasWitnessCommit()) throw errorWitnessNotSegwit
const actualWitnessCommit = Block.calculateMerkleRoot(this.transactions, true) const actualWitnessCommit = Block.calculateMerkleRoot(this.transactions, true)
return this.witnessCommit.compare(actualWitnessCommit) === 0 return (<Buffer>this.witnessCommit).compare(actualWitnessCommit) === 0
} }
checkProofOfWork (): boolean { checkProofOfWork (): boolean {

2
tsconfig.json

@ -13,7 +13,7 @@
"strictNullChecks": true, "strictNullChecks": true,
"strictFunctionTypes": true, "strictFunctionTypes": true,
"strictBindCallApply": true, "strictBindCallApply": true,
"strictPropertyInitialization": false, "strictPropertyInitialization": true,
"noImplicitThis": true, "noImplicitThis": true,
"alwaysStrict": true, "alwaysStrict": true,
"esModuleInterop": true "esModuleInterop": true

Loading…
Cancel
Save