enforce checklocktimeverify for nLockTime when adding input. tx.prevOut method.

This commit is contained in:
Christopher Jeffrey 2015-12-17 17:56:46 -08:00
parent aac4911b4e
commit 7f70b573c1

View File

@ -97,6 +97,20 @@ TX.prototype._input = function _input(i, index) {
seq: i.seq === undefined ? 0xffffffff : i.seq
};
if (input.out.tx) {
var prev = input.out.tx.outputs[input.out.index].script;
var lock = bcoin.script.lockTime(prev);
if (lock) {
this.lock = Math.max(lock.toNumber(), this.lock);
// if (this.lock === 0)
// this.lock = lock.toNumber();
// if (!bcoin.script.spendable(this, this.lock))
// throw new Error('Cannot spend ' + utils.revHex(input.out.hash));
if (input.seq === 0xffffffff)
input.seq = 0;
}
}
// Try modifying existing input first
var index = this._inputIndex(hash, index);
if (index !== -1) {
@ -125,6 +139,18 @@ TX.prototype._inputIndex = function _inputIndex(hash, index) {
return -1;
};
TX.prototype.prevOut = function prevOut(i, def) {
if (typeof i === 'object')
i = this.inputs.indexOf(i);
var input = this.inputs[i];
if (!input || !input.out.tx || input.out.index == null)
return def;
return input.out.tx.outputs[input.out.index] || def;
};
TX.prototype.signatureHash = function signatureHash(i, type) {
if (typeof i === 'object')
i = this.inputs.indexOf(i);