Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: events, push notifications and activities #302

Merged
merged 145 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
9722326
Using network id instead of string for getting pocketnet developers
lostystyg Apr 18, 2022
c0e9504
Method to get
lostystyg Apr 18, 2022
af71bdf
Base events logic
lostystyg Apr 25, 2022
dbea23e
Merge remote-tracking branch 'origin/0.21.todo' into feature/events
lostystyg Apr 25, 2022
3d8e46b
Do not check for last for boost events
lostystyg Apr 25, 2022
7a51e15
Better indexing content from private subscribers event
lostystyg Apr 25, 2022
192ad0c
Events optimization
lostystyg Apr 29, 2022
7f3d953
Fixed events rpc description
lostystyg Apr 29, 2022
2600f31
Sorting events by height outside of sqlite
lostystyg Apr 30, 2022
3deae2e
FIlters, height and blocknum for events request
lostystyg May 4, 2022
244a198
Fixed filtering for events
lostystyg May 4, 2022
19591f2
Updated events
lostystyg May 5, 2022
d77c6b6
Fixed filtering for events
lostystyg May 6, 2022
086a1fa
Fixed binding for events
lostystyg May 6, 2022
1ae34c2
privatecontent for events
lostystyg May 6, 2022
b7ec0f7
constant depth for events
lostystyg May 6, 2022
4030e74
Events for single address
lostystyg May 6, 2022
8d23c2e
Updated args description for getevents
lostystyg May 6, 2022
78681c8
Forgotten finalizing stmt
lostystyg May 6, 2022
0b2aca0
Raw sql query to get all events at height for each account
lostystyg May 30, 2022
dfd80a5
Added short forms
lostystyg May 30, 2022
03c0bd4
ShortTxType for short forms
lostystyg May 30, 2022
b8f1308
Updated short forms
lostystyg Jun 2, 2022
7127a3e
Short forms for events
lostystyg Jun 2, 2022
423d4f9
Merge remote-tracking branch 'origin/0.21' into feature/events
lostystyg Jun 2, 2022
aff9e13
Events fixes
lostystyg Jun 6, 2022
0421fbf
Optimizing event queries
lostystyg Jun 6, 2022
367fa1a
Formatting
andyoknen Apr 22, 2022
0c3319a
Downgrade likers count for testnet
andyoknen May 23, 2022
134f309
Throwing in case of event reconstructor error
lostystyg Jun 6, 2022
c97d7f5
Fixed description for scores events
lostystyg Jun 6, 2022
af47ba0
Fix comment answers sql index
andyoknen Jun 10, 2022
a62fd17
Fixed select ordering in events
boommyop Jun 10, 2022
011f94f
Fix sql typo
andyoknen Jun 10, 2022
7805b8e
Sql fixes
andyoknen Jun 10, 2022
6d09852
comment
andyoknen Jun 10, 2022
1b5a496
Add height limit for answer comments
andyoknen Jun 10, 2022
775c8d4
index comment answer
andyoknen Jun 10, 2022
e4f3666
Comment answer events fulfilled with data
boommyop Jun 10, 2022
7b2c630
Events queries formatting
boommyop Jun 10, 2022
337c1ef
Disabled hight border in related content for events
boommyop Jun 10, 2022
576fed8
Fixed events height
boommyop Jun 10, 2022
854e6f5
Donate value for comment event
boommyop Jun 10, 2022
156ed36
Answer fixes for events
boommyop Jun 10, 2022
3207e0f
Merge branch '0.21' into feature/events
lostystyg Jun 13, 2022
78eb615
Merge branch '0.21' into feature/events
lostystyg Jun 23, 2022
5c9755a
Some minor fixes
lostystyg Jun 24, 2022
21b3c71
Merge branch '0.21' into feature/events
lostystyg Jun 27, 2022
8090d0e
Merge branch 'minor_fixes' into feature/events
lostystyg Jun 27, 2022
f862108
Merge branch '0.21' into feature/events
lostystyg Jun 27, 2022
b8f37cb
Merge remote-tracking branch 'origin/0.21' into feature/events
lostystyg Jun 28, 2022
b9f3b6a
Restructured events
lostystyg Jun 29, 2022
061a7ab
A bit generalization in processing filters for events
lostystyg Jun 29, 2022
9c8a9b3
Fixed ShortAccount
lostystyg Jul 1, 2022
16a3455
Notifications
lostystyg Jul 1, 2022
ef32565
Merge branch '0.21' into feature/events
lostystyg Jul 1, 2022
b227a1c
Extracted common bind for notifications
lostystyg Jul 4, 2022
6828322
Money notification
lostystyg Jul 4, 2022
a665883
Merge branch '0.21' into feature/events
lostystyg Jul 5, 2022
5e1740f
Updated getevents rpc description
lostystyg Jul 5, 2022
60e0489
Updated getnotifications rpc description
lostystyg Jul 5, 2022
1576c8d
Only orig entries for notifications + some optimizations
lostystyg Jul 6, 2022
071f6ed
Ignore badge fort short account
lostystyg Jul 6, 2022
d560b5a
Fixed acc's rep for getevents
lostystyg Jul 6, 2022
3665c80
Renamed notifications rpc
lostystyg Jul 8, 2022
f3a2026
Base activities rpc request
lostystyg Jul 8, 2022
638c874
Fixed answers request for activities
lostystyg Jul 8, 2022
b5d0c40
Added comments for activities
lostystyg Jul 8, 2022
0a936ad
Subscriber activity
lostystyg Jul 8, 2022
d3c243d
Comment score activity
lostystyg Jul 8, 2022
5bb78a6
Updated activities query
lostystyg Jul 12, 2022
5d7e566
Inner join instead of cross for activities and events
lostystyg Jul 12, 2022
aaac24a
Fixed content description for contentscore in activities
lostystyg Jul 13, 2022
848abca
Fixed typo in contentscore for activities
lostystyg Jul 13, 2022
39b478d
Ignoring empty avatar for short form account
lostystyg Jul 13, 2022
5e8b806
Fixed var name for events contentscore
lostystyg Jul 13, 2022
5c26124
Moved pocketnetteam posts for notifications to a specific key in answer
lostystyg Jul 15, 2022
427d320
Fixed reposts for notifications
lostystyg Jul 15, 2022
e3f474b
Added optional related content (in case of reposts) for pocketnetteam…
lostystyg Jul 15, 2022
1d0d17e
getnotification better todos and fixed index
lostystyg Jul 18, 2022
814a958
Fix incoming money
andyoknen Jul 18, 2022
8c423e4
Optimize reposts query
andyoknen Jul 18, 2022
dadabe0
Fix private content from subscribers (not reposts)
andyoknen Jul 18, 2022
e265c7f
Optimize reposts
andyoknen Jul 18, 2022
c137b10
Fixed binds for notifications
lostystyg Jul 18, 2022
91d8529
Optimizing pocketnetteam notifications
lostystyg Jul 18, 2022
c01a274
Optimizing activity queries
lostystyg Jul 19, 2022
7e865aa
Fixed subscriber in activities
lostystyg Jul 20, 2022
f782b68
Fixed repost queries for activities and events
lostystyg Jul 20, 2022
fabcc4e
Inner join instead of cross for repost in activities
lostystyg Jul 20, 2022
86e5df5
Full comment text in description for events and activities
lostystyg Jul 20, 2022
d60cfd3
A bit cosmetics for events
lostystyg Jul 20, 2022
eb5c9e6
Merge branch '0.21' into feature/events
lostystyg Jul 22, 2022
9845755
Orig height for activities
lostystyg Jul 22, 2022
67febbe
Fixed referals for events
lostystyg Jul 22, 2022
a433e3a
Removed orig height from activities because it breaks pagination
lostystyg Aug 8, 2022
fa8543b
Merge branch '0.21' into feature/events
lostystyg Aug 10, 2022
3ae1ff8
Fixed address positioning in sql query for activities in ContentScore…
lostystyg Aug 10, 2022
1b256cd
Explicitly set index for account joins in activities
lostystyg Aug 11, 2022
3339a73
Removed unnecessary todos
lostystyg Aug 11, 2022
5365be1
Correct ordering by original txs in activities
lostystyg Aug 11, 2022
3a49aa5
Merge remote-tracking branch 'origin/0.21' into feature/events
lostystyg Aug 11, 2022
c26ddf0
Merge remote-tracking branch 'origin/0.21' into feature/events
lostystyg Aug 12, 2022
29164ac
Fixed help for getnotifications
lostystyg Aug 15, 2022
46edf27
Notifications summary
lostystyg Aug 17, 2022
fcf526c
Merge remote-tracking branch 'origin/fixes/multiplelocks' into featur…
lostystyg Aug 19, 2022
1d371a0
Allow to specify union separator
lostystyg Aug 20, 2022
f1be170
Optimization and fixed for notifications summary queries
lostystyg Aug 20, 2022
35375ed
Validating filters for getnotificationssummary
lostystyg Aug 20, 2022
6057f91
Removed commented out queries for notifications
lostystyg Aug 20, 2022
99c1108
Fixed typo in query
lostystyg Aug 20, 2022
9c7438f
Merge remote-tracking branch 'origin/0.21' into feature/events
lostystyg Aug 22, 2022
5732263
Removed todo for money in activities
lostystyg Aug 22, 2022
876e7b5
Fixed crash if non-valid filters are specified for notifications/acti…
lostystyg Aug 24, 2022
fcb2fed
Removed pocketnetteam from events and activities
lostystyg Aug 24, 2022
ac03dcb
Validate filters for activities on rpc level
lostystyg Aug 24, 2022
e4c102c
Validate filters for events on rpc level
lostystyg Aug 24, 2022
b5631e7
Merge remote-tracking branch 'origin/0.21' into feature/events
lostystyg Aug 24, 2022
8848937
Removed reposts from activities
lostystyg Aug 24, 2022
e291315
Removed not up to date todo
lostystyg Aug 25, 2022
077f0f2
Added blocking shorttype
lostystyg Aug 25, 2022
f6fa4a4
Full history for notifications
lostystyg Aug 30, 2022
328a3ec
Added root tx hash to shortform
lostystyg Aug 30, 2022
cf5021c
Collect roottxhash in activity queries
lostystyg Aug 30, 2022
cabb060
All action history for comments and answers in activities
lostystyg Aug 30, 2022
736748f
Some todo's
lostystyg Aug 30, 2022
c29ab12
Removed unnecessary todo
lostystyg Aug 30, 2022
c23e94c
Added optional multiple addresses to shortform
lostystyg Aug 31, 2022
6d8148d
Added blockings for notifications
lostystyg Sep 1, 2022
f8924a6
Ported notifications from 0.20-based dropped branch
lostystyg Sep 1, 2022
66e9054
Removed trash from badge field in notification queries
lostystyg Sep 1, 2022
2b3a016
Removed trash from badge in activities
lostystyg Sep 1, 2022
8ef4a5b
Merge remote-tracking branch 'origin/0.21' into feature/events
lostystyg Sep 1, 2022
77f9e87
Order outputs by number for activities and notifications
lostystyg Sep 2, 2022
2453407
Reuse height binder in notifications for money
lostystyg Sep 5, 2022
88ed33a
Removed number from outputs in activities and notifications
lostystyg Sep 5, 2022
57f275e
Cosmetics for blocking query in activities
lostystyg Sep 5, 2022
5b04354
Removed outdated comment
lostystyg Sep 5, 2022
710886c
Correctly filling notifications answer
lostystyg Sep 8, 2022
1344fe5
Language for short account
lostystyg Sep 8, 2022
24e63f4
Filling notification result with account info
lostystyg Sep 8, 2022
32b0e15
Optimized notifications collecting
lostystyg Sep 8, 2022
bbd0574
Merge remote-tracking branch 'origin/0.21' into feature/events
lostystyg Sep 8, 2022
314c1a8
Temporarily disable getevents rpc
lostystyg Sep 8, 2022
b6b9f45
Fix new line
lostystyg Sep 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ add_library(${POCKETDB}
pocketdb/models/shortform/ShortAccount.h
pocketdb/models/shortform/ShortAccount.cpp
pocketdb/models/shortform/ShortTxType.h
pocketdb/models/shortform/ShortTxOutput.h
pocketdb/models/shortform/ShortTxOutput.cpp
)
target_link_libraries(${POCKETDB} PRIVATE ${POCKETCOIN_COMMON} ${POCKETCOIN_UTIL} ${POCKETCOIN_CRYPTO} univalue leveldb)

