use of org.aion.rpc.types.RPCTypes.BlockDetails in project aion by aionnetwork.
the class RPCMethods method serializeBlockDetails.
private BlockDetails serializeBlockDetails(Block block) {
if (block == null) {
// occurs if the requested block does not exist in the db
return null;
} else {
final BigInteger blkReward = // get the block reward
chainHolder.calculateReward(block);
final BigInteger totalDiff = chainHolder.getTotalDifficultyByHash(// get the total difficulty
block.getHash());
List<AionTxInfo> txInfoList = new ArrayList<>();
logger.debug("Retrieving transactions for block: {}", "0x" + ByteUtil.toHexString(block.getHash()));
for (AionTransaction transaction : block.getTransactionsList()) {
AionTxInfo txInfo = chainHolder.getTransactionInfo(transaction.getTransactionHash());
txInfoList.add(txInfo);
}
Block previousBlock = // get the parent block
chainHolder.getBlockByHash(block.getParentHash());
final Long previousTimestamp;
if (previousBlock == null) {
previousTimestamp = null;
} else {
previousTimestamp = previousBlock.getTimestamp();
// block time
}
if (block.getHeader().getSealType().equals(// return a block based on the seal type
Seal.PROOF_OF_WORK))
return new BlockDetails(block.getNumber(), ByteArray.wrap(block.getHash()), ByteArray.wrap(block.getParentHash()), ByteArray.wrap(block.getLogBloom()), ByteArray.wrap(block.getTxTrieRoot()), ByteArray.wrap(block.getStateRoot()), ByteArray.wrap(block.getReceiptsRoot()), ByteUtil.bytesToBigInteger(block.getDifficulty()), totalDiff, block.getCoinbase(), block.getTimestamp(), block.getNrgConsumed(), block.getNrgLimit(), block.getNrgConsumed(), block.getNrgLimit(), block.getHeader().getSealType().getSealId(), block.isMainChain(), ByteArray.wrap(block.getHeader().getExtraData()), block.size(), block.getTransactionsList().size(), ByteArray.wrap(block.getTxTrieRoot()), blkReward, serializeTxDetails(txInfoList, block), ByteArray.wrap(((MiningBlock) block).getNonce()), ByteArray.wrap(((MiningBlock) block).getHeader().getSolution()), null, null, null, previousBlock == null ? null : Math.toIntExact((block.getTimestamp() - previousTimestamp)));
else
return new BlockDetails(block.getNumber(), ByteArray.wrap(block.getHash()), ByteArray.wrap(block.getParentHash()), ByteArray.wrap(block.getLogBloom()), ByteArray.wrap(block.getTxTrieRoot()), ByteArray.wrap(block.getStateRoot()), ByteArray.wrap(block.getReceiptsRoot()), ByteUtil.bytesToBigInteger(block.getDifficulty()), totalDiff, block.getCoinbase(), block.getTimestamp(), block.getNrgConsumed(), block.getNrgLimit(), block.getNrgConsumed(), block.getNrgLimit(), block.getHeader().getSealType().getSealId(), block.isMainChain(), ByteArray.wrap(block.getHeader().getExtraData()), block.size(), block.getTransactionsList().size(), ByteArray.wrap(block.getTxTrieRoot()), blkReward, serializeTxDetails(txInfoList, block), null, null, ByteArray.wrap(((StakingBlock) block).getHeader().getSeedOrProof()), ByteArray.wrap(((StakingBlock) block).getHeader().getSignature()), ByteArray.wrap(((StakingBlock) block).getHeader().getSigningPublicKey()), previousBlock == null ? null : Math.toIntExact((block.getTimestamp() - previousTimestamp)));
}
}
Aggregations