use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult in project besu by hyperledger.
the class EthGetMinerDataByBlockHash method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Hash hash = requestContext.getRequest().getRequiredParameter(0, Hash.class);
BlockWithMetadata<TransactionWithMetadata, Hash> block = blockchain.get().blockByHash(hash).orElse(null);
MinerDataResult minerDataResult = null;
if (block != null) {
minerDataResult = createMinerDataResult(block, protocolSchedule, blockchain.get());
}
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), minerDataResult);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult in project besu by hyperledger.
the class EthGetMinerDataByBlockHash method createMinerDataResult.
public static MinerDataResult createMinerDataResult(final BlockWithMetadata<TransactionWithMetadata, Hash> block, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries) {
final BlockHeader blockHeader = block.getHeader();
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final Wei staticBlockReward = protocolSpec.getBlockReward();
final Wei transactionFee = block.getTransactions().stream().map(t -> blockchainQueries.transactionReceiptByTransactionHash(t.getTransaction().getHash()).map(receipt -> receipt.getTransaction().getEffectiveGasPrice(receipt.getBaseFee()).multiply(receipt.getGasUsed())).orElse(Wei.ZERO)).reduce(Wei.ZERO, BaseUInt256Value::add);
final Wei uncleInclusionReward = staticBlockReward.multiply(block.getOmmers().size()).divide(32);
final Wei netBlockReward = staticBlockReward.add(transactionFee).add(uncleInclusionReward);
final List<UncleRewardResult> uncleRewards = new ArrayList<>();
blockchainQueries.getBlockchain().getBlockByNumber(block.getHeader().getNumber()).ifPresent(blockBody -> blockBody.getBody().getOmmers().forEach(header -> uncleRewards.add(ImmutableUncleRewardResult.builder().hash(header.getHash().toHexString()).coinbase(header.getCoinbase().toHexString()).build())));
return ImmutableMinerDataResult.builder().netBlockReward(netBlockReward.toHexString()).staticBlockReward(staticBlockReward.toHexString()).transactionFee(transactionFee.toHexString()).uncleInclusionReward(uncleInclusionReward.toHexString()).uncleRewards(uncleRewards).coinbase(blockHeader.getCoinbase().toHexString()).extraData(blockHeader.getExtraData().toHexString()).difficulty(blockHeader.getDifficulty().toHexString()).totalDifficulty(block.getTotalDifficulty().toHexString()).build();
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult in project besu by hyperledger.
the class EthGetMinerDataByBlockNumber method resultByBlockNumber.
@Override
protected Object resultByBlockNumber(final JsonRpcRequestContext request, final long blockNumber) {
BlockWithMetadata<TransactionWithMetadata, Hash> block = getBlockchainQueries().blockByNumber(blockNumber).orElse(null);
MinerDataResult minerDataResult = null;
if (block != null) {
minerDataResult = EthGetMinerDataByBlockHash.createMinerDataResult(block, protocolSchedule, getBlockchainQueries());
}
return minerDataResult;
}
Aggregations