Skip to content

Commit

Permalink
Allow satoshis to be a string on output creation
Browse files Browse the repository at this point in the history
  • Loading branch information
eordano committed Jan 28, 2015
1 parent b7ef077 commit 614a228
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/transaction/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Object.defineProperty(Output.prototype, 'satoshis', {
if (num instanceof BN) {
this._satoshisBN = num;
this._satoshis = num.toNumber();
} else if (_.isString(num)) {
this._satoshis = parseInt(num);
this._satoshisBN = BN.fromNumber(this._satoshis);
} else {
this._satoshisBN = BN.fromNumber(num);
this._satoshis = num;
Expand Down
5 changes: 5 additions & 0 deletions test/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ describe('Transaction', function() {
object.outputs[0].satoshis.should.equal(testAmount - 10000);
});

it('can take a string argument as an amount', function() {
var stringTx = new Transaction().to('mrU9pEmAx26HcbKVrABvgL7AwA5fjNFoDc', '10000');
(stringTx._outputAmount).should.equal(10000);
});

it('returns the fee correctly', function() {
testTransaction.getFee().should.equal(10000);
});
Expand Down

0 comments on commit 614a228

Please sign in to comment.