diff --git a/bit-wallet/bit-address b/bit-wallet/bit-address index 0ffe053..057a25c 100755 --- a/bit-wallet/bit-address +++ b/bit-wallet/bit-address @@ -9,8 +9,9 @@ program .parse(process.argv); var args = program.args; -var client = utils.getClient(program); -client.createAddress(function(err, x) { - utils.die(err); - console.log('* New Address %s ', x.address); +utils.getClient(program, function (client) { + client.createAddress(function(err, x) { + utils.die(err); + console.log('* New Address %s ', x.address); + }); }); diff --git a/bit-wallet/bit-addresses b/bit-wallet/bit-addresses index 5987e6b..a746030 100755 --- a/bit-wallet/bit-addresses +++ b/bit-wallet/bit-addresses @@ -10,14 +10,20 @@ program .parse(process.argv); var args = program.args; -var client = utils.getClient(program); -client.getMainAddresses({ - doNotVerify: true -}, function(err, x) { - utils.die(err); - console.log('* Addresses:'); - _.each(x, function(a) { - console.log(' ', a.address); +utils.getClient(program, function (client) { + client.getMainAddresses({ + doNotVerify: true + }, function(err, x) { + utils.die(err); + + if (x.length > 0) { + console.log('* Addresses:'); + _.each(x, function(a) { + console.log(' ', a.address); + }); + } else { + console.log('* No addresses.'); + } }); }); diff --git a/bit-wallet/bit-balance b/bit-wallet/bit-balance index 9f9cc40..c32e8b2 100755 --- a/bit-wallet/bit-balance +++ b/bit-wallet/bit-balance @@ -9,9 +9,10 @@ program .parse(process.argv); var args = program.args; -var client = utils.getClient(program); -client.getBalance(function(err, x) { - utils.die(err); - console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount) ); +utils.getClient(program, function (client) { + client.getBalance(function(err, x) { + utils.die(err); + console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount) ); + }); }); diff --git a/bit-wallet/bit-broadcast b/bit-wallet/bit-broadcast index cb94701..a186d19 100755 --- a/bit-wallet/bit-broadcast +++ b/bit-wallet/bit-broadcast @@ -11,19 +11,16 @@ program .parse(process.argv); var args = program.args; -if (!args[0]) - program.help(); +var txpid = args[0] || ''; -var txpid = args[0]; -var client = utils.getClient(program); - -client.getTxProposals({}, function(err, txps) { - utils.die(err); - - var txp = utils.findOneTxProposal(txps, txpid); - client.broadcastTxProposal(txp, function(err, txid) { +utils.getClient(program, function (client) { + client.getTxProposals({}, function(err, txps) { utils.die(err); - console.log('Transaction Broadcasted: TXID: ' + x.txid); - + + var txp = utils.findOneTxProposal(txps, txpid); + client.broadcastTxProposal(txp, function(err, txp) { + utils.die(err); + console.log('Transaction Broadcasted: TXID: ' + txp.txid); + }); }); }); diff --git a/bit-wallet/bit-confirm b/bit-wallet/bit-confirm index 99d4386..9d3002e 100755 --- a/bit-wallet/bit-confirm +++ b/bit-wallet/bit-confirm @@ -9,24 +9,27 @@ program = utils.configureCommander(program); program .parse(process.argv); -var client = utils.getClient(program); +utils.getClient(program, function (client) { + client.getStatus(function(err, x) { + utils.die(err); -client.getStatus(function(err, x, myCopayerId) { - utils.die(err); - console.log('\n To be sure that none Copayer has joined more that once to this wallet, you can asked them their confirmation number. They can grab them using this (bit confirm) command.'); + if (x.wallet.n == 1) { + console.log('Confirmations only work on shared wallets'); + process.exit(1); + } + console.log('\n To be sure that no copayer has joined this wallet more than once, you can asked them for their confirmation number. They can get theirs by running the bit-confirm command.'); + console.log('\n * Copayer confirmation IDs:'); - console.log('\n * Copayer confirmations ids:'); + var myConfirmationId; + _.each(x.wallet.copayers, function(x) { + var confirmationId = utils.confirmationId(x); + if (x.id != client.credentials.copayerId) + console.log('\t\t* %s : %s', x.name, confirmationId); + else + myConfirmationId = confirmationId; + }); - var myConfirmationId; - _.each(x.wallet.copayers, function(x) { - var confirmationId = utils.confirmationId(x); - if (x.id != myCopayerId) - console.log('\t\t* %s : %s', x.name, confirmationId); - else - myConfirmationId = confirmationId; + console.log('\t\t---'); + console.log('\t\tYour confirmation ID: %s', myConfirmationId); }); - - - console.log('\t\t---'); - console.log('\t\tYour confirmation ID: %s', myConfirmationId); }); diff --git a/bit-wallet/bit-history b/bit-wallet/bit-history index 7f250c2..f2bb8db 100755 --- a/bit-wallet/bit-history +++ b/bit-wallet/bit-history @@ -4,40 +4,39 @@ var _ = require('lodash'); var fs = require('fs'); var moment = require('moment'); var program = require('commander'); -var Utils = require('./cli-utils'); -program = Utils.configureCommander(program); +var utils = require('./cli-utils'); +program = utils.configureCommander(program); program .parse(process.argv); var args = program.args; -var client = Utils.getClient(program); -var txData; +utils.getClient(program, function (client) { + client.getTxHistory({}, function (err, txs) { + if (_.isEmpty(txs)) + return; -client.getTxHistory({}, function (err, txs) { - if (_.isEmpty(txs)) - return; + console.log("* TX History:") - console.log("* TX History:") + _.each(txs, function(tx) { + var time = moment(tx.time * 1000).fromNow(); + var amount = utils.renderAmount(tx.amount); + var confirmations = tx.confirmations || 0; + var proposal = tx.proposalId ? '["' + tx.message + '" by ' + tx.creatorName + '] ' : ''; + switch (tx.action) { + case 'received': + direction = '<='; + break; + case 'moved': + direction = '=='; + break; + case 'sent': + direction = '=>'; + break; + } - _.each(txs, function(tx) { - var time = moment(tx.time * 1000).fromNow(); - var amount = Utils.renderAmount(tx.amount); - var confirmations = tx.confirmations || 0; - var proposal = tx.proposalId ? '["' + tx.message + '" by ' + tx.creatorName + '] ' : ''; - switch (tx.action) { - case 'received': - direction = '<='; - break; - case 'moved': - direction = '=='; - break; - case 'sent': - direction = '=>'; - break; - } - - console.log("\t%s: %s %s %s %s(%s confirmations)", time, direction, tx.action, amount, proposal, confirmations); + console.log("\t%s: %s %s %s %s(%s confirmations)", time, direction, tx.action, amount, proposal, confirmations); + }); }); }); diff --git a/bit-wallet/bit-reject b/bit-wallet/bit-reject index de0858c..bdf1fd6 100755 --- a/bit-wallet/bit-reject +++ b/bit-wallet/bit-reject @@ -13,17 +13,18 @@ program var args = program.args; var txpid = args[0] || ''; var reason = args[1] || ''; -var client = utils.getClient(program); -client.getTxProposals({}, function(err, txps) { - utils.die(err); - - var txp = utils.findOneTxProposal(txps, txpid); - client.rejectTxProposal(txp, reason, function(err, tx) { +utils.getClient(program, function (client) { + client.getTxProposals({}, function(err, txps) { utils.die(err); - if (tx.status == 'rejected') - console.log('Transaction finally rejected.'); - else - console.log('Transaction rejected by you.'); + + var txp = utils.findOneTxProposal(txps, txpid); + client.rejectTxProposal(txp, reason, function(err, tx) { + utils.die(err); + if (tx.status == 'rejected') + console.log('Transaction finally rejected.'); + else + console.log('Transaction rejected by you.'); + }); }); }); diff --git a/bit-wallet/bit-rm b/bit-wallet/bit-rm index a27a787..b0472aa 100755 --- a/bit-wallet/bit-rm +++ b/bit-wallet/bit-rm @@ -12,26 +12,20 @@ program .parse(process.argv); var args = program.args; -if (!args[0]) - program.help(); +var txpid = args[0] || ''; -var txpid = args[0]; - -var cli = new Client({ - filename: program.config -}); - -cli.getTxProposals({}, function(err, txps) { - utils.die(err); - - if (program.verbose) - console.log('* Raw Server Response:\n', txps); //TODO - - var txp = utils.findOneTxProposal(txps, txpid); - - cli.removeTxProposal(txp, function(err) { +utils.getClient(program, function (client) { + client.getTxProposals({}, function(err, txps) { utils.die(err); - console.log('Transaction removed.'); + if (program.verbose) + console.log('* Raw Server Response:\n', txps); //TODO + + var txp = utils.findOneTxProposal(txps, txpid); + client.removeTxProposal(txp, function(err) { + utils.die(err); + + console.log('Transaction removed.'); + }); }); }); diff --git a/bit-wallet/bit-send b/bit-wallet/bit-send index b8b8194..780eba5 100755 --- a/bit-wallet/bit-send +++ b/bit-wallet/bit-send @@ -31,14 +31,14 @@ try { } var note = args[2]; -var client = utils.getClient(program); - -client.sendTxProposal({ - toAddress: address, - amount: amount, - message: note -}, function(err, x) { - utils.die(err); - console.log(' * Tx created: ID %s [%s] RequiredSignatures:', - x.id, x.status, x.requiredSignatures); +utils.getClient(program, function (client) { + client.sendTxProposal({ + toAddress: address, + amount: amount, + message: note + }, function(err, x) { + utils.die(err); + console.log(' * Tx created: ID %s [%s] RequiredSignatures:', + x.id, x.status, x.requiredSignatures); + }); }); diff --git a/bit-wallet/bit-sign b/bit-wallet/bit-sign index 9faad47..b11c32d 100755 --- a/bit-wallet/bit-sign +++ b/bit-wallet/bit-sign @@ -15,9 +15,7 @@ program var args = program.args; var txpid = args[0] || ''; -var client = utils.getClient(program); - -function end(txp) { +function end(client, txp) { if (program.output) { client.getSignatures(txp, function(err, signatures) { utils.die(err); @@ -50,14 +48,16 @@ function end(txp) { }; -if (program.input && program.output) { - var inFile = JSON.parse(fs.readFileSync(program.input)); - end(inFile.txps[0]); -} else { - client.getTxProposals({}, function(err, txps) { - utils.die(err); - var txp = utils.findOneTxProposal(txps, txpid); - utils.die(err); - end(txp); - }); -} +utils.getClient(program, function (client) { + if (program.input && program.output) { + var inFile = JSON.parse(fs.readFileSync(program.input)); + end(client, inFile.txps[0]); + } else { + client.getTxProposals({}, function(err, txps) { + utils.die(err); + var txp = utils.findOneTxProposal(txps, txpid); + utils.die(err); + end(client, txp); + }); + } +}); diff --git a/bit-wallet/bit-status b/bit-wallet/bit-status index 37bd1e2..4f29ce4 100755 --- a/bit-wallet/bit-status +++ b/bit-wallet/bit-status @@ -14,7 +14,7 @@ utils.getClient(program, function (client) { utils.die(err); var x = res.wallet; - console.log('* Wallet %s [%s]: %d-%d %s ', x.name, x.network, x.m, x.n, x.status); + console.log('* Wallet %s [%s]: %d-of-%d %s ', x.name, x.network, x.m, x.n, x.status); if (x.status != 'complete') console.log(' Missing copayers:', x.n - x.copayers.length); diff --git a/bit-wallet/bit-txproposals b/bit-wallet/bit-txproposals index 26a27ae..2bcef75 100755 --- a/bit-wallet/bit-txproposals +++ b/bit-wallet/bit-txproposals @@ -7,39 +7,20 @@ var utils = require('./cli-utils'); program = utils.configureCommander(program); program - .option('-i, --input [filename]', 'use input file instead of server\'s') - .option('-o, --output [filename]', 'write tx to output file') + .option('-o, --output [filename]', 'write tx to output file for offline signing') .parse(process.argv); var args = program.args; -var client = utils.getClient(program); -var txData; - -function end(err, txps, rawtxps) { - utils.die(err); - if (program.input) { - console.log('\n* From File : %s\n', program.input); - } - utils.renderTxProposals(txps); - if (program.output) { - - client.getEncryptedWalletData(function (err, toComplete) { - var txData = { - toComplete: toComplete, - txps: txps, - }; - fs.writeFileSync(program.output, JSON.stringify(txData)); - console.log(' * Proposals Saved to: %s\n', program.output); - }); - } -}; - - -if (program.input) { - var txData = fs.readFileSync(program.input); - txData = JSON.parse(txData); - client.parseTxProposals(txData, end); -} else { - client.getTxProposals({getRawTxps: !!program.output}, end); -} +utils.getClient(program, function (client) { + client.getTxProposals({forAirGapped: !!program.output}, function (err, res) { + utils.die(err); + + if (program.output) { + fs.writeFileSync(program.output, JSON.stringify(res)); + console.log(' * Tx proposals saved to: %s\n', program.output); + } else { + utils.renderTxProposals(res); + } + }); +}); diff --git a/bit-wallet/cli-utils.js b/bit-wallet/cli-utils.js index 4613a19..b621c24 100644 --- a/bit-wallet/cli-utils.js +++ b/bit-wallet/cli-utils.js @@ -195,7 +195,11 @@ Utils.renderTxProposals = function(txps) { return a.copayerName + ' ' + (a.type == 'accept' ? '✓' : '✗') + (a.comment ? ' (' + a.comment + ')' : ''); }).join('. ')); } - console.log('\t\tMissing signatures: ' + missingSignatures); + if (missingSignatures > 0) { + console.log('\t\tMissing signatures: ' + missingSignatures); + } else { + console.log('\t\tReady to broadcast'); + } }); }; diff --git a/lib/client/api.js b/lib/client/api.js index fc73851..82fbcee 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -344,7 +344,7 @@ API.prototype.getStatus = function(cb) { self._doGetRequest('/v1/wallets/', function(err, result) { _processTxps(result.pendingTxps, self.credentials.sharedEncryptingKey); - return cb(err, result, self.credentials.copayerId); + return cb(err, result); }); }; diff --git a/lib/client/credentials.js b/lib/client/credentials.js index 29f9373..becf254 100644 --- a/lib/client/credentials.js +++ b/lib/client/credentials.js @@ -17,6 +17,7 @@ var FIELDS = [ 'm', 'n', 'walletPrivKey', + 'personalEncryptingKey', 'sharedEncryptingKey', 'copayerName', ];