Merge pull request #16 from matiu/ref/client
move / rename client files
This commit is contained in:
commit
f4b01c1925
|
@ -1,6 +1,7 @@
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
*.sw*
|
||||||
|
|
||||||
# Runtime data
|
# Runtime data
|
||||||
pids
|
pids
|
||||||
|
@ -31,4 +32,4 @@ node_modules
|
||||||
out/
|
out/
|
||||||
db/
|
db/
|
||||||
|
|
||||||
.bit
|
.bit
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
ClientLib
|
||||||
|
- check derive address
|
||||||
|
- check change address
|
||||||
|
- remove storage from clientlib
|
||||||
|
- check prposal signature
|
||||||
|
- check xpriv keys correspond to wallet's network
|
||||||
|
- check secret format in join
|
||||||
|
- test raw tx have signatures
|
||||||
|
- add broadcast API to server
|
||||||
|
- enhance 'no network (internet)' error
|
||||||
|
- /Users/ematiu/devel/bitcore-wallet-service/node_modules/bitcore/lib/transaction/transaction.js:137
|
||||||
|
throw new errors.Transaction.DustOutputs();
|
||||||
|
and others TX errores now appear at broadcast time.
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var Client = require('../lib/client');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -11,11 +11,11 @@ program
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
var cli = new ClientLib({
|
var cli = new Client({
|
||||||
filename: program.config
|
filename: program.config
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.address(function(err, x) {
|
cli.createAddress(function(err, x) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
console.log('* New Address %s ', x.address);
|
console.log('* New Address %s ', x.address);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var Client = require('../lib/client');
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
.version('0.0.1')
|
||||||
|
@ -12,11 +12,11 @@ program
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
var cli = new ClientLib({
|
var cli = new Client({
|
||||||
filename: program.config
|
filename: program.config
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.addresses(function(err, x) {
|
cli.getAddresses(function(err, x) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
|
|
||||||
console.log('* Addresses:');
|
console.log('* Addresses:');
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var Client = require('../lib/client');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -11,11 +11,11 @@ program
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
var cli = new ClientLib({
|
var cli = new Client({
|
||||||
filename: program.config
|
filename: program.config
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.balance(function(err, x) {
|
cli.getBalance(function(err, x) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
console.log('* Wallet balance', x);
|
console.log('* Wallet balance', x);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var ClientLib = require('../lib/client');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var ClientLib = require('../lib/client');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var Client = require('../lib/client');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -18,11 +18,11 @@ if (!args[0])
|
||||||
|
|
||||||
var txpid = args[0];
|
var txpid = args[0];
|
||||||
|
|
||||||
var cli = new ClientLib({
|
var cli = new Client({
|
||||||
filename: program.config
|
filename: program.config
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.txProposals({}, function(err, x) {
|
cli.getTxProposals({}, function(err, x) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
|
|
||||||
if (program.verbose)
|
if (program.verbose)
|
||||||
|
@ -41,7 +41,7 @@ cli.txProposals({}, function(err, x) {
|
||||||
}).join(' '));;
|
}).join(' '));;
|
||||||
|
|
||||||
var txp = txps[0];
|
var txp = txps[0];
|
||||||
cli.reject(txp, function(err, x) {
|
cli.rejectTxProposal(txp, function(err, x) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
|
|
||||||
if (program.verbose)
|
if (program.verbose)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var Client = require('../lib/client');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -19,11 +19,11 @@ if (!args[0] || !args[1] || !args[2])
|
||||||
var amount = args[1];
|
var amount = args[1];
|
||||||
var message = args[2];
|
var message = args[2];
|
||||||
|
|
||||||
var cli = new ClientLib({
|
var cli = new Client({
|
||||||
filename: program.config
|
filename: program.config
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.send({toAddress: address, amount: amount, message:message}, function(err, x) {
|
cli.sendTxProposal({toAddress: address, amount: amount, message:message}, function(err, x) {
|
||||||
common.die(err);
|
common.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);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var ClientLib = require('../lib/client');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -22,7 +22,7 @@ var cli = new ClientLib({
|
||||||
filename: program.config
|
filename: program.config
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.txProposals({}, function(err, x) {
|
cli.getTxProposals({}, function(err, x) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
|
|
||||||
if (program.verbose)
|
if (program.verbose)
|
||||||
|
@ -41,7 +41,7 @@ cli.txProposals({}, function(err, x) {
|
||||||
}).join(' '));;
|
}).join(' '));;
|
||||||
|
|
||||||
var txp = txps[0];
|
var txp = txps[0];
|
||||||
cli.sign(txp, function(err, x) {
|
cli.signTxProposal(txp, function(err, x) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
|
|
||||||
if (program.verbose)
|
if (program.verbose)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
|
|
||||||
var ClientLib = require('../lib/clientlib.js');
|
var Client = require('../lib/client');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -13,11 +13,11 @@ program
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
var cli = new ClientLib({
|
var cli = new Client({
|
||||||
filename: program.config
|
filename: program.config
|
||||||
});
|
});
|
||||||
|
|
||||||
cli.status(function(err, res) {
|
cli.getStatus(function(err, res) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
|
|
||||||
var x = res.wallet;
|
var x = res.wallet;
|
||||||
|
|
|
@ -9,7 +9,7 @@ log.level = 'debug';
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
|
||||||
var Bitcore = require('bitcore')
|
var Bitcore = require('bitcore')
|
||||||
var SignUtils = require('./signutils');
|
var SignUtils = require('../signutils');
|
||||||
|
|
||||||
var BASE_URL = 'http://localhost:3001/copay/api';
|
var BASE_URL = 'http://localhost:3001/copay/api';
|
||||||
|
|
||||||
|
@ -47,24 +47,24 @@ function _createXPrivKey(network) {
|
||||||
return new Bitcore.HDPrivateKey(network).toString();
|
return new Bitcore.HDPrivateKey(network).toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
function ClientLib(opts) {
|
function API(opts) {
|
||||||
if (!opts.filename) {
|
if (!opts.filename) {
|
||||||
throw new Error('Please set the config filename');
|
throw new Error('Please set the config filename');
|
||||||
}
|
}
|
||||||
this.filename = opts.filename;
|
this.filename = opts.filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype._save = function(data) {
|
API.prototype._save = function(data) {
|
||||||
fs.writeFileSync(this.filename, JSON.stringify(data));
|
fs.writeFileSync(this.filename, JSON.stringify(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype._load = function() {
|
API.prototype._load = function() {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(this.filename));
|
return JSON.parse(fs.readFileSync(this.filename));
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype._loadAndCheck = function() {
|
API.prototype._loadAndCheck = function() {
|
||||||
var data = this._load();
|
var data = this._load();
|
||||||
if (!data) {
|
if (!data) {
|
||||||
log.error('Wallet file not found.');
|
log.error('Wallet file not found.');
|
||||||
|
@ -107,17 +107,17 @@ ClientLib.prototype._doRequest = function(method, url, args, data, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ClientLib.prototype._doPostRequest = function(url, args, data, cb) {
|
API.prototype._doPostRequest = function(url, args, data, cb) {
|
||||||
return this._doRequest('post', url, args, data, cb);
|
return this._doRequest('post', url, args, data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype._doGetRequest = function(url, data, cb) {
|
API.prototype._doGetRequest = function(url, data, cb) {
|
||||||
return this._doRequest('get', url, {}, data, cb);
|
return this._doRequest('get', url, {}, data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ClientLib.prototype.createWallet = function(walletName, copayerName, m, n, network, cb) {
|
API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
network = network || 'livenet';
|
network = network || 'livenet';
|
||||||
if (!_.contains(['testnet', 'livenet'], network))
|
if (!_.contains(['testnet', 'livenet'], network))
|
||||||
|
@ -146,6 +146,8 @@ ClientLib.prototype.createWallet = function(walletName, copayerName, m, n, netwo
|
||||||
var url = '/v1/wallets/';
|
var url = '/v1/wallets/';
|
||||||
|
|
||||||
this._doPostRequest(url, args, data, function(err, body) {
|
this._doPostRequest(url, args, data, function(err, body) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
|
||||||
var walletId = body.walletId;
|
var walletId = body.walletId;
|
||||||
var secret = walletId + ':' + privKey.toString() + ':' + (network == 'testnet' ? 'T' : 'L');
|
var secret = walletId + ':' + privKey.toString() + ':' + (network == 'testnet' ? 'T' : 'L');
|
||||||
data.secret = secret;
|
data.secret = secret;
|
||||||
|
@ -159,7 +161,7 @@ ClientLib.prototype.createWallet = function(walletName, copayerName, m, n, netwo
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype._joinWallet = function(data, secret, copayerName, cb) {
|
API.prototype._joinWallet = function(data, secret, copayerName, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
data = data || {};
|
data = data || {};
|
||||||
|
|
||||||
|
@ -196,7 +198,7 @@ ClientLib.prototype._joinWallet = function(data, secret, copayerName, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype.joinWallet = function(secret, copayerName, cb) {
|
API.prototype.joinWallet = function(secret, copayerName, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = this._load();
|
var data = this._load();
|
||||||
|
@ -205,7 +207,7 @@ ClientLib.prototype.joinWallet = function(secret, copayerName, cb) {
|
||||||
self._joinWallet(data, secret, copayerName, cb);
|
self._joinWallet(data, secret, copayerName, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype.status = function(cb) {
|
API.prototype.getStatus = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
@ -249,7 +251,7 @@ ClientLib.prototype.status = function(cb) {
|
||||||
* @param inArgs.amount
|
* @param inArgs.amount
|
||||||
* @param inArgs.message
|
* @param inArgs.message
|
||||||
*/
|
*/
|
||||||
ClientLib.prototype.send = function(inArgs, cb) {
|
API.prototype.sendTxProposal = function(inArgs, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
@ -260,7 +262,7 @@ ClientLib.prototype.send = function(inArgs, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get addresses
|
// Get addresses
|
||||||
ClientLib.prototype.addresses = function(cb) {
|
API.prototype.getAddresses = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
@ -272,7 +274,7 @@ ClientLib.prototype.addresses = function(cb) {
|
||||||
|
|
||||||
// Creates a new address
|
// Creates a new address
|
||||||
// TODO: verify derivation!!
|
// TODO: verify derivation!!
|
||||||
ClientLib.prototype.address = function(cb) {
|
API.prototype.createAddress = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
@ -281,11 +283,11 @@ ClientLib.prototype.address = function(cb) {
|
||||||
this._doPostRequest(url, {}, data, cb);
|
this._doPostRequest(url, {}, data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype.history = function(limit, cb) {
|
API.prototype.history = function(limit, cb) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype.balance = function(cb) {
|
API.prototype.getBalance = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
@ -295,7 +297,7 @@ ClientLib.prototype.balance = function(cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ClientLib.prototype.txProposals = function(opts, cb) {
|
API.prototype.getTxProposals = function(opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
@ -304,7 +306,7 @@ ClientLib.prototype.txProposals = function(opts, cb) {
|
||||||
this._doGetRequest(url, data, cb);
|
this._doGetRequest(url, data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype.sign = function(txp, cb) {
|
API.prototype.signTxProposal = function(txp, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
|
||||||
|
@ -346,7 +348,7 @@ ClientLib.prototype.sign = function(txp, cb) {
|
||||||
this._doPostRequest(url, args, data, cb);
|
this._doPostRequest(url, args, data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientLib.prototype.reject = function(txp, reason, cb) {
|
API.prototype.rejectTxProposal = function(txp, reason, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
|
||||||
|
@ -357,4 +359,4 @@ ClientLib.prototype.reject = function(txp, reason, cb) {
|
||||||
this._doPostRequest(url, args, data, cb);
|
this._doPostRequest(url, args, data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ClientLib;
|
module.exports = API;
|
|
@ -0,0 +1,8 @@
|
||||||
|
//var client = ;
|
||||||
|
|
||||||
|
module.exports = require('./API');
|
||||||
|
//client.verificator = require('./API');
|
||||||
|
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
//module.exports.storage = require('./storage');
|
Loading…
Reference in New Issue