Browse Source

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

activeAddress
Ivan Socolsky 10 years ago
parent
commit
f89c863419
  1. 9
      bit-wallet/bit-address
  2. 22
      bit-wallet/bit-addresses
  3. 9
      bit-wallet/bit-balance
  4. 21
      bit-wallet/bit-broadcast
  5. 41
      bit-wallet/bit-confirm
  6. 57
      bit-wallet/bit-history
  7. 21
      bit-wallet/bit-reject
  8. 28
      bit-wallet/bit-rm
  9. 20
      bit-wallet/bit-send
  10. 28
      bit-wallet/bit-sign
  11. 2
      bit-wallet/bit-status
  12. 45
      bit-wallet/bit-txproposals
  13. 6
      bit-wallet/cli-utils.js
  14. 2
      lib/client/api.js
  15. 1
      lib/client/credentials.js

9
bit-wallet/bit-address

@ -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);
});
}); });

22
bit-wallet/bit-addresses

@ -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.');
}
}); });
}); });

9
bit-wallet/bit-balance

@ -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) );
});
}); });

21
bit-wallet/bit-broadcast

@ -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);
});
}); });
}); });

41
bit-wallet/bit-confirm

@ -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.'); if (x.wallet.n == 1) {
console.log('Confirmations only work on shared wallets');
console.log('\n * Copayer confirmations ids:'); process.exit(1);
}
var myConfirmationId; 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.');
_.each(x.wallet.copayers, function(x) { console.log('\n * Copayer confirmation IDs:');
var confirmationId = utils.confirmationId(x);
if (x.id != myCopayerId) var myConfirmationId;
console.log('\t\t* %s : %s', x.name, confirmationId); _.each(x.wallet.copayers, function(x) {
else var confirmationId = utils.confirmationId(x);
myConfirmationId = confirmationId; if (x.id != client.credentials.copayerId)
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);
}); });

57
bit-wallet/bit-history

@ -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) {
client.getTxHistory({}, function (err, txs) { if (_.isEmpty(txs))
if (_.isEmpty(txs)) return;
return;
console.log("* TX History:")
console.log("* TX History:")
_.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) { case 'received':
case 'received': direction = '<=';
direction = '<='; break;
break; case 'moved':
case 'moved': direction = '==';
direction = '=='; break;
break; case 'sent':
case 'sent': direction = '=>';
direction = '=>'; break;
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); });
}); });
}); });

21
bit-wallet/bit-reject

@ -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.');
});
}); });
}); });

28
bit-wallet/bit-rm

@ -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({ utils.die(err);
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); if (program.verbose)
console.log('* Raw Server Response:\n', txps); //TODO
cli.removeTxProposal(txp, function(err) { var txp = utils.findOneTxProposal(txps, txpid);
utils.die(err); client.removeTxProposal(txp, function(err) {
utils.die(err);
console.log('Transaction removed.'); console.log('Transaction removed.');
});
}); });
}); });

20
bit-wallet/bit-send

@ -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); });
}); });

28
bit-wallet/bit-sign

@ -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);
} });
}
});

2
bit-wallet/bit-status

@ -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);

45
bit-wallet/bit-txproposals

@ -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);
}

6
bit-wallet/cli-utils.js

@ -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');
}
}); });
}; };

2
lib/client/api.js

@ -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);
}); });
}; };

1
lib/client/credentials.js

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

Loading…
Cancel
Save