tx/block: remove hashAsync.
This commit is contained in:
parent
7f5e0cb493
commit
0e40eb6491
@ -1318,8 +1318,6 @@ Chain.prototype._add = co(function* add(block) {
|
|||||||
'error parsing message',
|
'error parsing message',
|
||||||
100);
|
100);
|
||||||
}
|
}
|
||||||
if (util.isBrowser)
|
|
||||||
yield block.cacheHashes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the block height early
|
// Update the block height early
|
||||||
|
|||||||
@ -917,9 +917,6 @@ Pool.prototype._handleBlock = co(function* _handleBlock(block, peer) {
|
|||||||
// Fulfill the load request.
|
// Fulfill the load request.
|
||||||
requested = this.fulfill(block);
|
requested = this.fulfill(block);
|
||||||
|
|
||||||
if (util.isBrowser)
|
|
||||||
yield block.hashAsync();
|
|
||||||
|
|
||||||
// Someone is sending us blocks without
|
// Someone is sending us blocks without
|
||||||
// us requesting them.
|
// us requesting them.
|
||||||
if (!requested) {
|
if (!requested) {
|
||||||
@ -1333,9 +1330,6 @@ Pool.prototype.hasReject = function hasReject(hash) {
|
|||||||
Pool.prototype._handleTX = co(function* _handleTX(tx, peer) {
|
Pool.prototype._handleTX = co(function* _handleTX(tx, peer) {
|
||||||
var i, requested, missing;
|
var i, requested, missing;
|
||||||
|
|
||||||
if (util.isBrowser)
|
|
||||||
yield tx.hashAsync();
|
|
||||||
|
|
||||||
// Fulfill the load request.
|
// Fulfill the load request.
|
||||||
requested = this.fulfill(tx);
|
requested = this.fulfill(tx);
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var constants = require('../protocol/constants');
|
var constants = require('../protocol/constants');
|
||||||
var util = require('../utils/util');
|
var util = require('../utils/util');
|
||||||
var co = require('../utils/co');
|
|
||||||
var crypto = require('../crypto/crypto');
|
var crypto = require('../crypto/crypto');
|
||||||
var btcutils = require('../btc/utils');
|
var btcutils = require('../btc/utils');
|
||||||
var VerifyResult = require('../btc/errors').VerifyResult;
|
var VerifyResult = require('../btc/errors').VerifyResult;
|
||||||
@ -161,54 +160,6 @@ AbstractBlock.prototype.hash = function hash(enc) {
|
|||||||
return hash;
|
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.
|
* Serialize the block headers.
|
||||||
* @returns {Buffer}
|
* @returns {Buffer}
|
||||||
|
|||||||
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var util = require('../utils/util');
|
var util = require('../utils/util');
|
||||||
var co = require('../utils/co');
|
|
||||||
var crypto = require('../crypto/crypto');
|
var crypto = require('../crypto/crypto');
|
||||||
var btcutils = require('../btc/utils');
|
var btcutils = require('../btc/utils');
|
||||||
var Amount = require('../btc/amount');
|
var Amount = require('../btc/amount');
|
||||||
@ -242,35 +241,6 @@ TX.prototype.hash = function _hash(enc) {
|
|||||||
return hash;
|
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
|
* Hash the transaction with the witness
|
||||||
* serialization, return the wtxid (normal
|
* serialization, return the wtxid (normal
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user