fix bit cmds: address, addresses, balance, broadcast, confirm, history, reject, rm, send, sign, status & txproposals

This commit is contained in:
Ivan Socolsky 2015-03-02 09:39:43 -03:00
parent f486ecacd3
commit f89c863419
15 changed files with 145 additions and 157 deletions

View File

@ -9,8 +9,9 @@ program
.parse(process.argv); .parse(process.argv);
var args = program.args; var args = program.args;
var client = utils.getClient(program); utils.getClient(program, function (client) {
client.createAddress(function(err, x) { client.createAddress(function(err, x) {
utils.die(err); utils.die(err);
console.log('* New Address %s ', x.address); console.log('* New Address %s ', x.address);
});
}); });

View File

@ -10,14 +10,20 @@ program
.parse(process.argv); .parse(process.argv);
var args = program.args; var args = program.args;
var client = utils.getClient(program);
client.getMainAddresses({
doNotVerify: true
}, function(err, x) {
utils.die(err);
console.log('* Addresses:'); utils.getClient(program, function (client) {
_.each(x, function(a) { client.getMainAddresses({
console.log(' ', a.address); 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.');
}
}); });
}); });

View File

@ -9,9 +9,10 @@ program
.parse(process.argv); .parse(process.argv);
var args = program.args; var args = program.args;
var client = utils.getClient(program);
client.getBalance(function(err, x) { utils.getClient(program, function (client) {
utils.die(err); client.getBalance(function(err, x) {
console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount) ); utils.die(err);
console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount) );
});
}); });

View File

@ -11,19 +11,16 @@ program
.parse(process.argv); .parse(process.argv);
var args = program.args; var args = program.args;
if (!args[0]) var txpid = args[0] || '';
program.help();
var txpid = args[0]; utils.getClient(program, function (client) {
var client = utils.getClient(program); client.getTxProposals({}, function(err, txps) {
client.getTxProposals({}, function(err, txps) {
utils.die(err);
var txp = utils.findOneTxProposal(txps, txpid);
client.broadcastTxProposal(txp, function(err, txid) {
utils.die(err); 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);
});
}); });
}); });

View File

@ -9,24 +9,27 @@ program = utils.configureCommander(program);
program program
.parse(process.argv); .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) { if (x.wallet.n == 1) {
utils.die(err); console.log('Confirmations only work on shared wallets');
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.'); 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; console.log('\t\t---');
_.each(x.wallet.copayers, function(x) { console.log('\t\tYour confirmation ID: %s', myConfirmationId);
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);
}); });

View File

@ -4,40 +4,39 @@ var _ = require('lodash');
var fs = require('fs'); var fs = require('fs');
var moment = require('moment'); var moment = require('moment');
var program = require('commander'); var program = require('commander');
var Utils = require('./cli-utils'); var utils = require('./cli-utils');
program = Utils.configureCommander(program); program = utils.configureCommander(program);
program program
.parse(process.argv); .parse(process.argv);
var args = program.args; 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) { console.log("* TX History:")
if (_.isEmpty(txs))
return;
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) { console.log("\t%s: %s %s %s %s(%s confirmations)", time, direction, tx.action, amount, proposal, confirmations);
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);
}); });
}); });

View File

@ -13,17 +13,18 @@ program
var args = program.args; var args = program.args;
var txpid = args[0] || ''; var txpid = args[0] || '';
var reason = args[1] || ''; var reason = args[1] || '';
var client = utils.getClient(program);
client.getTxProposals({}, function(err, txps) { utils.getClient(program, function (client) {
utils.die(err); client.getTxProposals({}, function(err, txps) {
var txp = utils.findOneTxProposal(txps, txpid);
client.rejectTxProposal(txp, reason, function(err, tx) {
utils.die(err); utils.die(err);
if (tx.status == 'rejected')
console.log('Transaction finally rejected.'); var txp = utils.findOneTxProposal(txps, txpid);
else client.rejectTxProposal(txp, reason, function(err, tx) {
console.log('Transaction rejected by you.'); utils.die(err);
if (tx.status == 'rejected')
console.log('Transaction finally rejected.');
else
console.log('Transaction rejected by you.');
});
}); });
}); });

View File

@ -12,26 +12,20 @@ program
.parse(process.argv); .parse(process.argv);
var args = program.args; var args = program.args;
if (!args[0]) var txpid = args[0] || '';
program.help();
var txpid = args[0]; utils.getClient(program, function (client) {
client.getTxProposals({}, function(err, txps) {
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.die(err); 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.');
});
}); });
}); });

