Browse Source

use constants from Bitcore

activeAddress
Ivan Socolsky 10 years ago
parent
commit
51e453730f
  1. 23
      lib/server.js

23
lib/server.js

@ -25,9 +25,6 @@ var Address = require('./model/address');
var TxProposal = require('./model/txproposal');
var Notification = require('./model/Notification');
var MINIMUM_FEE_SAT = 10000;
var DUST_THRESHOLD = 5430;
var initialized = false;
var storage;
@ -427,16 +424,16 @@ CopayServer.prototype._selectUtxos = function(txp, utxos) {
selected.push(inputs[i]);
total += this._inputSatoshis(inputs[i]);
if (total >= txp.amount + MINIMUM_FEE_SAT) {
if (total >= txp.amount + Bitcore.Transaction.FEE_PER_KB) {
try {
// Check if there are enough fees
txp.inputs = selected;
var raw = txp.getRawTx();
return;
} catch (ex) {
//if (ex.name != 'bitcore.ErrorTransactionFeeError') {}
//if (ex.name != 'bitcore.ErrorTransactionDustOutputs') {}
console.log(ex);
if (ex.name != 'bitcore.ErrorTransactionFeeError') {
throw ex.message;
}
}
}
i++;
@ -480,7 +477,7 @@ CopayServer.prototype.createTx = function(opts, cb) {
if (toAddress.network != wallet.getNetworkName())
return cb(new ClientError('INVALIDADDRESS', 'Incorrect address network'));
if (opts.amount < DUST_THRESHOLD)
if (opts.amount < Bitcore.Transaction.DUST_AMOUNT)
return cb(new ClientError('DUSTAMOUNT', 'Amount below dust threshold'));
self._getUtxos(function(err, utxos) {
@ -502,11 +499,15 @@ CopayServer.prototype.createTx = function(opts, cb) {
requiredRejections: Math.min(wallet.m, wallet.n - wallet.m + 1),
});
self._selectUtxos(txp, utxos);
if (!txp.inputs) {
return cb(new ClientError('INSUFFICIENTFUNDS', 'Insufficient funds'));
try {
self._selectUtxos(txp, utxos);
} catch (ex) {
return cb(new ClientError(ex));
}
if (!txp.inputs)
return cb(new ClientError('INSUFFICIENTFUNDS', 'Insufficient funds'));
txp.inputPaths = _.pluck(txp.inputs, 'path');
self.storage.storeAddressAndWallet(wallet, changeAddress, function(err) {

Loading…
Cancel
Save