Skip to content

Commit

Permalink
Progress FollowMyVote#32: Fix builds, fix bugs
Browse files Browse the repository at this point in the history
I'm now testing on a real graphene testnet!
  • Loading branch information
nathanielhourt committed Jun 30, 2016
1 parent 769c947 commit 1afbd72
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions GrapheneBackend/BackendConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions GrapheneBackend/BackendPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();});
Expand Down
19 changes: 18 additions & 1 deletion GrapheneBackend/BackendServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ BackendServer::BackendServer(VoteDatabase& db)
BackendServer::~BackendServer() {}

::kj::Promise<void> BackendServer::getContestFeed(Backend::Server::GetContestFeedContext context) {
KJ_LOG(DBG, __FUNCTION__);
auto& contestIndex = vdb.contestIndex().indices();
auto& startTimeIndex = contestIndex.get<ByStartTime>();
auto itr = startTimeIndex.lower_bound(vdb.db().head_block_time());
Expand Down Expand Up @@ -131,8 +132,20 @@ inline const Contest* findFirstContest<ById, ById>(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<gch::account_id_type>();
else {
auto& index = db.get_index_type<gch::account_index>().indices().get<gch::by_name>();
auto itr = index.find(nameOrId);
KJ_REQUIRE(itr != index.end(), "No such account", nameOrId);
return itr->get_id();
}
}

template<typename SearchIndex>
ContestGenerator::Client FilteredGenerator(capnp::List<Backend::Filter>::Reader filters, const gch::database& db) {
KJ_LOG(DBG, __FUNCTION__);
std::vector<typename FeedGenerator<SearchIndex>::Filter> filterFunctions;
using Filter = Backend::Filter::Type;
using Results = typename FeedGenerator<SearchIndex>::FilterResult;
Expand All @@ -157,7 +170,7 @@ ContestGenerator::Client FilteredGenerator(capnp::List<Backend::Filter>::Reader
KJ_REQUIRE(filter.getArguments().size() == 1, "Unexpected number of arguments for creator filter");
try {
using Selector = ResultSelector<SearchIndex, ByCreator>;
auto creator = fc::json::from_string(filter.getArguments()[0]).as<gch::account_id_type>();
auto creator = getAccountId(filter.getArguments()[0], db);
firstContest = findFirstContest<SearchIndex, ByCreator>(creator, db, firstContest);
filterFunctions.emplace_back([creator = kj::mv(creator)] (const Contest& contest,
const gch::database&) {
Expand Down Expand Up @@ -209,6 +222,7 @@ ContestGenerator::Client FilteredGenerator(capnp::List<Backend::Filter>::Reader
}

::kj::Promise<void> 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
Expand Down Expand Up @@ -243,17 +257,20 @@ ::kj::Promise<void> BackendServer::searchContests(Backend::Server::SearchContest
}

::kj::Promise<void> 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<ContestResultsServer>(vdb, contestId));
return kj::READY_NOW;
}

::kj::Promise<void> BackendServer::createContest(Backend::Server::CreateContestContext context) {
KJ_LOG(DBG, __FUNCTION__);
context.initResults().setCreator(kj::heap<ContestCreatorServer>(vdb));
return kj::READY_NOW;
}

::kj::Promise<void> BackendServer::getCoinDetails(Backend::Server::GetCoinDetailsContext context) {
KJ_LOG(DBG, __FUNCTION__);
auto details = context.initResults().initDetails();
auto& contestsByCoin = vdb.contestIndex().indices().get<ByCoin>();
auto coinId = gch::asset_id_type(context.getParams().getCoinId());
Expand Down
2 changes: 1 addition & 1 deletion GrapheneBackend/BackendServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class BackendServer : public Backend::Server
BackendServer(VoteDatabase& vdb);
virtual ~BackendServer();

// Backend::Server interface
protected:
// Backend::Server interface
virtual ::kj::Promise<void> getContestFeed(GetContestFeedContext context) override;
virtual ::kj::Promise<void> searchContests(SearchContestsContext context) override;
virtual ::kj::Promise<void> getContestResults(GetContestResultsContext context) override;
Expand Down
18 changes: 8 additions & 10 deletions VotingApp/Apis/BackendApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<ContestCreatorApi>(m_backend.createContestRequest().send().getCreator());
Expand Down
2 changes: 1 addition & 1 deletion VotingApp/BitsharesWalletBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ kj::Promise<void> 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
Expand Down
4 changes: 3 additions & 1 deletion VotingApp/VotingApp.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VotingApp/VotingSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Promise* VotingSystem::configureChainAdaptor(bool useTestingBackend) {
} else {
if (!d->bitsharesBridge)
d->bitsharesBridge = kj::heap<bts::BitsharesWalletBridge>(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;
}
Expand Down
1 change: 1 addition & 0 deletions VotingApp/qml/CreateContestPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions VotingApp/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion qbs/modules/VPlay/VPlay.qbs
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion qbs/modules/graphene/graphene.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Module {
"graphene_db",
"graphene_debug_witness",
"graphene_market_history",
qbs.hostOS.contains("osx")? "fc_debug" : "fc",
"fc_debug",
"secp256k1",
"z"
]
Expand Down
4 changes: 2 additions & 2 deletions shared/shared.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down Expand Up @@ -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) })
}
Expand Down

0 comments on commit 1afbd72

Please sign in to comment.