Skip to content

Commit

Permalink
Merge pull request #364 from input-output-hk/feature/stake-pool-hash-…
Browse files Browse the repository at this point in the history
…over-slot-leader

feat: use stake pool hash over slot leader reference
  • Loading branch information
rhyslbw authored Sep 23, 2020
2 parents 3f419d1 + 0f345dd commit 73bf657
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions source/features/blocks/api/BlockOverview.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ fragment BlockOverview on Block {
forgedAt
slotLeader {
description
stakePool {
hash
}
}
epochNo,
hash
Expand Down
13 changes: 10 additions & 3 deletions source/features/blocks/api/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ export const blockOverviewTransformer = (
} else {
epoch = b.epochNo;
}
const createdBy = b.slotLeader.stakePool?.hash !== undefined ?
shortenCreatedBy(b.slotLeader.stakePool.hash) :
formatSlotLeaderDescription(b.slotLeader.description)
return {
...b,
createdAt: b.forgedAt,
createdBy: formatCreatedBy(b.slotLeader.description),
createdBy,
epoch,
id: b.hash,
number: b.number || '-',
Expand Down Expand Up @@ -50,7 +53,11 @@ export const blockDetailsTransformer = (
.map(transactionDetailsTransformer),
});

function formatCreatedBy(value: IBlockOverview['createdBy']): string {
function shortenCreatedBy (createdBy: string) {
return createdBy.substring(0, 7)
}

function formatSlotLeaderDescription (value: IBlockOverview['createdBy']): string {
switch (value) {
case 'Genesis slot leader':
return 'Genesis';
Expand All @@ -61,7 +68,7 @@ function formatCreatedBy(value: IBlockOverview['createdBy']): string {
if (!Array.isArray(selection)) {
return '';
}
return selection[1].substring(0, 7);
return shortenCreatedBy(selection[1]);
}
}

Expand Down

0 comments on commit 73bf657

Please sign in to comment.