Browse Source

Add fee to serialization

patch-2
Esteban Ordano 10 years ago
parent
commit
1f45e88268
  1. 4
      lib/transaction/transaction.js
  2. 8
      test/transaction/transaction.js

4
lib/transaction/transaction.js

@ -239,6 +239,7 @@ Transaction.prototype.toObject = function toObject() {
}); });
return { return {
change: this._change ? this._change.toString() : undefined, change: this._change ? this._change.toString() : undefined,
fee: this._fee ? this._fee : undefined,
version: this.version, version: this.version,
inputs: inputs, inputs: inputs,
outputs: outputs, outputs: outputs,
@ -269,6 +270,9 @@ Transaction.prototype.fromObject = function(transaction) {
if (transaction.change) { if (transaction.change) {
this.change(transaction.change); this.change(transaction.change);
} }
if (transaction.fee) {
this.fee(transaction.fee);
}
this.nLockTime = transaction.nLockTime; this.nLockTime = transaction.nLockTime;
this.version = transaction.version; this.version = transaction.version;
}; };

8
test/transaction/transaction.js

@ -245,6 +245,14 @@ describe('Transaction', function() {
return transaction.serialize(true); return transaction.serialize(true);
}).to.not.throw(); }).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() { describe('checked serialize', function() {

Loading…
Cancel
Save