67f0535607
commit f1c09cbbdf228cefbfbd339567ba337083e93e52 Author: TomZ <tomz@freedommail.ch> Date: Wed Sep 2 13:56:38 2020 +0200 Fix sorting in address/utxo call commit c61b03b05de04c9d53c6fdf413dd1b6d33dc17f6 Author: TomZ <tomz@freedommail.ch> Date: Wed Sep 2 13:03:43 2020 +0200 Also catch missing services for more complex searches We did catch it on 'start()' which may not actually use a service that was missing and only in a followup would the missing service be used. So also catch the exception for missing service on the other event handling methods. This means that we now show a nice "setup needed" message to client when a call is done that is not supported because of missing backing service. commit fbcfe60c7d21b309e9c827dd927de0e196d7f5b6 Author: TomZ <tomz@freedommail.ch> Date: Tue Sep 1 16:03:19 2020 +0200 Also use the complex UTXO lookup to do callbacks. commit d948225ae7786aa6b62ff9355c2d768a85569642 Author: TomZ <tomz@freedommail.ch> Date: Tue Sep 1 15:47:48 2020 +0200 Add address/utxo call. commit cbc4695d4abae1404afe03f34b10427e48f819ae Author: TomZ <tomz@freedommail.ch> Date: Tue Sep 1 14:34:31 2020 +0200 Add address/details API call This mostly implements the API call to list an address. commit 1d215032af09551e2b3eda314c072a200e5fb37a Author: TomZ <tomz@freedommail.ch> Date: Tue Sep 1 14:30:26 2020 +0200 Fix warnings This fixes warnings from the compiler and the linter. commit b61e7dd42222537b456a79e14439a0d36007e8d7 Author: TomZ <tomz@freedommail.ch> Date: Tue Sep 1 14:27:27 2020 +0200 Blockchain::Search: Clean a little and fix bugs This follows the API docs on the utxoLookup() callback and we indeed return back the blockheight/etc parameters even if the utxo is already spent (represented by unspent=false). commit 7ec3ebf937d7f2fb6a7a18f21d2e8b645db6fe3e Author: TomZ <tomz@freedommail.ch> Date: Mon Aug 31 12:24:18 2020 +0200 Fixes and move to v2 url commit 32b8018af805ce068da7d3e149add66a90c92264 Author: TomZ <tomz@freedommail.ch> Date: Mon Aug 31 11:29:35 2020 +0200 Build the rest service commit c386adff9d28a0f844916019602ea0032bbc360a Author: TomZ <tomz@freedommail.ch> Date: Sun Aug 30 19:24:29 2020 +0200 Cleanup old code and make vin work commit 5b88457863892ff8391e42a7eff61cd243851b41 Author: TomZ <tomz@freedommail.ch> Date: Sun Aug 30 18:42:41 2020 +0200 Output addresses. commit 46c2ce680409c38f1a67730e23cde942db2ecc46 Author: TomZ <tomz@freedommail.ch> Date: Sun Aug 30 17:51:03 2020 +0200 Make tx-refs easier for the Blockchain::Search commit b0591b5a6b57e2eb7022db7b7a351c694220e5ad Author: TomZ <tomz@freedommail.ch> Date: Fri Aug 28 18:28:48 2020 +0200 Make printing of tx work better commit d337ac91ad4ab9eeb768695c639dcbbbcc463837 Author: TomZ <tomz@freedommail.ch> Date: Fri Aug 28 15:46:04 2020 +0200 Make rest service show a nice help for setup. commit 5997ff1fa06bd1a6b51ead93eef094a5561fdb53 Author: TomZ <tomz@freedommail.ch> Date: Wed Aug 26 17:43:09 2020 +0200 Parse the json automatically. commit 5ed7d6e53761828e2e385e085f44d530449b0b3b Author: TomZ <tomz@freedommail.ch> Date: Wed Aug 26 13:07:04 2020 +0200 Start project rest-service.
124 lines
4.1 KiB
C++
124 lines
4.1 KiB
C++
/*
|
|
* This file is part of the Flowee project
|
|
* Copyright (C) 2019-2020 Tom Zander <tomz@freedommail.ch>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <FloweeServiceApplication.h>
|
|
#include <WorkerThreads.h>
|
|
#include <httpengine/server.h>
|
|
#include <Message.h>
|
|
|
|
#include "RestService.h"
|
|
|
|
#define PORT 3200
|
|
|
|
class Server : public HttpEngine::Server
|
|
{
|
|
public:
|
|
explicit Server(const std::function<void(HttpEngine::WebRequest*)> &handler)
|
|
: m_func(handler)
|
|
{
|
|
}
|
|
HttpEngine::WebRequest *createRequest(qintptr socketDescriptor) override {
|
|
return new RestServiceWebRequest(socketDescriptor, m_func);
|
|
}
|
|
|
|
void setProxy(RestService *proxy) { m_handler = proxy; }
|
|
private:
|
|
RestService *m_handler = nullptr;
|
|
std::function<void(HttpEngine::WebRequest*)> m_func;
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(Message)
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
FloweeServiceApplication app(argc, argv);
|
|
app.setOrganizationName("flowee");
|
|
app.setOrganizationDomain("flowee.org");
|
|
app.setApplicationName("rest-service");
|
|
|
|
QCommandLineParser parser;
|
|
parser.setApplicationDescription("REST service");
|
|
parser.addHelpOption();
|
|
QCommandLineOption conf(QStringList() << "conf", "config file", "FILENAME");
|
|
parser.addOption(conf);
|
|
app.addServerOptions(parser);
|
|
parser.process(app.arguments());
|
|
|
|
app.setup("restservice.log", parser.value(conf));
|
|
|
|
qRegisterMetaType<Message>();
|
|
|
|
RestService handler;
|
|
Server server(std::bind(&RestService::onIncomingConnection, &handler, std::placeholders::_1));
|
|
server.setProxy(&handler);
|
|
|
|
auto listenAddresses = app.bindingEndPoints(parser, PORT);
|
|
if (listenAddresses.isEmpty()) {
|
|
using boost::asio::ip::tcp;
|
|
listenAddresses.push_back(tcp::endpoint(boost::asio::ip::address_v4::loopback(), PORT));
|
|
listenAddresses.push_back(tcp::endpoint(boost::asio::ip::address_v6::loopback(), PORT));
|
|
}
|
|
bool success = false;
|
|
for (auto ep : listenAddresses) {
|
|
logCritical().nospace() << "Binding http server to " << ep.address().to_string().c_str() << ":" << ep.port();
|
|
try {
|
|
if (!server.listen(QHostAddress(QString::fromStdString(ep.address().to_string())), ep.port())) {
|
|
logCritical() << " Failed to listen on interface";
|
|
} else {
|
|
success = true;
|
|
break;
|
|
}
|
|
} catch (std::exception &e) {
|
|
logCritical() << " " << e << "skipping";
|
|
}
|
|
}
|
|
if (!success) {
|
|
logFatal() << "Please pass --bind to tell me which network to listen to";
|
|
return 1;
|
|
}
|
|
|
|
try {
|
|
auto ep = app.serverAddressFromArguments(1235);
|
|
if (!ep.hostname.empty())
|
|
handler.addHub(ep);
|
|
} catch (const std::exception &e) {
|
|
logFatal() << e;
|
|
return 1;
|
|
}
|
|
|
|
QString confFile;
|
|
if (parser.isSet(conf)) {
|
|
confFile = parser.value(conf);
|
|
} else {
|
|
confFile = QStandardPaths::locate(QStandardPaths::AppConfigLocation, "rest-service.conf");
|
|
if (confFile.isEmpty()) {
|
|
logCritical() << "No config file (rest-service.conf) found, assuming defaults and no indexer";
|
|
for (auto dir : QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation)) {
|
|
logInfo() << " - not found in" << dir + '/';
|
|
}
|
|
}
|
|
}
|
|
handler.setConfigFile(confFile.toStdString());
|
|
|
|
QObject::connect (&app, SIGNAL(reparseConfig()), &handler, SLOT(onReparseConfig()));
|
|
|
|
return app.exec();
|
|
}
|