Coverage Summary for Class: BridgeSupportFactory (co.rsk.peg)

Class Class, % Method, % Line, %
BridgeSupportFactory 100% (1/1) 50% (1/2) 33.3% (5/15)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2018 RSK Labs Ltd. 4  * 5  * This program is free software: you can redistribute it and/or modify 6  * it under the terms of the GNU Lesser General Public License as published by 7  * the Free Software Foundation, either version 3 of the License, or 8  * (at your option) any later version. 9  * 10  * This program is distributed in the hope that it will be useful, 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  * GNU Lesser General Public License for more details. 14  * 15  * You should have received a copy of the GNU Lesser General Public License 16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 17  */ 18  19 package co.rsk.peg; 20  21 import co.rsk.bitcoinj.core.Context; 22 import co.rsk.config.BridgeConstants; 23 import co.rsk.core.RskAddress; 24 import co.rsk.peg.BtcBlockStoreWithCache.Factory; 25 import co.rsk.peg.btcLockSender.BtcLockSenderProvider; 26 import co.rsk.peg.pegininstructions.PeginInstructionsProvider; 27 import co.rsk.peg.utils.BridgeEventLogger; 28 import co.rsk.peg.utils.BridgeEventLoggerImpl; 29 import java.util.List; 30 import org.ethereum.config.blockchain.upgrades.ActivationConfig; 31 import org.ethereum.core.Block; 32 import org.ethereum.core.Repository; 33 import org.ethereum.vm.LogInfo; 34  35 /** 36  * BridgeSupportFactory allows BridgeSupport instantiation. 37  */ 38 public class BridgeSupportFactory { 39  40  private final Factory btcBlockStoreFactory; 41  private final BridgeConstants bridgeConstants; 42  private final ActivationConfig activationConfig; 43  44  public BridgeSupportFactory(Factory btcBlockStoreFactory, 45  BridgeConstants bridgeConstants, ActivationConfig activationConfig) { 46  47  this.btcBlockStoreFactory = btcBlockStoreFactory; 48  this.bridgeConstants = bridgeConstants; 49  this.activationConfig = activationConfig; 50  } 51  52  public BridgeSupport newInstance(Repository repository, Block executionBlock, 53  RskAddress contractAddress, List<LogInfo> logs) { 54  ActivationConfig.ForBlock activations = activationConfig.forBlock(executionBlock.getNumber()); 55  Context btcContext = new Context(bridgeConstants.getBtcParams()); 56  57  BridgeStorageProvider provider = new BridgeStorageProvider( 58  repository, 59  contractAddress, 60  bridgeConstants, 61  activations 62  ); 63  64  FederationSupport federationSupport = new FederationSupport(bridgeConstants, provider, executionBlock); 65  66  BridgeEventLogger eventLogger; 67  if (logs == null) { 68  eventLogger = null; 69  } else { 70  eventLogger = new BridgeEventLoggerImpl(bridgeConstants, activations, logs); 71  } 72  73  BtcLockSenderProvider btcLockSenderProvider = new BtcLockSenderProvider(); 74  PeginInstructionsProvider peginInstructionsProvider = new PeginInstructionsProvider(); 75  76  return new BridgeSupport( 77  bridgeConstants, 78  provider, 79  eventLogger, 80  btcLockSenderProvider, 81  peginInstructionsProvider, 82  repository, 83  executionBlock, 84  btcContext, 85  federationSupport, 86  btcBlockStoreFactory, 87  activations 88  ); 89  } 90 }