Skip to content

Commit

Permalink
Updated short forms
Browse files Browse the repository at this point in the history
  • Loading branch information
lostystyg committed Jun 2, 2022
1 parent 03c0bd4 commit b8f1308
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 17 deletions.
42 changes: 41 additions & 1 deletion src/pocketdb/models/shortform/ShortAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,44 @@ UniValue PocketDb::ShortAccount::Serialize() const
data.pushKV("reputation", m_reputation);

return data;
}
}

const std::string& PocketDb::ShortAccount::GetName() const
{
return m_name;
}

void PocketDb::ShortAccount::SetName(const std::string& name)
{
m_name = name;
}

const std::string& PocketDb::ShortAccount::GetAvatar() const
{
return m_avatar;
}

void PocketDb::ShortAccount::SetAvatar(const std::string& avatar)
{
m_avatar = avatar;
}

const std::string& PocketDb::ShortAccount::GetBadge() const
{
return m_badge;
}

void PocketDb::ShortAccount::SetBadge(const std::string& badge)
{
m_badge = badge;
}

const int64_t& PocketDb::ShortAccount::GetReputation() const
{
return m_reputation;
}

void PocketDb::ShortAccount::SetReputation(const int64_t& reputation)
{
m_reputation = reputation;
}
12 changes: 11 additions & 1 deletion src/pocketdb/models/shortform/ShortAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ namespace PocketDb
{
public:
ShortAccount(std::string name, std::string avatar, std::string badge, int64_t reputation);
ShortAccount() = default;
UniValue Serialize() const;

const std::string& GetName() const;
void SetName(const std::string& name);
const std::string& GetAvatar() const;
void SetAvatar(const std::string& name);
const std::string& GetBadge() const;
void SetBadge(const std::string& name);
const int64_t& GetReputation() const;
void SetReputation(const int64_t& reputation);
private:
std::string m_avatar;
std::string m_name;
std::string m_badge;
int64_t m_reputation;
int64_t m_reputation {0};
};
}

Expand Down
18 changes: 15 additions & 3 deletions src/pocketdb/models/shortform/ShortForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@

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

PocketDb::ShortForm::ShortForm(ShortTxData txData, std::optional<ShortTxData> relatedContent)
: m_txData(std::move(txData)),
#include "pocketdb/helpers/ShortFormHelper.h"

PocketDb::ShortForm::ShortForm(PocketDb::ShortTxType type, ShortTxData txData, std::optional<ShortTxData> relatedContent)
: m_type(type),
m_txData(std::move(txData)),
m_relatedContent(std::move(relatedContent))
{}

UniValue PocketDb::ShortForm::Serialize() const
{
auto data = m_txData.Serialize();
data.pushKV("type", PocketHelpers::ShortTxTypeConvertor::toString(m_type));
if (m_relatedContent) data.pushKV("relatedContent", m_relatedContent->Serialize());

return data;
}
}

PocketDb::ShortTxType PocketDb::ShortForm::GetType() const { return m_type; }

const PocketDb::ShortTxData& PocketDb::ShortForm::GetTxData() const { return m_txData; }

const std::optional<PocketDb::ShortTxData>& PocketDb::ShortForm::GetRelaytedContent() const { return m_relatedContent; }

void PocketDb::ShortForm::SetRelatedContent(const std::optional<ShortTxData> &relatedContent) { m_relatedContent = relatedContent; }
10 changes: 9 additions & 1 deletion src/pocketdb/models/shortform/ShortForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define POCKETDB_SHORTFORM_H

#include "pocketdb/models/shortform/ShortTxData.h"
#include "pocketdb/models/shortform/ShortTxType.h"

#include <optional>

Expand All @@ -14,10 +15,17 @@ namespace PocketDb
class ShortForm
{
public:
ShortForm(ShortTxData txData, std::optional<ShortTxData> relatedContent);
// TODO tomorrow: serialize me correctly!!!
ShortForm(PocketDb::ShortTxType type, ShortTxData txData, std::optional<ShortTxData> relatedContent);

UniValue Serialize() const;

PocketDb::ShortTxType GetType() const;
const ShortTxData& GetTxData() const;
const std::optional<ShortTxData>& GetRelaytedContent() const;
void SetRelatedContent(const std::optional<ShortTxData> &relatedContent);
private:
PocketDb::ShortTxType m_type;
ShortTxData m_txData;
std::optional<ShortTxData> m_relatedContent;
};
Expand Down
49 changes: 43 additions & 6 deletions src/pocketdb/models/shortform/ShortTxData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,64 @@
#include "pocketdb/helpers/ShortFormHelper.h"


