This commit introduces a websocket server via the --daemon argument.

```
./wowlet --daemon 127.0.0.1:1234 --daemon-password "sekrit"
```

The wallet will start in the background and expose a websocket port that you can connect to using a websocket client. This way, you will be able to control the wallet via websockets. The commands are defined in wsserver.cpp, in the `processBinaryMessage()` function.

- `openWallet` - opens a wallet by path/password.
- `closeWallet` - close current wallet.
- `addressList` - Returns a list of receive addresses.
- `sendTransaction` - Creates and sends a transaction.
- `createWallet` - Create a wallet by path/password.
- `transactionHistory` - Returns the complete list of transactions
- `addressBook` - Returns the complete list of address book entries.

Messages sent back and forth between the server and client are JSON. There is a Python example client available over at https://git.wownero.com/wownero/wowlet-ws-client
This commit is contained in:
dsc
2021-03-28 21:50:55 +02:00
parent 40a575a5d6
commit 8968a8cbce
24 changed files with 732 additions and 80 deletions
+31 -2
View File
@@ -78,6 +78,12 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
QCommandLineOption exportTxHistoryOption(QStringList() << "export-txhistory", "Output wallet transaction history as CSV to specified path.", "file");
parser.addOption(exportTxHistoryOption);
QCommandLineOption backgroundOption(QStringList() << "daemon", "Start Feather in the background and start a websocket server (IPv4:port)", "backgroundAddress");
parser.addOption(backgroundOption);
QCommandLineOption backgroundPasswordOption(QStringList() << "daemon-password", "Password for connecting to the wowlet websocket service", "backgroundPassword");
parser.addOption(backgroundPasswordOption);
auto parsed = parser.parse(argv_);
if(!parsed) {
qCritical() << parser.errorText();
@@ -92,7 +98,10 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
bool quiet = parser.isSet(quietModeOption);
bool exportContacts = parser.isSet(exportContactsOption);
bool exportTxHistory = parser.isSet(exportTxHistoryOption);
bool cliMode = exportContacts || exportTxHistory;
bool backgroundAddressEnabled = parser.isSet(backgroundOption);
bool cliMode = exportContacts || exportTxHistory || backgroundAddressEnabled;
qRegisterMetaType<QVector<QString>>();
if(cliMode) {
QCoreApplication cli_app(argc, argv);
@@ -116,6 +125,27 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
if(!quiet)
qInfo() << "CLI mode: Transaction history export";
cli->mode = CLIMode::CLIModeExportTxHistory;
QTimer::singleShot(0, cli, &CLI::run);
} else if(backgroundAddressEnabled) {
if(!quiet)
qInfo() << "CLI mode: daemonize";
cli->mode = CLIMode::CLIDaemonize;
auto backgroundHostPort = parser.value(backgroundOption);
if(!backgroundHostPort.contains(":")) {
qCritical() << "the format is: --background ipv4:port";
return 1;
}
auto spl = backgroundHostPort.split(":");
cli->backgroundWebsocketAddress = spl.at(0);
cli->backgroundWebsocketPort = (quint16) spl.at(1).toInt();
cli->backgroundWebsocketPassword = parser.value(backgroundPasswordOption);
if(cli->backgroundWebsocketPassword.isEmpty()) {
qCritical() << "--daemon-password needs to be set when using --daemon";
return 1;
}
QTimer::singleShot(0, cli, &CLI::run);
}
@@ -161,7 +191,6 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
#endif
qInstallMessageHandler(Utils::applicationLogHandler);
qRegisterMetaType<QVector<QString>>();
auto *mainWindow = new MainWindow(ctx);
return QApplication::exec();