Search in sources :

Example 6 with Block

use of bisq.core.dao.state.blockchain.Block in project bisq-core by bisq-network.

the class FullNode method parseBlock.

// Recursively request and parse all blocks
private void parseBlock(int blockHeight, int chainHeadHeight, Consumer<Block> newBlockHandler, ResultHandler resultHandler, Consumer<Throwable> errorHandler) {
    rpcService.requestBtcBlock(blockHeight, rawBlock -> {
        if (!isBlockAlreadyAdded(rawBlock)) {
            try {
                Block block = blockParser.parseBlock(rawBlock);
                newBlockHandler.accept(block);
                // Increment blockHeight and recursively call parseBlockAsync until we reach chainHeadHeight
                if (blockHeight < chainHeadHeight) {
                    final int newBlockHeight = blockHeight + 1;
                    parseBlock(newBlockHeight, chainHeadHeight, newBlockHandler, resultHandler, errorHandler);
                } else {
                    // We are done
                    resultHandler.handleResult();
                }
            } catch (BlockNotConnectingException e) {
                errorHandler.accept(e);
            }
        }
    }, errorHandler);
}
Also used : Block(bisq.core.dao.state.blockchain.Block) BlockNotConnectingException(bisq.core.dao.node.parser.exceptions.BlockNotConnectingException)

Aggregations

Block (bisq.core.dao.state.blockchain.Block)6 BlockNotConnectingException (bisq.core.dao.node.parser.exceptions.BlockNotConnectingException)3 RawBlock (bisq.core.dao.state.blockchain.RawBlock)3 GetBlocksResponse (bisq.core.dao.node.messages.GetBlocksResponse)1 Tx (bisq.core.dao.state.blockchain.Tx)1 Connection (bisq.network.p2p.network.Connection)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1