From 8a8c1118272359fb65cdf7b67e15a350ee34359f Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 12 Feb 2015 16:50:10 -0300 Subject: [PATCH] CLI lib --- cli.js => lib/clilib.js | 42 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 25 deletions(-) rename cli.js => lib/clilib.js (70%) diff --git a/cli.js b/lib/clilib.js similarity index 70% rename from cli.js rename to lib/clilib.js index 26d1f86..6c0a52a 100644 --- a/cli.js +++ b/lib/clilib.js @@ -10,11 +10,14 @@ log.level = 'debug'; var fs = require('fs') var Bitcore = require('bitcore') -var SignUtils = require('./lib/signutils'); +var SignUtils = require('./signutils'); var BASE_URL = 'http://localhost:3001/copay/api/'; -function getUrl(path) { +var cli = {}; + + +function _getUrl(path) { return BASE_URL + path; }; @@ -35,7 +38,7 @@ function load() { -function createWallet(walletName, copayerName, m, n, cb) { +clilib.createWallet = function(walletName, copayerName, m, n, cb) { var data = load(); if (!data) { data = {}; @@ -54,7 +57,7 @@ function createWallet(walletName, copayerName, m, n, cb) { request({ method: 'post', - url: getUrl('v1/wallets'), + url: _getUrl('v1/wallets'), body: args, json: true, }, function(err, res, body) { @@ -71,7 +74,7 @@ function createWallet(walletName, copayerName, m, n, cb) { }); }; -function joinWallet(secret, copayerName, cb) { +clilib.joinWallet = function(secret, copayerName, cb) { var data = load(); if (!data) { data = {}; @@ -94,7 +97,7 @@ function joinWallet(secret, copayerName, cb) { request({ method: 'post', - url: getUrl('v1/wallets/' + walletId + '/copayers'), + url: _getUrl('v1/wallets/' + walletId + '/copayers'), body: args, json: true, }, function(err, res, body) { @@ -107,10 +110,10 @@ function joinWallet(secret, copayerName, cb) { }); }; -function status(cb) { +clilib.status = function(cb) { request({ method: 'get', - url: getUrl('v1/dump/'), + url: _getUrl('v1/dump/'), }, function(err, res, body) { if (err) return cb(err); @@ -119,35 +122,24 @@ function status(cb) { }); }; -function send(addressTo, amount, message, cb) { +clilib.send = function(addressTo, amount, message, cb) { }; -function sign(proposalId, cb) { +clilib.sign = function(proposalId, cb) { }; -function reject(proposalId, cb) { +clilib.reject = function(proposalId, cb) { }; -function address(cb) { +clilib.address = function(cb) { }; -function history(limit, cb) { +clilib.history = function(limit, cb) { }; - -// createWallet('test wallet', 'test copayer', 2, 2, function(err, secret) { -// if (err) process.exit(err); -// var data = load(); -// console.log('ESTE ES EL SECRET', secret); -// console.log('ESTE ES EL STORAGE', data); -// }); - - -// joinWallet('1b44f598-ced5-4fe1-bac3-d9f4563c3011|9b483158c271036035ea639a57761247902222784ef03142b552800e35082929', 'otro copayer', function(err) { -// if (err) process.exit(err); -// }); +module.exports = clilib;