check for dust before creating transaction
This commit is contained in:
parent
913b48e87f
commit
7c81bfef72
2 changed files with 22 additions and 4 deletions
|
@ -179,6 +179,8 @@ var Wallet = function (seed, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createTx = function(to, value, fixedFee) {
|
this.createTx = function(to, value, fixedFee) {
|
||||||
|
checkDust(value)
|
||||||
|
|
||||||
var tx = new Transaction()
|
var tx = new Transaction()
|
||||||
tx.addOutput(to, value)
|
tx.addOutput(to, value)
|
||||||
|
|
||||||
|
@ -206,6 +208,12 @@ var Wallet = function (seed, options) {
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkDust(value){
|
||||||
|
if (isNullOrUndefined(value) || value < 5430) {
|
||||||
|
throw new Error("Value below dust threshold")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function estimateFeePadChangeOutput(tx){
|
function estimateFeePadChangeOutput(tx){
|
||||||
var tmpTx = tx.clone()
|
var tmpTx = tx.clone()
|
||||||
tmpTx.addOutput(getChangeAddress(), 0)
|
tmpTx.addOutput(getChangeAddress(), 0)
|
||||||
|
|
|
@ -367,10 +367,6 @@ describe('Wallet', function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function fakeTxHash(i) {
|
|
||||||
return "txtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtx" + i
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('choosing utxo', function(){
|
describe('choosing utxo', function(){
|
||||||
it('calculates fees', function(){
|
it('calculates fees', function(){
|
||||||
var tx = wallet.createTx(to, value)
|
var tx = wallet.createTx(to, value)
|
||||||
|
@ -441,6 +437,20 @@ describe('Wallet', function() {
|
||||||
assert(Transaction.prototype.sign.calledWith(1, wallet.getPrivateKeyForAddress(address1)))
|
assert(Transaction.prototype.sign.calledWith(1, wallet.getPrivateKeyForAddress(address1)))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('when value is below dust threshold', function(){
|
||||||
|
it('throws an error', function(){
|
||||||
|
var value = 5429
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
wallet.createTx(to, value)
|
||||||
|
}, Error, 'Value below dust threshold')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function fakeTxHash(i) {
|
||||||
|
return "txtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtx" + i
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function assertEqual(obj1, obj2){
|
function assertEqual(obj1, obj2){
|
||||||
|
|
Loading…
Add table
Reference in a new issue