Skip to content
Snippets Groups Projects
Commit 4090eda0 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

URI /blockchain/hardship now accepts UIDs

parent 2729dbaf
No related branches found
No related tags found
No related merge requests found
...@@ -154,37 +154,29 @@ function BlockchainBinding (server) { ...@@ -154,37 +154,29 @@ function BlockchainBinding (server) {
this.hardship = function (req, res) { this.hardship = function (req, res) {
res.type('application/json'); res.type('application/json');
var member = ""; return co(function *() {
var nextBlockNumber = 0; let nextBlockNumber = 0;
async.waterfall([ try {
function (next){ let search = yield ParametersService.getSearchP(req);
ParametersService.getPubkey(req, next); let idty = yield IdentityService.findMemberWithoutMemberships(search);
}, if (!idty) {
function (pubkey, next){ throw 'Identity not found';
member = pubkey;
server.dal.isMember(pubkey, next);
},
function (isMember, next){
if (!isMember)
next('Not a member');
else
BlockchainService.current(next);
},
function (current, next){
if (current) {
nextBlockNumber = current ? current.number + 1 : 0;
} }
globalValidator(conf, blockchainDao(null, server.dal)).getTrialLevel(member, next); if (!idty.member) {
throw 'Not a member';
} }
], function (err, nbZeros) { let current = yield BlockchainService.current();
if(err){ if (current) {
res.send(404, err); nextBlockNumber = current ? current.number + 1 : 0;
return;
} }
let nbZeros = yield globalValidator(conf, blockchainDao(null, server.dal)).getTrialLevel(idty.pubkey);
res.send(200, JSON.stringify({ res.send(200, JSON.stringify({
"block": nextBlockNumber, "block": nextBlockNumber,
"level": nbZeros "level": nbZeros
}, null, " ")); }, null, " "));
} catch(e) {
res.send(400, e);
}
}); });
}; };
......
...@@ -69,7 +69,7 @@ module.exports = function(server, interfaces, httpLogs) { ...@@ -69,7 +69,7 @@ module.exports = function(server, interfaces, httpLogs) {
answerForGet( '/blockchain/block/:number', blockchain.promoted); answerForGet( '/blockchain/block/:number', blockchain.promoted);
answerForGet( '/blockchain/blocks/:count/:from', blockchain.blocks); answerForGet( '/blockchain/blocks/:count/:from', blockchain.blocks);
answerForGet( '/blockchain/current', blockchain.current); answerForGet( '/blockchain/current', blockchain.current);
answerForGet( '/blockchain/hardship/:pubkey', blockchain.hardship); answerForGet( '/blockchain/hardship/:search', blockchain.hardship);
answerForGet( '/blockchain/with/newcomers', blockchain.with.newcomers); answerForGet( '/blockchain/with/newcomers', blockchain.with.newcomers);
answerForGet( '/blockchain/with/certs', blockchain.with.certs); answerForGet( '/blockchain/with/certs', blockchain.with.certs);
answerForGet( '/blockchain/with/joiners', blockchain.with.joiners); answerForGet( '/blockchain/with/joiners', blockchain.with.joiners);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment