FindAndDelete. misc cleanup.
This commit is contained in:
parent
64b92ab073
commit
690f1629c3
@ -483,11 +483,6 @@ Mempool.prototype.addTX = function addTX(tx, callback, force) {
|
|||||||
if (tx.mutable)
|
if (tx.mutable)
|
||||||
tx = tx.toTX();
|
tx = tx.toTX();
|
||||||
|
|
||||||
if (this.chain.segwitActive) {
|
|
||||||
flags |= constants.flags.VERIFY_WITNESS;
|
|
||||||
flags |= constants.flags.VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback = utils.wrap(callback, unlock);
|
callback = utils.wrap(callback, unlock);
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
@ -684,11 +679,8 @@ Mempool.prototype.verify = function verify(tx, callback) {
|
|||||||
var ret = {};
|
var ret = {};
|
||||||
var fee, now, free, minFee;
|
var fee, now, free, minFee;
|
||||||
|
|
||||||
if (this.chain.segwitActive) {
|
if (this.chain.segwitActive)
|
||||||
flags |= constants.flags.VERIFY_WITNESS;
|
|
||||||
flags |= constants.flags.VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM;
|
|
||||||
mandatory |= constants.flags.VERIFY_WITNESS;
|
mandatory |= constants.flags.VERIFY_WITNESS;
|
||||||
}
|
|
||||||
|
|
||||||
this.checkLocks(tx, lockFlags, function(err, result) {
|
this.checkLocks(tx, lockFlags, function(err, result) {
|
||||||
if (err)
|
if (err)
|
||||||
|
|||||||
@ -501,7 +501,7 @@ testnet.block = {
|
|||||||
pruneAfterHeight: 1000,
|
pruneAfterHeight: 1000,
|
||||||
// maxTipAge: 0x7fffffff
|
// maxTipAge: 0x7fffffff
|
||||||
maxTipAge: 24 * 60 * 60,
|
maxTipAge: 24 * 60 * 60,
|
||||||
slowHeight: 700000
|
slowHeight: 500000
|
||||||
};
|
};
|
||||||
|
|
||||||
testnet.witness = false;
|
testnet.witness = false;
|
||||||
|
|||||||
@ -944,6 +944,8 @@ Script.prototype.getSubscript = function getSubscript(lastSep) {
|
|||||||
assert(lastSep <= 0 || this.code[lastSep] === opcodes.OP_CODESEPARATOR);
|
assert(lastSep <= 0 || this.code[lastSep] === opcodes.OP_CODESEPARATOR);
|
||||||
|
|
||||||
for (i = lastSep + 1; i < this.code.length; i++) {
|
for (i = lastSep + 1; i < this.code.length; i++) {
|
||||||
|
if (Script.isBadPush(this.code[i]))
|
||||||
|
break;
|
||||||
if (this.code[i] !== opcodes.OP_CODESEPARATOR)
|
if (this.code[i] !== opcodes.OP_CODESEPARATOR)
|
||||||
code.push(this.code[i]);
|
code.push(this.code[i]);
|
||||||
}
|
}
|
||||||
@ -1931,26 +1933,48 @@ Script.array = function(value) {
|
|||||||
|
|
||||||
Script.prototype.removeData = function removeData(data) {
|
Script.prototype.removeData = function removeData(data) {
|
||||||
var total = 0;
|
var total = 0;
|
||||||
var opcode, sig, raw, i, a, b;
|
var p, sig, raw, i, a, b;
|
||||||
|
|
||||||
if (!this.raw)
|
// We need to reserialize the
|
||||||
return this.removeDataFast(data);
|
// signature as a minimal push
|
||||||
|
// Note that this is _NOT_
|
||||||
|
// minimaldata completely. It
|
||||||
|
// _always_ encodes a pushdata
|
||||||
|
// op!
|
||||||
|
p = new BufferWriter();
|
||||||
|
if (data.length <= 0x4b) {
|
||||||
|
p.writeU8(data.length);
|
||||||
|
p.writeBytes(data);
|
||||||
|
} else if (data.length <= 0xff) {
|
||||||
|
p.writeU8(opcodes.OP_PUSHDATA1);
|
||||||
|
p.writeU8(data.length);
|
||||||
|
p.writeBytes(data);
|
||||||
|
} else if (data.length <= 0xffff) {
|
||||||
|
p.writeU8(opcodes.OP_PUSHDATA2);
|
||||||
|
p.writeU16(data.length);
|
||||||
|
p.writeBytes(data);
|
||||||
|
} else if (data.length <= 0xffffffff) {
|
||||||
|
p.writeU8(opcodes.OP_PUSHDATA4);
|
||||||
|
p.writeU32(data.length);
|
||||||
|
p.writeBytes(data);
|
||||||
|
} else {
|
||||||
|
assert(false, 'Bad pushdata op.');
|
||||||
|
}
|
||||||
|
sig = p.render();
|
||||||
|
|
||||||
// We need to reserialize
|
// Should never happen, but
|
||||||
// the signature as minimaldata.
|
// bitcoind does this anyway.
|
||||||
opcode = data.opcode;
|
if (sig.length === 0)
|
||||||
delete data.opcode;
|
return total;
|
||||||
sig = Script.encode([data]);
|
|
||||||
if (opcode != null)
|
|
||||||
data.opcode = opcode;
|
|
||||||
|
|
||||||
|
// Compare on the byte level.
|
||||||
raw = this.encode();
|
raw = this.encode();
|
||||||
|
|
||||||
// Note that this is _faster_ than Buffer#indexOf.
|
// Note that this is _faster_ than Buffer#indexOf.
|
||||||
for (i = 0; i < raw.length; i++) {
|
for (i = 0; i < raw.length; i++) {
|
||||||
if (raw.length - i < sig.length)
|
if (raw.length - i < sig.length)
|
||||||
break;
|
break;
|
||||||
if (this._cmp(raw, sig, i) === 0) {
|
if (utils.icmp(raw, sig, i) === 0) {
|
||||||
a = raw.slice(0, i);
|
a = raw.slice(0, i);
|
||||||
b = raw.slice(i + sig.length);
|
b = raw.slice(i + sig.length);
|
||||||
raw = Buffer.concat([a, b]);
|
raw = Buffer.concat([a, b]);
|
||||||
@ -1958,47 +1982,10 @@ Script.prototype.removeData = function removeData(data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.raw = raw;
|
if (total > 0) {
|
||||||
|
this.code = Script.decode(raw);
|
||||||
return total;
|
if (this.raw)
|
||||||
};
|
this.raw = raw;
|
||||||
|
|
||||||
Script.prototype._cmp = function _cmp(target, data, start) {
|
|
||||||
var i, a, b;
|
|
||||||
|
|
||||||
if (target.length - start < data.length)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
for (i = 0; i < data.length; i++) {
|
|
||||||
a = target[i + start];
|
|
||||||
b = data[i];
|
|
||||||
if (a < b)
|
|
||||||
return -1;
|
|
||||||
if (a > b)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
Script.prototype.removeDataFast = function removeData(data) {
|
|
||||||
var total = 0;
|
|
||||||
var i;
|
|
||||||
|
|
||||||
for (i = this.code.length - 1; i >= 0; i--) {
|
|
||||||
if (!Buffer.isBuffer(this.code[i]))
|
|
||||||
continue;
|
|
||||||
if (!Script.checkMinimal(this.code[i]))
|
|
||||||
continue;
|
|
||||||
if (utils.equals(this.code[i], data)) {
|
|
||||||
this.code.splice(i, 1);
|
|
||||||
total++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.raw && total > 0) {
|
|
||||||
this.raw = null;
|
|
||||||
this.encode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
@ -2032,6 +2019,9 @@ Script.checkMinimal = function checkMinimal(value, flags) {
|
|||||||
if (value.opcode == null)
|
if (value.opcode == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (value.length === 0)
|
||||||
|
return value.opcode === opcodes.OP_0;
|
||||||
|
|
||||||
if (value.length === 1 && value[0] >= 1 && value[0] <= 16)
|
if (value.length === 1 && value[0] >= 1 && value[0] <= 16)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -2580,10 +2570,10 @@ Script.prototype.isNulldata = function isNulldata() {
|
|||||||
op = this.code[i];
|
op = this.code[i];
|
||||||
if (Buffer.isBuffer(op))
|
if (Buffer.isBuffer(op))
|
||||||
continue;
|
continue;
|
||||||
if (op > opcodes.OP_16)
|
|
||||||
return false;
|
|
||||||
if (Script.isBadPush(op))
|
if (Script.isBadPush(op))
|
||||||
return false;
|
return false;
|
||||||
|
if (op > opcodes.OP_16)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -3413,10 +3403,10 @@ Script.prototype.isPushOnly = function isPushOnly() {
|
|||||||
op = this.code[i];
|
op = this.code[i];
|
||||||
if (Buffer.isBuffer(op))
|
if (Buffer.isBuffer(op))
|
||||||
continue;
|
continue;
|
||||||
if (op > opcodes.OP_16)
|
|
||||||
return false;
|
|
||||||
if (Script.isBadPush(op))
|
if (Script.isBadPush(op))
|
||||||
return false;
|
return false;
|
||||||
|
if (op > opcodes.OP_16)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -457,18 +457,21 @@ utils.isHex = function isHex(msg) {
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
utils.equals = function isEqual(a, b) {
|
utils.equals = function equals(a, b) {
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
assert(Buffer.isBuffer(a));
|
if (!Buffer.isBuffer(a))
|
||||||
assert(Buffer.isBuffer(b));
|
return false;
|
||||||
|
|
||||||
if (a.length !== b.length)
|
if (!Buffer.isBuffer(b))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (a.compare)
|
if (a.compare)
|
||||||
return a.compare(b) === 0;
|
return a.compare(b) === 0;
|
||||||
|
|
||||||
|
if (a.length !== b.length)
|
||||||
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < a.length; i++) {
|
for (i = 0; i < a.length; i++) {
|
||||||
if (a[i] !== b[i])
|
if (a[i] !== b[i])
|
||||||
return false;
|
return false;
|
||||||
@ -2152,6 +2155,32 @@ utils.cmp = function cmp(a, b) {
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Memcmp for comparing a needle to a haystack.
|
||||||
|
* @param {Buffer} target - Haystack.
|
||||||
|
* @param {Buffer} data - Needle.
|
||||||
|
* @param {Number} start - Index in haystack to begin the comparison.
|
||||||
|
* @returns {Number} -1, 1, or 0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
utils.icmp = function icmp(target, data, start) {
|
||||||
|
var i, a, b;
|
||||||
|
|
||||||
|
if (target.length - start < data.length)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (i = 0; i < data.length; i++) {
|
||||||
|
a = target[i + start];
|
||||||
|
b = data[i];
|
||||||
|
if (a < b)
|
||||||
|
return -1;
|
||||||
|
if (a > b)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* memcmp in constant time (can only return true or false).
|
* memcmp in constant time (can only return true or false).
|
||||||
* This protects us against timing attacks when
|
* This protects us against timing attacks when
|
||||||
@ -2167,8 +2196,11 @@ utils.ccmp = function ccmp(a, b) {
|
|||||||
var res = 0;
|
var res = 0;
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
assert(Buffer.isBuffer(a));
|
if (!Buffer.isBuffer(a))
|
||||||
assert(Buffer.isBuffer(b));
|
return false;
|
||||||
|
|
||||||
|
if (!Buffer.isBuffer(b))
|
||||||
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < a.length; i++)
|
for (i = 0; i < a.length; i++)
|
||||||
res |= a[i] ^ b[i];
|
res |= a[i] ^ b[i];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user