Browse Source

Added ability to add fees in createSend.

hk-custom-address
Stefan Thomas 14 years ago
parent
commit
721d0791bf
  1. 11
      src/wallet.js

11
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();

Loading…
Cancel
Save