|
|
@ -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; |
|
|
|