View File

@ -31,14 +31,14 @@ try {
} }
var note = args[2]; var note = args[2];
var client = utils.getClient(program); utils.getClient(program, function (client) {
client.sendTxProposal({
client.sendTxProposal({ toAddress: address,
toAddress: address, amount: amount,
amount: amount, message: note
message: note }, function(err, x) {
}, function(err, x) { utils.die(err);
utils.die(err); console.log(' * Tx created: ID %s [%s] RequiredSignatures:',
console.log(' * Tx created: ID %s [%s] RequiredSignatures:', x.id, x.status, x.requiredSignatures);
x.id, x.status, x.requiredSignatures); });
}); });

View File

@ -15,9 +15,7 @@ program
var args = program.args; var args = program.args;
var txpid = args[0] || ''; var txpid = args[0] || '';
var client = utils.getClient(program); function end(client, txp) {
function end(txp) {
if (program.output) { if (program.output) {
client.getSignatures(txp, function(err, signatures) { client.getSignatures(txp, function(err, signatures) {
utils.die(err); utils.die(err);
@ -50,14 +48,16 @@ function end(txp) {
}; };
if (program.input && program.output) { utils.getClient(program, function (client) {
var inFile = JSON.parse(fs.readFileSync(program.input)); if (program.input && program.output) {
end(inFile.txps[0]); var inFile = JSON.parse(fs.readFileSync(program.input));
} else { end(client, inFile.txps[0]);
client.getTxProposals({}, function(err, txps) { } else {
utils.die(err); client.getTxProposals({}, function(err, txps) {
var txp = utils.findOneTxProposal(txps, txpid); utils.die(err);
utils.die(err); var txp = utils.findOneTxProposal(txps, txpid);
end(txp); utils.die(err);
}); end(client, txp);
} });
}
});

View File

@ -14,7 +14,7 @@ utils.getClient(program, function (client) {
utils.die(err); utils.die(err);
var x = res.wallet; 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') if (x.status != 'complete')
console.log(' Missing copayers:', x.n - x.copayers.length); console.log(' Missing copayers:', x.n - x.copayers.length);

View File

@ -7,39 +7,20 @@ var utils = require('./cli-utils');
program = utils.configureCommander(program); program = utils.configureCommander(program);
program program
.option('-i, --input [filename]', 'use input file instead of server\'s') .option('-o, --output [filename]', 'write tx to output file for offline signing')
.option('-o, --output [filename]', 'write tx to output file')
.parse(process.argv); .parse(process.argv);
var args = program.args; var args = program.args;
var client = utils.getClient(program);
var txData; utils.getClient(program, function (client) {
client.getTxProposals({forAirGapped: !!program.output}, function (err, res) {
function end(err, txps, rawtxps) { utils.die(err);
utils.die(err);
if (program.input) { if (program.output) {
console.log('\n* From File : %s\n', program.input); fs.writeFileSync(program.output, JSON.stringify(res));
} console.log(' * Tx proposals saved to: %s\n', program.output);
utils.renderTxProposals(txps); } else {
if (program.output) { utils.renderTxProposals(res);
}
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);
}

View File

@ -195,7 +195,11 @@ Utils.renderTxProposals = function(txps) {
return a.copayerName + ' ' + (a.type == 'accept' ? '✓' : '✗') + (a.comment ? ' (' + a.comment + ')' : ''); return a.copayerName + ' ' + (a.type == 'accept' ? '✓' : '✗') + (a.comment ? ' (' + a.comment + ')' : '');
}).join('. ')); }).join('. '));
} }
console.log('\t\tMissing signatures: ' + missingSignatures); if (missingSignatures > 0) {
console.log('\t\tMissing signatures: ' + missingSignatures);
} else {
console.log('\t\tReady to broadcast');
}
}); });
}; };

View File

@ -344,7 +344,7 @@ API.prototype.getStatus = function(cb) {
self._doGetRequest('/v1/wallets/', function(err, result) { self._doGetRequest('/v1/wallets/', function(err, result) {
_processTxps(result.pendingTxps, self.credentials.sharedEncryptingKey); _processTxps(result.pendingTxps, self.credentials.sharedEncryptingKey);
return cb(err, result, self.credentials.copayerId); return cb(err, result);
}); });
}; };

View File

@ -17,6 +17,7 @@ var FIELDS = [
'm', 'm',
'n', 'n',
'walletPrivKey', 'walletPrivKey',
'personalEncryptingKey',
'sharedEncryptingKey', 'sharedEncryptingKey',
'copayerName', 'copayerName',
]; ];