Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions src/pocketdb/consensus/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// https://www.apache.org/licenses/LICENSE-2.0

#include "pocketdb/consensus/Helper.h"
#include "pocketdb/models/base/PocketTypes.h"
#include "pocketdb/models/base/SocialTransaction.h"

namespace PocketConsensus
{
Expand Down Expand Up @@ -137,6 +139,11 @@ namespace PocketConsensus
// Check transactions with consensus logic
switch (*ptx->GetType())
{
// Universal Social Transaction
case SOCIAL:
return ConsensusFactoryInst_UTS.Instance(height)->Check(tx, static_pointer_cast<SocialTransaction>(ptx));

// DTOs
case ACCOUNT_SETTING:
return ConsensusFactoryInst_AccountSetting.Instance(height)->Check(tx, static_pointer_cast<AccountSetting>(ptx));
case ACCOUNT_DELETE:
Expand Down Expand Up @@ -211,6 +218,11 @@ namespace PocketConsensus
// Validate transactions with consensus logic
switch (*ptx->GetType())
{
// Universal Social Transaction
case SOCIAL:
return ConsensusFactoryInst_UTS.Instance(height)->Validate(tx, static_pointer_cast<SocialTransaction>(ptx), pBlock);

// DTOs
case ACCOUNT_SETTING:
return ConsensusFactoryInst_AccountSetting.Instance(height)->Validate(tx, static_pointer_cast<AccountSetting>(ptx), pBlock);
case ACCOUNT_DELETE:
Expand Down
5 changes: 3 additions & 2 deletions src/pocketdb/consensus/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

#include "pocketdb/helpers/TransactionHelper.h"
#include "pocketdb/models/base/Transaction.h"
#include "pocketdb/models/base/SocialTransaction.h"
#include "pocketdb/consensus/Reputation.h"


#include "pocketdb/consensus/UTS.hpp"
#include "pocketdb/consensus/social/Blocking.hpp"
#include "pocketdb/consensus/social/BlockingCancel.hpp"
#include "pocketdb/consensus/social/BoostContent.hpp"
Expand All @@ -32,10 +35,8 @@
#include "pocketdb/consensus/social/account/AccountSetting.hpp"
#include "pocketdb/consensus/social/account/AccountDelete.hpp"
#include "pocketdb/consensus/social/ContentDelete.hpp"

#include "pocketdb/consensus/moderation/Flag.hpp"
#include "pocketdb/consensus/moderation/Vote.hpp"

#include "pocketdb/consensus/barteron/Offer.hpp"
#include "pocketdb/consensus/barteron/OfferPaid.hpp"
#include "pocketdb/consensus/barteron/Account.hpp"
Expand Down
68 changes: 68 additions & 0 deletions src/pocketdb/consensus/UTS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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 POCKETCONSENSUS_UTS_HPP
#define POCKETCONSENSUS_UTS_HPP

#include "pocketdb/consensus/Social.h"
#include "pocketdb/models/base/SocialTransaction.h"

namespace PocketConsensus
{
typedef shared_ptr<SocialTransaction> SocialTransactionRef;

/*******************************************************************************************************************
* UTS consensus base class
*******************************************************************************************************************/
class UTSConsensus : public SocialConsensus<SocialTransaction>
{
public:
UTSConsensus() : SocialConsensus<SocialTransaction>()
{
Limits.Set("payload_size", 120000, 60000, 60000);
}

ConsensusValidateResult Validate(const CTransactionRef& tx, const SocialTransactionRef& ptx, const PocketBlockRef& block) override
{
if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate)
return {false, baseValidateCode};

return Success;
}

ConsensusValidateResult Check(const CTransactionRef& tx, const SocialTransactionRef& ptx) override
{
if (auto[baseCheck, baseCheckCode] = SocialConsensus::Check(tx, ptx); !baseCheck)
return {false, baseCheckCode};

return Success;
}

protected:

ConsensusValidateResult ValidateBlock(const SocialTransactionRef& ptx, const PocketBlockRef& block) override
{
return Success;
}

ConsensusValidateResult ValidateMempool(const SocialTransactionRef& ptx) override
{
return Success;
}

};

class UTSConsensusFactory : public BaseConsensusFactory<UTSConsensus>
{
public:
UTSConsensusFactory()
{
Checkpoint({ 9999999, 9999999, -1, make_shared<UTSConsensus>() });
}
};

static UTSConsensusFactory ConsensusFactoryInst_UTS;
}

#endif // POCKETCONSENSUS_UTS_HPP
30 changes: 22 additions & 8 deletions src/pocketdb/helpers/TransactionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ namespace PocketHelpers
else if (op == OR_BARTERON_OFFER_PAID)
return TxType::BARTERON_OFFER_PAID;

// UST (Universal Social Transaction)
else if (op.substr(0, 8) == OR_SOCIAL)
return TxType::SOCIAL;

return TxType::TX_DEFAULT;
}

Expand Down Expand Up @@ -169,6 +173,8 @@ namespace PocketHelpers
// TODO (aok) (v0.21.0): need remove for next generation serialization
switch (*transaction.GetType())
{
case TxType::SOCIAL:
return "Social";
case TxType::ACCOUNT_USER:
return "Users";
case TxType::ACCOUNT_SETTING:
Expand Down Expand Up @@ -293,8 +299,7 @@ namespace PocketHelpers
switch (txType)
{
case TxType::BARTERON_OFFER_PAID:
// TODO (aok) (v0.23.0): need add new transaction type
// case TxType::UNIVERSAL_TRANSACTION_NEED_NAME:
case TxType::SOCIAL:
return true;
default:
return false;
Expand Down Expand Up @@ -372,6 +377,9 @@ namespace PocketHelpers
case TX_DEFAULT:
ptx = make_shared<Default>(tx);
break;
case SOCIAL:
ptx = make_shared<SocialTransaction>(tx);
break;
case ACCOUNT_SETTING:
ptx = make_shared<AccountSetting>(tx);
break;
Expand Down Expand Up @@ -477,6 +485,9 @@ namespace PocketHelpers
case TX_DEFAULT:
ptx = make_shared<Default>();
break;
case SOCIAL:
ptx = make_shared<SocialTransaction>();
break;
case ACCOUNT_SETTING:
ptx = make_shared<AccountSetting>();
break;
Expand Down Expand Up @@ -581,6 +592,8 @@ namespace PocketHelpers
{
switch (type)
{
case SOCIAL:
return "social";
case CONTENT_DELETE:
return "contentDelete";
case CONTENT_POST:
Expand Down Expand Up @@ -638,7 +651,8 @@ namespace PocketHelpers

TxType TransactionHelper::TxIntType(const string& type)
{
if (type == "contentDelete" || type == OR_CONTENT_DELETE) return TxType::CONTENT_DELETE;
if (type == "social" || type.substr(0, 8) == OR_SOCIAL) return TxType::SOCIAL;
else if (type == "contentDelete" || type == OR_CONTENT_DELETE) return TxType::CONTENT_DELETE;
else if (type == "share" || type == "shareEdit" || type == OR_POST || type == OR_POSTEDIT) return TxType::CONTENT_POST;
else if (type == "video" || type == OR_VIDEO) return TxType::CONTENT_VIDEO;
else if (type == "article" || type == OR_ARTICLE) return TxType::CONTENT_ARTICLE;
Expand All @@ -658,11 +672,11 @@ namespace PocketHelpers
else if (type == "commentDelete" || type == OR_COMMENT_DELETE) return TxType::CONTENT_COMMENT_DELETE;
else if (type == "cScore" || type == OR_COMMENT_SCORE) return TxType::ACTION_SCORE_COMMENT;
else if (type == "contentBoost" || type == OR_CONTENT_BOOST) return TxType::BOOST_CONTENT;
else if (type == "modFlag") return TxType::MODERATION_FLAG;
else if (type == "modVote") return TxType::MODERATION_VOTE;
else if (type == "brtaccount") return TxType::BARTERON_ACCOUNT;
else if (type == "brtoffer") return TxType::BARTERON_OFFER;
else if (type == "brtofferpaid") return TxType::BARTERON_OFFER_PAID;
else if (type == "modFlag" || type == OR_MODERATION_FLAG) return TxType::MODERATION_FLAG;
else if (type == "modVote" || type == OR_MODERATION_VOTE) return TxType::MODERATION_VOTE;
else if (type == "brtaccount" || type == OR_BARTERON_ACCOUNT) return TxType::BARTERON_ACCOUNT;
else if (type == "brtoffer" || type == OR_BARTERON_OFFER) return TxType::BARTERON_OFFER;
else if (type == "brtofferpaid" || type == OR_BARTERON_OFFER_PAID) return TxType::BARTERON_OFFER_PAID;
else return TxType::NOT_SUPPORTED;
}
}
1 change: 1 addition & 0 deletions src/pocketdb/helpers/TransactionHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "pocketdb/models/base/DtoModels.h"
#include "pocketdb/models/base/PocketTypes.h"
#include "pocketdb/models/base/SocialTransaction.h"

#include "pocketdb/models/dto/money/Coinbase.h"
#include "pocketdb/models/dto/money/Coinstake.h"
Expand Down
12 changes: 10 additions & 2 deletions src/pocketdb/migrations/web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,25 @@ namespace PocketDb
);
)sql");

_tables.emplace_back(R"sql(
create table if not exists UST
(
TxId int not null,
Type int not null,
primary key (TxId, Type)
);
)sql");

//
// INDEXES
//
_indexes = R"sql(
create unique index if not exists Tags_Lang_Value on Tags (Lang, Value);
create index if not exists Tags_Lang_Value_Id on Tags (Lang, Value, Id);
create index if not exists Tags_Value on Tags (Value);

create index if not exists TagsMap_TagId_ContentId on TagsMap (TagId, ContentId);

create index if not exists BarteronOffers_OfferId_Tag_AccountId on BarteronOffers(OfferId, Tag, AccountId);
create index if not exists UST_Type_TxId on (Type, TxId);
)sql";
}
}
17 changes: 8 additions & 9 deletions src/pocketdb/models/base/PocketTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace PocketTx

