pushin, pushout

Add convenience methods for adding new inputs and outputs.
This commit is contained in:
Ryan X. Charles 2014-09-23 22:09:41 -07:00
parent c07d509623
commit 8e85eba08b
2 changed files with 36 additions and 0 deletions

View File

@ -140,4 +140,16 @@ Transaction.prototype.id = function() {
return BufferReader(this.hash()).reverse().read();
};
Transaction.prototype.pushin = function(txin) {
this.txins.push(txin);
this.txinsvi = Varint(this.txinsvi.toNumber() + 1);
return this;
};
Transaction.prototype.pushout = function(txout) {
this.txouts.push(txout);
this.txoutsvi = Varint(this.txoutsvi.toNumber() + 1);
return this;
};
module.exports = Transaction;

View File

@ -168,4 +168,28 @@ describe('Transaction', function() {
});
describe('#pushin', function() {
it('should add an input', function() {
var txin = Txin();
var tx = Transaction();
tx.pushin(txin);
tx.txinsvi.toNumber().should.equal(1);
tx.txins.length.should.equal(1);
});
});
describe('#pushout', function() {
it('should add an output', function() {
var txout = Txout();
var tx = Transaction();
tx.pushout(txout);
tx.txoutsvi.toNumber().should.equal(1);
tx.txouts.length.should.equal(1);
});
});
});