add limits to TXs

This commit is contained in:
Matias Alejo Garcia 2014-11-02 23:53:53 -03:00
parent 3108969b7c
commit abc5023107
1 changed files with 21 additions and 1 deletions

View File

@ -30,6 +30,8 @@ var Async = require('./Async');
var Insight = module.exports.Insight = require('./Insight'); var Insight = module.exports.Insight = require('./Insight');
var copayConfig = require('../../config'); var copayConfig = require('../../config');
var TX_MAX_SIZE_KB = 60;
var TX_MAX_INS = 100;
/** /**
* @desc * @desc
* Wallet manages a private key for Copay, network, storage of the wallet for * Wallet manages a private key for Copay, network, storage of the wallet for
@ -2317,7 +2319,13 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb)
this.getUnspent(function(err, safeUnspent) { this.getUnspent(function(err, safeUnspent) {
if (err) return cb(new Error('Could not get list of UTXOs')); if (err) return cb(new Error('Could not get list of UTXOs'));
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts); var ntxid;
try {
ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
} catch (e) {
return cb(e);
}
if (!ntxid) { if (!ntxid) {
return cb(new Error('Error creating the transaction')); return cb(new Error('Error creating the transaction'));
} }
@ -2369,7 +2377,13 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
amountSatStr: amountSatStr, amountSatStr: amountSatStr,
}]); }]);
var selectedUtxos = b.getSelectedUnspent(); var selectedUtxos = b.getSelectedUnspent();
if (selectedUtxos.size > TX_MAX_INS)
throw new Error('Resulting TX is TOO big:' + selectedUtxos.size + ' inputs. Aborting');
var inputChainPaths = selectedUtxos.map(function(utxo) { var inputChainPaths = selectedUtxos.map(function(utxo) {
return pkr.pathForAddress(utxo.address); return pkr.pathForAddress(utxo.address);
}); });
@ -2386,6 +2400,12 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
if (!tx.countInputSignatures(0)) if (!tx.countInputSignatures(0))
throw new Error('Could not sign generated tx'); throw new Error('Could not sign generated tx');
var txSize = tx.getSize();
if (txSize/1024 > TX_MAX_SIZE_KB)
throw new Error('Resulting TX is TOO big ' + txSize + ' bytes. Aborting');
var me = {}; var me = {};
me[myId] = now; me[myId] = now;