// OpReturn hex codes

// Special op_return code - ust:<custom_identifier>
#define OR_SOCIAL "7573743a" // Universal social transaction - "ust:"

#define OR_USERINFO "75736572496e666f"
#define OR_ACCOUNT_SETTING "616363536574"
#define OR_ACCOUNT_DELETE "61636344656c"
Expand Down Expand Up @@ -59,12 +62,6 @@ namespace PocketTx
#define OR_COMPLAIN "636f6d706c61696e5368617265"
#define OR_MODERATION_FLAG "6d6f64466c6167" // Flag for moderation
#define OR_MODERATION_VOTE "6d6f64566f7465" // Vote from moderator
// #define OR_MODERATOR_REQUEST_SUBS "6d6f6452657153756273"
// #define OR_MODERATOR_REQUEST_COIN "6d6f64526571436f696e"
// #define OR_MODERATOR_REQUEST_CANCEL "6d6f64526571436e"
// #define OR_MODERATOR_REGISTER_SELF "6d6f6452656753656c66"
// #define OR_MODERATOR_REGISTER_REQUEST "6d6f64526567526571"
// #define OR_MODERATOR_REGISTER_CANCEL "6d6f64526567436e"


// Int tx type
Expand All @@ -76,6 +73,8 @@ namespace PocketTx
TX_COINBASE = 2,
TX_COINSTAKE = 3,

