Merge pull request #58 from matiu/ref/arg-parsing
default bit.dat file;
This commit is contained in:
commit
bfb9781c15
|
@ -3,12 +3,9 @@
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-v, --verbose', 'be verbose')
|
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
|
|
|
@ -4,12 +4,9 @@ var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-v, --verbose', 'be verbose')
|
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-v, --verbose', 'be verbose')
|
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
|
|
|
@ -4,12 +4,9 @@ var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c,--config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-v,--verbose', 'be verbose')
|
|
||||||
.usage('[options] <txpid>')
|
.usage('[options] <txpid>')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,11 @@ var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-v, --verbose', 'be verbose')
|
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var client = utils.getClient(program);
|
var client = utils.getClient(program);
|
||||||
|
|
||||||
client.getStatus(function(err, x, myCopayerId) {
|
client.getStatus(function(err, x, myCopayerId) {
|
||||||
|
|
|
@ -4,11 +4,9 @@ var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/client');
|
var ClientLib = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-t, --testnet', 'Create a Testnet Wallet')
|
.option('-t, --testnet', 'Create a Testnet Wallet')
|
||||||
.usage('[options] <walletName> <m-n> [copayerName]')
|
.usage('[options] <walletName> <m-n> [copayerName]')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
|
@ -5,12 +5,9 @@ var qr = require('qr-image');
|
||||||
|
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-v, --verbose', 'be verbose')
|
|
||||||
.option('-q, --qr')
|
.option('-q, --qr')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,13 @@
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
|
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
.version('0.0.1')
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-v, --verbose', 'be verbose')
|
|
||||||
.usage('import [options] <file>')
|
.usage('import [options] <file>')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,9 @@
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.usage('[options] <secret> [copayerName]')
|
.usage('[options] <secret> [copayerName]')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,9 @@ var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/client');
|
var ClientLib = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.usage('[options] walletname')
|
.usage('[options] walletname')
|
||||||
.description('Creates a wallet on the remove server given the local information')
|
.description('Creates a wallet on the remove server given the local information')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
|
@ -4,12 +4,9 @@ var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c,--config [file]', 'Wallet config filename')
|
|
||||||
.option('-v,--verbose', 'be verbose')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.usage('[options] <txpid> [reason]')
|
.usage('[options] <txpid> [reason]')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,10 @@ var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c,--config [file]', 'Wallet config filename')
|
|
||||||
.option('-v,--verbose', 'be verbose')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.usage('[options] <txpid>')
|
.usage('[options] <txpid>')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var Client = require('../lib/client');
|
var Client = require('../lib/client');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-v, --verbose', 'be verbose')
|
|
||||||
.usage('[options] <address> <amount> [note]')
|
.usage('[options] <address> <amount> [note]')
|
||||||
.description('Create a proposal for sending bitcoins to a destination address.\n The amount can be specified in bit, btc or sat (the default).');
|
.description('Create a proposal for sending bitcoins to a destination address.\n The amount can be specified in bit, btc or sat (the default).');
|
||||||
|
|
||||||
|
@ -19,7 +16,6 @@ program.on('--help', function(){
|
||||||
console.log(' $ bit-send mgWeRvUC6d1LRPKtdDbvYEpaUEmApS4XrY 0.2btc "dinner with friends"');
|
console.log(' $ bit-send mgWeRvUC6d1LRPKtdDbvYEpaUEmApS4XrY 0.2btc "dinner with friends"');
|
||||||
console.log('');
|
console.log('');
|
||||||
});
|
});
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c,--config [file]', 'Wallet config filename')
|
|
||||||
.option('-v,--verbose', 'be verbose')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.usage('[options] <txpid>')
|
.usage('[options] <txpid>')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,9 @@
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var utils = require('./cli-utils');
|
var utils = require('./cli-utils');
|
||||||
|
program = utils.configureCommander(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
|
||||||
.option('-c, --config [file]', 'Wallet config filename')
|
|
||||||
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
|
||||||
.option('-v, --verbose', 'be verbose')
|
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
|
|
|
@ -36,7 +36,7 @@ Utils.confirmationId = function(copayer) {
|
||||||
|
|
||||||
Utils.getClient = function(args) {
|
Utils.getClient = function(args) {
|
||||||
var storage = new Client.FileStorage({
|
var storage = new Client.FileStorage({
|
||||||
filename: args.config || process.env['BIT_FILE'],
|
filename: args.file || process.env['BIT_FILE'],
|
||||||
});
|
});
|
||||||
return new Client({
|
return new Client({
|
||||||
storage: storage,
|
storage: storage,
|
||||||
|
@ -89,5 +89,14 @@ Utils.parseAmount = function(text) {
|
||||||
return amountSat;
|
return amountSat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Utils.configureCommander = function(program) {
|
||||||
|
program
|
||||||
|
.version('0.0.1')
|
||||||
|
.option('-f, --file [filename]', 'Wallet file', 'bit.dat')
|
||||||
|
.option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api')
|
||||||
|
.option('-v, --verbose', 'be verbose')
|
||||||
|
|
||||||
|
return program;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = Utils;
|
module.exports = Utils;
|
||||||
|
|
|
@ -227,7 +227,7 @@ API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb
|
||||||
|
|
||||||
this.storage.load(function(err, data) {
|
this.storage.load(function(err, data) {
|
||||||
if (data)
|
if (data)
|
||||||
return cb('Storage already contains a wallet');
|
return cb(self.storage.getName() + ' already contains a wallet');
|
||||||
|
|
||||||
var walletPrivKey = new Bitcore.PrivateKey();
|
var walletPrivKey = new Bitcore.PrivateKey();
|
||||||
var args = {
|
var args = {
|
||||||
|
|
|
@ -3,12 +3,15 @@ var fs = require('fs')
|
||||||
|
|
||||||
function FileStorage(opts) {
|
function FileStorage(opts) {
|
||||||
if (!opts.filename) {
|
if (!opts.filename) {
|
||||||
throw new Error('Please set the config filename');
|
throw new Error('Please set wallet filename');
|
||||||
}
|
}
|
||||||
this.filename = opts.filename;
|
this.filename = opts.filename;
|
||||||
this.fs = opts.fs || fs;
|
this.fs = opts.fs || fs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FileStorage.prototype.getName = function() {
|
||||||
|
return this.filename;
|
||||||
|
};
|
||||||
|
|
||||||
FileStorage.prototype.save = function(data, cb) {
|
FileStorage.prototype.save = function(data, cb) {
|
||||||
this.fs.writeFile(this.filename, JSON.stringify(data), cb);
|
this.fs.writeFile(this.filename, JSON.stringify(data), cb);
|
||||||
|
|
Loading…
Reference in New Issue