peer: fix checksum optimization for spv serving.

This commit is contained in:
Christopher Jeffrey 2016-09-17 18:25:45 -07:00
parent 061548f2ac
commit 1096cd0bd9
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -746,14 +746,18 @@ Peer.prototype.write = function write(data) {
*/
Peer.prototype.send = function send(packet) {
var checksum;
var tx, checksum;
// Used cached hashes as the
// packet checksum for speed.
if (packet.type === packetTypes.TX) {
checksum = packet.witness
? packet.tx.witnessHash()
: packet.tx.hash();
tx = packet.tx;
if (packet.witness) {
if (!tx.isCoinbase())
checksum = tx.witnessHash()
} else {
checksum = tx.hash();
}
}
this.write(this.framer.packet(packet.cmd, packet.toRaw(), checksum));