tx: remove .inputTx() method
This commit is contained in:
parent
c6eeb66f6d
commit
fa48b02d96
@ -58,27 +58,36 @@ TX.prototype.input = function input(i, index) {
|
|||||||
else
|
else
|
||||||
hash = i.hash;
|
hash = i.hash;
|
||||||
|
|
||||||
this.inputs.push({
|
if (typeof hash !== 'string')
|
||||||
|
hash = utils.toHex(hash);
|
||||||
|
|
||||||
|
var input = {
|
||||||
out: {
|
out: {
|
||||||
tx: i.tx,
|
tx: i.tx || null,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
index: i.out ? i.out.index : i.index,
|
index: i.out ? i.out.index : i.index,
|
||||||
},
|
},
|
||||||
script: i.script ? i.script.slice() : [],
|
script: i.script ? i.script.slice() : [],
|
||||||
seq: i.seq === undefined ? 0xffffffff : i.seq
|
seq: i.seq === undefined ? 0xffffffff : i.seq
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Try modifying existing input first
|
||||||
|
for (var i = 0; i < this.inputs.length; i++) {
|
||||||
|
var ex = this.inputs[i];
|
||||||
|
if (ex.out.hash !== hash && ex.out.index !== index)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ex.out.tx = input.out.tx || ex.out.tx;
|
||||||
|
ex.seq = input.seq || ex.seq;
|
||||||
|
ex.script = input.script.length ? input.script : ex.script;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i === this.inputs.length)
|
||||||
|
this.inputs.push(input);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
TX.prototype.inputTx = function inputTx(i, tx) {
|
|
||||||
if (!(tx instanceof TX))
|
|
||||||
tx = new TX(tx);
|
|
||||||
|
|
||||||
assert(i <= this.inputs.length);
|
|
||||||
this.inputs[i].out.tx = tx;
|
|
||||||
};
|
|
||||||
|
|
||||||
TX.prototype.out = function out(output, value) {
|
TX.prototype.out = function out(output, value) {
|
||||||
if (typeof output === 'string') {
|
if (typeof output === 'string') {
|
||||||
output = {
|
output = {
|
||||||
|
|||||||
@ -48,7 +48,7 @@ describe('TX', function() {
|
|||||||
|
|
||||||
it('should be verifiable', function() {
|
it('should be verifiable', function() {
|
||||||
var tx = bcoin.tx(parser.parseTx(bcoin.utils.toArray(raw, 'hex')));
|
var tx = bcoin.tx(parser.parseTx(bcoin.utils.toArray(raw, 'hex')));
|
||||||
tx.inputTx(0, bcoin.tx(parser.parseTx(bcoin.utils.toArray(inp, 'hex'))));
|
tx.input(bcoin.tx(parser.parseTx(bcoin.utils.toArray(inp, 'hex'))), 0);
|
||||||
|
|
||||||
assert(tx.verify());
|
assert(tx.verify());
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user