ForwardingService: use BitcoinNetwork.fromString() to parse network CLI parameter
@@ -32,7 +32,6 @@ import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet;
import java.io.File;
-import java.util.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -51,13 +50,13 @@ public class ForwardingService {
// This line makes the log output more compact and easily read, especially when using the JDK log adapter.
BriefLogFormatter.init();
if (args.length < 1) {
- System.err.println("Usage: address-to-send-back-to [main|regtest|testnet|signet]");
+ System.err.println("Usage: address-to-send-back-to [mainnet|testnet|signet|regtest]");
return;
}
// Figure out which network we should connect to. Each one gets its own set of files.
String networkArgument = (args.length > 1) ? args[1] : "main";
- BitcoinNetwork network = parseNetwork(networkArgument).orElseThrow();
+ BitcoinNetwork network = BitcoinNetwork.fromString(networkArgument).orElseThrow();
// Parse the address given as the first parameter.
var address = Address.fromString(NetworkParameters.of(network), args[0]);
@@ -156,16 +155,6 @@ public class ForwardingService {
}
}
- static Optional<BitcoinNetwork> parseNetwork(String networkOption) {
- switch (networkOption) {
- case "main": return Optional.of(BitcoinNetwork.MAINNET);
- case "testnet": return Optional.of(BitcoinNetwork.TESTNET);
- case "regtest": return Optional.of(BitcoinNetwork.REGTEST);
- case "signet": return Optional.of(BitcoinNetwork.SIGNET);
- default: return Optional.empty();
- }
- }
-
private void forwardCoins() {
try {
// Now send the coins onwards.
