From 1f45e882686b3355464490b0837908ff480ec38c Mon Sep 17 00:00:00 2001 From: Esteban Ordano Date: Wed, 4 Feb 2015 12:45:02 -0300 Subject: [PATCH] Add fee to serialization --- lib/transaction/transaction.js | 4 ++++ test/transaction/transaction.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/transaction/transaction.js b/lib/transaction/transaction.js index 02b6276..33b00ed 100644 --- a/lib/transaction/transaction.js +++ b/lib/transaction/transaction.js @@ -239,6 +239,7 @@ Transaction.prototype.toObject = function toObject() { }); return { change: this._change ? this._change.toString() : undefined, + fee: this._fee ? this._fee : undefined, version: this.version, inputs: inputs, outputs: outputs, @@ -269,6 +270,9 @@ Transaction.prototype.fromObject = function(transaction) { if (transaction.change) { this.change(transaction.change); } + if (transaction.fee) { + this.fee(transaction.fee); + } this.nLockTime = transaction.nLockTime; this.version = transaction.version; }; diff --git a/test/transaction/transaction.js b/test/transaction/transaction.js index 3460712..c0ff98d 100644 --- a/test/transaction/transaction.js +++ b/test/transaction/transaction.js @@ -245,6 +245,14 @@ describe('Transaction', function() { return transaction.serialize(true); }).to.not.throw(); }); + it('stores the fee set by the user', function() { + var fee = 1000000; + var serialized = new Transaction() + .fee(fee) + .toObject(); + var deserialized = new Transaction(serialized); + expect(deserialized._fee).to.equal(fee); + }); }); describe('checked serialize', function() {