Skip to content

Commit

Permalink
Merge branch 'v2' of https://github.com/RiseVision/rise-explorer into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
crypt0jan committed Nov 7, 2019
2 parents e1a209e + 1a21160 commit fcd69a0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/api/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ module.exports = function (app) {
function TopAccount() {
const getDelegate = (account, cb) => {
request.get({
url: `${app.get('lisk address')}/api/delegates/get?publicKey=${account.publicKey}`,
url: `${app.get('lisk address')}/api/delegates/get?username=${account.username}`,
json: true,
}, (err, response, body) => {
if (err || response.statusCode !== 200) {
Expand All @@ -285,7 +285,7 @@ module.exports = function (app) {
this.getKnowledge = (account, cb) => {
account.knowledge = knowledge.inAccount(account);

if (!account.knowledge && account.forgingPK) {
if (!account.knowledge && account.username) {
return getDelegate(account, cb);
}
return cb(null, account);
Expand Down
6 changes: 1 addition & 5 deletions lib/api/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ module.exports = function (app) {
const b = body.block;

b.confirmations = (height - b.height) + 1;
<<<<<<< HEAD
b.payloadHash = new Buffer.alloc(b.payloadHash).toString('hex');
=======
b.payloadHash = new Buffer.alloc(b.payloadHash, 'hex');
>>>>>>> eefeb0b82819698034d15b5629e572d69be12e95
b.payloadHash = new Buffer.alloc(parseInt(b.payloadHash, 10)).toString('hex');

return body;
};
Expand Down
10 changes: 9 additions & 1 deletion lib/api/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const {cachedRequest} = require('../cachedRequest');
module.exports = function (app) {
const parseDelegates = (delegates) => {
_.each(delegates, (d) => {
d.productivity = Math.abs(parseFloat(d.productivity)) || 0.0;
d.productivity = Math.abs(parseFloat(d.infos.productivity)) || 0.0;
// TODO rankV2 isnt stable
// d.rate = Math.abs(parseFloat(d.infos.rankV2)) || 0.0;
d.rate = Math.abs(parseFloat(d.infos.rankV1)) || 0.0;
});

return delegates;
Expand Down Expand Up @@ -148,6 +151,8 @@ module.exports = function (app) {
};

this.getDelegate = function (tx, cb) {
// let account = accounts.Account();
// let username = account.getAccountByPublicKey(tx.senderPubData);
cachedRequest({
url: `${app.get('lisk address')}/api/delegates/get?publicKey=${tx.senderPubData}`,
json: true,
Expand All @@ -156,6 +161,9 @@ module.exports = function (app) {
return cb(err || 'Response was unsuccessful');
} else if (body.success === true) {
tx.delegate = body.delegate;
if (body.forgingPKs && body.forgingPKs.length) {
tx.forgingPK = body.forgingPKs[body.forgingPKs.length - 1].forgingPK;
}
return cb();
} else if (body.error && body.error === 'Delegate not found') {
tx.delegate = {};
Expand Down
3 changes: 2 additions & 1 deletion lib/api/forgingChance.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ module.exports = function (app) {
(err, res) => {
if (err) return cb(err);
const toRet = (res[0] || []).concat(res[1] || []).slice(0, M)
// TODO why mapped
.map((d) => {
return {
address : d.address,
username : d.username,
publicKey: d.forgingPK,
forgingPK: d.forgingPK,
vote : d.votesWeight,
rank : d.infos.rankV2,
};
Expand Down
20 changes: 14 additions & 6 deletions sockets/delegateMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ module.exports = function (app, connectionHandler, socket) {
};

const findActive = delegate =>
data.active.delegates.find(d => d.publicKey === delegate.publicKey);
data.active.delegates.find(d => d.forgingPK === delegate.forgingPK);

const findActiveByBlock = block =>
data.active.delegates.find(d => d.publicKey === block.generatorPublicKey);
data.active.delegates.find(d => d.forgingPK === block.generatorPublicKey);

const updateDelegate = (delegate, updateForgingTime) => {
// Update delegate with forging time
if (updateForgingTime) {
// eslint-disable-next-line prefer-const
let index = tmpData.nextForgers.delegates.indexOf(delegate.publicKey);
let index = tmpData.nextForgers.delegates.indexOf(delegate.forgingPK);
delegate.forgingTime = index * app.get('blockTime');
if (index === -1) {
delegate.forgingTime = 200 * app.get('blockTime'); // Workaround for tables sorting;
}
}

delegate.isInRound = tmpData.nextForgers.delegates.indexOf(delegate.publicKey) > -1;
delegate.isInRound = tmpData.nextForgers.delegates.indexOf(delegate.forgingPK) > -1;
return delegate;
};

Expand Down Expand Up @@ -197,7 +197,7 @@ module.exports = function (app, connectionHandler, socket) {
});
};

const delegateName = delegate => `${delegate.username}[${delegate.rate}]`;
const delegateName = delegate => `${delegate.username}[${delegate.infos && delegate.infos.productivity || '??'}]`;

const emitDelegate = (delegate) => {
log('info', `Emitting last blocks for: ${delegateName(delegate)}`);
Expand Down Expand Up @@ -229,7 +229,15 @@ module.exports = function (app, connectionHandler, socket) {
(result, callback) => {
// Set last block and his delegate (we will emit it later in emitData)
data.lastBlock.block = result.blocks[0];

const lastBlockDelegate = findActiveByBlock(data.lastBlock.block);

if (!lastBlockDelegate) {
// couldnt find the delegate who minded the last block
callback('couldnt find the delegate who minded the last block ID ' + result.blocks[0].id);
return;
}

data.lastBlock.block.delegate = {
username: lastBlockDelegate.username,
address: lastBlockDelegate.address,
Expand Down Expand Up @@ -267,7 +275,7 @@ module.exports = function (app, connectionHandler, socket) {
return cb(null);
}
return delegates.getLastBlocks(
{ publicKey: delegate.publicKey,
{ publicKey: delegate.forgingPK,
limit: 1 },
(res) => {
log('error', `Error retrieving last blocks for: ${delegateName(delegate)}`);
Expand Down
4 changes: 2 additions & 2 deletions src/components/delegate-monitor/delegate-monitor.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const DelegateMonitor = function ($scope, $rootScope, forgingMonitor) {

let found = false;
const existing = $scope.activeDelegates.filter((d) => {
if (!found && (d.publicKey === delegate.publicKey)) {
if (!found && (d.forgingPK === delegate.forgingPK)) {
found = true;
return true;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ AppDelegateMonitor.factory('delegateMonitor',
});

ns.on('delegate', (res) => {
if (res.publicKey) {
if (res.forgingPK) {
delegateMonitor.updateLastBlocks(res);
}
});
Expand Down
5 changes: 4 additions & 1 deletion src/directives/account-href.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ const accountHref = AppTools.directive('accountHref', () => {
if ($attrs.type === 'sender' || $attrs.type === 'recipient') {
username = getUserName($scope, $attrs);
id = $scope.accountHref[joinCameCased($attrs.type, 'id')];
} else {
} else if ($scope.accountHref) {
username = $attrs.type === 'delegate' && $scope.accountHref.username;
id = $scope.id ? $scope.id : $scope.accountHref.address;
} else {
username = 'unknown';
id = 'unknown';
}

$attrs.$set('href', username ? `/delegate/${id}` : `/address/${id}`);
Expand Down

0 comments on commit fcd69a0

Please sign in to comment.