more parsing.
This commit is contained in:
parent
30148368a8
commit
e9c0e24b21
@ -76,6 +76,8 @@ Mempool.prototype._init = function _init() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var unlock = this._lock(utils.nop, []);
|
var unlock = this._lock(utils.nop, []);
|
||||||
|
|
||||||
|
assert(unlock);
|
||||||
|
|
||||||
bcoin.ldb.destroy('mempool', 'memdown', function(err) {
|
bcoin.ldb.destroy('mempool', 'memdown', function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
unlock();
|
unlock();
|
||||||
@ -380,7 +382,7 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback, force) {
|
|||||||
|
|
||||||
Mempool.prototype.addUnchecked = function addUnchecked(tx, peer, callback) {
|
Mempool.prototype.addUnchecked = function addUnchecked(tx, peer, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.tx.addUnchecked(tx, function(err) {
|
this.tx.addUnchecked(tx, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
|
|||||||
@ -20,12 +20,13 @@ function MerkleBlock(data) {
|
|||||||
this.type = 'merkleblock';
|
this.type = 'merkleblock';
|
||||||
|
|
||||||
this.hashes = (data.hashes || []).map(function(hash) {
|
this.hashes = (data.hashes || []).map(function(hash) {
|
||||||
return utils.toHex(hash);
|
return utils.toBuffer(hash, 'hex');
|
||||||
});
|
});
|
||||||
|
|
||||||
this.flags = data.flags || [];
|
this.flags = data.flags || [];
|
||||||
|
|
||||||
// List of matched TXs
|
// List of matched TXs
|
||||||
|
this.txMap = {};
|
||||||
this.tx = [];
|
this.tx = [];
|
||||||
|
|
||||||
// TXs that will be pushed on
|
// TXs that will be pushed on
|
||||||
@ -53,12 +54,13 @@ MerkleBlock.prototype.getRaw = function getRaw() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MerkleBlock.prototype.hasTX = function hasTX(hash) {
|
MerkleBlock.prototype.hasTX = function hasTX(hash) {
|
||||||
return this.tx.indexOf(hash) !== -1;
|
return this.txMap[hash] === true;
|
||||||
};
|
};
|
||||||
|
|
||||||
MerkleBlock.prototype._verifyPartial = function _verifyPartial() {
|
MerkleBlock.prototype._verifyPartial = function _verifyPartial() {
|
||||||
var height = 0;
|
var height = 0;
|
||||||
var tx = [];
|
var tx = [];
|
||||||
|
var txMap = {};
|
||||||
var j = 0;
|
var j = 0;
|
||||||
var hashes = this.hashes;
|
var hashes = this.hashes;
|
||||||
var flags = this.flags;
|
var flags = this.flags;
|
||||||
@ -81,8 +83,10 @@ MerkleBlock.prototype._verifyPartial = function _verifyPartial() {
|
|||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (flag === 0 || depth === height) {
|
if (flag === 0 || depth === height) {
|
||||||
if (depth === height)
|
if (depth === height) {
|
||||||
tx.push(hashes[j]);
|
tx.push(utils.toHex(hashes[j]));
|
||||||
|
txMap[tx[tx.length - 1]] = true;
|
||||||
|
}
|
||||||
return hashes[j++];
|
return hashes[j++];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,21 +96,22 @@ MerkleBlock.prototype._verifyPartial = function _verifyPartial() {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
right = visit(depth + 1);
|
right = visit(depth + 1);
|
||||||
if (right === left)
|
if (right && utils.isEqual(right, left))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (!right)
|
if (!right)
|
||||||
right = left;
|
right = left;
|
||||||
|
|
||||||
return utils.toHex(utils.dsha256(left + right, 'hex'));
|
return utils.dsha256(Buffer.concat([left, right]));
|
||||||
}
|
}
|
||||||
|
|
||||||
root = visit(1);
|
root = utils.toHex(visit(1));
|
||||||
|
|
||||||
if (!root || root !== this.merkleRoot)
|
if (!root || root !== this.merkleRoot)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this.tx = tx;
|
this.tx = tx;
|
||||||
|
this.txMap = txMap;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -232,7 +232,7 @@ Parser.parseInvList = function parseInvList(p) {
|
|||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
items.push({
|
items.push({
|
||||||
type: constants.invByVal[p.readU32()],
|
type: constants.invByVal[p.readU32()],
|
||||||
hash: p.readHash()
|
hash: p.readHash('hex')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,8 +249,8 @@ Parser.parseMerkleBlock = function parseMerkleBlock(p) {
|
|||||||
p.start();
|
p.start();
|
||||||
|
|
||||||
version = p.read32();
|
version = p.read32();
|
||||||
prevBlock = p.readHash();
|
prevBlock = p.readHash('hex');
|
||||||
merkleRoot = p.readHash();
|
merkleRoot = p.readHash('hex');
|
||||||
ts = p.readU32();
|
ts = p.readU32();
|
||||||
bits = p.readU32();
|
bits = p.readU32();
|
||||||
nonce = p.readU32();
|
nonce = p.readU32();
|
||||||
@ -261,7 +261,7 @@ Parser.parseMerkleBlock = function parseMerkleBlock(p) {
|
|||||||
hashes = new Array(hashCount);
|
hashes = new Array(hashCount);
|
||||||
|
|
||||||
for (i = 0; i < hashCount; i++)
|
for (i = 0; i < hashCount; i++)
|
||||||
hashes[i] = p.readHash();
|
hashes[i] = p.readHash('hex');
|
||||||
|
|
||||||
flags = p.readVarBytes();
|
flags = p.readVarBytes();
|
||||||
|
|
||||||
@ -291,8 +291,8 @@ Parser.parseHeaders = function parseHeaders(p) {
|
|||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
headers.push({
|
headers.push({
|
||||||
version: p.read32(),
|
version: p.read32(),
|
||||||
prevBlock: p.readHash(),
|
prevBlock: p.readHash('hex'),
|
||||||
merkleRoot: p.readHash(),
|
merkleRoot: p.readHash('hex'),
|
||||||
ts: p.readU32(),
|
ts: p.readU32(),
|
||||||
bits: p.readU32(),
|
bits: p.readU32(),
|
||||||
nonce: p.readU32(),
|
nonce: p.readU32(),
|
||||||
@ -470,7 +470,7 @@ Parser.parseCoin = function parseCoin(p, extended) {
|
|||||||
coinbase = p.readU8() === 1;
|
coinbase = p.readU8() === 1;
|
||||||
|
|
||||||
if (extended) {
|
if (extended) {
|
||||||
hash = p.readHash();
|
hash = p.readHash('hex');
|
||||||
index = p.readU32();
|
index = p.readU32();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -639,7 +639,7 @@ Parser.parseReject = function parseReject(p) {
|
|||||||
reason = p.readVarString('ascii');
|
reason = p.readVarString('ascii');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = p.readHash();
|
data = p.readHash('hex');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data = null;
|
data = null;
|
||||||
}
|
}
|
||||||
@ -709,7 +709,7 @@ Parser.parseAlert = function parseAlert(p) {
|
|||||||
var version, relayUntil, expiration, id, cancel;
|
var version, relayUntil, expiration, id, cancel;
|
||||||
var cancels, count, i, minVer, maxVer, subVers;
|
var cancels, count, i, minVer, maxVer, subVers;
|
||||||
var priority, comment, statusBar, msg;
|
var priority, comment, statusBar, msg;
|
||||||
var payload, p2, size;
|
var payload, size;
|
||||||
|
|
||||||
p = new BufferReader(p);
|
p = new BufferReader(p);
|
||||||
p.start();
|
p.start();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user