remove old FindAndDelete.
This commit is contained in:
parent
51ebcf999b
commit
a370bd74ed
@ -2009,96 +2009,6 @@ Script.prototype.removeData = function removeData(data) {
|
||||
return index.length;
|
||||
};
|
||||
|
||||
Script.prototype.removeDataRaw = function removeDataRaw(data) {
|
||||
var total = 0;
|
||||
var p, sig, raw, i, a, b, op, size;
|
||||
|
||||
// We need to reserialize the
|
||||
// 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();
|
||||
|
||||
// Should never happen, but
|
||||
// bitcoind does this anyway.
|
||||
if (sig.length === 0)
|
||||
return total;
|
||||
|
||||
// Compare on the byte level.
|
||||
raw = this.encode();
|
||||
|
||||
p = new BufferReader(raw, true);
|
||||
|
||||
while (p.left() >= sig.length) {
|
||||
if (utils.icmp(raw, sig, p.offset) === 0) {
|
||||
a = raw.slice(0, p.offset);
|
||||
b = raw.slice(p.offset + sig.length);
|
||||
raw = Buffer.concat([a, b]);
|
||||
p.data = raw;
|
||||
total++;
|
||||
}
|
||||
|
||||
if (p.left() === 0)
|
||||
break;
|
||||
|
||||
op = p.readU8();
|
||||
if (op >= 0x01 && op <= 0x4b) {
|
||||
if (p.left() < op)
|
||||
break;
|
||||
} else if (op === opcodes.OP_PUSHDATA1) {
|
||||
if (p.left() < 1)
|
||||
break;
|
||||
size = p.readU8();
|
||||
if (p.left() < size)
|
||||
break;
|
||||
p.seek(size);
|
||||
} else if (op === opcodes.OP_PUSHDATA2) {
|
||||
if (p.left() < 2)
|
||||
break;
|
||||
size = p.readU16();
|
||||
if (p.left() < size)
|
||||
break;
|
||||
p.seek(size);
|
||||
} else if (op === opcodes.OP_PUSHDATA4) {
|
||||
if (p.left() < 4)
|
||||
break;
|
||||
size = p.readU32();
|
||||
if (p.left() < size)
|
||||
break;
|
||||
p.seek(size);
|
||||
}
|
||||
}
|
||||
|
||||
if (total > 0) {
|
||||
this.code = Script.decode(raw);
|
||||
if (this.raw)
|
||||
this.raw = raw;
|
||||
}
|
||||
|
||||
return total;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find a data element in a script.
|
||||
* @param {Buffer} data - Data element to match against.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user