PocketDb::ShortTxData::ShortTxData(std::string hash, PocketDb::ShortTxType type, std::string address,
std::optional<ShortAccount> account, std::optional<int> val,
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)
: m_hash(std::move(hash)),
m_type(type),
m_txType(txType),
m_height(std::move(height)),
m_blockNum(std::move(blockNum)),
m_address(std::move(address)),
m_account(std::move(account)),
m_val(std::move(val)),
m_description(std::move(description))
{}

PocketDb::ShortTxData::ShortTxData(std::string hash, PocketTx::TxType txType)
: m_hash(std::move(hash)),
m_txType(txType)
{}

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

data.pushKV("hash", m_hash);
data.pushKV("type", PocketHelpers::ShortTxTypeConvertor::toString(m_type));
data.pushKV("address", m_address);
data.pushKV("txType", (int)m_txType);
if (m_height) data.pushKV("height", m_height.value());
if (m_blockNum) data.pushKV("blockNum", m_blockNum.value());
if (m_address) data.pushKV("address", m_address.value());
if (m_account) data.pushKV("account", m_account->Serialize());
if (m_val) data.pushKV("val", m_val.value());
if (m_description) data.pushKV("description", m_description.value());

return data;
}
}

const std::string& PocketDb::ShortTxData::GetHash() const { return m_hash; }

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

void PocketDb::ShortTxData::SetAddress(const std::optional<std::string>& address) { m_address = address; }

PocketTx::TxType PocketDb::ShortTxData::GetTxType() const { return m_txType; }

const std::optional<int64_t>& PocketDb::ShortTxData::GetHeight() const { return m_height; }

void PocketDb::ShortTxData::SetHeight(const std::optional<int64_t>& height) { m_height = height; }

const std::optional<int64_t>& PocketDb::ShortTxData::GetBlockNum() const { return m_blockNum; }

void PocketDb::ShortTxData::SetBlockNum(const std::optional<int64_t>& blockNum) { m_blockNum = blockNum; }

const std::optional<PocketDb::ShortAccount>& PocketDb::ShortTxData::GetAccount() const { return m_account; }

void PocketDb::ShortTxData::SetAccount(const std::optional<ShortAccount>& account) { m_account = account; }

const std::optional<int>& PocketDb::ShortTxData::GetVal() const { return m_val; }

void PocketDb::ShortTxData::SetVal(const std::optional<int>& val) { m_val = val; }

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

void PocketDb::ShortTxData::SetDescription(const std::optional<std::string>& description) { m_description = description; }
28 changes: 23 additions & 5 deletions src/pocketdb/models/shortform/ShortTxData.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

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

#include <univalue.h>

Expand All @@ -20,14 +19,33 @@ namespace PocketDb
class ShortTxData
{
public:
ShortTxData(std::string hash, PocketDb::ShortTxType type, std::string address,
std::optional<ShortAccount> account, std::optional<int> val,
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);
ShortTxData(std::string hash, PocketTx::TxType txType);

UniValue Serialize() const;

const std::string& GetHash() const;
const std::optional<std::string>& GetAddress() const;
void SetAddress(const std::optional<std::string>& address);
PocketTx::TxType GetTxType() const;
const std::optional<int64_t>& GetHeight() const;
void SetHeight(const std::optional<int64_t>& height);
const std::optional<int64_t>& GetBlockNum() const;
void SetBlockNum(const std::optional<int64_t>& height);
const std::optional<ShortAccount>& GetAccount() const;
void SetAccount(const std::optional<ShortAccount>& account);
const std::optional<int>& GetVal() const;
void SetVal(const std::optional<int>& val);
const std::optional<std::string>& GetDescription() const;
void SetDescription(const std::optional<std::string>& description);
private:
std::string m_hash;
PocketDb::ShortTxType m_type;
std::string m_address; // Creator of tx.
PocketTx::TxType m_txType;
std::optional<std::string> m_address; // Creator of tx. // This field is optional if we are requesting a lot of txs for one address and want to not duplicate meaningless data
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<int> m_val;
std::optional<std::string> m_description; // Short description of content, e.x. first lines of post's text
Expand Down

0 comments on commit b8f1308

Please sign in to comment.