Search in sources :

Example 1 with BlockDetails

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)));
    }
}
Also used : BlockDetails(org.aion.rpc.types.RPCTypes.BlockDetails) AionTxInfo(org.aion.zero.impl.types.AionTxInfo) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) StakingBlock(org.aion.zero.impl.types.StakingBlock) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) StakingBlock(org.aion.zero.impl.types.StakingBlock)

Aggregations

BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 AionTransaction (org.aion.base.AionTransaction)1 BlockDetails (org.aion.rpc.types.RPCTypes.BlockDetails)1 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)1 Block (org.aion.zero.impl.types.Block)1 MiningBlock (org.aion.zero.impl.types.MiningBlock)1 StakingBlock (org.aion.zero.impl.types.StakingBlock)1