diff --git a/bit-wallet/bit b/bit-wallet/bit
index 6316611..297adf8 100755
--- a/bit-wallet/bit
+++ b/bit-wallet/bit
@@ -10,6 +10,7 @@ program
.command('status', 'get wallet status')
.command('address', 'create a new address from server')
.command('addresses', 'list addresses')
+ .command('balance', 'wallet balance')
.command('send
', 'send bitcoins')
.parse(process.argv);
diff --git a/bit-wallet/bit-balance b/bit-wallet/bit-balance
new file mode 100644
index 0000000..3a9763c
--- /dev/null
+++ b/bit-wallet/bit-balance
@@ -0,0 +1,24 @@
+#!/usr/bin/env node
+
+var program = require('commander');
+var CliLib = require('../lib/clilib.js');
+var common = require('./common');
+
+program
+ .version('0.0.1')
+ .option('-c,--config [file]', 'Wallet config filename')
+ .option('-v,--verbose', 'be verbose')
+ .parse(process.argv);
+
+var args = program.args;
+var cli = new CliLib({
+ filename: program.config
+});
+
+cli.balance(function(err, x) {
+ common.die(err);
+ console.log('* Wallet balance', x);
+
+ if (program.verbose)
+ console.log('* Raw Server Response:\n', x); //TODO
+});
diff --git a/bit-wallet/bit-send b/bit-wallet/bit-send
index 61dda10..e0db849 100644
--- a/bit-wallet/bit-send
+++ b/bit-wallet/bit-send
@@ -7,6 +7,7 @@ var common = require('./common');
program
.version('0.0.1')
.option('-c,--config [file]', 'Wallet config filename')
+.option('-v,--verbose', 'be verbose')
.usage('[options] ')
.parse(process.argv);
@@ -22,7 +23,11 @@ if (!args[0] || !args[1] || !args[2])
filename: program.config
});
-cli.send({toAddress: address, amount: amount, message:message}, function(err, xx) {
+cli.send({toAddress: address, amount: amount, message:message}, function(err, x) {
common.die(err);
- console.log(' * Wallet Joined.', xx || '');
- });
+ console.log(' * Tx created: ID %s [%s] RequiredSignatures:',
+ x.id, x.status, x.requiredSignatures);
+
+ if (program.verbose)
+ console.log('* Raw Server Response:\n', x); //TODO
+});
diff --git a/lib/clilib.js b/lib/clilib.js
index 14a4ab5..463672f 100644
--- a/lib/clilib.js
+++ b/lib/clilib.js
@@ -26,9 +26,11 @@ function _getUrl(path) {
function _parseError(body) {
if (_.isString(body)) {
try {
- body = JSON.parse(body);
+ body = JSON.parse(body);
} catch (e) {
- body = {error: body};
+ body = {
+ error: body
+ };
}
}
var code = body.code || 'ERROR';
@@ -69,6 +71,9 @@ CliLib.prototype._loadAndCheck = function() {
log.error('Wallet file not found.');
process.exit(1);
}
+
+ // TODO
+ delete data['verified'];
if (data.verified == 'corrupt') {
log.error('The wallet is tagged as corrupt. Some of the copayers cannot be verified to have known the wallet secret.');
process.exit(1);
@@ -212,12 +217,19 @@ CliLib.prototype.status = function(cb) {
return cb('Request error');
}
var wallet = body;
+ // TODO
+ //console.log('[clilib.js.214:wallet:]',wallet); //TODO
if (wallet.n > 0 && wallet.status === 'complete' && !data.verified) {
var pubKey = Bitcore.PrivateKey.fromString(data.walletPrivKey).toPublicKey().toString();
var fake = [];
_.each(wallet.copayers, function(copayer) {
+
+
+ console.log('[clilib.js.224]', copayer.xPubKey, copayer.xPubKeySignature, pubKey); //TODO
if (!SignUtils.verify(copayer.xPubKey, copayer.xPubKeySignature, pubKey)) {
+
+ console.log('[clilib.js.227] FAKE'); //TODO
fake.push(copayer);
}
});
@@ -265,12 +277,12 @@ CliLib.prototype.send = function(inArgs, cb) {
_parseError(body);
return cb('Request error');
}
-console.log('[clilib.js.251:body:]',body); //TODO
return cb(null, body);
});
};
+// TODO check change address
CliLib.prototype.sign = function(proposalId, cb) {
};
@@ -339,4 +351,58 @@ CliLib.prototype.history = function(limit, cb) {
};
+CliLib.prototype.balance = function(cb) {
+ var self = this;
+
+ var data = this._loadAndCheck();
+
+ var url = '/v1/balance/';
+ var signature = _signRequest(url, {}, data.signingPrivKey);
+
+ request({
+ headers: {
+ 'x-identity': data.copayerId,
+ 'x-signature': signature,
+ },
+ method: 'get',
+ url: _getUrl(url),
+ json: true,
+ }, function(err, res, body) {
+ if (err) return cb(err);
+ if (res.statusCode != 200) {
+ _parseError(body);
+ return cb('Request error');
+ }
+ return cb(null, body);
+ });
+};
+
+
+CliLib.prototype.txProposals = function(cb) {
+ var self = this;
+
+ var data = this._loadAndCheck();
+
+ var url = '/v1/txproposals/';
+ var signature = _signRequest(url, {}, data.signingPrivKey);
+
+ request({
+ headers: {
+ 'x-identity': data.copayerId,
+ 'x-signature': signature,
+ },
+ method: 'get',
+ url: _getUrl(url),
+ json: true,
+ }, function(err, res, body) {
+ if (err) return cb(err);
+ if (res.statusCode != 200) {
+ _parseError(body);
+ return cb('Request error');
+ }
+ return cb(null, body);
+ });
+};
+
+
module.exports = CliLib;
diff --git a/lib/model/wallet.js b/lib/model/wallet.js
index 7d49fc8..80b4ed4 100644
--- a/lib/model/wallet.js
+++ b/lib/model/wallet.js
@@ -28,7 +28,7 @@ function Wallet(opts) {
this.addressIndex = 0;
this.copayers = [];
this.pubKey = opts.pubKey;
- this.isTestnet = false;
+ this.isTestnet = opts.isTestnet;
this.addressManager = new AddressManager();
};
diff --git a/lib/server.js b/lib/server.js
index 5d8cdf6..c6a727e 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -119,12 +119,12 @@ CopayServer.prototype.createWallet = function(opts, cb) {
name: opts.name,
m: opts.m,
n: opts.n,
- network: opts.network || 'livenet',
+ isTestnet: network === 'testnet',
pubKey: pubKey,
});
self.storage.storeWallet(wallet, function(err) {
- log.debug('Wallet created', wallet.id);
+ log.debug('Wallet created', wallet.id, network);
return cb(err, wallet.id);
});
};
@@ -332,13 +332,14 @@ CopayServer.prototype._getUtxos = function(cb) {
// Get addresses for this wallet
self.storage.fetchAddresses(self.walletId, function(err, addresses) {
+console.log('[server.js.334:addresses:]',addresses); //TODO
if (err) return cb(err);
if (addresses.length == 0)
return cb(null, []);
var addressStrs = _.pluck(addresses, 'address');
var addressToPath = _.indexBy(addresses, 'address'); // TODO : check performance
- var networkName = Bitcore.Address(addressStrs[0]).toObject().networkName;
+ var networkName = Bitcore.Address(addressStrs[0]).toObject().network;
var bc = self._getBlockExplorer('insight', networkName);
bc.getUnspentUtxos(addressStrs, function(err, utxos) {
@@ -388,6 +389,7 @@ CopayServer.prototype.getBalance = function(opts, cb) {
var self = this;
self._getUtxos(function(err, utxos) {
+console.log('[server.js.390:utxos:]',utxos); //TODO
if (err) return cb(err);
var balance = {};