Coverage Summary for Class: BlocksBloomService (co.rsk.logfilter)

Class Method, % Line, %
BlocksBloomService 0% (0/5) 0% (0/10)
BlocksBloomService$OnBlockListener 0% (0/2) 0% (0/2)
Total 0% (0/7) 0% (0/12)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package co.rsk.logfilter; 21  22 import co.rsk.config.InternalService; 23 import org.ethereum.core.Block; 24 import org.ethereum.core.TransactionReceipt; 25 import org.ethereum.db.BlockStore; 26 import org.ethereum.listener.CompositeEthereumListener; 27 import org.ethereum.listener.EthereumListenerAdapter; 28 import org.slf4j.Logger; 29 import org.slf4j.LoggerFactory; 30  31 import java.util.List; 32  33 /** 34  * A wrapper to use a BlocksBloomProcessor as an internal service 35  * 36  * The block heights to be processed are obtained from block events 37  * 38  * Created by ajlopez on 01/10/2020. 39  */ 40 public class BlocksBloomService implements InternalService { 41  private static final Logger logger = LoggerFactory.getLogger("blooms"); 42  43  private final CompositeEthereumListener emitter; 44  private final BlocksBloomProcessor blocksBloomProcessor; 45  46  private final BlocksBloomService.OnBlockListener listener = new BlocksBloomService.OnBlockListener(); 47  48  public BlocksBloomService(CompositeEthereumListener emitter, BlocksBloomStore blocksBloomStore, BlockStore blockStore) { 49  this.emitter = emitter; 50  this.blocksBloomProcessor = new BlocksBloomProcessor(blocksBloomStore, blockStore); 51  } 52  53  @Override 54  public void start() { 55  logger.info("blocks bloom service started"); 56  57  emitter.addListener(listener); 58  } 59  60  @Override 61  public void stop() { 62  logger.info("blocks bloom service stopped"); 63  64  emitter.removeListener(listener); 65  } 66  67  public void processNewBlock(long blockNumber) { 68  this.blocksBloomProcessor.processNewBlockNumber(blockNumber); 69  } 70  71  private class OnBlockListener extends EthereumListenerAdapter { 72  @Override 73  public void onBlock(Block block, List<TransactionReceipt> receipts) { 74  processNewBlock(block.getNumber()); 75  } 76  } 77 }