Search in sources :

Example 31 with Block

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

the class GetVersionEventHandler method process.

@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
    GetVersionEvent event = (GetVersionEvent) networkEvent;
    // String key = event.getHeader().getEventType() + "-" + node.getId();
    // if (cacheService.existEvent(key)) {
    // Log.info("----------GetVersionEventHandler  cacheService  existEvent--------");
    // getNetworkService().removeNode(node.getId());
    // return null;
    // }
    // cacheService.putEvent(key, event, true);
    Block block = NulsContext.getInstance().getBestBlock();
    while (block == null) {
        try {
            Thread.sleep(1000);
            block = NulsContext.getInstance().getBestBlock();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    VersionEvent replyMessage = new VersionEvent(getNetworkService().getNetworkParam().getExternalPort(), block.getHeader().getHeight(), block.getHeader().getHash().getDigestHex());
    node.setPort(event.getExternalPort());
    return new NetworkEventResult(true, replyMessage);
}
Also used : GetVersionEvent(io.nuls.network.message.entity.GetVersionEvent) VersionEvent(io.nuls.network.message.entity.VersionEvent) GetVersionEvent(io.nuls.network.message.entity.GetVersionEvent) Block(io.nuls.core.chain.entity.Block) NetworkEventResult(io.nuls.network.message.NetworkEventResult)

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