From 721d0791bfe814e2503732119e358fa45a68f420 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Thu, 18 Aug 2011 05:00:48 +0100 Subject: [PATCH] Added ability to add fees in createSend. --- src/wallet.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wallet.js b/src/wallet.js index a7927f6..f6ac8ad 100755 --- a/src/wallet.js +++ b/src/wallet.js @@ -176,19 +176,24 @@ Bitcoin.Wallet = (function () { return balance; }; - Wallet.prototype.createSend = function (address, sendValue) { + Wallet.prototype.createSend = function (address, sendValue, feeValue) { var selectedOuts = []; + var txValue = sendValue.add(feeValue); var availableValue = BigInteger.ZERO; for (var i = 0; i < this.unspentOuts.length; i++) { selectedOuts.push(this.unspentOuts[i]); availableValue = availableValue.add(Bitcoin.Util.valueToBigInt(this.unspentOuts[i].out.value)); - if (availableValue.compareTo(sendValue) >= 0) break; + if (availableValue.compareTo(txValue) >= 0) break; } + if (availableValue.compareTo(txValue) < 0) { + throw new Error('Insufficient funds.'); + } + console.log(selectedOuts); - var changeValue = availableValue.subtract(sendValue); + var changeValue = availableValue.subtract(txValue); var sendTx = new Bitcoin.Transaction();