Expand Down
6 changes: 4 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ POCKETDB_H = \
pocketdb/models/shortform/ShortForm.h \
pocketdb/models/shortform/ShortAccount.h \
pocketdb/models/shortform/ShortTxData.h \
pocketdb/models/shortform/ShortTxType.h
pocketdb/models/shortform/ShortTxType.h \
pocketdb/models/shortform/ShortTxOutput.h

# PocketDb CPP
POCKETDB_CPP = \
Expand Down Expand Up @@ -310,7 +311,8 @@ POCKETDB_CPP = \
pocketdb/models/dto/moderation/Flag.cpp \
pocketdb/models/shortform/ShortForm.cpp \
pocketdb/models/shortform/ShortAccount.cpp \
pocketdb/models/shortform/ShortTxData.cpp
pocketdb/models/shortform/ShortTxData.cpp \
pocketdb/models/shortform/ShortTxOutput.cpp

# CORE
POCKETCOIN_CORE_H = \
Expand Down
1 change: 1 addition & 0 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ void HTTPSocket::BindAddress(std::string ipAddr, int port)
{
CNetAddr addr;
if (ipAddr.empty() || (LookupHost(ipAddr, addr, false) && addr.IsBindAny())) {
// TODO (brangr, lostystyg): only for private ports
LogPrintf("WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet\n");
}
m_boundSockets.push_back(bind_handle);
Expand Down
8 changes: 4 additions & 4 deletions src/pocketdb/helpers/PocketnetHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace PocketHelpers
{
using namespace std;

static map<string, vector<string>> PocketnetDevelopers{
{"main", {
static map<NetworkId, vector<string>> PocketnetDevelopers{
{NetworkId::NetworkMain, {
"P9EkPPJPPRYxmK541WJkmH8yBM4GuWDn2m",
"PUGBtfmivvcg1afnEt9vqVi3yZ7v6S9BcC",
"PDtuJDVXaq82HH7fafgwBmcoxbqqWdJ9u9",
Expand All @@ -28,7 +28,7 @@ namespace PocketHelpers
"PMyjUzHtzsmbejB87ATbrcQNatiGsT4NzG",
"PHdW4pwWbFdoofVhSEfPSHgradmrvZdbE5"
}},
{"test", {
{NetworkId::NetworkTest, {
"TG69Jioc81PiwMAJtRanfZqUmRY4TUG7nt",
"TLnfXcFNxxrpEUUzrzZvbW7b9gWFtAcc8x",
"TYMo5HRFpc7tqzccaVifx7s2x2ZDqMikCR",
Expand All @@ -37,7 +37,7 @@ namespace PocketHelpers

static inline bool IsDeveloper(const string& address)
{
auto net = Params().NetworkIDString();
auto net = Params().NetworkID();
return find(PocketnetDevelopers[net].begin(), PocketnetDevelopers[net].end(), address) != PocketnetDevelopers[net].end();
}

Expand Down
56 changes: 55 additions & 1 deletion src/pocketdb/helpers/ShortFormHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static const std::map<PocketDb::ShortTxType, std::string>& GetTypesMap() {
{ PocketDb::ShortTxType::PrivateContent, "privatecontent" },
{ PocketDb::ShortTxType::Boost, "boost" },
{ PocketDb::ShortTxType::Repost, "repost" },
{ PocketDb::ShortTxType::Blocking, "blocking" }
};
return typesMap;
}
Expand All @@ -41,7 +42,60 @@ bool PocketHelpers::ShortTxFilterValidator::Notifications::IsFilterAllowed(Pocke
PocketDb::ShortTxType::Money,
PocketDb::ShortTxType::Answer,
PocketDb::ShortTxType::PrivateContent,
PocketDb::ShortTxType::Boost
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();
Expand Down
18 changes: 18 additions & 0 deletions src/pocketdb/helpers/ShortFormHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ namespace PocketHelpers
public:
static bool IsFilterAllowed(PocketDb::ShortTxType type);
};

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

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

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

// STMT here is used to avoid including here any of sqlite3 headers, however
Expand Down
3 changes: 3 additions & 0 deletions src/pocketdb/migrations/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ namespace PocketDb
create index if not exists Transactions_Id_Last on Transactions (Id, Last);
create index if not exists Transactions_Hash_Height on Transactions (Hash, Height);
create index if not exists Transactions_Height_Type on Transactions (Height, Type);
create index if not exists Transactions_Hash_Type_Height on Transactions (Hash, Type, Height);
create index if not exists TxOutputs_AddressHash_TxHeight_TxHash on TxOutputs (AddressHash, TxHeight, TxHash);
create index if not exists Transactions_Type_Last_String1_Height_Id on Transactions (Type, Last, String1, Height, Id);
create index if not exists Transactions_Type_Last_String2_Height on Transactions (Type, Last, String2, Height);
create index if not exists Transactions_Type_Last_String3_Height on Transactions (Type, Last, String3, Height);
create index if not exists Transactions_Type_Last_String4_Height on Transactions (Type, Last, String4, Height);
create index if not exists Transactions_Type_Last_String5_Height on Transactions (Type, Last, String5, Height);
create index if not exists Transactions_Type_Last_String1_String2_Height on Transactions (Type, Last, String1, String2, Height);
create index if not exists Transactions_Type_Last_Height_String5_String1 on Transactions (Type, Last, Height, String5, String1);
create index if not exists Transactions_Type_Last_Height_Id on Transactions (Type, Last, Height, Id);
Expand Down
11 changes: 11 additions & 0 deletions src/pocketdb/models/shortform/ShortAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ UniValue PocketDb::ShortAccount::Serialize() const
data.pushKV("avatar", m_avatar);
data.pushKV("badge", m_badge);
data.pushKV("reputation", m_reputation);
if (m_lang) data.pushKV("lang", *m_lang);

return data;
}
Expand Down Expand Up @@ -64,3 +65,13 @@ void PocketDb::ShortAccount::SetReputation(const int64_t& reputation)
{
m_reputation = reputation;
}

const std::optional<std::string>& PocketDb::ShortAccount::GetLang() const
{
return m_lang;
}

void PocketDb::ShortAccount::SetLang(const std::optional<std::string>& lang)
{
m_lang = lang;
}
5 changes: 4 additions & 1 deletion src/pocketdb/models/shortform/ShortAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <univalue.h>

#include <string>

#include <optional>

namespace PocketDb
{
Expand All @@ -27,10 +27,13 @@ namespace PocketDb
void SetBadge(const std::string& name);
const int64_t& GetReputation() const;
void SetReputation(const int64_t& reputation);
const std::optional<std::string>& GetLang() const;
void SetLang(const std::optional<std::string>& lang);
private:
std::string m_avatar;
std::string m_name;
std::string m_badge;
std::optional<std::string> m_lang;
int64_t m_reputation {0};
};
}
Expand Down
1 change: 0 additions & 1 deletion src/pocketdb/models/shortform/ShortForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace PocketDb
class ShortForm
{
public:
// TODO tomorrow: serialize me correctly!!!
ShortForm(PocketDb::ShortTxType type, ShortTxData txData, std::optional<ShortTxData> relatedContent);

UniValue Serialize() const;
Expand Down
52 changes: 49 additions & 3 deletions src/pocketdb/models/shortform/ShortTxData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
PocketDb::ShortTxData::ShortTxData(std::string hash, PocketTx::TxType txType, std::optional<std::string> address, std::optional<int64_t> height,
std::optional<int64_t> blockNum, std::optional<ShortAccount> account, std::optional<int> val,
std::optional<std::string> description, std::optional<std::string> commentParentId,
std::optional<std::string> commentAnswerId
std::optional<std::string> commentAnswerId, std::optional<std::string> rootTxHash,
std::optional<std::vector<std::pair<std::string, std::optional<ShortAccount>>>> multipleAddresses
)
: m_hash(std::move(hash)),
m_txType(txType),
Expand All @@ -21,7 +22,9 @@ PocketDb::ShortTxData::ShortTxData(std::string hash, PocketTx::TxType txType, st
m_val(std::move(val)),
m_description(std::move(description)),
m_commentParentId(std::move(commentParentId)),
m_commentAnswerId(std::move(commentAnswerId))
m_commentAnswerId(std::move(commentAnswerId)),
m_rootTxHash(std::move(rootTxHash)),
m_multipleAddresses(std::move(multipleAddresses))
{}

PocketDb::ShortTxData::ShortTxData(std::string hash, PocketTx::TxType txType)
Expand All @@ -43,6 +46,33 @@ UniValue PocketDb::ShortTxData::Serialize() const
if (m_description) data.pushKV("description", m_description.value());
if (m_commentParentId) data.pushKV("commentParentId", m_commentParentId.value());
if (m_commentAnswerId) data.pushKV("commentAnswerId", m_commentAnswerId.value());
if (m_rootTxHash) data.pushKV("rootTxHash", *m_rootTxHash);
if (m_inputs) {
UniValue inputs (UniValue::VARR);
std::vector<UniValue> tmp;
for (const auto& input: *m_inputs) {
tmp.emplace_back(std::move(input.Serialize()));
}
inputs.push_backV(tmp);
data.pushKV("inputs", inputs);
}
if (m_outputs) {
UniValue outputs (UniValue::VARR);
std::vector<UniValue> tmp;
for (const auto& output: *m_outputs) {
tmp.emplace_back(std::move(output.Serialize()));
}
outputs.push_backV(tmp);
data.pushKV("outputs", outputs);
}
if (m_multipleAddresses) {
UniValue multipleAddresses(UniValue::VOBJ);
multipleAddresses.reserveKVSize(m_multipleAddresses->size());
for (const auto& addressData: *m_multipleAddresses) {
multipleAddresses.pushKV(addressData.first, std::move(addressData.second->Serialize()), false);
}
data.pushKV("multipleAddresses", multipleAddresses);
}

return data;
}
Expand Down Expand Up @@ -81,4 +111,20 @@ const std::optional<std::string>& PocketDb::ShortTxData::GetCommentParentId() co

void PocketDb::ShortTxData::SetCommentAnswerId(const std::optional<std::string>& commentAnswerId) { m_commentAnswerId = commentAnswerId; }

const std::optional<std::string>& PocketDb::ShortTxData::GetCommentAnswerId() const { return m_commentAnswerId; }
const std::optional<std::string>& PocketDb::ShortTxData::GetCommentAnswerId() const { return m_commentAnswerId; }

void PocketDb::ShortTxData::SetRootTxHash(const std::optional<std::string>& rootTxHash) { m_rootTxHash = rootTxHash; }

const std::optional<std::string>& PocketDb::ShortTxData::GetRootTxHash() const { return m_rootTxHash; }

void PocketDb::ShortTxData::SetMultipleAddresses(const std::optional<std::vector<std::pair<std::string, std::optional<ShortAccount>>>>& multipleAddresses) { m_multipleAddresses = multipleAddresses; }

const std::optional<std::vector<std::pair<std::string, std::optional<PocketDb::ShortAccount>>>>& PocketDb::ShortTxData::GetMultipleAddresses() { return m_multipleAddresses; }

void PocketDb::ShortTxData::SetOutputs(const std::optional<std::vector<ShortTxOutput>>& outputs) { m_outputs = outputs; }

const std::optional<std::vector<PocketDb::ShortTxOutput>>& PocketDb::ShortTxData::GetOutputs() const { return m_outputs; }

void PocketDb::ShortTxData::SetInputs(const std::optional<std::vector<ShortTxOutput>>& inputs) { m_inputs = inputs; }

const std::optional<std::vector<PocketDb::ShortTxOutput>>& PocketDb::ShortTxData::GetInputs() const { return m_inputs; }
16 changes: 15 additions & 1 deletion src/pocketdb/models/shortform/ShortTxData.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "pocketdb/models/base/PocketTypes.h"
#include "pocketdb/models/shortform/ShortAccount.h"
#include "pocketdb/models/shortform/ShortTxOutput.h"

#include <univalue.h>

Expand All @@ -23,7 +24,8 @@ namespace PocketDb
std::optional<int64_t> height, std::optional<int64_t> blockNum,
std::optional<ShortAccount> account, std::optional<int> val,
std::optional<std::string> description,
std::optional<std::string> commentParentId, std::optional<std::string> commentAnswerId);
std::optional<std::string> commentParentId, std::optional<std::string> commentAnswerId,
std::optional<std::string> rootTxHash, std::optional<std::vector<std::pair<std::string, std::optional<ShortAccount>>>> multipleAddresses);

ShortTxData(std::string hash, PocketTx::TxType txType);

Expand All @@ -47,6 +49,14 @@ namespace PocketDb
const std::optional<std::string>& GetCommentParentId() const;
void SetCommentAnswerId(const std::optional<std::string>& commentAnswerId);
const std::optional<std::string>& GetCommentAnswerId() const;
void SetRootTxHash(const std::optional<std::string>& rootTxHash);
const std::optional<std::string>& GetRootTxHash() const;
void SetMultipleAddresses(const std::optional<std::vector<std::pair<std::string, std::optional<ShortAccount>>>>& multipleAddresses);
const std::optional<std::vector<std::pair<std::string, std::optional<ShortAccount>>>>& GetMultipleAddresses();
void SetOutputs(const std::optional<std::vector<ShortTxOutput>>& outputs);
const std::optional<std::vector<ShortTxOutput>>& GetOutputs() const;
void SetInputs(const std::optional<std::vector<ShortTxOutput>>& inputs);
const std::optional<std::vector<ShortTxOutput>>& GetInputs() const;

private:
std::string m_hash;
Expand All @@ -55,8 +65,12 @@ namespace PocketDb
std::optional<int64_t> m_height; // This field is optional if we are requesting a lot of txs for one height and want to not duplicate meaningless data
std::optional<int64_t> m_blockNum; // TODO (losty): probably some filters for these fields
std::optional<ShortAccount> m_account; // Account data associated with address
std::optional<std::vector<std::pair<std::string, std::optional<ShortAccount>>>> m_multipleAddresses;
std::optional<int> m_val;
std::optional<std::vector<ShortTxOutput>> m_inputs;
std::optional<std::vector<ShortTxOutput>> m_outputs;
std::optional<std::string> m_description; // Short description of content, e.x. first lines of post's text
std::optional<std::string> m_rootTxHash;

// Special-case fields for comments
std::optional<std::string> m_commentParentId;
Expand Down
45 changes: 45 additions & 0 deletions src/pocketdb/models/shortform/ShortTxOutput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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/models/shortform/ShortTxOutput.h"


UniValue PocketDb::ShortTxOutput::Serialize() const
{
UniValue data (UniValue::VOBJ);

if (m_txHash) data.pushKV("txhash", *m_txHash);
if (m_spentTxHash) data.pushKV("spenttxhash", *m_spentTxHash);
if (m_addressHash) data.pushKV("addresshash", *m_addressHash);
if (m_number) data.pushKV("number", *m_number);
if (m_value) data.pushKV("value", *m_value);
if (m_scriptPubKey) data.pushKV("scriptpubkey", *m_scriptPubKey);

return data;
}

void PocketDb::ShortTxOutput::SetTxHash(const std::optional<std::string>& txHash) { m_txHash = txHash; }

const std::optional<std::string>& PocketDb::ShortTxOutput::GetTxHash() const { return m_txHash; }

void PocketDb::ShortTxOutput::SetSpentTxHash(const std::optional<std::string>& spentTxHash) { m_spentTxHash = spentTxHash; }

const std::optional<std::string>& PocketDb::ShortTxOutput::GetSpentTxHash() const { return m_spentTxHash; }

void PocketDb::ShortTxOutput::SetNumber(const std::optional<int>& number) { m_number = number; }

const std::optional<int>& PocketDb::ShortTxOutput::GetNumber() const { return m_number; }

void PocketDb::ShortTxOutput::SetAddressHash(const std::optional<std::string>& addressHash) { m_addressHash = addressHash; }

const std::optional<std::string>& PocketDb::ShortTxOutput::GetAddressHash() const { return m_addressHash; }

void PocketDb::ShortTxOutput::SetScriptPubKey(const std::optional<std::string>& scriptPubKey) { m_scriptPubKey = scriptPubKey; }

const std::optional<std::string>& PocketDb::ShortTxOutput::GetcriptPubKey() const { return m_scriptPubKey; }

void PocketDb::ShortTxOutput::SetValue(const std::optional<int64_t>& value) { m_value = value; }

const std::optional<int64_t>& PocketDb::ShortTxOutput::GetValue() const { return m_value; }

Loading