From 1afbd72df4f7fe963ffeb20bc5e085a94768565b Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 30 Jun 2016 14:18:23 -0500 Subject: [PATCH] Progress #32: Fix builds, fix bugs I'm now testing on a real graphene testnet! --- GrapheneBackend/BackendConfiguration.cpp | 1 + GrapheneBackend/BackendPlugin.cpp | 1 + GrapheneBackend/BackendServer.cpp | 19 ++++++++++++++++++- GrapheneBackend/BackendServer.hpp | 2 +- VotingApp/Apis/BackendApi.cpp | 18 ++++++++---------- VotingApp/BitsharesWalletBridge.cpp | 2 +- VotingApp/VotingApp.qbs | 4 +++- VotingApp/VotingSystem.cpp | 2 +- VotingApp/qml/CreateContestPage.qml | 1 + VotingApp/qml/main.qml | 4 ++-- qbs/modules/VPlay/VPlay.qbs | 3 ++- qbs/modules/graphene/graphene.qbs | 2 +- shared/shared.qbs | 4 ++-- 13 files changed, 42 insertions(+), 21 deletions(-) diff --git a/GrapheneBackend/BackendConfiguration.cpp b/GrapheneBackend/BackendConfiguration.cpp index 7ccd1ef..b1e291f 100644 --- a/GrapheneBackend/BackendConfiguration.cpp +++ b/GrapheneBackend/BackendConfiguration.cpp @@ -15,6 +15,7 @@ namespace swv { BackendConfiguration::BackendConfiguration() {} void BackendConfiguration::open(kj::StringPtr configFilePath, bool createIfMissing) { + KJ_LOG(DBG, "Opening Follow My Vote configuration", configFilePath); auto fd = ::open(configFilePath.cStr(), O_RDONLY); if (!createIfMissing) diff --git a/GrapheneBackend/BackendPlugin.cpp b/GrapheneBackend/BackendPlugin.cpp index b0c174e..3128446 100644 --- a/GrapheneBackend/BackendPlugin.cpp +++ b/GrapheneBackend/BackendPlugin.cpp @@ -42,6 +42,7 @@ void BackendPlugin::plugin_initialize(const boost::program_options::variables_ma void BackendPlugin::plugin_startup() { database->startup(); running = true; + server.set_reuse_address(); server.listen(serverPort); KJ_LOG(INFO, "Server is up", server.get_port()); fc::async([this]{acceptLoop();}); diff --git a/GrapheneBackend/BackendServer.cpp b/GrapheneBackend/BackendServer.cpp index e4fd323..0288852 100644 --- a/GrapheneBackend/BackendServer.cpp +++ b/GrapheneBackend/BackendServer.cpp @@ -53,6 +53,7 @@ BackendServer::BackendServer(VoteDatabase& db) BackendServer::~BackendServer() {} ::kj::Promise BackendServer::getContestFeed(Backend::Server::GetContestFeedContext context) { + KJ_LOG(DBG, __FUNCTION__); auto& contestIndex = vdb.contestIndex().indices(); auto& startTimeIndex = contestIndex.get(); auto itr = startTimeIndex.lower_bound(vdb.db().head_block_time()); @@ -131,8 +132,20 @@ inline const Contest* findFirstContest(decltype (nullptr), const gch return index.empty()? nullValue : &*index.begin(); } +gch::account_id_type getAccountId(kj::StringPtr nameOrId, const gch::database& db) { + if (std::isdigit(nameOrId[0])) + return fc::json::from_string(nameOrId).as(); + else { + auto& index = db.get_index_type().indices().get(); + auto itr = index.find(nameOrId); + KJ_REQUIRE(itr != index.end(), "No such account", nameOrId); + return itr->get_id(); + } +} + template ContestGenerator::Client FilteredGenerator(capnp::List::Reader filters, const gch::database& db) { + KJ_LOG(DBG, __FUNCTION__); std::vector::Filter> filterFunctions; using Filter = Backend::Filter::Type; using Results = typename FeedGenerator::FilterResult; @@ -157,7 +170,7 @@ ContestGenerator::Client FilteredGenerator(capnp::List::Reader KJ_REQUIRE(filter.getArguments().size() == 1, "Unexpected number of arguments for creator filter"); try { using Selector = ResultSelector; - auto creator = fc::json::from_string(filter.getArguments()[0]).as(); + auto creator = getAccountId(filter.getArguments()[0], db); firstContest = findFirstContest(creator, db, firstContest); filterFunctions.emplace_back([creator = kj::mv(creator)] (const Contest& contest, const gch::database&) { @@ -209,6 +222,7 @@ ContestGenerator::Client FilteredGenerator(capnp::List::Reader } ::kj::Promise BackendServer::searchContests(Backend::Server::SearchContestsContext context) { + KJ_LOG(DBG, __FUNCTION__); auto filters = context.getParams().getFilters(); // There are multiple search strategies available to us, depending on which filters are in play. Optimally, we rule @@ -243,17 +257,20 @@ ::kj::Promise BackendServer::searchContests(Backend::Server::SearchContest } ::kj::Promise BackendServer::getContestResults(Backend::Server::GetContestResultsContext context) { + KJ_LOG(DBG, __FUNCTION__); auto contestId = gch::operation_history_id_type(context.getParams().getContestId().getOperationId()); context.initResults().setResults(kj::heap(vdb, contestId)); return kj::READY_NOW; } ::kj::Promise BackendServer::createContest(Backend::Server::CreateContestContext context) { + KJ_LOG(DBG, __FUNCTION__); context.initResults().setCreator(kj::heap(vdb)); return kj::READY_NOW; } ::kj::Promise BackendServer::getCoinDetails(Backend::Server::GetCoinDetailsContext context) { + KJ_LOG(DBG, __FUNCTION__); auto details = context.initResults().initDetails(); auto& contestsByCoin = vdb.contestIndex().indices().get(); auto coinId = gch::asset_id_type(context.getParams().getCoinId()); diff --git a/GrapheneBackend/BackendServer.hpp b/GrapheneBackend/BackendServer.hpp index cc0ca1f..5e05014 100644 --- a/GrapheneBackend/BackendServer.hpp +++ b/GrapheneBackend/BackendServer.hpp @@ -31,8 +31,8 @@ class BackendServer : public Backend::Server BackendServer(VoteDatabase& vdb); virtual ~BackendServer(); - // Backend::Server interface protected: + // Backend::Server interface virtual ::kj::Promise getContestFeed(GetContestFeedContext context) override; virtual ::kj::Promise searchContests(SearchContestsContext context) override; virtual ::kj::Promise getContestResults(GetContestResultsContext context) override; diff --git a/VotingApp/Apis/BackendApi.cpp b/VotingApp/Apis/BackendApi.cpp index 6e1a89c..2b41c16 100644 --- a/VotingApp/Apis/BackendApi.cpp +++ b/VotingApp/Apis/BackendApi.cpp @@ -44,13 +44,12 @@ BackendApi::BackendApi(Backend::Client backend, PromiseConverter& promiseConvert BackendApi::~BackendApi() noexcept {} -ContestGeneratorApi* BackendApi::getFeedGenerator() -{ +ContestGeneratorApi* BackendApi::getFeedGenerator() { return new ContestGeneratorApi(m_backend.getContestFeedRequest().send().getGenerator(), promiseConverter); } -ContestGeneratorApi* BackendApi::getContestsByCreator(QString creator) -{ +ContestGeneratorApi* BackendApi::getContestsByCreator(QString creator) { + KJ_LOG(DBG, "Getting contests by creator", creator.toStdString()); auto request = m_backend.searchContestsRequest(); auto filters = request.initFilters(1); filters[0].setType(Backend::Filter::Type::CONTEST_CREATOR); @@ -60,8 +59,8 @@ ContestGeneratorApi* BackendApi::getContestsByCreator(QString creator) return new ContestGeneratorApi(request.send().getGenerator(), promiseConverter); } -ContestGeneratorApi* BackendApi::getContestsByCoin(quint64 coinId) -{ +ContestGeneratorApi* BackendApi::getContestsByCoin(quint64 coinId) { + KJ_LOG(DBG, "Getting contests by coin", coinId); auto request = m_backend.searchContestsRequest(); auto filters = request.initFilters(1); filters[0].setType(Backend::Filter::Type::CONTEST_COIN); @@ -71,8 +70,8 @@ ContestGeneratorApi* BackendApi::getContestsByCoin(quint64 coinId) return new ContestGeneratorApi(request.send().getGenerator(), promiseConverter); } -ContestGeneratorApi*BackendApi::getVotedContests() -{ +ContestGeneratorApi*BackendApi::getVotedContests() { + KJ_LOG(DBG, "Getting contests by voter"); auto request = m_backend.searchContestsRequest(); auto filters = request.initFilters(1); filters[0].setType(Backend::Filter::Type::CONTEST_VOTER); @@ -89,8 +88,7 @@ ContestResultsApi* BackendApi::getContestResults(QString contestId) { return new ContestResultsApi(request.send().getResults()); } -ContestCreatorApi* BackendApi::contestCreator() -{ +ContestCreatorApi* BackendApi::contestCreator() { // Lazy load the creator; most runs we will probably never need it. if (creator.get() == nullptr) creator = kj::heap(m_backend.createContestRequest().send().getCreator()); diff --git a/VotingApp/BitsharesWalletBridge.cpp b/VotingApp/BitsharesWalletBridge.cpp index c7d2612..5aefa1d 100644 --- a/VotingApp/BitsharesWalletBridge.cpp +++ b/VotingApp/BitsharesWalletBridge.cpp @@ -253,7 +253,7 @@ kj::Promise BWB::BlockchainWalletServer::getContestById(GetContestByIdCont auto datagramReader = datagramMessage->getRoot<::Datagram>(); auto key = datagramReader.getKey().getKey(); KJ_REQUIRE(key.isContestKey(), "Invalid contest ID references a datagram which does not contain a contest", - key.which(), operationInstance); + operationInstance); auto result = context.initResults().initContest(); // Set creator's signature, if present diff --git a/VotingApp/VotingApp.qbs b/VotingApp/VotingApp.qbs index 018ac1f..1e0377c 100644 --- a/VotingApp/VotingApp.qbs +++ b/VotingApp/VotingApp.qbs @@ -9,9 +9,11 @@ QtGuiApplication { Depends { name: "Qt"; submodules: ["network", "qml", "charts"] } Depends { name: "libqtqmltricks-qtquickuielements" } Depends { name: "VPlay" } - VPlay.sdkPath: Qt.core.incPath + "/.." + // 'original' is a keyword: https://doc.qt.io/qbs/module-item.html#special-property-values + VPlay.sdkPath: original? original : Qt.core.incPath + "/.." qmlImportPaths: [VPlay.sdkPath + "/qml"] + cpp.cxxLanguageVersion: "c++14" cpp.includePaths: [".", "qml-promise/src", VPlay.includePath] cpp.libraryPaths: VPlay.sdkPath + "/lib" cpp.staticLibraries: VPlay.staticLibrary diff --git a/VotingApp/VotingSystem.cpp b/VotingApp/VotingSystem.cpp index e4f7339..353f9c2 100644 --- a/VotingApp/VotingSystem.cpp +++ b/VotingApp/VotingSystem.cpp @@ -299,7 +299,7 @@ Promise* VotingSystem::configureChainAdaptor(bool useTestingBackend) { } else { if (!d->bitsharesBridge) d->bitsharesBridge = kj::heap(qApp->applicationName()); - if (!d->bitsharesBridge->isListening() && !d->bitsharesBridge->listen(QHostAddress::LocalHost)) { + if (!d->bitsharesBridge->isListening() && !d->bitsharesBridge->listen(QHostAddress::LocalHost, 27073)) { setLastError(tr("Unable to listen for Bitshares wallet: %1").arg(d->bitsharesBridge->errorString())); return nullptr; } diff --git a/VotingApp/qml/CreateContestPage.qml b/VotingApp/qml/CreateContestPage.qml index 4305d3c..9c9a0c4 100644 --- a/VotingApp/qml/CreateContestPage.qml +++ b/VotingApp/qml/CreateContestPage.qml @@ -17,6 +17,7 @@ Page { property var contestCreator function showError(message) { + var errorString = message // Ignore errors that come within 1 second of the last error if (new Date().getTime() - internal.lastErrorTime < 1000) return diff --git a/VotingApp/qml/main.qml b/VotingApp/qml/main.qml index 52563b1..15167f6 100644 --- a/VotingApp/qml/main.qml +++ b/VotingApp/qml/main.qml @@ -111,8 +111,8 @@ App { title: qsTr("My Polls") votingSystem: _votingSystem getContestGeneratorFunction: function() { - if (votingSystem.isReady) - return votingSystem.backend.getContestsByCreator(votingSystem.currentAccount) + if (votingSystem.isReady && votingSystem.currentAccount) + return votingSystem.backend.getContestsByCreator(votingSystem.currentAccount.name) } listView.headerPositioning: ListView.PullBackHeader listView.header: CreateContestPlaceholder { diff --git a/qbs/modules/VPlay/VPlay.qbs b/qbs/modules/VPlay/VPlay.qbs index fcd2db4..638ae2d 100644 --- a/qbs/modules/VPlay/VPlay.qbs +++ b/qbs/modules/VPlay/VPlay.qbs @@ -1,10 +1,11 @@ import qbs +import qbs.Environment Module { name: "VPlay" // include vplay header, lib and resources - property string sdkPath + property string sdkPath: Environment.getEnv("VPLAY_PATH") property string qtIncPath: sdkPath + "/include" property string includePath: qtIncPath+"/VPlay" property string staticLibrary: "VPlay" diff --git a/qbs/modules/graphene/graphene.qbs b/qbs/modules/graphene/graphene.qbs index 268a699..09f3fc0 100644 --- a/qbs/modules/graphene/graphene.qbs +++ b/qbs/modules/graphene/graphene.qbs @@ -29,7 +29,7 @@ Module { "graphene_db", "graphene_debug_witness", "graphene_market_history", - qbs.hostOS.contains("osx")? "fc_debug" : "fc", + "fc_debug", "secp256k1", "z" ] diff --git a/shared/shared.qbs b/shared/shared.qbs index 5a31d50..1ec74bf 100644 --- a/shared/shared.qbs +++ b/shared/shared.qbs @@ -7,7 +7,7 @@ StaticLibrary { Depends { name: "cpp" } cpp.includePaths: ["capnp"] cpp.cxxLanguageVersion: "c++14" - cpp.cxxStandardLibrary: "libc++" + cpp.cxxStandardLibrary: "libstdc++" Depends { name: "Qt"; submodules: ["qml"] } Depends { name: "capnp" } @@ -35,7 +35,7 @@ StaticLibrary { Depends { name : "cpp" } cpp.includePaths: [".", "capnp"] cpp.cxxLanguageVersion: "c++14" - cpp.cxxStandardLibrary: "libc++" + cpp.cxxStandardLibrary: "libstdc++" cpp.cxxFlags: capnpProbe.cflags cpp.dynamicLibraries: capnpProbe.libs.filter(function(name) { return name.startsWith("-l") }).map(function(name) { return name === "-pthread"? "" : name.slice(2) }) }