tx: remove .inputTx() method

This commit is contained in:
Fedor Indutny 2014-05-06 14:06:17 +04:00
parent c6eeb66f6d
commit fa48b02d96
2 changed files with 21 additions and 12 deletions

View File

@ -58,27 +58,36 @@ TX.prototype.input = function input(i, index) {
else
hash = i.hash;
this.inputs.push({
if (typeof hash !== 'string')
hash = utils.toHex(hash);
var input = {
out: {
tx: i.tx,
tx: i.tx || null,
hash: hash,
index: i.out ? i.out.index : i.index,
},
script: i.script ? i.script.slice() : [],
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;
};
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) {
if (typeof output === 'string') {
output = {

View File

@ -48,7 +48,7 @@ describe('TX', function() {
it('should be verifiable', function() {
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());
});