Skip to content

Commit

Permalink
Add block size calculation (#41)
Browse files Browse the repository at this point in the history
* 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 <ilnur.a.g@gmail.com>
  • Loading branch information
ramilexe and n0cte authored Jun 23, 2021
1 parent b0cfbe3 commit f23ee86
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ export interface HeaderDetails {
difficulty: string;
td: string;
gasLimit: string;
size: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ query getHeaderByNumber($blockRef: BigInt!) {
stateRoot
ethTransactionCidsByHeaderId {
totalCount
nodes {
blockByMhKey {
data
}
}
}
uncleCidsByHeaderId {
nodes {
blockByMhKey {
data
}
}
}
}
}
Expand Down

0 comments on commit f23ee86

Please sign in to comment.