Added ability to add fees in createSend.
This commit is contained in:
parent
90c30f248e
commit
721d0791bf
1 changed files with 8 additions and 3 deletions
|
@ -176,19 +176,24 @@ Bitcoin.Wallet = (function () {
|
||||||
return balance;
|
return balance;
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.createSend = function (address, sendValue) {
|
Wallet.prototype.createSend = function (address, sendValue, feeValue) {
|
||||||
var selectedOuts = [];
|
var selectedOuts = [];
|
||||||
|
var txValue = sendValue.add(feeValue);
|
||||||
var availableValue = BigInteger.ZERO;
|
var availableValue = BigInteger.ZERO;
|
||||||
for (var i = 0; i < this.unspentOuts.length; i++) {
|
for (var i = 0; i < this.unspentOuts.length; i++) {
|
||||||
selectedOuts.push(this.unspentOuts[i]);
|
selectedOuts.push(this.unspentOuts[i]);
|
||||||
availableValue = availableValue.add(Bitcoin.Util.valueToBigInt(this.unspentOuts[i].out.value));
|
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);
|
console.log(selectedOuts);
|
||||||
|
|
||||||
var changeValue = availableValue.subtract(sendValue);
|
var changeValue = availableValue.subtract(txValue);
|
||||||
|
|
||||||
var sendTx = new Bitcoin.Transaction();
|
var sendTx = new Bitcoin.Transaction();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue