fix bit cmds: address, addresses, balance, broadcast, confirm, history, reject, rm, send, sign, status & txproposals
This commit is contained in:
parent
f486ecacd3
commit
f89c863419
|
@ -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);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -10,14 +10,20 @@ 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.getMainAddresses({
|
client.getMainAddresses({
|
||||||
doNotVerify: true
|
doNotVerify: true
|
||||||
}, function(err, x) {
|
}, function(err, x) {
|
||||||
utils.die(err);
|
utils.die(err);
|
||||||
|
|
||||||
|
if (x.length > 0) {
|
||||||
console.log('* Addresses:');
|
console.log('* Addresses:');
|
||||||
_.each(x, function(a) {
|
_.each(x, function(a) {
|
||||||
console.log(' ', a.address);
|
console.log(' ', a.address);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log('* No addresses.');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,9 +9,10 @@ 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.getBalance(function(err, x) {
|
client.getBalance(function(err, x) {
|
||||||
utils.die(err);
|
utils.die(err);
|
||||||
console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount) );
|
console.log('* Wallet balance %s (Locked %s)', utils.renderAmount(x.totalAmount), utils.renderAmount(x.lockedAmount) );
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -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];
|
|
||||||
var client = utils.getClient(program);
|
|
||||||
|
|
||||||
|
utils.getClient(program, function (client) {
|
||||||
client.getTxProposals({}, function(err, txps) {
|
client.getTxProposals({}, function(err, txps) {
|
||||||
utils.die(err);
|
utils.die(err);
|
||||||
|
|
||||||
var txp = utils.findOneTxProposal(txps, txpid);
|
var txp = utils.findOneTxProposal(txps, txpid);
|
||||||
client.broadcastTxProposal(txp, function(err, txid) {
|
client.broadcastTxProposal(txp, function(err, txp) {
|
||||||
utils.die(err);
|
utils.die(err);
|
||||||
console.log('Transaction Broadcasted: TXID: ' + x.txid);
|
console.log('Transaction Broadcasted: TXID: ' + txp.txid);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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) {
|
||||||
client.getStatus(function(err, x, myCopayerId) {
|
|
||||||
utils.die(err);
|
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.');
|
|
||||||
|
|
||||||
console.log('\n * Copayer confirmations ids:');
|
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:');
|
||||||
|
|
||||||
var myConfirmationId;
|
var myConfirmationId;
|
||||||
_.each(x.wallet.copayers, function(x) {
|
_.each(x.wallet.copayers, function(x) {
|
||||||
var confirmationId = utils.confirmationId(x);
|
var confirmationId = utils.confirmationId(x);
|
||||||
if (x.id != myCopayerId)
|
if (x.id != client.credentials.copayerId)
|
||||||
console.log('\t\t* %s : %s', x.name, confirmationId);
|
console.log('\t\t* %s : %s', x.name, confirmationId);
|
||||||
else
|
else
|
||||||
myConfirmationId = confirmationId;
|
myConfirmationId = confirmationId;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
console.log('\t\t---');
|
console.log('\t\t---');
|
||||||
console.log('\t\tYour confirmation ID: %s', myConfirmationId);
|
console.log('\t\tYour confirmation ID: %s', myConfirmationId);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -4,17 +4,15 @@ 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) {
|
client.getTxHistory({}, function (err, txs) {
|
||||||
if (_.isEmpty(txs))
|
if (_.isEmpty(txs))
|
||||||
return;
|
return;
|
||||||
|
@ -23,7 +21,7 @@ client.getTxHistory({}, function (err, txs) {
|
||||||
|
|
||||||
_.each(txs, function(tx) {
|
_.each(txs, function(tx) {
|
||||||
var time = moment(tx.time * 1000).fromNow();
|
var time = moment(tx.time * 1000).fromNow();
|
||||||
var amount = Utils.renderAmount(tx.amount);
|
var amount = utils.renderAmount(tx.amount);
|
||||||
var confirmations = tx.confirmations || 0;
|
var confirmations = tx.confirmations || 0;
|
||||||
var proposal = tx.proposalId ? '["' + tx.message + '" by ' + tx.creatorName + '] ' : '';
|
var proposal = tx.proposalId ? '["' + tx.message + '" by ' + tx.creatorName + '] ' : '';
|
||||||
switch (tx.action) {
|
switch (tx.action) {
|
||||||
|
@ -41,3 +39,4 @@ client.getTxHistory({}, function (err, txs) {
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -13,8 +13,8 @@ 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);
|
|
||||||
|
|
||||||
|
utils.getClient(program, function (client) {
|
||||||
client.getTxProposals({}, function(err, txps) {
|
client.getTxProposals({}, function(err, txps) {
|
||||||
utils.die(err);
|
utils.die(err);
|
||||||
|
|
||||||
|
@ -27,3 +27,4 @@ client.getTxProposals({}, function(err, txps) {
|
||||||
console.log('Transaction rejected by you.');
|
console.log('Transaction rejected by you.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -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);
|
utils.die(err);
|
||||||
|
|
||||||
if (program.verbose)
|
if (program.verbose)
|
||||||
console.log('* Raw Server Response:\n', txps); //TODO
|
console.log('* Raw Server Response:\n', txps); //TODO
|
||||||
|
|
||||||
var txp = utils.findOneTxProposal(txps, txpid);
|
var txp = utils.findOneTxProposal(txps, txpid);
|
||||||
|
client.removeTxProposal(txp, function(err) {
|
||||||
cli.removeTxProposal(txp, function(err) {
|
|
||||||
utils.die(err);
|
utils.die(err);
|
||||||
|
|
||||||
console.log('Transaction removed.');
|
console.log('Transaction removed.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -31,8 +31,7 @@ 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,
|
||||||
|
@ -42,3 +41,4 @@ client.sendTxProposal({
|
||||||
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);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
utils.getClient(program, function (client) {
|
||||||
if (program.input && program.output) {
|
if (program.input && program.output) {
|
||||||
var inFile = JSON.parse(fs.readFileSync(program.input));
|
var inFile = JSON.parse(fs.readFileSync(program.input));
|
||||||
end(inFile.txps[0]);
|
end(client, inFile.txps[0]);
|
||||||
} else {
|
} else {
|
||||||
client.getTxProposals({}, function(err, txps) {
|
client.getTxProposals({}, function(err, txps) {
|
||||||
utils.die(err);
|
utils.die(err);
|
||||||
var txp = utils.findOneTxProposal(txps, txpid);
|
var txp = utils.findOneTxProposal(txps, txpid);
|
||||||
utils.die(err);
|
utils.die(err);
|
||||||
end(txp);
|
end(client, txp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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) {
|
|
||||||
console.log('\n* From File : %s\n', program.input);
|
|
||||||
}
|
|
||||||
utils.renderTxProposals(txps);
|
|
||||||
if (program.output) {
|
if (program.output) {
|
||||||
|
fs.writeFileSync(program.output, JSON.stringify(res));
|
||||||
client.getEncryptedWalletData(function (err, toComplete) {
|
console.log(' * Tx proposals saved to: %s\n', program.output);
|
||||||
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 {
|
} else {
|
||||||
client.getTxProposals({getRawTxps: !!program.output}, end);
|
utils.renderTxProposals(res);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -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('. '));
|
||||||
}
|
}
|
||||||
|
if (missingSignatures > 0) {
|
||||||
console.log('\t\tMissing signatures: ' + missingSignatures);
|
console.log('\t\tMissing signatures: ' + missingSignatures);
|
||||||
|
} else {
|
||||||
|
console.log('\t\tReady to broadcast');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ var FIELDS = [
|
||||||
'm',
|
'm',
|
||||||
'n',
|
'n',
|
||||||
'walletPrivKey',
|
'walletPrivKey',
|
||||||
|
'personalEncryptingKey',
|
||||||
'sharedEncryptingKey',
|
'sharedEncryptingKey',
|
||||||
'copayerName',
|
'copayerName',
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue