rename utils.slice.
This commit is contained in:
parent
5d1c39bf41
commit
64830059d7
@ -1676,7 +1676,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, version) {
|
|||||||
case opcodes.OP_INVERT: {
|
case opcodes.OP_INVERT: {
|
||||||
if (stack.length < 1)
|
if (stack.length < 1)
|
||||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||||
val = utils.slice(stack.pop());
|
val = utils.copy(stack.pop());
|
||||||
for (i = 0; i < val.length; i++)
|
for (i = 0; i < val.length; i++)
|
||||||
val[i] = ~val[i] & 0xff;
|
val[i] = ~val[i] & 0xff;
|
||||||
stack.push(val);
|
stack.push(val);
|
||||||
@ -1688,7 +1688,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, version) {
|
|||||||
if (stack.length < 2)
|
if (stack.length < 2)
|
||||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||||
v2 = stack.pop();
|
v2 = stack.pop();
|
||||||
v1 = utils.slice(stack.pop());
|
v1 = utils.copy(stack.pop());
|
||||||
if (v1.length < v2.length) {
|
if (v1.length < v2.length) {
|
||||||
v3 = new Buffer(v2.length - v1.length);
|
v3 = new Buffer(v2.length - v1.length);
|
||||||
v3.fill(0);
|
v3.fill(0);
|
||||||
|
|||||||
@ -201,7 +201,7 @@ TX.prototype.witnessHash = function witnessHash(enc) {
|
|||||||
if (this.isCoinbase()) {
|
if (this.isCoinbase()) {
|
||||||
return enc === 'hex'
|
return enc === 'hex'
|
||||||
? constants.NULL_HASH
|
? constants.NULL_HASH
|
||||||
: utils.slice(constants.ZERO_HASH);
|
: utils.copy(constants.ZERO_HASH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.hasWitness())
|
if (!this.hasWitness())
|
||||||
@ -451,7 +451,7 @@ TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
|||||||
// Bitcoind used to return 1 as an error code:
|
// Bitcoind used to return 1 as an error code:
|
||||||
// it ended up being treated like a hash.
|
// it ended up being treated like a hash.
|
||||||
if (index >= copy.outputs.length)
|
if (index >= copy.outputs.length)
|
||||||
return utils.slice(constants.ONE_HASH);
|
return utils.copy(constants.ONE_HASH);
|
||||||
|
|
||||||
// Drop all the outputs after the input index.
|
// Drop all the outputs after the input index.
|
||||||
copy.outputs.length = index + 1;
|
copy.outputs.length = index + 1;
|
||||||
@ -512,7 +512,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, type) {
|
|||||||
this._hashPrevouts = hashPrevouts;
|
this._hashPrevouts = hashPrevouts;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hashPrevouts = utils.slice(constants.ZERO_HASH);
|
hashPrevouts = utils.copy(constants.ZERO_HASH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(type & constants.hashType.ANYONECANPAY)
|
if (!(type & constants.hashType.ANYONECANPAY)
|
||||||
@ -529,7 +529,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, type) {
|
|||||||
this._hashSequence = hashSequence;
|
this._hashSequence = hashSequence;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hashSequence = utils.slice(constants.ZERO_HASH);
|
hashSequence = utils.copy(constants.ZERO_HASH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type & 0x1f) !== constants.hashType.SINGLE
|
if ((type & 0x1f) !== constants.hashType.SINGLE
|
||||||
@ -548,7 +548,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, type) {
|
|||||||
hashOutputs = bcoin.protocol.framer.output(this.outputs[index]);
|
hashOutputs = bcoin.protocol.framer.output(this.outputs[index]);
|
||||||
hashOutputs = utils.dsha256(hashOutputs);
|
hashOutputs = utils.dsha256(hashOutputs);
|
||||||
} else {
|
} else {
|
||||||
hashOutputs = utils.slice(constants.ZERO_HASH);
|
hashOutputs = utils.copy(constants.ZERO_HASH);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.write32(this.version);
|
p.write32(this.version);
|
||||||
|
|||||||
@ -70,23 +70,14 @@ utils.nop = function() {};
|
|||||||
utils.gc = !utils.isBrowser && typeof gc === 'function' ? gc : utils.nop;
|
utils.gc = !utils.isBrowser && typeof gc === 'function' ? gc : utils.nop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A slow buffer slice (will allocate a new buffer).
|
* Clone a buffer.
|
||||||
* @param {Buffer} data
|
* @param {Buffer} data
|
||||||
* @param {Number?} start
|
|
||||||
* @param {Number?} end
|
|
||||||
* @returns {Buffer}
|
* @returns {Buffer}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
utils.slice = function slice(data, start, end) {
|
utils.copy = function copy(data) {
|
||||||
var clone;
|
var clone = new Buffer(data.length);
|
||||||
|
|
||||||
if (start != null)
|
|
||||||
data = data.slice(start, end);
|
|
||||||
|
|
||||||
clone = new Buffer(data.length);
|
|
||||||
|
|
||||||
data.copy(clone, 0, 0, data.length);
|
data.copy(clone, 0, 0, data.length);
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -917,7 +908,7 @@ utils.ip2version = function ip2version(ip, version) {
|
|||||||
|
|
||||||
// Found an ipv4 address
|
// Found an ipv4 address
|
||||||
if (ip.length - i === 6 && ip[i] === 0xff && ip[i + 1] === 0xff)
|
if (ip.length - i === 6 && ip[i] === 0xff && ip[i + 1] === 0xff)
|
||||||
return utils.slice(ip, -4);
|
return utils.copy(ip.slice(-4));
|
||||||
|
|
||||||
// No ipv4 address
|
// No ipv4 address
|
||||||
return new Buffer([0, 0, 0, 0]);
|
return new Buffer([0, 0, 0, 0]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user