From f23ee866820a85be0a236276adac7b6e2cb3ccf4 Mon Sep 17 00:00:00 2001 From: Ramil Amerzyanov Date: Wed, 23 Jun 2021 17:47:10 +0300 Subject: [PATCH] Add block size calculation (#41) * fix transaction data * show input in textarea * break text for app details row * add extra data decoding * add block size calculation Co-authored-by: n0cte --- .../handlers/BlockDetails/BlockDetails.vue | 19 ++++++++++++++----- .../BlockDetails/apolloTypes/BlockDetails.ts | 1 + .../BlockDetails/blockDetails.graphql | 12 ++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/newclient/src/modules/blocks/handlers/BlockDetails/BlockDetails.vue b/newclient/src/modules/blocks/handlers/BlockDetails/BlockDetails.vue index 6758604..74e7493 100644 --- a/newclient/src/modules/blocks/handlers/BlockDetails/BlockDetails.vue +++ b/newclient/src/modules/blocks/handlers/BlockDetails/BlockDetails.vue @@ -60,15 +60,24 @@ import { decodeHeaderData, decodeExtra, extractMinerFromExtra } from '@vulcanize update: data => data.getBlockByHash || data.getHeaderById, result({ data }) { if (data.ethHeaderCidByBlockNumber && data.ethHeaderCidByBlockNumber.nodes.length) { - const blockRlp = data.ethHeaderCidByBlockNumber.nodes[0].blockByMhKey.data; + const block = data.ethHeaderCidByBlockNumber.nodes[0] + const uncle = block.uncleCidsByHeaderId.nodes || [] + const trans = block.ethTransactionCidsByHeaderId.nodes || [] + + const blockRlp = block.blockByMhKey.data; const _obj = decodeHeaderData(blockRlp); + const headerSize: number = block.blockByMhKey.data.slice(2).length / 2 + const unclesSize: number = uncle.reduce((sz, { blockByMhKey: { data } }) => sz + data.slice(2).length / 2, 0) + const txheadsSize: number = trans.reduce((sz, { blockByMhKey: { data } }) => sz + data.slice(2).length / 2, 0) + const transactionsCount = trans.totalCount + if (configs.IS_POA_NETWORK) { const minerAddress = extractMinerFromExtra(blockRlp); _obj.address = minerAddress; } - const transactionsCount = data.ethHeaderCidByBlockNumber.nodes[0].ethTransactionCidsByHeaderId.totalCount - this.header = {...data.ethHeaderCidByBlockNumber.nodes[0], ..._obj, transactionsCount} - } + this.header = { ...block, ..._obj, transactionsCount, size: headerSize + unclesSize + txheadsSize } + + } if (this.header) { if (this.isHash) { this.emitBlockNumber() @@ -210,7 +219,7 @@ export default class BlockDetails extends Mixins(NumberFormatMixin, NewBlockSubs }, { title: this.$i18n.t('common.size'), - detail: '-', // `${this.formatNumber(this.block.size)} ${this.$i18n.t('block.bytes')}` + detail: `${this.formatNumber(new BN(this.header.size).toNumber())} Byte`, }, { title: this.$i18n.t('common.nonce'), diff --git a/newclient/src/modules/blocks/handlers/BlockDetails/apolloTypes/BlockDetails.ts b/newclient/src/modules/blocks/handlers/BlockDetails/apolloTypes/BlockDetails.ts index 5d8622f..9ba2744 100644 --- a/newclient/src/modules/blocks/handlers/BlockDetails/apolloTypes/BlockDetails.ts +++ b/newclient/src/modules/blocks/handlers/BlockDetails/apolloTypes/BlockDetails.ts @@ -47,4 +47,5 @@ export interface HeaderDetails { difficulty: string; td: string; gasLimit: string; + size: number; } diff --git a/newclient/src/modules/blocks/handlers/BlockDetails/blockDetails.graphql b/newclient/src/modules/blocks/handlers/BlockDetails/blockDetails.graphql index 3111292..f80d4fd 100644 --- a/newclient/src/modules/blocks/handlers/BlockDetails/blockDetails.graphql +++ b/newclient/src/modules/blocks/handlers/BlockDetails/blockDetails.graphql @@ -65,6 +65,18 @@ query getHeaderByNumber($blockRef: BigInt!) { stateRoot ethTransactionCidsByHeaderId { totalCount + nodes { + blockByMhKey { + data + } + } + } + uncleCidsByHeaderId { + nodes { + blockByMhKey { + data + } + } } } }