add amount param

This commit is contained in:
Matias Alejo Garcia 2014-11-03 08:40:53 -03:00
parent abc5023107
commit 8b4e866472
2 changed files with 21 additions and 13 deletions

View File

@ -2381,7 +2381,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
var selectedUtxos = b.getSelectedUnspent(); var selectedUtxos = b.getSelectedUnspent();
if (selectedUtxos.size > TX_MAX_INS) if (selectedUtxos.size > TX_MAX_INS)
throw new Error('Resulting TX is TOO big:' + selectedUtxos.size + ' inputs. Aborting'); throw new Error('BIG: Resulting TX is too big:' + selectedUtxos.size + ' inputs. Aborting');
var inputChainPaths = selectedUtxos.map(function(utxo) { var inputChainPaths = selectedUtxos.map(function(utxo) {
@ -2403,7 +2403,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
var txSize = tx.getSize(); var txSize = tx.getSize();
if (txSize/1024 > TX_MAX_SIZE_KB) if (txSize/1024 > TX_MAX_SIZE_KB)
throw new Error('Resulting TX is TOO big ' + txSize + ' bytes. Aborting'); throw new Error('BIG: Resulting TX is too big ' + txSize + ' bytes. Aborting');
var me = {}; var me = {};

View File

@ -22,7 +22,8 @@ program
.option('-d, --destination <n>', 'Destination Address') .option('-d, --destination <n>', 'Destination Address')
.option('-n, --required <n>', 'Required number of signatures', parseInt) .option('-n, --required <n>', 'Required number of signatures', parseInt)
.option('-k, --keys <items>', 'master private keys', list) .option('-k, --keys <items>', 'master private keys', list)
.option('-f, --fee [n]', 'Set fee in BTC (default 0.0001 BTC)', parseFloat) .option('-a, --amount <n>', 'Optional, amount to transfer, in Satoshis', parseInt)
.option('-f, --fee [n]', 'Optional, fee in BTC (default 0.0001 BTC)', parseFloat)
.parse(process.argv); .parse(process.argv);
// Fee to asign to the tx. Please put a bigger number if you get 'unsufficient unspent' // Fee to asign to the tx. Please put a bigger number if you get 'unsufficient unspent'
@ -38,6 +39,7 @@ var requiredCopayers = program.required;
var extPrivKeys = program.keys; var extPrivKeys = program.keys;
var totalCopayers = extPrivKeys.length; var totalCopayers = extPrivKeys.length;
var destAddr = program.destination; var destAddr = program.destination;
var amount = program.amount;
if (!requiredCopayers || !extPrivKeys || !extPrivKeys.length || !destAddr){ if (!requiredCopayers || !extPrivKeys || !extPrivKeys.length || !destAddr){
program.outputHelp(); program.outputHelp();
@ -140,20 +142,26 @@ firstWallet.updateIndexes(function() {
console.log('Balance per address:', balanceByAddr); //TODO console.log('Balance per address:', balanceByAddr); //TODO
if (!balance) { if (!balance) {
console.log('Could not find any coins in the generated wallet'); //TODO throw ('Could not find any coins in the generated wallet');
process.exit(1);
} }
// rl.question("\n\tShould I swipe the wallet (destination address is:" + destAddr + ")?\n\t(`yes` to continue)\n\t", function(answer) {
// if (answer !== 'yes')
// process.exit(1);
var amount = balance - fee * bitcore.util.COIN; if (amount && amount >= balance)
throw ('Not enought balance fund to fullfill ' + amount + ' satoshis');
rl.question("\n\tShould I swipe the wallet (destination address is:" + destAddr + " Amount: "+ amount + "Satoshis )?\n\t(`yes` to continue)\n\t", function(answer) {
if (answer !== 'yes')
process.exit(1);
amount = amount || balance - fee * bitcore.util.COIN;
console.log('[swipeWallet.js.136]'); //TODO
firstWallet.createTx(destAddr, amount, '', {}, function(err, ntxid) { firstWallet.createTx(destAddr, amount, '', {}, function(err, ntxid) {
if (err || !ntxid) { if (err || !ntxid) {
throw new Error('Could not create tx' + err + '. Try a bigger fee (--fee).'); if (err && err.toString().match('BIG')) {
throw new Error('Could not create tx' + err );
} else {
throw new Error('Could not create tx' + err + '. Try a bigger fee (--fee).');
}
} }
console.log('\n\t### Tx Proposal Created...\n\tWith copayer 0 signature.'); console.log('\n\t### Tx Proposal Created...\n\tWith copayer 0 signature.');
@ -191,7 +199,7 @@ console.log('[swipeWallet.js.136]'); //TODO
console.log('\t FULLY SIGNED. BROADCASTING NOW....'); console.log('\t FULLY SIGNED. BROADCASTING NOW....');
var tx = p.builder.build(); var tx = p.builder.build();
var txHex = tx.serialize().toString('hex'); var txHex = tx.serialize().toString('hex');
console.log('\t RAW TX: ', txHex); //console.log('\t RAW TX: ', txHex);
firstWallet.sendTx(ntxid, function(txid) { firstWallet.sendTx(ntxid, function(txid) {
console.log('\t ####### SENT TXID:', txid); console.log('\t ####### SENT TXID:', txid);
process.exit(1); process.exit(1);
@ -202,6 +210,6 @@ console.log('[swipeWallet.js.136]'); //TODO
} }
) )
}); });
// }); });
}); });
}); });