Update TypeScript to use ! instead of casting

This commit is contained in:
junderw 2019-01-15 17:47:30 +09:00
parent bc28949056
commit 1732bafbc1
No known key found for this signature in database
GPG key ID: B256185D3A971908
17 changed files with 99 additions and 97 deletions
ts_src

View file

@ -129,7 +129,7 @@ export class Block {
if (transactions.length === 0) throw errorMerkleNoTxes
if (forWitness && !txesHaveWitness(transactions)) throw errorWitnessNotSegwit
const hashes = transactions.map(transaction => transaction.getHash((<boolean>forWitness)))
const hashes = transactions.map(transaction => transaction.getHash(forWitness!))
const rootHash = fastMerkleRoot(hashes, bcrypto.hash256)
@ -139,7 +139,7 @@ export class Block {
}
hasWitnessCommit (): boolean {
return txesHaveWitness(<Array<Transaction>>this.transactions)
return txesHaveWitness(this.transactions!)
}
byteLength (headersOnly: boolean): number {
@ -184,8 +184,8 @@ export class Block {
}
writeInt32(this.version)
writeSlice(<Buffer>this.prevHash)
writeSlice(<Buffer>this.merkleRoot)
writeSlice(this.prevHash!)
writeSlice(this.merkleRoot!)
writeUInt32(this.timestamp)
writeUInt32(this.bits)
writeUInt32(this.nonce)
@ -212,7 +212,7 @@ export class Block {
if (!this.transactions) throw errorMerkleNoTxes
const actualMerkleRoot = Block.calculateMerkleRoot(this.transactions)
return (<Buffer>this.merkleRoot).compare(actualMerkleRoot) === 0
return this.merkleRoot!.compare(actualMerkleRoot) === 0
}
checkWitnessCommit (): boolean {
@ -220,7 +220,7 @@ export class Block {
if (!this.hasWitnessCommit()) throw errorWitnessNotSegwit
const actualWitnessCommit = Block.calculateMerkleRoot(this.transactions, true)
return (<Buffer>this.witnessCommit).compare(actualWitnessCommit) === 0
return this.witnessCommit!.compare(actualWitnessCommit) === 0
}
checkProofOfWork (): boolean {