use of org.apache.tuweni.units.bigints.BaseUInt256Value 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();
}
Aggregations