better wallet creation for 1-1
This commit is contained in:
parent
f359827d97
commit
18da32df64
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var _ = require('lodash');
|
||||
var program = require('commander');
|
||||
var ClientLib = require('../lib/client');
|
||||
var utils = require('./cli-utils');
|
||||
|
@ -7,7 +8,7 @@ var utils = require('./cli-utils');
|
|||
program
|
||||
.version('0.0.1')
|
||||
.option('-c, --config [file]', 'Wallet config filename')
|
||||
.option('-n, --network [networkname]', 'livenet|testnet', String, 'livenet')
|
||||
.option('-t, --testnet', 'Create a Testnet Wallet', String)
|
||||
.usage('[options] <walletName> <m-n> [copayerName]')
|
||||
.parse(process.argv);
|
||||
|
||||
|
@ -17,14 +18,14 @@ if (!args[0])
|
|||
|
||||
var walletName = args[0];
|
||||
var copayerName = args[2] || process.env.USER;
|
||||
var network = program.network;
|
||||
var network = program.testnet ? 'testnet' : 'livenet';
|
||||
|
||||
var mn = utils.parseMN(args[1]);
|
||||
|
||||
var client = utils.getClient(program);
|
||||
client.createWallet(walletName, copayerName, mn[0], mn[1], network, function(err, secret) {
|
||||
utils.die(err);
|
||||
console.log(' * Wallet Created.');
|
||||
console.log(' * ' + _.capitalize(network) + ' Wallet Created.');
|
||||
if (secret)
|
||||
console.log(' - Secret to share:\n\t' + secret);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
var _ = require('lodash');
|
||||
var Client = require('../lib/client');
|
||||
|
||||
var lib = function() {};
|
||||
var Utils = function() {};
|
||||
|
||||
var die = lib.die = function(err) {
|
||||
var die = Utils.die = function(err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
lib.parseMN = function(MN) {
|
||||
Utils.parseMN = function(MN) {
|
||||
if (!MN)
|
||||
die('No m-n parameter');
|
||||
var mn = MN.split('-');
|
||||
|
@ -27,11 +27,11 @@ lib.parseMN = function(MN) {
|
|||
};
|
||||
|
||||
|
||||
lib.shortID = function(id) {
|
||||
Utils.shortID = function(id) {
|
||||
return id.substr(id.length - 4);
|
||||
};
|
||||
|
||||
lib.getClient = function(args) {
|
||||
Utils.getClient = function(args) {
|
||||
var storage = new Client.FileStorage({
|
||||
filename: args.config
|
||||
});
|
||||
|
@ -41,16 +41,16 @@ lib.getClient = function(args) {
|
|||
});
|
||||
}
|
||||
|
||||
lib.findOneTxProposal = function(txps, id) {
|
||||
Utils.findOneTxProposal = function(txps, id) {
|
||||
var matches = _.filter(txps, function(tx) {
|
||||
return _.endsWith(lib.shortID(tx.id), id);
|
||||
return _.endsWith(Utils.shortID(tx.id), id);
|
||||
});
|
||||
|
||||
if (!matches.length)
|
||||
lib.die('Could not find TX Proposal:' + id);
|
||||
Utils.die('Could not find TX Proposal:' + id);
|
||||
|
||||
if (matches.length > 1)
|
||||
lib.die('More than one TX Proposals match:' + id + ' : ' + _.map(matches, function(tx) {
|
||||
Utils.die('More than one TX Proposals match:' + id + ' : ' + _.map(matches, function(tx) {
|
||||
return tx.id;
|
||||
}).join(' '));;
|
||||
|
||||
|
@ -59,4 +59,4 @@ lib.findOneTxProposal = function(txps, id) {
|
|||
|
||||
|
||||
|
||||
module.exports = lib;
|
||||
module.exports = Utils;
|
||||
|
|
|
@ -148,13 +148,16 @@ API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb
|
|||
|
||||
var walletId = body.walletId;
|
||||
var secret = walletId + ':' + privKey.toString() + ':' + (network == 'testnet' ? 'T' : 'L');
|
||||
data.secret = secret;
|
||||
var ret;
|
||||
|
||||
if (n > 1)
|
||||
ret = data.secret = secret;
|
||||
|
||||
self.storage.save(data);
|
||||
self._joinWallet(data, secret, copayerName, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
return cb(null, data.secret);
|
||||
return cb(null, ret);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue