use of com.google.bitcoin.protocols.channels.StoredPaymentChannelServerStates in project PayFile by mikehearn.
the class Server method main.
public static void main(String[] args) throws Exception {
BriefLogFormatter.init();
// Usage: --file-directory=<file-directory> [--network=[mainnet|testnet|regtest]] [--port=<port>]"
OptionParser parser = new OptionParser();
OptionSpec<File> fileDir = parser.accepts("file-directory").withRequiredArg().required().ofType(File.class);
parser.accepts("network").withRequiredArg().withValuesConvertedBy(regex("(mainnet)|(testnet)|(regtest)")).defaultsTo("mainnet");
parser.accepts("port").withRequiredArg().ofType(Integer.class).defaultsTo(PORT);
parser.accepts("help").forHelp();
parser.formatHelpWith(new BuiltinHelpFormatter(120, 10));
OptionSet options;
try {
options = parser.parse(args);
} catch (OptionException e) {
System.err.println(e.getMessage());
System.err.println("");
parser.printHelpOn(System.err);
return;
}
if (options.has("help")) {
parser.printHelpOn(System.out);
return;
}
directoryToServe = options.valueOf(fileDir);
if (!buildFileList())
return;
if (options.valueOf("network").equals(("testnet"))) {
params = TestNet3Params.get();
filePrefix = "testnet-";
} else if (options.valueOf("network").equals(("mainnet"))) {
params = MainNetParams.get();
filePrefix = "";
} else if (options.valueOf("network").equals(("regtest"))) {
params = RegTestParams.get();
filePrefix = "regtest-";
}
final int port = Integer.parseInt(options.valueOf("port").toString());
WalletAppKit appkit = new WalletAppKit(params, new File("."), filePrefix + "payfile-server-" + port) {
@Override
protected void addWalletExtensions() throws Exception {
super.addWalletExtensions();
wallet().addExtension(new StoredPaymentChannelServerStates(wallet(), peerGroup()));
}
};
if (params == RegTestParams.get()) {
appkit.connectToLocalHost();
}
appkit.setUserAgent("PayFile Server", "1.0").startAndWait();
System.out.println(appkit.wallet().toString(false, true, true, appkit.chain()));
ServerSocket socket = new ServerSocket(port);
Socket clientSocket;
do {
clientSocket = socket.accept();
final Server server = new Server(appkit.wallet(), appkit.peerGroup(), clientSocket);
Thread clientThread = new Thread(server, clientSocket.toString());
clientThread.start();
} while (true);
}
Aggregations