From 8e85eba08b0c421804352fdbe15838aaa8c0bf22 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Tue, 23 Sep 2014 22:09:41 -0700 Subject: [PATCH] pushin, pushout Add convenience methods for adding new inputs and outputs. --- lib/transaction.js | 12 ++++++++++++ test/transaction.js | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/transaction.js b/lib/transaction.js index 4deb23b..ffa3ffa 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -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; diff --git a/test/transaction.js b/test/transaction.js index 9083b56..c5e6a9d 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -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); + }); + + }); + });