Browse Source

pushin, pushout

Add convenience methods for adding new inputs and outputs.
patch-2
Ryan X. Charles 10 years ago
parent
commit
8e85eba08b
  1. 12
      lib/transaction.js
  2. 24
      test/transaction.js

12
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;

24
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);
});
});
});

Loading…
Cancel
Save