SOCIAL = 10,

ACCOUNT_USER = 100,
ACCOUNT_SETTING = 103,
ACCOUNT_DELETE = 170,
Expand Down Expand Up @@ -192,16 +191,16 @@ namespace PocketTx
}

bool IsContent() const {
return Type == TxType::CONTENT_POST ||
return Type == TxType::CONTENT_DELETE ||
Type == TxType::CONTENT_POST ||
Type == TxType::CONTENT_VIDEO ||
Type == TxType::CONTENT_ARTICLE ||
Type == TxType::CONTENT_STREAM ||
Type == TxType::CONTENT_AUDIO ||
Type == TxType::CONTENT_COLLECTION ||
Type == TxType::BARTERON_OFFER ||
Type == TxType::BARTERON_OFFER_PAID ||
Type == TxType::APP ||
Type == TxType::CONTENT_DELETE;
Type == TxType::APP;
}

bool IsComment() const
Expand Down
2 changes: 2 additions & 0 deletions src/pocketdb/models/base/SocialTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ namespace PocketTx
{
SocialTransaction::SocialTransaction() : Transaction()
{
SetType(TxType::SOCIAL);
}

SocialTransaction::SocialTransaction(const CTransactionRef& tx) : Transaction(tx)
{
SetType(TxType::SOCIAL);
}

optional<UniValue> SocialTransaction::Serialize() const
Expand Down
11 changes: 11 additions & 0 deletions src/pocketdb/repositories/web/USTRepository.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2018-2025 The Pocketnet developers
// Distributed under the Apache 2.0 software license, see the accompanying
// https://www.apache.org/licenses/LICENSE-2.0

#include "pocketdb/repositories/web/USTRepository.h"

namespace PocketDb
{


}
37 changes: 37 additions & 0 deletions src/pocketdb/repositories/web/USTRepository.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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_UST_REPOSITORY_H
#define POCKETDB_UST_REPOSITORY_H

#include "pocketdb/repositories/BaseRepository.h"

namespace PocketDb
{
using namespace PocketTx;


struct USTRequest : public Pagination
{

};


class USTRepository : public BaseRepository
{
public:
explicit USTRepository(SQLiteDatabase& db, bool timeouted) : BaseRepository(db, timeouted) {}

UniValue ustlist(const USTRequest& request);

private:

};

typedef shared_ptr<USTRepository> USTRepositoryRef;

} // namespace PocketDb

#endif // POCKETDB_UST_REPOSITORY_H

Loading