Skip to content

Commit

Permalink
Merge pull request #429 from pocketnetteam/fix/build
Browse files Browse the repository at this point in the history
fix: build issues
  • Loading branch information
lostystyg authored Oct 9, 2022
2 parents 09b34d9 + 3ff72e4 commit 1c3de31
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 160 deletions.
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ add_library(${POCKETDB}
pocketdb/models/shortform/ShortTxType.h
pocketdb/models/shortform/ShortTxOutput.h
pocketdb/models/shortform/ShortTxOutput.cpp
pocketdb/helpers/ShortFormModelsHelper.h
pocketdb/helpers/ShortFormModelsHelper.cpp
)
target_link_libraries(${POCKETDB} PRIVATE ${POCKETCOIN_COMMON} ${POCKETCOIN_UTIL} ${POCKETCOIN_CRYPTO} univalue leveldb)

Expand Down Expand Up @@ -1050,8 +1052,8 @@ add_library(${POCKETCOIN_SERVER}
pocketdb/helpers/PocketnetHelper.h
pocketdb/helpers/TransactionHelper.h
pocketdb/helpers/TransactionHelper.cpp
pocketdb/helpers/ShortFormHelper.h
pocketdb/helpers/ShortFormHelper.cpp
pocketdb/helpers/ShortFormRepositoryHelper.h
pocketdb/helpers/ShortFormRepositoryHelper.cpp
pocketdb/SQLiteDatabase.h
pocketdb/SQLiteConnection.h
pocketdb/SQLiteDatabase.cpp
Expand Down
6 changes: 4 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ POCKETDB_H = \
\
pocketdb/helpers/PocketnetHelper.h \
pocketdb/helpers/TransactionHelper.h \
pocketdb/helpers/ShortFormHelper.h \
pocketdb/helpers/ShortFormRepositoryHelper.h \
pocketdb/helpers/ShortFormModelsHelper.h \
\
pocketdb/web/PocketContentRpc.h \
pocketdb/web/PocketCommentsRpc.h \
Expand Down Expand Up @@ -239,7 +240,8 @@ POCKETDB_CPP = \
pocketdb/migrations/web.cpp \
\
pocketdb/helpers/TransactionHelper.cpp \
pocketdb/helpers/ShortFormHelper.cpp \
pocketdb/helpers/ShortFormRepositoryHelper.cpp \
pocketdb/helpers/ShortFormModelsHelper.cpp \
\
pocketdb/services/WsNotifier.cpp \
pocketdb/services/Serializer.cpp \
Expand Down
112 changes: 112 additions & 0 deletions src/pocketdb/helpers/ShortFormModelsHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) 2018-2022 The Pocketnet developers
// Distributed under the Apache 2.0 software license, see the accompanying
// https://www.apache.org/licenses/LICENSE-2.0

#include "pocketdb/helpers/ShortFormModelsHelper.h"

#include <map>
#include <algorithm>
#include <set>


static const std::map<PocketDb::ShortTxType, std::string>& GetTypesMap() {
static const std::map<PocketDb::ShortTxType, std::string> typesMap = {
{ PocketDb::ShortTxType::Money, "money" },
{ PocketDb::ShortTxType::Referal, "referal" },
{ PocketDb::ShortTxType::Answer, "answer" },
{ PocketDb::ShortTxType::Comment, "comment" },
{ PocketDb::ShortTxType::Subscriber, "subscriber" },
{ PocketDb::ShortTxType::CommentScore, "commentscore" },
{ PocketDb::ShortTxType::ContentScore, "contentscore" },
{ PocketDb::ShortTxType::PrivateContent, "privatecontent" },
{ PocketDb::ShortTxType::Boost, "boost" },
{ PocketDb::ShortTxType::Repost, "repost" },
{ PocketDb::ShortTxType::Blocking, "blocking" }
};
return typesMap;
}

std::string PocketHelpers::ShortTxTypeConvertor::toString(PocketDb::ShortTxType type)
{
static const auto& typesMap = GetTypesMap();
auto str = typesMap.find(type);
if (str != typesMap.end()) {
return str->second;
}
return "";
}

bool PocketHelpers::ShortTxFilterValidator::Notifications::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::Money,
PocketDb::ShortTxType::Answer,
PocketDb::ShortTxType::PrivateContent,
PocketDb::ShortTxType::Boost,
PocketDb::ShortTxType::Referal,
PocketDb::ShortTxType::Comment,
PocketDb::ShortTxType::Subscriber,
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::Repost
};

return allowed.find(type) != allowed.end();
}

bool PocketHelpers::ShortTxFilterValidator::NotificationsSummary::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::Referal,
PocketDb::ShortTxType::Comment,
PocketDb::ShortTxType::Subscriber,
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::Repost,
};

return allowed.find(type) != allowed.end();
}

bool PocketHelpers::ShortTxFilterValidator::Activities::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::Answer,
PocketDb::ShortTxType::Comment,
PocketDb::ShortTxType::Subscriber,
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::Boost,
PocketDb::ShortTxType::Blocking,
};

return allowed.find(type) != allowed.end();
}

bool PocketHelpers::ShortTxFilterValidator::Events::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::Money,
PocketDb::ShortTxType::Referal,
PocketDb::ShortTxType::Answer,
PocketDb::ShortTxType::Comment,
PocketDb::ShortTxType::Subscriber,
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::PrivateContent,
PocketDb::ShortTxType::Boost,
PocketDb::ShortTxType::Repost,
};

return allowed.find(type) != allowed.end();
}

PocketDb::ShortTxType PocketHelpers::ShortTxTypeConvertor::strToType(const std::string& typeStr)
{
static const auto& typesMap = GetTypesMap();
auto type = std::find_if(typesMap.begin(), typesMap.end(), [&](const auto& elem) { return elem.second == typeStr; });
if (type != typesMap.end()) {
return type->first;
}
return PocketDb::ShortTxType::NotSet;
}
52 changes: 52 additions & 0 deletions src/pocketdb/helpers/ShortFormModelsHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2018-2022 The Pocketnet developers
// Distributed under the Apache 2.0 software license, see the accompanying
// https://www.apache.org/licenses/LICENSE-2.0

#ifndef POCKETDB_SHORTFORMMODELSHELPER_H
#define POCKETDB_SHORTFORMMODELSHELPER_H

#include "pocketdb/models/shortform/ShortForm.h"

#include <string>

namespace PocketHelpers
{
using namespace PocketDb;

class ShortTxTypeConvertor
{
public:
static std::string toString(ShortTxType type);
static ShortTxType strToType(const std::string& typeStr);
};

class ShortTxFilterValidator
{
public:
class Notifications
{
public:
static bool IsFilterAllowed(ShortTxType type);
};

class NotificationsSummary
{
public:
static bool IsFilterAllowed(ShortTxType type);
};

class Activities
{
public:
static bool IsFilterAllowed(ShortTxType type);
};

class Events
{
public:
static bool IsFilterAllowed(ShortTxType type);
};
};
}

#endif // POCKETDB_SHORTFORMMODELSHELPER_H
Original file line number Diff line number Diff line change
Expand Up @@ -2,114 +2,7 @@
// Distributed under the Apache 2.0 software license, see the accompanying
// https://www.apache.org/licenses/LICENSE-2.0

#include "pocketdb/helpers/ShortFormHelper.h"

#include <map>
#include <algorithm>
#include <set>


static const std::map<PocketDb::ShortTxType, std::string>& GetTypesMap() {
static const std::map<PocketDb::ShortTxType, std::string> typesMap = {
{ PocketDb::ShortTxType::Money, "money" },
{ PocketDb::ShortTxType::Referal, "referal" },
{ PocketDb::ShortTxType::Answer, "answer" },
{ PocketDb::ShortTxType::Comment, "comment" },
{ PocketDb::ShortTxType::Subscriber, "subscriber" },
{ PocketDb::ShortTxType::CommentScore, "commentscore" },
{ PocketDb::ShortTxType::ContentScore, "contentscore" },
{ PocketDb::ShortTxType::PrivateContent, "privatecontent" },
{ PocketDb::ShortTxType::Boost, "boost" },
{ PocketDb::ShortTxType::Repost, "repost" },
{ PocketDb::ShortTxType::Blocking, "blocking" }
};
return typesMap;
}

std::string PocketHelpers::ShortTxTypeConvertor::toString(PocketDb::ShortTxType type)
{
static const auto& typesMap = GetTypesMap();
auto str = typesMap.find(type);
if (str != typesMap.end()) {
return str->second;
}
return "";
}

bool PocketHelpers::ShortTxFilterValidator::Notifications::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::Money,
PocketDb::ShortTxType::Answer,
PocketDb::ShortTxType::PrivateContent,
PocketDb::ShortTxType::Boost,
PocketDb::ShortTxType::Referal,
PocketDb::ShortTxType::Comment,
PocketDb::ShortTxType::Subscriber,
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::Repost
};

return allowed.find(type) != allowed.end();
}

bool PocketHelpers::ShortTxFilterValidator::NotificationsSummary::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::Referal,
PocketDb::ShortTxType::Comment,
PocketDb::ShortTxType::Subscriber,
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::Repost,
};

return allowed.find(type) != allowed.end();
}

bool PocketHelpers::ShortTxFilterValidator::Activities::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::Answer,
PocketDb::ShortTxType::Comment,
PocketDb::ShortTxType::Subscriber,
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::Boost,
PocketDb::ShortTxType::Blocking,
};

return allowed.find(type) != allowed.end();
}

bool PocketHelpers::ShortTxFilterValidator::Events::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::Money,
PocketDb::ShortTxType::Referal,
PocketDb::ShortTxType::Answer,
PocketDb::ShortTxType::Comment,
PocketDb::ShortTxType::Subscriber,
PocketDb::ShortTxType::CommentScore,
PocketDb::ShortTxType::ContentScore,
PocketDb::ShortTxType::PrivateContent,
PocketDb::ShortTxType::Boost,
PocketDb::ShortTxType::Repost,
};

return allowed.find(type) != allowed.end();
}

PocketDb::ShortTxType PocketHelpers::ShortTxTypeConvertor::strToType(const std::string& typeStr)
{
static const auto& typesMap = GetTypesMap();
auto type = std::find_if(typesMap.begin(), typesMap.end(), [&](const auto& elem) { return elem.second == typeStr; });
if (type != typesMap.end()) {
return type->first;
}
return PocketDb::ShortTxType::NotSet;
}
#include "pocketdb/helpers/ShortFormRepositoryHelper.h"

std::optional<std::vector<PocketDb::ShortTxOutput>> _parseOutputs(const std::string& jsonStr)
{
Expand Down Expand Up @@ -410,4 +303,4 @@ void PocketHelpers::NotificationSummaryReconstructor::FeedRow(sqlite3_stmt* stmt
if (auto type = PocketHelpers::ShortTxTypeConvertor::strToType(typeStr); type != PocketDb::ShortTxType::NotSet) {
m_result[address][type]++;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// Distributed under the Apache 2.0 software license, see the accompanying
// https://www.apache.org/licenses/LICENSE-2.0

#ifndef POCKETDB_SHORTFORMHELPER_H
#define POCKETDB_SHORTFORMHELPER_H
#ifndef POCKETDB_SHORTFORMREPOSITORYSHELPER_H
#define POCKETDB_SHORTFORMREPOSITORYSHELPER_H

#include "pocketdb/models/shortform/ShortForm.h"
#include "pocketdb/repositories/RowAccessor.hpp"

#include "univalue.h"
#include "sqlite3.h"
#include "pocketdb/helpers/ShortFormModelsHelper.h"

#include <string>
#include <map>
Expand All @@ -19,43 +16,7 @@
namespace PocketHelpers
{
using namespace PocketDb;

class ShortTxTypeConvertor
{
public:
static std::string toString(ShortTxType type);
static ShortTxType strToType(const std::string& typeStr);
};

class ShortTxFilterValidator
{
public:
class Notifications
{
public:
static bool IsFilterAllowed(ShortTxType type);
};

class NotificationsSummary
{
public:
static bool IsFilterAllowed(ShortTxType type);
};

class Activities
{
public:
static bool IsFilterAllowed(ShortTxType type);
};

class Events
{
public:
static bool IsFilterAllowed(ShortTxType type);
};
};

// STMT here is used to avoid including here any of sqlite3 headers, however
// STMT here is used to avoid including here any of sqlite3 headers, however
// it is expected that STMT is a correct sqlite3_stmt ptr.
// QueryPrarams can differ between queries.
template <class STMT, class QueryParams>
Expand Down Expand Up @@ -158,4 +119,4 @@ namespace PocketHelpers
};
}

#endif // POCKETDB_SHORTFORMHELPER_H
#endif // POCKETDB_SHORTFORMREPOSITORYSHELPER_H
Loading

0 comments on commit 1c3de31

Please sign in to comment.