mirror of https://github.com/hyperledger/besu
[NC-1394] Add shortcut --rinkeby command line to use clique on rinkeby test network (#16)
parent
e5a17733cf
commit
28094cee58
@ -0,0 +1,124 @@ |
||||
package net.consensys.pantheon.cli; |
||||
|
||||
import static net.consensys.pantheon.controller.CliquePantheonController.RINKEBY_NETWORK_ID; |
||||
import static net.consensys.pantheon.controller.MainnetPantheonController.MAINNET_NETWORK_ID; |
||||
import static net.consensys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES; |
||||
import static net.consensys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES; |
||||
|
||||
import java.net.URI; |
||||
import java.net.URISyntaxException; |
||||
import java.util.Collection; |
||||
import java.util.Objects; |
||||
|
||||
import com.google.common.base.Preconditions; |
||||
import com.google.common.io.Resources; |
||||
|
||||
public class EthNetworkConfig { |
||||
private static final String MAINNET_GENESIS = "mainnet.json"; |
||||
private static final String RINKEBY_GENESIS = "rinkeby.json"; |
||||
private final URI genesisConfig; |
||||
private final int networkId; |
||||
private final Collection<?> bootNodes; |
||||
|
||||
public EthNetworkConfig( |
||||
final URI genesisConfig, final int networkId, final Collection<?> bootNodes) { |
||||
Preconditions.checkNotNull(genesisConfig); |
||||
Preconditions.checkNotNull(bootNodes); |
||||
this.genesisConfig = genesisConfig; |
||||
this.networkId = networkId; |
||||
this.bootNodes = bootNodes; |
||||
} |
||||
|
||||
public URI getGenesisConfig() { |
||||
return genesisConfig; |
||||
} |
||||
|
||||
public int getNetworkId() { |
||||
return networkId; |
||||
} |
||||
|
||||
public Collection<?> getBootNodes() { |
||||
return bootNodes; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(final Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (o == null || getClass() != o.getClass()) { |
||||
return false; |
||||
} |
||||
EthNetworkConfig that = (EthNetworkConfig) o; |
||||
return networkId == that.networkId |
||||
&& Objects.equals(genesisConfig, that.genesisConfig) |
||||
&& Objects.equals(bootNodes, that.bootNodes); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
return Objects.hash(genesisConfig, networkId, bootNodes); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "EthNetworkConfig{" |
||||
+ "genesisConfig=" |
||||
+ genesisConfig |
||||
+ ", networkId=" |
||||
+ networkId |
||||
+ ", bootNodes=" |
||||
+ bootNodes |
||||
+ '}'; |
||||
} |
||||
|
||||
public static EthNetworkConfig mainnet() { |
||||
final URI genesisConfig = jsonConfigURI(MAINNET_GENESIS); |
||||
return new EthNetworkConfig(genesisConfig, MAINNET_NETWORK_ID, MAINNET_BOOTSTRAP_NODES); |
||||
} |
||||
|
||||
public static EthNetworkConfig rinkeby() { |
||||
final URI genesisConfig = jsonConfigURI(RINKEBY_GENESIS); |
||||
return new EthNetworkConfig(genesisConfig, RINKEBY_NETWORK_ID, RINKEBY_BOOTSTRAP_NODES); |
||||
} |
||||
|
||||
private static URI jsonConfigURI(final String resourceName) { |
||||
try { |
||||
return Resources.getResource(resourceName).toURI(); |
||||
} catch (URISyntaxException e) { |
||||
throw new IllegalStateException(e); |
||||
} |
||||
} |
||||
|
||||
public static class Builder { |
||||
|
||||
private URI genesisConfig; |
||||
private int networkId; |
||||
private Collection<?> bootNodes; |
||||
|
||||
public Builder(final EthNetworkConfig ethNetworkConfig) { |
||||
this.genesisConfig = ethNetworkConfig.genesisConfig; |
||||
this.networkId = ethNetworkConfig.networkId; |
||||
this.bootNodes = ethNetworkConfig.bootNodes; |
||||
} |
||||
|
||||
public Builder setGenesisConfig(final URI genesisConfig) { |
||||
this.genesisConfig = genesisConfig; |
||||
return this; |
||||
} |
||||
|
||||
public Builder setNetworkId(final int networkId) { |
||||
this.networkId = networkId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder setBootNodes(final Collection<?> bootNodes) { |
||||
this.bootNodes = bootNodes; |
||||
return this; |
||||
} |
||||
|
||||
public EthNetworkConfig build() { |
||||
return new EthNetworkConfig(genesisConfig, networkId, bootNodes); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue