Coverage Summary for Class: EthereumImpl (org.ethereum.facade)
Class |
Class, %
|
Method, %
|
Line, %
|
EthereumImpl |
0%
(0/1)
|
0%
(0/6)
|
0%
(0/15)
|
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 org.ethereum.facade;
21
22 import co.rsk.core.Coin;
23 import co.rsk.net.TransactionGateway;
24 import org.ethereum.core.*;
25 import org.ethereum.listener.CompositeEthereumListener;
26 import org.ethereum.listener.EthereumListener;
27 import org.ethereum.listener.GasPriceTracker;
28 import org.ethereum.net.server.ChannelManager;
29
30 import javax.annotation.Nonnull;
31
32 public class EthereumImpl implements Ethereum {
33
34 private final ChannelManager channelManager;
35 private final TransactionGateway transactionGateway;
36 private final CompositeEthereumListener compositeEthereumListener;
37 private final Blockchain blockchain;
38
39 private GasPriceTracker gasPriceTracker = new GasPriceTracker();
40
41 public EthereumImpl(
42 ChannelManager channelManager,
43 TransactionGateway transactionGateway,
44 CompositeEthereumListener compositeEthereumListener,
45 Blockchain blockchain) {
46 this.channelManager = channelManager;
47 this.transactionGateway = transactionGateway;
48
49 this.compositeEthereumListener = compositeEthereumListener;
50 this.blockchain = blockchain;
51
52 compositeEthereumListener.addListener(gasPriceTracker);
53 }
54
55 @Override
56 public ImportResult addNewMinedBlock(final @Nonnull Block block) {
57 final ImportResult importResult = blockchain.tryToConnect(block);
58
59 if (blockchain.getBlockByHash(block.getHash().getBytes()) != null) {
60 channelManager.broadcastBlock(block);
61 }
62 return importResult;
63 }
64
65 @Override
66 public void addListener(EthereumListener listener) {
67 compositeEthereumListener.addListener(listener);
68 }
69
70 @Override
71 public void removeListener(EthereumListener listener) {
72 compositeEthereumListener.removeListener(listener);
73 }
74
75 @Override
76 public void submitTransaction(Transaction transaction) {
77 transactionGateway.receiveTransaction(transaction);
78 }
79
80 @Override
81 public Coin getGasPrice() {
82 return gasPriceTracker.getGasPrice();
83 }
84 }