mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
Network: add two more static constructors for convenience
This commit is contained in:
parent
1283fe6f36
commit
6ab20a098b
1 changed files with 33 additions and 0 deletions
|
@ -50,4 +50,37 @@ public enum Network {
|
|||
public NetworkParameters networkParameters() {
|
||||
return NetworkParameters.fromID(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the correct enum for a NetworkParameters
|
||||
* Note: UNITTEST is not supported as an enum
|
||||
* @param networkParameters specifies the network
|
||||
* @return the enum
|
||||
*/
|
||||
public static Network of(NetworkParameters networkParameters) {
|
||||
return of(networkParameters.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the correct enum for a network id string
|
||||
* Note: UNITTEST is not supported as an enum
|
||||
* @param idString specifies the network
|
||||
* @return the enum
|
||||
*/
|
||||
public static Network of(String idString) {
|
||||
switch (idString) {
|
||||
case NetworkParameters.ID_MAINNET:
|
||||
return MAIN;
|
||||
case NetworkParameters.ID_TESTNET:
|
||||
return TEST;
|
||||
case NetworkParameters.ID_SIGNET:
|
||||
return SIGNET;
|
||||
case NetworkParameters.ID_REGTEST:
|
||||
return REGTEST;
|
||||
case NetworkParameters.ID_UNITTESTNET:
|
||||
return REGTEST;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal NetworkParameters: " + idString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue