Search in sources :

Example 26 with Block

use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.

the class BlockResource method getBlock.

@GET
@Path("/height/{height}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBlock(@PathParam("height") Long height) {
    RpcResult result;
    if (height < 0) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    Block block = blockService.getBlock(height);
    if (block == null) {
        result = RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
    } else {
        result = RpcResult.getSuccess();
        long reward = ledgerService.getBlockReward(block.getHeader().getHeight());
        long fee = ledgerService.getBlockFee(block.getHeader().getHeight());
        try {
            result.setData(new BlockDto(block, reward, fee));
        } catch (IOException e) {
            // todo
            e.printStackTrace();
        }
    }
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) Block(io.nuls.core.chain.entity.Block) IOException(java.io.IOException) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 27 with Block

use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.

the class BlockManager method checkNextblock.

private void checkNextblock(String hash) {
    String nextHash = blockCacheBuffer.getNextHash(hash);
    if (null == nextHash) {
        return;
    }
    Block block = blockCacheBuffer.getBlock(nextHash);
    if (null == block) {
        return;
    }
    blockCacheBuffer.removeBlock(nextHash);
    this.addBlock(block, true, null);
}
Also used : Block(io.nuls.core.chain.entity.Block)

Example 28 with Block

use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.

the class BlockEventHandler method onEvent.

@Override
public void onEvent(BlockEvent event, String fromId) {
    Block block = event.getEventBody();
    if (null == block) {
        Log.warn("recieved a null blockEvent form " + fromId);
        return;
    }
    ValidateResult result = block.verify();
    if (result.isFailed() && result.getErrorCode() != ErrorCode.ORPHAN_TX) {
        if (result.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
            networkService.blackNode(fromId, NodePo.YELLOW);
        }
        Log.warn("recieved a wrong blockEvent:{},form:{}", result.getMessage(), fromId);
        return;
    }
    if (BlockBatchDownloadUtils.getInstance().downloadedBlock(fromId, block)) {
        return;
    }
    blockCacheManager.addBlock(block, false, fromId);
}
Also used : ValidateResult(io.nuls.core.validate.ValidateResult) Block(io.nuls.core.chain.entity.Block)

Example 29 with Block

use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.

the class GetTxGroupHandler method onEvent.

@Override
public void onEvent(GetTxGroupRequest event, String fromId) {
    GetTxGroupParam eventBody = event.getEventBody();
    Block block = blockService.getBlock(eventBody.getBlockHash().getDigestHex());
    if (null == block) {
        return;
    }
    TxGroupEvent txGroupEvent = new TxGroupEvent();
    TxGroup txGroup = new TxGroup();
    txGroup.setBlockHash(block.getHeader().getHash());
    List<Transaction> txList = getTxList(block, eventBody.getTxHashList());
    txGroup.setTxList(txList);
    txGroupEvent.setEventBody(txGroup);
    eventBroadcaster.sendToNode(txGroupEvent, fromId);
}
Also used : TxGroup(io.nuls.consensus.entity.TxGroup) Transaction(io.nuls.core.chain.entity.Transaction) GetTxGroupParam(io.nuls.consensus.entity.GetTxGroupParam) Block(io.nuls.core.chain.entity.Block) TxGroupEvent(io.nuls.consensus.event.TxGroupEvent)

Example 30 with Block

use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.

the class ConfrimingBlockCacheManager method getBlock.

public Block getBlock(String hash) {
    if (null == txsCacheMap || headerCacheMap == null) {
        return null;
    }
    BlockHeader header = headerCacheMap.get(hash);
    List<Transaction> txs = txsCacheMap.get(hash);
    if (null == header || null == txs || txs.isEmpty()) {
        return null;
    }
    Block block = new Block();
    block.setHeader(header);
    block.setTxs(txs);
    return block;
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) Block(io.nuls.core.chain.entity.Block) BlockHeader(io.nuls.core.chain.entity.BlockHeader)

Aggregations

Block (io.nuls.core.chain.entity.Block)31 BlockHeader (io.nuls.core.chain.entity.BlockHeader)11 NulsException (io.nuls.core.exception.NulsException)9 Transaction (io.nuls.core.chain.entity.Transaction)8 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)6 IOException (java.io.IOException)5 ValidateResult (io.nuls.core.validate.ValidateResult)4 ArrayList (java.util.ArrayList)4 BestCorrectBlock (io.nuls.consensus.entity.block.BestCorrectBlock)3 BlockInfo (io.nuls.consensus.utils.BlockInfo)3 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)3 BlockHeaderPo (io.nuls.db.entity.BlockHeaderPo)3 BlockRoundData (io.nuls.consensus.entity.block.BlockRoundData)2 BlockHeaderEvent (io.nuls.consensus.event.BlockHeaderEvent)2 BlockDto (io.nuls.rpc.entity.BlockDto)2 RpcResult (io.nuls.rpc.entity.RpcResult)2 BlockHashResponse (io.nuls.consensus.entity.BlockHashResponse)1 GetSmallBlockParam (io.nuls.consensus.entity.GetSmallBlockParam)1 GetTxGroupParam (io.nuls.consensus.entity.GetTxGroupParam)1 NodeDownloadingStatus (io.nuls.consensus.entity.NodeDownloadingStatus)1