Search in sources :

Example 1 with GetBlockHeaderEvent

use of io.nuls.consensus.event.GetBlockHeaderEvent in project nuls by nuls-io.

the class GetBlockHeaderHandler method onEvent.

@Override
public void onEvent(GetBlockHeaderEvent event, String fromId) {
    BlockHeader header;
    if (null == event.getEventBody() || event.getEventBody().getHeight() == 0) {
        header = blockService.getLocalBestBlock().getHeader();
    } else {
        Block block = blockService.getBlock(event.getEventBody().getHeight());
        if (null == block) {
            header = new BlockHeader();
            header.setHeight(event.getEventBody().getHeight());
        } else {
            header = block.getHeader();
        }
    }
    if (header == null) {
        Log.error("header cannot be null");
        return;
    }
    this.eventBroadcaster.sendToNode(new BlockHeaderEvent(header), fromId);
}
Also used : BlockHeaderEvent(io.nuls.consensus.event.BlockHeaderEvent) GetBlockHeaderEvent(io.nuls.consensus.event.GetBlockHeaderEvent) Block(io.nuls.core.chain.entity.Block) BlockHeader(io.nuls.core.chain.entity.BlockHeader)

Aggregations

BlockHeaderEvent (io.nuls.consensus.event.BlockHeaderEvent)1 GetBlockHeaderEvent (io.nuls.consensus.event.GetBlockHeaderEvent)1 Block (io.nuls.core.chain.entity.Block)1 BlockHeader (io.nuls.core.chain.entity.BlockHeader)1