Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"maxcomplexity": 6, // Cyclomatic complexity (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
"maxdepth": 4, // Maximum depth of nested control structures
"maxlen": 120, // Maximum number of cols in a line
"multistr": true // Allow use of multiline EOL escaping
"multistr": true, // Allow use of multiline EOL escaping

"predef": [ // Extra globals.
"after",
Expand Down
3 changes: 3 additions & 0 deletions lib/errors/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ module.exports = [{
}, {
name: 'UnableToVerifySignature',
message: format('Unable to verify signature: {0}')
}, {
name: 'DustOutputs',
message: format('Dust amount detected in one output')
}, {
name: 'FeeError',
message: format('Fees are not correctly set {0}'),
Expand Down
15 changes: 15 additions & 0 deletions lib/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ Transaction.prototype.checkedSerialize = Transaction.prototype.toString = functi
throw new errors.Transaction.FeeError(feeError);
}
}
if (this._hasDustOutputs()) {
throw new errors.Transaction.DustOutputs();
}
return this.uncheckedSerialize();
};

Expand All @@ -143,6 +146,18 @@ Transaction.prototype._validateChange = function() {
}
};

Transaction.DUST_AMOUNT = 5460;

Transaction.prototype._hasDustOutputs = function() {
var output;
for (output in this.outputs) {
if (this.outputs[output].satoshis < Transaction.DUST_AMOUNT) {
return true;
}
}
return false;
};

Transaction.prototype.inspect = function() {
return '<Transaction: ' + this.toString() + '>';
};
Expand Down
4 changes: 2 additions & 2 deletions test/transaction/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Transaction deserialization', function() {
vectors_valid.forEach(function(vector) {
if (vector.length > 1) {
var hexa = vector[1];
Transaction(hexa).serialize().should.equal(hexa);
Transaction(hexa).serialize(true).should.equal(hexa);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this boolean indicate unsafe serialization?

index++;
}
});
Expand All @@ -22,7 +22,7 @@ describe('Transaction deserialization', function() {
vectors_invalid.forEach(function(vector) {
if (vector.length > 1) {
var hexa = vector[1];
Transaction(hexa).serialize().should.equal(hexa);
Transaction(hexa).serialize(true).should.equal(hexa);
index++;
}
});
Expand Down
10 changes: 10 additions & 0 deletions test/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ describe('Transaction', function() {
return transaction.serialize();
}).to.throw(errors.Transaction.FeeError);
});
it('fails if a dust transaction is created', function() {
var transaction = new Transaction()
.from(simpleUtxoWith1BTC)
.to(toAddress, 1)
.change(changeAddress)
.sign(privateKey);
expect(function() {
return transaction.serialize();
}).to.throw(errors.Transaction.DustOutputs);
});
});
});

Expand Down