From 614a228c7958cf626a6676e5baf3d6cc093e38d1 Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Wed, 28 Jan 2015 12:02:41 -0300 Subject: [PATCH] Allow satoshis to be a string on output creation --- lib/transaction/output.js | 3 +++ test/transaction/transaction.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/transaction/output.js b/lib/transaction/output.js index fcbab1d3e..767941a37 100644 --- a/lib/transaction/output.js +++ b/lib/transaction/output.js @@ -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; diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index cb8938c2b..096bf8fdb 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -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); });