From 0e40eb6491beca05646352f5f17cc1049c2f7c0e Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 22 Nov 2016 10:28:54 -0800 Subject: [PATCH] tx/block: remove hashAsync. --- lib/blockchain/chain.js | 2 -- lib/net/pool.js | 6 ---- lib/primitives/abstractblock.js | 49 --------------------------------- lib/primitives/tx.js | 30 -------------------- 4 files changed, 87 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 8fe4d1d0..7dc13e1f 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -1318,8 +1318,6 @@ Chain.prototype._add = co(function* add(block) { 'error parsing message', 100); } - if (util.isBrowser) - yield block.cacheHashes(); } // Update the block height early diff --git a/lib/net/pool.js b/lib/net/pool.js index 9d63359e..03f77bd3 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -917,9 +917,6 @@ Pool.prototype._handleBlock = co(function* _handleBlock(block, peer) { // Fulfill the load request. requested = this.fulfill(block); - if (util.isBrowser) - yield block.hashAsync(); - // Someone is sending us blocks without // us requesting them. if (!requested) { @@ -1333,9 +1330,6 @@ Pool.prototype.hasReject = function hasReject(hash) { Pool.prototype._handleTX = co(function* _handleTX(tx, peer) { var i, requested, missing; - if (util.isBrowser) - yield tx.hashAsync(); - // Fulfill the load request. requested = this.fulfill(tx); diff --git a/lib/primitives/abstractblock.js b/lib/primitives/abstractblock.js index 82f28e7d..e7044890 100644 --- a/lib/primitives/abstractblock.js +++ b/lib/primitives/abstractblock.js @@ -10,7 +10,6 @@ var assert = require('assert'); var constants = require('../protocol/constants'); var util = require('../utils/util'); -var co = require('../utils/co'); var crypto = require('../crypto/crypto'); var btcutils = require('../btc/utils'); var VerifyResult = require('../btc/errors').VerifyResult; @@ -161,54 +160,6 @@ AbstractBlock.prototype.hash = function hash(enc) { return hash; }; -/** - * Hash the block headers (async). - * @param {String?} enc - Can be `'hex'` or `null`. - * @returns {Hash|Buffer} hash - */ - -AbstractBlock.prototype.hashAsync = co(function* hashAsync(enc) { - var hash = this._hash; - var hex; - - if (!hash) { - hash = yield crypto.hash256Async(this.abbr()); - if (!this.mutable) - this._hash = hash; - } - - if (enc === 'hex') { - hex = this._hhash; - if (!hex) { - hex = hash.toString('hex'); - if (!this.mutable) - this._hhash = hex; - } - hash = hex; - } - - return hash; -}); - -/** - * Cache hashes. - * @private - */ - -AbstractBlock.prototype.cacheHashes = co(function* cacheHashes() { - var i, tx; - - yield this.hashAsync(); - - if (!this.txs) - return; - - for (i = 0; i < this.txs.length; i++) { - tx = this.txs[i]; - yield tx.hashAsync(); - } -}); - /** * Serialize the block headers. * @returns {Buffer} diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 590e7053..eba52316 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -9,7 +9,6 @@ var assert = require('assert'); var util = require('../utils/util'); -var co = require('../utils/co'); var crypto = require('../crypto/crypto'); var btcutils = require('../btc/utils'); var Amount = require('../btc/amount'); @@ -242,35 +241,6 @@ TX.prototype.hash = function _hash(enc) { return hash; }; -/** - * Hash the transaction with the non-witness serialization (async). - * @param {String?} enc - Can be `'hex'` or `null`. - * @returns {Hash|Buffer} hash - */ - -TX.prototype.hashAsync = co(function* _hashAsync(enc) { - var hash = this._hash; - var hex; - - if (!hash) { - hash = yield crypto.hash256Async(this.toNormal()); - if (!this.mutable) - this._hash = hash; - } - - if (enc === 'hex') { - hex = this._hhash; - if (!hex) { - hex = hash.toString('hex'); - if (!this.mutable) - this._hhash = hex; - } - hash = hex; - } - - return hash; -}); - /** * Hash the transaction with the witness * serialization, return the wtxid (normal