Make use of the new ots_getBlockDetails API
This commit is contained in:
parent
610be8191e
commit
3cbc0b0d3c
|
@ -83,7 +83,7 @@ const Block: React.FC = () => {
|
||||||
className="bg-link-blue bg-opacity-10 text-link-blue hover:bg-opacity-100 hover:text-white rounded-lg px-2 py-1 text-xs"
|
className="bg-link-blue bg-opacity-10 text-link-blue hover:bg-opacity-100 hover:text-white rounded-lg px-2 py-1 text-xs"
|
||||||
to={blockTxsURL(block.number)}
|
to={blockTxsURL(block.number)}
|
||||||
>
|
>
|
||||||
{block.transactions.length} transactions
|
{block.transactionCount} transactions
|
||||||
</NavLink>{" "}
|
</NavLink>{" "}
|
||||||
in this block
|
in this block
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
|
|
|
@ -22,6 +22,7 @@ export interface ExtendedBlock extends ethers.providers.Block {
|
||||||
sha3Uncles: string;
|
sha3Uncles: string;
|
||||||
stateRoot: string;
|
stateRoot: string;
|
||||||
totalDifficulty: BigNumber;
|
totalDifficulty: BigNumber;
|
||||||
|
transactionCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const readBlock = async (
|
export const readBlock = async (
|
||||||
|
@ -30,38 +31,33 @@ export const readBlock = async (
|
||||||
) => {
|
) => {
|
||||||
let blockPromise: Promise<any>;
|
let blockPromise: Promise<any>;
|
||||||
if (ethers.utils.isHexString(blockNumberOrHash, 32)) {
|
if (ethers.utils.isHexString(blockNumberOrHash, 32)) {
|
||||||
|
// TODO: fix
|
||||||
blockPromise = provider.send("eth_getBlockByHash", [
|
blockPromise = provider.send("eth_getBlockByHash", [
|
||||||
blockNumberOrHash,
|
blockNumberOrHash,
|
||||||
false,
|
false,
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
blockPromise = provider.send("eth_getBlockByNumber", [
|
blockPromise = provider.send("ots_getBlockDetails", [blockNumberOrHash]);
|
||||||
blockNumberOrHash,
|
|
||||||
false,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
const [_rawBlock, _rawIssuance, _rawReceipts] = await Promise.all([
|
|
||||||
blockPromise,
|
|
||||||
provider.send("erigon_issuance", [blockNumberOrHash]),
|
|
||||||
provider.send("eth_getBlockReceipts", [blockNumberOrHash]),
|
|
||||||
]);
|
|
||||||
const receipts = (_rawReceipts as any[]).map((r) =>
|
|
||||||
provider.formatter.receipt(r)
|
|
||||||
);
|
|
||||||
const fees = receipts.reduce(
|
|
||||||
(acc, r) => acc.add(r.effectiveGasPrice.mul(r.gasUsed)),
|
|
||||||
BigNumber.from(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
const _block = provider.formatter.block(_rawBlock);
|
const _rawBlock = await blockPromise;
|
||||||
|
const _block = provider.formatter.block(_rawBlock.block);
|
||||||
|
const _rawIssuance = _rawBlock.issuance;
|
||||||
|
const fees = provider.formatter.bigNumber(_rawBlock.totalFees);
|
||||||
|
|
||||||
const extBlock: ExtendedBlock = {
|
const extBlock: ExtendedBlock = {
|
||||||
blockReward: provider.formatter.bigNumber(_rawIssuance.blockReward ?? 0),
|
blockReward: provider.formatter.bigNumber(_rawIssuance.blockReward ?? 0),
|
||||||
unclesReward: provider.formatter.bigNumber(_rawIssuance.uncleReward ?? 0),
|
unclesReward: provider.formatter.bigNumber(_rawIssuance.uncleReward ?? 0),
|
||||||
feeReward: fees,
|
feeReward: fees,
|
||||||
size: provider.formatter.number(_rawBlock.size),
|
size: provider.formatter.number(_rawBlock.block.size),
|
||||||
sha3Uncles: _rawBlock.sha3Uncles,
|
sha3Uncles: _rawBlock.block.sha3Uncles,
|
||||||
stateRoot: _rawBlock.stateRoot,
|
stateRoot: _rawBlock.block.stateRoot,
|
||||||
totalDifficulty: provider.formatter.bigNumber(_rawBlock.totalDifficulty),
|
totalDifficulty: provider.formatter.bigNumber(
|
||||||
|
_rawBlock.block.totalDifficulty
|
||||||
|
),
|
||||||
|
transactionCount: provider.formatter.number(
|
||||||
|
_rawBlock.block.transactionCount
|
||||||
|
),
|
||||||
..._block,
|
..._block,
|
||||||
};
|
};
|
||||||
return extBlock;
|
return extBlock;
|
||||||
|
|
Loading…
Reference in New Issue