balance send working
This commit is contained in:
parent
20272d895a
commit
238aeca3b2
|
@ -10,6 +10,7 @@ program
|
||||||
.command('status', 'get wallet status')
|
.command('status', 'get wallet status')
|
||||||
.command('address', 'create a new address from server')
|
.command('address', 'create a new address from server')
|
||||||
.command('addresses', 'list addresses')
|
.command('addresses', 'list addresses')
|
||||||
|
.command('balance', 'wallet balance')
|
||||||
.command('send <address> <amount> <note>', 'send bitcoins')
|
.command('send <address> <amount> <note>', 'send bitcoins')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
});
|
|
@ -7,6 +7,7 @@ var common = require('./common');
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
.version('0.0.1')
|
||||||
.option('-c,--config [file]', 'Wallet config filename')
|
.option('-c,--config [file]', 'Wallet config filename')
|
||||||
|
.option('-v,--verbose', 'be verbose')
|
||||||
.usage('[options] <address> <amount> <message>')
|
.usage('[options] <address> <amount> <message>')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
@ -22,7 +23,11 @@ if (!args[0] || !args[1] || !args[2])
|
||||||
filename: program.config
|
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);
|
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
|
||||||
|
});
|
||||||
|
|
|
@ -28,7 +28,9 @@ function _parseError(body) {
|
||||||
try {
|
try {
|
||||||
body = JSON.parse(body);
|
body = JSON.parse(body);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
body = {error: body};
|
body = {
|
||||||
|
error: body
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var code = body.code || 'ERROR';
|
var code = body.code || 'ERROR';
|
||||||
|
@ -69,6 +71,9 @@ CliLib.prototype._loadAndCheck = function() {
|
||||||
log.error('Wallet file not found.');
|
log.error('Wallet file not found.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
delete data['verified'];
|
||||||
if (data.verified == 'corrupt') {
|
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.');
|
log.error('The wallet is tagged as corrupt. Some of the copayers cannot be verified to have known the wallet secret.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -212,12 +217,19 @@ CliLib.prototype.status = function(cb) {
|
||||||
return cb('Request error');
|
return cb('Request error');
|
||||||
}
|
}
|
||||||
var wallet = body;
|
var wallet = body;
|
||||||
|
// TODO
|
||||||
|
//console.log('[clilib.js.214:wallet:]',wallet); //TODO
|
||||||
|
|
||||||
if (wallet.n > 0 && wallet.status === 'complete' && !data.verified) {
|
if (wallet.n > 0 && wallet.status === 'complete' && !data.verified) {
|
||||||
var pubKey = Bitcore.PrivateKey.fromString(data.walletPrivKey).toPublicKey().toString();
|
var pubKey = Bitcore.PrivateKey.fromString(data.walletPrivKey).toPublicKey().toString();
|
||||||
var fake = [];
|
var fake = [];
|
||||||
_.each(wallet.copayers, function(copayer) {
|
_.each(wallet.copayers, function(copayer) {
|
||||||
|
|
||||||
|
|
||||||
|
console.log('[clilib.js.224]', copayer.xPubKey, copayer.xPubKeySignature, pubKey); //TODO
|
||||||
if (!SignUtils.verify(copayer.xPubKey, copayer.xPubKeySignature, pubKey)) {
|
if (!SignUtils.verify(copayer.xPubKey, copayer.xPubKeySignature, pubKey)) {
|
||||||
|
|
||||||
|
console.log('[clilib.js.227] FAKE'); //TODO
|
||||||
fake.push(copayer);
|
fake.push(copayer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -265,12 +277,12 @@ CliLib.prototype.send = function(inArgs, cb) {
|
||||||
_parseError(body);
|
_parseError(body);
|
||||||
return cb('Request error');
|
return cb('Request error');
|
||||||
}
|
}
|
||||||
console.log('[clilib.js.251:body:]',body); //TODO
|
|
||||||
return cb(null, body);
|
return cb(null, body);
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO check change address
|
||||||
CliLib.prototype.sign = function(proposalId, cb) {
|
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;
|
module.exports = CliLib;
|
||||||
|
|
|
@ -28,7 +28,7 @@ function Wallet(opts) {
|
||||||
this.addressIndex = 0;
|
this.addressIndex = 0;
|
||||||
this.copayers = [];
|
this.copayers = [];
|
||||||
this.pubKey = opts.pubKey;
|
this.pubKey = opts.pubKey;
|
||||||
this.isTestnet = false;
|
this.isTestnet = opts.isTestnet;
|
||||||
this.addressManager = new AddressManager();
|
this.addressManager = new AddressManager();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -119,12 +119,12 @@ CopayServer.prototype.createWallet = function(opts, cb) {
|
||||||
name: opts.name,
|
name: opts.name,
|
||||||
m: opts.m,
|
m: opts.m,
|
||||||
n: opts.n,
|
n: opts.n,
|
||||||
network: opts.network || 'livenet',
|
isTestnet: network === 'testnet',
|
||||||
pubKey: pubKey,
|
pubKey: pubKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
self.storage.storeWallet(wallet, function(err) {
|
self.storage.storeWallet(wallet, function(err) {
|
||||||
log.debug('Wallet created', wallet.id);
|
log.debug('Wallet created', wallet.id, network);
|
||||||
return cb(err, wallet.id);
|
return cb(err, wallet.id);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -332,13 +332,14 @@ CopayServer.prototype._getUtxos = function(cb) {
|
||||||
|
|
||||||
// Get addresses for this wallet
|
// Get addresses for this wallet
|
||||||
self.storage.fetchAddresses(self.walletId, function(err, addresses) {
|
self.storage.fetchAddresses(self.walletId, function(err, addresses) {
|
||||||
|
console.log('[server.js.334:addresses:]',addresses); //TODO
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (addresses.length == 0)
|
if (addresses.length == 0)
|
||||||
return cb(null, []);
|
return cb(null, []);
|
||||||
|
|
||||||
var addressStrs = _.pluck(addresses, 'address');
|
var addressStrs = _.pluck(addresses, 'address');
|
||||||
var addressToPath = _.indexBy(addresses, 'address'); // TODO : check performance
|
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);
|
var bc = self._getBlockExplorer('insight', networkName);
|
||||||
bc.getUnspentUtxos(addressStrs, function(err, utxos) {
|
bc.getUnspentUtxos(addressStrs, function(err, utxos) {
|
||||||
|
@ -388,6 +389,7 @@ CopayServer.prototype.getBalance = function(opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self._getUtxos(function(err, utxos) {
|
self._getUtxos(function(err, utxos) {
|
||||||
|
console.log('[server.js.390:utxos:]',utxos); //TODO
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
var balance = {};
|
var balance = {};
|
||||||
|
|
Loading…
Reference in New Issue