diff --git a/src/networks.js b/src/networks.js index da71d23..4b1f690 100644 --- a/src/networks.js +++ b/src/networks.js @@ -9,7 +9,9 @@ module.exports = { }, pubKeyHash: 0x00, scriptHash: 0x05, - wif: 0x80 + wif: 0x80, + dustThreshold: 5430, //should be 546 https://github.com/bitcoin/bitcoin/pull/2760/files + feePerKb: 20000 }, dogecoin: { magicPrefix: '\x19Dogecoin Signed Message:\n', @@ -19,7 +21,9 @@ module.exports = { }, pubKeyHash: 0x1e, scriptHash: 0x16, - wif: 0x9e + wif: 0x9e, + dustThreshold: 1000000, + feePerKb: 100000000 }, litecoin: { magicPrefix: '\x19Litecoin Signed Message:\n', @@ -29,7 +33,9 @@ module.exports = { }, pubKeyHash: 0x30, scriptHash: 0x05, - wif: 0xb0 + wif: 0xb0, + dustThreshold: 1000, + feePerKb: 100000 }, testnet: { magicPrefix: '\x18Bitcoin Signed Message:\n', @@ -39,6 +45,8 @@ module.exports = { }, pubKeyHash: 0x6f, scriptHash: 0xc4, - wif: 0xef + wif: 0xef, + dustThreshold: 5430, + feePerKb: 20000 } } diff --git a/src/wallet.js b/src/wallet.js index 1501456..1e484f2 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -20,9 +20,6 @@ function Wallet(seed, network) { this.addresses = [] this.changeAddresses = [] - // Dust value - this.dustThreshold = 5430 - // Transaction output data this.outputs = {} @@ -182,7 +179,7 @@ function Wallet(seed, network) { } this.createTx = function(to, value, fixedFee, changeAddress) { - assert(value > this.dustThreshold, value + ' must be above dust threshold (' + this.dustThreshold + ' Satoshis)') + assert(value > network.dustThreshold, value + ' must be above dust threshold (' + network.dustThreshold + ' Satoshis)') var utxos = getCandidateOutputs(value) var accum = 0 @@ -206,7 +203,7 @@ function Wallet(seed, network) { if (accum >= subTotal) { var change = accum - subTotal - if (change > this.dustThreshold) { + if (change > network.dustThreshold) { tx.addOutput(changeAddress || getChangeAddress(), change) } @@ -235,13 +232,12 @@ function Wallet(seed, network) { return sortByValueDesc } - var feePerKb = 20000 function estimateFeePadChangeOutput(tx) { var tmpTx = tx.clone() tmpTx.addOutput(getChangeAddress(), 0) var byteSize = tmpTx.toBuffer().length - return feePerKb * Math.ceil(byteSize / 1000) + return network.feePerKb * Math.ceil(byteSize / 1000) } function getChangeAddress() {