Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

outputBlockFormatter updated #2791

Merged
merged 5 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ Returns
- ``size`` - ``Number``: Integer the size of this block in bytes.
- ``gasLimit`` - ``Number``: The maximum gas allowed in this block.
- ``gasUsed`` - ``Number``: The total used gas by all transactions in this block.
- ``timestamp`` - ``Number``: The unix timestamp for when the block was collated.
- ``timestamp`` - ``Number | String`: The unix timestamp for when the block was collated (returns a string if a overflow got detected).
- ``transactions`` - ``Array``: Array of transaction objects, or 32 Bytes transaction hashes depending on the ``returnTransactionObjects`` parameter.
- ``uncles`` - ``Array``: Array of uncle hashes.

Expand Down
9 changes: 6 additions & 3 deletions packages/web3-core-helpers/src/Formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,12 @@ export const outputBlockFormatter = (block) => {
block.gasUsed = Utils.hexToNumber(block.gasUsed);
block.size = Utils.hexToNumber(block.size);

// Support Quorum 2.2.0 - timestamp is not present in the Quorum getBlock response
if (block.timestamp !== null) {
block.timestamp = Utils.hexToNumber(block.timestamp);
const timestamp = Utils.toBN(block.timestamp);

if (timestamp.bitLength() <= 53) {
block.timestamp = timestamp.toNumber();
} else {
block.timestamp = timestamp.toString(10);
}

if (block.number !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('OutputBlockFormatterTest', () => {
gasLimit: 0x0,
gasUsed: 0x0,
size: 0x0,
timestamp: 0x0,
timestamp: 0,
number: 0x0,
difficulty: '100', // Strange some numbers will be handled as string and some as number (gas & nonce)
totalDifficulty: '100',
Expand All @@ -51,8 +51,10 @@ describe('OutputBlockFormatterTest', () => {
miner: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
});
});
it('[Quorum] call outputBlockFormatter with a valid block without a timestamp', () => {

it('[Quorum] call outputBlockFormatter with a valid block without a timestamp who has nano seconds', () => {
const block = {
timestamp: '0x20000000000000',
gasLimit: 0x0,
gasUsed: 0x0,
size: 0x0,
Expand Down Expand Up @@ -93,7 +95,8 @@ describe('OutputBlockFormatterTest', () => {
from: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
}
],
miner: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
miner: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078',
timestamp: '9007199254740992'
});
});
});
2 changes: 1 addition & 1 deletion packages/web3-eth/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export interface BlockHeader {
extraData: string
gasLimit: number
gasUsed: number
timestamp: number
timestamp: number | string
}

export interface Block extends BlockHeader {
Expand Down