From d0f28ed9909a4e060bf623444c158f53875ac442 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Thu, 8 Sep 2022 13:56:01 +0300 Subject: [PATCH 01/49] Add type for account deleting transaction --- src/pocketdb/models/base/PocketTypes.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pocketdb/models/base/PocketTypes.h b/src/pocketdb/models/base/PocketTypes.h index 6a7b501b6..f0ab8c700 100644 --- a/src/pocketdb/models/base/PocketTypes.h +++ b/src/pocketdb/models/base/PocketTypes.h @@ -44,6 +44,7 @@ namespace PocketTx #define OR_CONTENT_DELETE "636f6e74656e7444656c657465" // Deleting content #define OR_CONTENT_BOOST "636f6e74656e74426f6f7374" // Boost content #define OR_ACCOUNT_SETTING "616363536574" // Public account settings (accSet) + #define OR_ACCOUNT_DELETE "61636344656c" // Public account settings (accSet) #define OR_MODERATION_FLAG "6d6f64466c6167" // Flag for moderation @@ -61,6 +62,7 @@ namespace PocketTx ACCOUNT_VIDEO_SERVER = 101, ACCOUNT_MESSAGE_SERVER = 102, ACCOUNT_SETTING = 103, + ACCOUNT_DELETE = 170, CONTENT_POST = 200, CONTENT_VIDEO = 201, From 4042f1ec61ea64d978ca9527216eaacddeb4c229 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Fri, 9 Sep 2022 15:30:25 +0300 Subject: [PATCH 02/49] Refactoring models & AccountDelete transaction --- src/CMakeLists.txt | 117 ++++++++++-------- src/Makefile.am | 94 +++++++------- src/pocketdb/consensus/Helper.cpp | 11 +- src/pocketdb/consensus/Helper.h | 8 +- .../consensus/social/AccountDelete.hpp | 93 ++++++++++++++ .../consensus/social/AccountSetting.hpp | 2 +- .../social/{User.hpp => AccountUser.hpp} | 36 +++--- src/pocketdb/consensus/social/Article.hpp | 2 +- src/pocketdb/consensus/social/Blocking.hpp | 2 +- .../consensus/social/BlockingCancel.hpp | 2 +- .../consensus/social/BoostContent.hpp | 2 +- src/pocketdb/consensus/social/Comment.hpp | 2 +- .../consensus/social/CommentDelete.hpp | 2 +- src/pocketdb/consensus/social/CommentEdit.hpp | 2 +- src/pocketdb/consensus/social/Complain.hpp | 2 +- .../consensus/social/ContentDelete.hpp | 2 +- src/pocketdb/consensus/social/Post.hpp | 2 +- .../consensus/social/ScoreComment.hpp | 4 +- .../consensus/social/ScoreContent.hpp | 2 +- src/pocketdb/consensus/social/Subscribe.hpp | 2 +- .../consensus/social/SubscribeCancel.hpp | 2 +- .../consensus/social/SubscribePrivate.hpp | 2 +- src/pocketdb/consensus/social/Video.hpp | 2 +- src/pocketdb/helpers/TransactionHelper.h | 42 +++---- src/pocketdb/models/dto/account/Delete.cpp | 20 +++ src/pocketdb/models/dto/account/Delete.h | 21 ++++ .../Setting.cpp} | 2 +- .../{AccountSetting.h => account/Setting.h} | 2 +- .../models/dto/{ => account}/User.cpp | 2 +- src/pocketdb/models/dto/{ => account}/User.h | 0 .../models/dto/{ => action}/Blocking.cpp | 2 +- .../models/dto/{ => action}/Blocking.h | 0 .../dto/{ => action}/BlockingCancel.cpp | 2 +- .../models/dto/{ => action}/BlockingCancel.h | 2 +- .../models/dto/{ => action}/BoostContent.cpp | 2 +- .../models/dto/{ => action}/BoostContent.h | 0 .../models/dto/{ => action}/Complain.cpp | 2 +- .../models/dto/{ => action}/Complain.h | 0 .../models/dto/{ => action}/ScoreComment.cpp | 2 +- .../models/dto/{ => action}/ScoreComment.h | 0 .../models/dto/{ => action}/ScoreContent.cpp | 2 +- .../models/dto/{ => action}/ScoreContent.h | 0 .../models/dto/{ => action}/Subscribe.cpp | 2 +- .../models/dto/{ => action}/Subscribe.h | 0 .../dto/{ => action}/SubscribeCancel.cpp | 2 +- .../models/dto/{ => action}/SubscribeCancel.h | 2 +- .../dto/{ => action}/SubscribePrivate.cpp | 2 +- .../dto/{ => action}/SubscribePrivate.h | 2 +- .../models/dto/{ => content}/Article.cpp | 2 +- .../models/dto/{ => content}/Article.h | 2 +- .../models/dto/{ => content}/Comment.cpp | 2 +- .../models/dto/{ => content}/Comment.h | 0 .../dto/{ => content}/CommentDelete.cpp | 2 +- .../models/dto/{ => content}/CommentDelete.h | 2 +- .../models/dto/{ => content}/CommentEdit.cpp | 2 +- .../models/dto/{ => content}/CommentEdit.h | 2 +- .../models/dto/{ => content}/Content.cpp | 2 +- .../models/dto/{ => content}/Content.h | 0 .../dto/{ => content}/ContentDelete.cpp | 2 +- .../models/dto/{ => content}/ContentDelete.h | 2 +- .../models/dto/{ => content}/Post.cpp | 2 +- src/pocketdb/models/dto/{ => content}/Post.h | 2 +- .../models/dto/{ => content}/Video.cpp | 2 +- src/pocketdb/models/dto/{ => content}/Video.h | 2 +- .../models/dto/{ => money}/Coinbase.cpp | 2 +- .../models/dto/{ => money}/Coinbase.h | 2 +- .../models/dto/{ => money}/Coinstake.cpp | 2 +- .../models/dto/{ => money}/Coinstake.h | 2 +- .../models/dto/{ => money}/Default.cpp | 2 +- src/pocketdb/models/dto/{ => money}/Default.h | 0 .../repositories/ConsensusRepository.cpp | 42 +++++++ .../repositories/ConsensusRepository.h | 2 + .../repositories/TransactionRepository.h | 3 - src/pocketdb/services/Serializer.h | 15 --- src/pocketdb/web/PocketTransactionRpc.cpp | 6 +- 75 files changed, 396 insertions(+), 218 deletions(-) create mode 100644 src/pocketdb/consensus/social/AccountDelete.hpp rename src/pocketdb/consensus/social/{User.hpp => AccountUser.hpp} (89%) create mode 100644 src/pocketdb/models/dto/account/Delete.cpp create mode 100644 src/pocketdb/models/dto/account/Delete.h rename src/pocketdb/models/dto/{AccountSetting.cpp => account/Setting.cpp} (97%) rename src/pocketdb/models/dto/{AccountSetting.h => account/Setting.h} (94%) rename src/pocketdb/models/dto/{ => account}/User.cpp (99%) rename src/pocketdb/models/dto/{ => account}/User.h (100%) rename src/pocketdb/models/dto/{ => action}/Blocking.cpp (98%) rename src/pocketdb/models/dto/{ => action}/Blocking.h (100%) rename src/pocketdb/models/dto/{ => action}/BlockingCancel.cpp (92%) rename src/pocketdb/models/dto/{ => action}/BlockingCancel.h (91%) rename src/pocketdb/models/dto/{ => action}/BoostContent.cpp (97%) rename src/pocketdb/models/dto/{ => action}/BoostContent.h (100%) rename src/pocketdb/models/dto/{ => action}/Complain.cpp (97%) rename src/pocketdb/models/dto/{ => action}/Complain.h (100%) rename src/pocketdb/models/dto/{ => action}/ScoreComment.cpp (97%) rename src/pocketdb/models/dto/{ => action}/ScoreComment.h (100%) rename src/pocketdb/models/dto/{ => action}/ScoreContent.cpp (97%) rename src/pocketdb/models/dto/{ => action}/ScoreContent.h (100%) rename src/pocketdb/models/dto/{ => action}/Subscribe.cpp (97%) rename src/pocketdb/models/dto/{ => action}/Subscribe.h (100%) rename src/pocketdb/models/dto/{ => action}/SubscribeCancel.cpp (92%) rename src/pocketdb/models/dto/{ => action}/SubscribeCancel.h (91%) rename src/pocketdb/models/dto/{ => action}/SubscribePrivate.cpp (92%) rename src/pocketdb/models/dto/{ => action}/SubscribePrivate.h (91%) rename src/pocketdb/models/dto/{ => content}/Article.cpp (90%) rename src/pocketdb/models/dto/{ => content}/Article.h (90%) rename src/pocketdb/models/dto/{ => content}/Comment.cpp (98%) rename src/pocketdb/models/dto/{ => content}/Comment.h (100%) rename src/pocketdb/models/dto/{ => content}/CommentDelete.cpp (95%) rename src/pocketdb/models/dto/{ => content}/CommentDelete.h (92%) rename src/pocketdb/models/dto/{ => content}/CommentEdit.cpp (90%) rename src/pocketdb/models/dto/{ => content}/CommentEdit.h (90%) rename src/pocketdb/models/dto/{ => content}/Content.cpp (94%) rename src/pocketdb/models/dto/{ => content}/Content.h (100%) rename src/pocketdb/models/dto/{ => content}/ContentDelete.cpp (97%) rename src/pocketdb/models/dto/{ => content}/ContentDelete.h (94%) rename src/pocketdb/models/dto/{ => content}/Post.cpp (99%) rename src/pocketdb/models/dto/{ => content}/Post.h (96%) rename src/pocketdb/models/dto/{ => content}/Video.cpp (90%) rename src/pocketdb/models/dto/{ => content}/Video.h (90%) rename src/pocketdb/models/dto/{ => money}/Coinbase.cpp (90%) rename src/pocketdb/models/dto/{ => money}/Coinbase.h (90%) rename src/pocketdb/models/dto/{ => money}/Coinstake.cpp (90%) rename src/pocketdb/models/dto/{ => money}/Coinstake.h (90%) rename src/pocketdb/models/dto/{ => money}/Default.cpp (93%) rename src/pocketdb/models/dto/{ => money}/Default.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1bd534265..8a7908236 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -557,74 +557,82 @@ set(POCKETDB pocketdb) add_library(${POCKETDB} pocketdb/migrations/base.h pocketdb/migrations/main.h + pocketdb/migrations/main.cpp pocketdb/migrations/web.h + pocketdb/migrations/web.cpp + pocketdb/models/base/PocketTypes.h - pocketdb/models/base/Base.h - pocketdb/models/base/Payload.h - pocketdb/models/base/Transaction.h - pocketdb/models/base/TransactionInput.h - pocketdb/models/base/TransactionOutput.h - pocketdb/models/base/SocialTransaction.h - pocketdb/models/base/Rating.h pocketdb/models/base/DtoModels.h - pocketdb/models/dto/Default.h - pocketdb/models/dto/Coinbase.h - pocketdb/models/dto/Coinstake.h - pocketdb/models/dto/Post.h - pocketdb/models/dto/User.h - pocketdb/models/dto/ScoreContent.h - pocketdb/models/dto/ScoreComment.h - pocketdb/models/dto/Blocking.h - pocketdb/models/dto/BlockingCancel.h - pocketdb/models/dto/CommentEdit.h - pocketdb/models/dto/CommentDelete.h - pocketdb/models/dto/Subscribe.h - pocketdb/models/dto/SubscribePrivate.h - pocketdb/models/dto/SubscribeCancel.h - pocketdb/models/dto/Complain.h - pocketdb/models/dto/Video.h - pocketdb/models/dto/AccountSetting.h - pocketdb/models/dto/ContentDelete.h - pocketdb/models/dto/BoostContent.h - pocketdb/migrations/main.cpp - pocketdb/migrations/web.cpp + pocketdb/models/base/Base.h pocketdb/models/base/Base.cpp + pocketdb/models/base/Payload.h pocketdb/models/base/Payload.cpp + pocketdb/models/base/Transaction.h pocketdb/models/base/Transaction.cpp + pocketdb/models/base/TransactionInput.h pocketdb/models/base/TransactionInput.cpp + pocketdb/models/base/TransactionOutput.h pocketdb/models/base/TransactionOutput.cpp + pocketdb/models/base/SocialTransaction.h pocketdb/models/base/SocialTransaction.cpp + pocketdb/models/base/Rating.h pocketdb/models/base/Rating.cpp - pocketdb/models/dto/Default.cpp - pocketdb/models/dto/Coinbase.cpp - pocketdb/models/dto/Coinstake.cpp - pocketdb/models/dto/Content.h - pocketdb/models/dto/Content.cpp - pocketdb/models/dto/Post.cpp - pocketdb/models/dto/Video.cpp - pocketdb/models/dto/Article.h - pocketdb/models/dto/Article.cpp - pocketdb/models/dto/User.cpp - pocketdb/models/dto/ScoreContent.cpp - pocketdb/models/dto/ScoreComment.cpp - pocketdb/models/dto/Blocking.cpp - pocketdb/models/dto/BlockingCancel.cpp - pocketdb/models/dto/Comment.h - pocketdb/models/dto/Comment.cpp - pocketdb/models/dto/CommentEdit.cpp - pocketdb/models/dto/CommentDelete.cpp - pocketdb/models/dto/Subscribe.cpp - pocketdb/models/dto/SubscribePrivate.cpp - pocketdb/models/dto/SubscribeCancel.cpp - pocketdb/models/dto/Complain.cpp - pocketdb/models/dto/AccountSetting.cpp - pocketdb/models/dto/ContentDelete.cpp + + pocketdb/models/dto/money/Default.h + pocketdb/models/dto/money/Default.cpp + pocketdb/models/dto/money/Coinbase.h + pocketdb/models/dto/money/Coinbase.cpp + pocketdb/models/dto/money/Coinstake.h + pocketdb/models/dto/money/Coinstake.cpp + + pocketdb/models/dto/account/User.h + pocketdb/models/dto/account/User.cpp + pocketdb/models/dto/account/Setting.h + pocketdb/models/dto/account/Setting.cpp + + pocketdb/models/dto/content/Content.h + pocketdb/models/dto/content/Content.cpp + pocketdb/models/dto/content/ContentDelete.h + pocketdb/models/dto/content/ContentDelete.cpp + pocketdb/models/dto/content/Post.h + pocketdb/models/dto/content/Post.cpp + pocketdb/models/dto/content/Video.h + pocketdb/models/dto/content/Video.cpp + pocketdb/models/dto/content/Article.h + pocketdb/models/dto/content/Article.cpp + pocketdb/models/dto/content/Comment.h + pocketdb/models/dto/content/Comment.cpp + pocketdb/models/dto/content/CommentEdit.h + pocketdb/models/dto/content/CommentEdit.cpp + pocketdb/models/dto/content/CommentDelete.h + pocketdb/models/dto/content/CommentDelete.cpp + + pocketdb/models/dto/action/ScoreContent.h + pocketdb/models/dto/action/ScoreContent.cpp + pocketdb/models/dto/action/ScoreComment.h + pocketdb/models/dto/action/ScoreComment.cpp + pocketdb/models/dto/action/Blocking.h + pocketdb/models/dto/action/Blocking.cpp + pocketdb/models/dto/action/BlockingCancel.h + pocketdb/models/dto/action/BlockingCancel.cpp + pocketdb/models/dto/action/Subscribe.h + pocketdb/models/dto/action/Subscribe.cpp + pocketdb/models/dto/action/SubscribePrivate.h + pocketdb/models/dto/action/SubscribePrivate.cpp + pocketdb/models/dto/action/SubscribeCancel.h + pocketdb/models/dto/action/SubscribeCancel.cpp + pocketdb/models/dto/action/Complain.h + pocketdb/models/dto/action/Complain.cpp + pocketdb/models/dto/action/BoostContent.h + pocketdb/models/dto/action/BoostContent.cpp + pocketdb/models/dto/moderation/Flag.h pocketdb/models/dto/moderation/Flag.cpp + pocketdb/models/web/WebTag.h pocketdb/models/web/WebContent.h - pocketdb/models/dto/BoostContent.cpp pocketdb/models/web/SearchRequest.h + pocketdb/models/shortform/ShortForm.h pocketdb/models/shortform/ShortForm.cpp pocketdb/models/shortform/ShortTxData.h @@ -1125,8 +1133,9 @@ add_library(${POCKETCOIN_SERVER} pocketdb/consensus/social/Subscribe.hpp pocketdb/consensus/social/SubscribeCancel.hpp pocketdb/consensus/social/SubscribePrivate.hpp - pocketdb/consensus/social/User.hpp + pocketdb/consensus/social/AccountUser.hpp pocketdb/consensus/social/AccountSetting.hpp + pocketdb/consensus/social/AccountDelete.hpp pocketdb/consensus/social/ContentDelete.hpp pocketdb/consensus/social/BoostContent.hpp pocketdb/consensus/moderation/Flag.hpp diff --git a/src/Makefile.am b/src/Makefile.am index b63ea6335..1325b4efe 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -177,7 +177,7 @@ POCKETDB_H = \ pocketdb/consensus/social/Subscribe.hpp \ pocketdb/consensus/social/SubscribeCancel.hpp \ pocketdb/consensus/social/SubscribePrivate.hpp \ - pocketdb/consensus/social/User.hpp \ + pocketdb/consensus/social/AccountUser.hpp \ pocketdb/consensus/social/AccountSetting.hpp \ pocketdb/consensus/social/ContentDelete.hpp \ \ @@ -194,28 +194,29 @@ POCKETDB_H = \ pocketdb/models/base/Payload.h \ pocketdb/models/base/DtoModels.h \ \ - pocketdb/models/dto/Default.h \ - pocketdb/models/dto/Coinbase.h \ - pocketdb/models/dto/Coinstake.h \ - pocketdb/models/dto/Content.h \ - pocketdb/models/dto/Post.h \ - pocketdb/models/dto/ContentDelete.h \ - pocketdb/models/dto/BoostContent.h \ - pocketdb/models/dto/AccountSetting.h \ - pocketdb/models/dto/User.h \ - pocketdb/models/dto/ScoreContent.h \ - pocketdb/models/dto/ScoreComment.h \ - pocketdb/models/dto/Blocking.h \ - pocketdb/models/dto/BlockingCancel.h \ - pocketdb/models/dto/Comment.h \ - pocketdb/models/dto/CommentEdit.h \ - pocketdb/models/dto/CommentDelete.h \ - pocketdb/models/dto/Subscribe.h \ - pocketdb/models/dto/SubscribePrivate.h \ - pocketdb/models/dto/SubscribeCancel.h \ - pocketdb/models/dto/Complain.h \ - pocketdb/models/dto/Video.h \ - pocketdb/models/dto/Article.h \ + pocketdb/models/dto/money/Default.h \ + pocketdb/models/dto/money/Coinbase.h \ + pocketdb/models/dto/money/Coinstake.h \ + pocketdb/models/dto/content/Content.h \ + pocketdb/models/dto/content/Post.h \ + pocketdb/models/dto/content/ContentDelete.h \ + pocketdb/models/dto/action/BoostContent.h \ + pocketdb/models/dto/account/Delete.h \ + pocketdb/models/dto/account/Setting.h \ + pocketdb/models/dto/account/User.h \ + pocketdb/models/dto/action/ScoreContent.h \ + pocketdb/models/dto/action/ScoreComment.h \ + pocketdb/models/dto/action/Blocking.h \ + pocketdb/models/dto/action/BlockingCancel.h \ + pocketdb/models/dto/content/Comment.h \ + pocketdb/models/dto/content/CommentEdit.h \ + pocketdb/models/dto/content/CommentDelete.h \ + pocketdb/models/dto/action/Subscribe.h \ + pocketdb/models/dto/action/SubscribePrivate.h \ + pocketdb/models/dto/action/SubscribeCancel.h \ + pocketdb/models/dto/action/Complain.h \ + pocketdb/models/dto/content/Video.h \ + pocketdb/models/dto/content/Article.h \ pocketdb/models/dto/moderation/Flag.h \ \ pocketdb/models/web/WebTag.h \ @@ -284,29 +285,30 @@ POCKETDB_CPP = \ pocketdb/web/PocketRpc.cpp \ pocketdb/web/WebRpcUtils.cpp \ \ - pocketdb/models/dto/Default.cpp \ - pocketdb/models/dto/Coinbase.cpp \ - pocketdb/models/dto/Coinstake.cpp \ - pocketdb/models/dto/Content.cpp \ - pocketdb/models/dto/Post.cpp \ - pocketdb/models/dto/ContentDelete.cpp \ - pocketdb/models/dto/BoostContent.cpp \ - pocketdb/models/dto/AccountSetting.cpp \ - pocketdb/models/dto/User.cpp \ - pocketdb/models/dto/ScoreContent.cpp \ - pocketdb/models/dto/ScoreComment.cpp \ - pocketdb/models/dto/Blocking.cpp \ - pocketdb/models/dto/BlockingCancel.cpp \ - pocketdb/models/dto/Comment.cpp \ - pocketdb/models/dto/CommentEdit.cpp \ - pocketdb/models/dto/CommentDelete.cpp \ - pocketdb/models/dto/Subscribe.cpp \ - pocketdb/models/dto/SubscribePrivate.cpp \ - pocketdb/models/dto/SubscribeCancel.cpp \ - pocketdb/models/dto/Complain.cpp \ - pocketdb/models/dto/Video.cpp \ - pocketdb/models/dto/BoostContent.cpp \ - pocketdb/models/dto/Article.cpp \ + pocketdb/models/dto/money/Default.cpp \ + pocketdb/models/dto/money/Coinbase.cpp \ + pocketdb/models/dto/money/Coinstake.cpp \ + pocketdb/models/dto/content/Content.cpp \ + pocketdb/models/dto/content/Post.cpp \ + pocketdb/models/dto/content/ContentDelete.cpp \ + pocketdb/models/dto/action/BoostContent.cpp \ + pocketdb/models/dto/account/Setting.cpp \ + pocketdb/models/dto/account/Delete.cpp \ + pocketdb/models/dto/account/User.cpp \ + pocketdb/models/dto/action/ScoreContent.cpp \ + pocketdb/models/dto/action/ScoreComment.cpp \ + pocketdb/models/dto/action/Blocking.cpp \ + pocketdb/models/dto/action/BlockingCancel.cpp \ + pocketdb/models/dto/content/Comment.cpp \ + pocketdb/models/dto/content/CommentEdit.cpp \ + pocketdb/models/dto/content/CommentDelete.cpp \ + pocketdb/models/dto/action/Subscribe.cpp \ + pocketdb/models/dto/action/SubscribePrivate.cpp \ + pocketdb/models/dto/action/SubscribeCancel.cpp \ + pocketdb/models/dto/action/Complain.cpp \ + pocketdb/models/dto/content/Video.cpp \ + pocketdb/models/dto/action/BoostContent.cpp \ + pocketdb/models/dto/content/Article.cpp \ pocketdb/models/dto/moderation/Flag.cpp \ pocketdb/models/shortform/ShortForm.cpp \ pocketdb/models/shortform/ShortAccount.cpp \ diff --git a/src/pocketdb/consensus/Helper.cpp b/src/pocketdb/consensus/Helper.cpp index f363ed35c..4437c2fff 100644 --- a/src/pocketdb/consensus/Helper.cpp +++ b/src/pocketdb/consensus/Helper.cpp @@ -10,7 +10,8 @@ namespace PocketConsensus VideoConsensusFactory SocialConsensusHelper::m_videoFactory; ArticleConsensusFactory SocialConsensusHelper::m_articleFactory; AccountSettingConsensusFactory SocialConsensusHelper::m_accountSettingFactory; - UserConsensusFactory SocialConsensusHelper::m_userFactory; + AccountDeleteConsensusFactory SocialConsensusHelper::m_accountDeleteFactory; + AccountUserConsensusFactory SocialConsensusHelper::m_accountUserFactory; CommentConsensusFactory SocialConsensusHelper::m_commentFactory; CommentEditConsensusFactory SocialConsensusHelper::m_commentEditFactory; CommentDeleteConsensusFactory SocialConsensusHelper::m_commentDeleteFactory; @@ -161,8 +162,10 @@ namespace PocketConsensus { case ACCOUNT_SETTING: return m_accountSettingFactory.Instance(height)->Check(tx, static_pointer_cast(ptx)); + case ACCOUNT_DELETE: + return m_accountDeleteFactory.Instance(height)->Check(tx, static_pointer_cast(ptx)); case ACCOUNT_USER: - return m_userFactory.Instance(height)->Check(tx, static_pointer_cast(ptx)); + return m_accountUserFactory.Instance(height)->Check(tx, static_pointer_cast(ptx)); case CONTENT_POST: return m_postFactory.Instance(height)->Check(tx, static_pointer_cast(ptx)); case CONTENT_VIDEO: @@ -216,8 +219,10 @@ namespace PocketConsensus { case ACCOUNT_SETTING: return m_accountSettingFactory.Instance(height)->Validate(tx, static_pointer_cast(ptx), pBlock); + case ACCOUNT_DELETE: + return m_accountDeleteFactory.Instance(height)->Validate(tx, static_pointer_cast(ptx), pBlock); case ACCOUNT_USER: - return m_userFactory.Instance(height)->Validate(tx, static_pointer_cast(ptx), pBlock); + return m_accountUserFactory.Instance(height)->Validate(tx, static_pointer_cast(ptx), pBlock); case CONTENT_POST: return m_postFactory.Instance(height)->Validate(tx, static_pointer_cast(ptx), pBlock); case CONTENT_VIDEO: diff --git a/src/pocketdb/consensus/Helper.h b/src/pocketdb/consensus/Helper.h index a1a5b9bf8..519c6b439 100644 --- a/src/pocketdb/consensus/Helper.h +++ b/src/pocketdb/consensus/Helper.h @@ -24,8 +24,9 @@ #include "pocketdb/consensus/social/Subscribe.hpp" #include "pocketdb/consensus/social/SubscribeCancel.hpp" #include "pocketdb/consensus/social/SubscribePrivate.hpp" -#include "pocketdb/consensus/social/User.hpp" +#include "pocketdb/consensus/social/AccountUser.hpp" #include "pocketdb/consensus/social/AccountSetting.hpp" +#include "pocketdb/consensus/social/AccountDelete.hpp" #include "pocketdb/consensus/social/ContentDelete.hpp" #include "pocketdb/consensus/moderation/Flag.hpp" @@ -50,10 +51,12 @@ namespace PocketConsensus static tuple check(const CTransactionRef& tx, const PTransactionRef& ptx, int height); static bool isConsensusable(TxType txType); private: + static AccountUserConsensusFactory m_accountUserFactory; + static AccountSettingConsensusFactory m_accountSettingFactory; + static AccountDeleteConsensusFactory m_accountDeleteFactory; static PostConsensusFactory m_postFactory; static VideoConsensusFactory m_videoFactory; static ArticleConsensusFactory m_articleFactory; - static UserConsensusFactory m_userFactory; static CommentConsensusFactory m_commentFactory; static CommentEditConsensusFactory m_commentEditFactory; static CommentDeleteConsensusFactory m_commentDeleteFactory; @@ -65,7 +68,6 @@ namespace PocketConsensus static BlockingConsensusFactory m_blockingFactory; static BlockingCancelConsensusFactory m_blockingCancelFactory; static ComplainConsensusFactory m_complainFactory; - static AccountSettingConsensusFactory m_accountSettingFactory; static ContentDeleteConsensusFactory m_contentDeleteFactory; static BoostContentConsensusFactory m_boostContentFactory; diff --git a/src/pocketdb/consensus/social/AccountDelete.hpp b/src/pocketdb/consensus/social/AccountDelete.hpp new file mode 100644 index 000000000..e63fb9cbe --- /dev/null +++ b/src/pocketdb/consensus/social/AccountDelete.hpp @@ -0,0 +1,93 @@ +// 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_ACCOUNT_DELETE_HPP +#define POCKETCONSENSUS_ACCOUNT_DELETE_HPP + +#include "pocketdb/consensus/Social.h" +#include "pocketdb/models/dto/account/Delete.h" + +namespace PocketConsensus +{ + using namespace std; + typedef shared_ptr AccountDeleteRef; + + /******************************************************************************************************************* + * AccountDelete consensus base class + *******************************************************************************************************************/ + class AccountDeleteConsensus : public SocialConsensus + { + public: + AccountDeleteConsensus(int height) : SocialConsensus(height) {} + + ConsensusValidateResult Check(const CTransactionRef& tx, const AccountDeleteRef& ptx) override + { + if (IsEmpty(ptx->GetAddress())) + return {false, SocialConsensusResult_Failed}; + + return SocialConsensus::Check(tx, ptx); + } + + protected: + + ConsensusValidateResult ValidateBlock(const AccountDeleteRef& ptx, const PocketBlockRef& block) override + { + // Only one transaction allowed in block + for (auto& blockTx : *block) + { + if (!TransactionHelper::IsIn(*blockTx->GetType(), { ACCOUNT_USER, ACCOUNT_SETTING, ACCOUNT_DELETE })) + continue; + + auto blockPtx = static_pointer_cast(blockTx); + if (*blockPtx->GetHash() == *ptx->GetHash()) + continue; + + if (*ptx->GetAddress() == *blockPtx->GetAddress()) + return {false, SocialConsensusResult_ManyTransactions}; + } + + return Success; + } + + ConsensusValidateResult ValidateMempool(const AccountDeleteRef& ptx) override + { + if (ConsensusRepoInst.ExistsInMempool(*ptx->GetAddress(), { ACCOUNT_USER, ACCOUNT_SETTING, ACCOUNT_DELETE })) + return {false, SocialConsensusResult_ManyTransactions}; + + return Success; + } + + vector GetAddressesForCheckRegistration(const AccountDeleteRef& ptx) override + { + return { *ptx->GetAddress() }; + } + }; + + // todo (0.21): set minimum height for this transaction + + /******************************************************************************************************************* + * Factory for select actual rules version + *******************************************************************************************************************/ + class AccountDeleteConsensusFactory + { + private: + const vector> m_rules = { + { 0, 0, [](int height) { return make_shared(height); }}, + }; + public: + shared_ptr Instance(int height) + { + int m_height = (height > 0 ? height : 0); + return (--upper_bound(m_rules.begin(), m_rules.end(), m_height, + [&](int target, const ConsensusCheckpoint& itm) + { + return target < itm.Height(Params().NetworkIDString()); + } + ))->m_func(m_height); + } + }; + +} // namespace PocketConsensus + +#endif // POCKETCONSENSUS_ACCOUNT_DELETE_HPP diff --git a/src/pocketdb/consensus/social/AccountSetting.hpp b/src/pocketdb/consensus/social/AccountSetting.hpp index 00df1342d..3ade87d85 100644 --- a/src/pocketdb/consensus/social/AccountSetting.hpp +++ b/src/pocketdb/consensus/social/AccountSetting.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_ACCOUNT_SETTING_HPP #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/AccountSetting.h" +#include "pocketdb/models/dto/account/Setting.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/User.hpp b/src/pocketdb/consensus/social/AccountUser.hpp similarity index 89% rename from src/pocketdb/consensus/social/User.hpp rename to src/pocketdb/consensus/social/AccountUser.hpp index 3b93ba86c..9471d42ff 100644 --- a/src/pocketdb/consensus/social/User.hpp +++ b/src/pocketdb/consensus/social/AccountUser.hpp @@ -8,7 +8,7 @@ #include #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/User.h" +#include "pocketdb/models/dto/account/User.h" namespace PocketConsensus { @@ -16,12 +16,12 @@ namespace PocketConsensus typedef shared_ptr UserRef; /******************************************************************************************************************* - * User consensus base class + * AccountUser consensus base class *******************************************************************************************************************/ - class UserConsensus : public SocialConsensus + class AccountUserConsensus : public SocialConsensus { public: - UserConsensus(int height) : SocialConsensus(height) {} + AccountUserConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const UserRef& ptx, const PocketBlockRef& block) override { // Base validation with calling block or mempool check @@ -184,10 +184,10 @@ namespace PocketConsensus /******************************************************************************************************************* * Start checkpoint at 1180000 block *******************************************************************************************************************/ - class UserConsensus_checkpoint_1180000 : public UserConsensus + class AccountUserConsensus_checkpoint_1180000 : public AccountUserConsensus { public: - UserConsensus_checkpoint_1180000(int height) : UserConsensus(height) {} + AccountUserConsensus_checkpoint_1180000(int height) : AccountUserConsensus(height) {} protected: ConsensusValidateResult ValidateEditLimit(const UserRef& ptx) override { @@ -206,10 +206,10 @@ namespace PocketConsensus /******************************************************************************************************************* * Start checkpoint at 1381841 block *******************************************************************************************************************/ - class UserConsensus_checkpoint_1381841 : public UserConsensus_checkpoint_1180000 + class AccountUserConsensus_checkpoint_1381841 : public AccountUserConsensus_checkpoint_1180000 { public: - UserConsensus_checkpoint_1381841(int height) : UserConsensus_checkpoint_1180000(height) {} + AccountUserConsensus_checkpoint_1381841(int height) : AccountUserConsensus_checkpoint_1180000(height) {} protected: ConsensusValidateResult ValidateEditLimit(const UserRef& ptx) override { @@ -228,10 +228,10 @@ namespace PocketConsensus /******************************************************************************************************************* * Limitations for username *******************************************************************************************************************/ - class UserConsensus_checkpoint_login_limitation : public UserConsensus_checkpoint_1381841 + class AccountUserConsensus_checkpoint_login_limitation : public AccountUserConsensus_checkpoint_1381841 { public: - UserConsensus_checkpoint_login_limitation(int height) : UserConsensus_checkpoint_1381841(height) {} + AccountUserConsensus_checkpoint_login_limitation(int height) : AccountUserConsensus_checkpoint_1381841(height) {} protected: ConsensusValidateResult CheckLogin(const UserRef& ptx) override @@ -283,21 +283,21 @@ namespace PocketConsensus /******************************************************************************************************************* * Factory for select actual rules version *******************************************************************************************************************/ - class UserConsensusFactory + class AccountUserConsensusFactory { private: - const vector> m_rules = { - { 0, -1, [](int height) { return make_shared(height); }}, - { 1180000, 0, [](int height) { return make_shared(height); }}, - { 1381841, 162000, [](int height) { return make_shared(height); }}, - { 1647000, 650000, [](int height) { return make_shared(height); }}, // ~ 03/25/2022 + const vector> m_rules = { + { 0, -1, [](int height) { return make_shared(height); }}, + { 1180000, 0, [](int height) { return make_shared(height); }}, + { 1381841, 162000, [](int height) { return make_shared(height); }}, + { 1647000, 650000, [](int height) { return make_shared(height); }}, // ~ 03/25/2022 }; public: - shared_ptr Instance(int height) + shared_ptr Instance(int height) { int m_height = (height > 0 ? height : 0); return (--upper_bound(m_rules.begin(), m_rules.end(), m_height, - [&](int target, const ConsensusCheckpoint& itm) + [&](int target, const ConsensusCheckpoint& itm) { return target < itm.Height(Params().NetworkIDString()); } diff --git a/src/pocketdb/consensus/social/Article.hpp b/src/pocketdb/consensus/social/Article.hpp index afa28ede2..ff59427bd 100644 --- a/src/pocketdb/consensus/social/Article.hpp +++ b/src/pocketdb/consensus/social/Article.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_ARTICLE_H #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/Article.h" +#include "pocketdb/models/dto/content/Article.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/Blocking.hpp b/src/pocketdb/consensus/social/Blocking.hpp index 7e0a1bbef..83cbc49e3 100644 --- a/src/pocketdb/consensus/social/Blocking.hpp +++ b/src/pocketdb/consensus/social/Blocking.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_BLOCKING_HPP #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/Blocking.h" +#include "pocketdb/models/dto/action/Blocking.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/BlockingCancel.hpp b/src/pocketdb/consensus/social/BlockingCancel.hpp index 5c68ce9de..705897814 100644 --- a/src/pocketdb/consensus/social/BlockingCancel.hpp +++ b/src/pocketdb/consensus/social/BlockingCancel.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_BLOCKINGCANCEL_HPP #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/BlockingCancel.h" +#include "pocketdb/models/dto/action/BlockingCancel.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/BoostContent.hpp b/src/pocketdb/consensus/social/BoostContent.hpp index e6e9ff8f2..41ad6f815 100644 --- a/src/pocketdb/consensus/social/BoostContent.hpp +++ b/src/pocketdb/consensus/social/BoostContent.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_BOOSTCONTENT_HPP #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/BoostContent.h" +#include "pocketdb/models/dto/action/BoostContent.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/Comment.hpp b/src/pocketdb/consensus/social/Comment.hpp index 88253c07e..7dc5312ff 100644 --- a/src/pocketdb/consensus/social/Comment.hpp +++ b/src/pocketdb/consensus/social/Comment.hpp @@ -8,7 +8,7 @@ #include "util/html.h" #include "pocketdb/consensus/Reputation.h" #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/Comment.h" +#include "pocketdb/models/dto/content/Comment.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/CommentDelete.hpp b/src/pocketdb/consensus/social/CommentDelete.hpp index c0dc0c336..b1fc39e95 100644 --- a/src/pocketdb/consensus/social/CommentDelete.hpp +++ b/src/pocketdb/consensus/social/CommentDelete.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_COMMENT_DELETE_HPP #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/CommentDelete.h" +#include "pocketdb/models/dto/content/CommentDelete.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/CommentEdit.hpp b/src/pocketdb/consensus/social/CommentEdit.hpp index 9d55a2dbd..d6aac0d69 100644 --- a/src/pocketdb/consensus/social/CommentEdit.hpp +++ b/src/pocketdb/consensus/social/CommentEdit.hpp @@ -8,7 +8,7 @@ #include "util/html.h" #include "pocketdb/consensus/Reputation.h" #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/CommentEdit.h" +#include "pocketdb/models/dto/content/CommentEdit.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/Complain.hpp b/src/pocketdb/consensus/social/Complain.hpp index b4734092b..f5581a15e 100644 --- a/src/pocketdb/consensus/social/Complain.hpp +++ b/src/pocketdb/consensus/social/Complain.hpp @@ -7,7 +7,7 @@ #include "pocketdb/consensus/Reputation.h" #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/Complain.h" +#include "pocketdb/models/dto/action/Complain.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/ContentDelete.hpp b/src/pocketdb/consensus/social/ContentDelete.hpp index 5fe2622d8..2a9b5821a 100644 --- a/src/pocketdb/consensus/social/ContentDelete.hpp +++ b/src/pocketdb/consensus/social/ContentDelete.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_CONTENT_DELETE_HPP #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/ContentDelete.h" +#include "pocketdb/models/dto/content/ContentDelete.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/Post.hpp b/src/pocketdb/consensus/social/Post.hpp index f9d9d19b7..eca08d63e 100644 --- a/src/pocketdb/consensus/social/Post.hpp +++ b/src/pocketdb/consensus/social/Post.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_POST_H #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/Post.h" +#include "pocketdb/models/dto/content/Post.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/ScoreComment.hpp b/src/pocketdb/consensus/social/ScoreComment.hpp index ba92b08b0..de3133a58 100644 --- a/src/pocketdb/consensus/social/ScoreComment.hpp +++ b/src/pocketdb/consensus/social/ScoreComment.hpp @@ -5,9 +5,9 @@ #ifndef POCKETCONSENSUS_SCORECOMMENT_HPP #define POCKETCONSENSUS_SCORECOMMENT_HPP -#include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/ScoreComment.h" #include "pocketdb/consensus/Reputation.h" +#include "pocketdb/consensus/Social.h" +#include "pocketdb/models/dto/action/ScoreComment.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/ScoreContent.hpp b/src/pocketdb/consensus/social/ScoreContent.hpp index 4e0391484..ae3a3047f 100644 --- a/src/pocketdb/consensus/social/ScoreContent.hpp +++ b/src/pocketdb/consensus/social/ScoreContent.hpp @@ -7,7 +7,7 @@ #include "pocketdb/consensus/Reputation.h" #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/ScoreContent.h" +#include "pocketdb/models/dto/action/ScoreContent.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/Subscribe.hpp b/src/pocketdb/consensus/social/Subscribe.hpp index 476806a5f..38d8a3069 100644 --- a/src/pocketdb/consensus/social/Subscribe.hpp +++ b/src/pocketdb/consensus/social/Subscribe.hpp @@ -7,7 +7,7 @@ #include "pocketdb/consensus/Social.h" #include "pocketdb/models/base/Transaction.h" -#include "pocketdb/models/dto/Subscribe.h" +#include "pocketdb/models/dto/action/Subscribe.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/SubscribeCancel.hpp b/src/pocketdb/consensus/social/SubscribeCancel.hpp index c4b2b8a6c..a27ce0f48 100644 --- a/src/pocketdb/consensus/social/SubscribeCancel.hpp +++ b/src/pocketdb/consensus/social/SubscribeCancel.hpp @@ -7,7 +7,7 @@ #include "pocketdb/consensus/Social.h" #include "pocketdb/models/base/Transaction.h" -#include "pocketdb/models/dto/SubscribeCancel.h" +#include "pocketdb/models/dto/action/SubscribeCancel.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/SubscribePrivate.hpp b/src/pocketdb/consensus/social/SubscribePrivate.hpp index cb0dc9997..a89357db4 100644 --- a/src/pocketdb/consensus/social/SubscribePrivate.hpp +++ b/src/pocketdb/consensus/social/SubscribePrivate.hpp @@ -6,7 +6,7 @@ #define POCKETCONSENSUS_SUBSCRIBEPRIVATE_HPP #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/SubscribePrivate.h" +#include "pocketdb/models/dto/action/SubscribePrivate.h" namespace PocketConsensus { diff --git a/src/pocketdb/consensus/social/Video.hpp b/src/pocketdb/consensus/social/Video.hpp index 35969a7ae..21d9da2e3 100644 --- a/src/pocketdb/consensus/social/Video.hpp +++ b/src/pocketdb/consensus/social/Video.hpp @@ -7,7 +7,7 @@ #include "pocketdb/consensus/Reputation.h" #include "pocketdb/consensus/Social.h" -#include "pocketdb/models/dto/Video.h" +#include "pocketdb/models/dto/content/Video.h" namespace PocketConsensus { diff --git a/src/pocketdb/helpers/TransactionHelper.h b/src/pocketdb/helpers/TransactionHelper.h index e63cff6db..a0134d100 100644 --- a/src/pocketdb/helpers/TransactionHelper.h +++ b/src/pocketdb/helpers/TransactionHelper.h @@ -16,27 +16,27 @@ #include "pocketdb/models/base/DtoModels.h" #include "pocketdb/models/base/PocketTypes.h" -#include "pocketdb/models/dto/Blocking.h" -#include "pocketdb/models/dto/BlockingCancel.h" -#include "pocketdb/models/dto/BoostContent.h" -#include "pocketdb/models/dto/Coinbase.h" -#include "pocketdb/models/dto/Coinstake.h" -#include "pocketdb/models/dto/Default.h" -#include "pocketdb/models/dto/Post.h" -#include "pocketdb/models/dto/Video.h" -#include "pocketdb/models/dto/Article.h" -#include "pocketdb/models/dto/Comment.h" -#include "pocketdb/models/dto/CommentEdit.h" -#include "pocketdb/models/dto/CommentDelete.h" -#include "pocketdb/models/dto/Subscribe.h" -#include "pocketdb/models/dto/SubscribeCancel.h" -#include "pocketdb/models/dto/SubscribePrivate.h" -#include "pocketdb/models/dto/Complain.h" -#include "pocketdb/models/dto/AccountSetting.h" -#include "pocketdb/models/dto/User.h" -#include "pocketdb/models/dto/ScoreContent.h" -#include "pocketdb/models/dto/ScoreComment.h" -#include "pocketdb/models/dto/ContentDelete.h" +#include "pocketdb/models/dto/action/Blocking.h" +#include "pocketdb/models/dto/action/BlockingCancel.h" +#include "pocketdb/models/dto/action/BoostContent.h" +#include "pocketdb/models/dto/money/Coinbase.h" +#include "pocketdb/models/dto/money/Coinstake.h" +#include "pocketdb/models/dto/money/Default.h" +#include "pocketdb/models/dto/content/Post.h" +#include "pocketdb/models/dto/content/Video.h" +#include "pocketdb/models/dto/content/Article.h" +#include "pocketdb/models/dto/content/Comment.h" +#include "pocketdb/models/dto/content/CommentEdit.h" +#include "pocketdb/models/dto/content/CommentDelete.h" +#include "pocketdb/models/dto/action/Subscribe.h" +#include "pocketdb/models/dto/action/SubscribeCancel.h" +#include "pocketdb/models/dto/action/SubscribePrivate.h" +#include "pocketdb/models/dto/action/Complain.h" +#include "pocketdb/models/dto/account/Setting.h" +#include "pocketdb/models/dto/account/User.h" +#include "pocketdb/models/dto/action/ScoreContent.h" +#include "pocketdb/models/dto/action/ScoreComment.h" +#include "pocketdb/models/dto/content/ContentDelete.h" #include "pocketdb/models/dto/moderation/Flag.h" diff --git a/src/pocketdb/models/dto/account/Delete.cpp b/src/pocketdb/models/dto/account/Delete.cpp new file mode 100644 index 000000000..95740ed3a --- /dev/null +++ b/src/pocketdb/models/dto/account/Delete.cpp @@ -0,0 +1,20 @@ +// 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 +#include "pocketdb/models/dto/account/Delete.h" + +namespace PocketTx +{ + AccountDelete::AccountDelete() : SocialTransaction() + { + SetType(TxType::ACCOUNT_DELETE); + } + + AccountDelete::AccountDelete(const CTransactionRef& tx) : SocialTransaction(tx) + { + SetType(TxType::ACCOUNT_DELETE); + } +} // namespace PocketTx + diff --git a/src/pocketdb/models/dto/account/Delete.h b/src/pocketdb/models/dto/account/Delete.h new file mode 100644 index 000000000..cf383ac1f --- /dev/null +++ b/src/pocketdb/models/dto/account/Delete.h @@ -0,0 +1,21 @@ +// 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 POCKETTX_ACCOUNT_DELETE_H +#define POCKETTX_ACCOUNT_DELETE_H + +#include "pocketdb/models/base/SocialTransaction.h" + +namespace PocketTx +{ + class AccountDelete : public SocialTransaction + { + public: + AccountDelete(); + AccountDelete(const CTransactionRef& tx); + }; // class AccountDelete + +} // namespace PocketTx + +#endif // POCKETTX_ACCOUNT_DELETE_H diff --git a/src/pocketdb/models/dto/AccountSetting.cpp b/src/pocketdb/models/dto/account/Setting.cpp similarity index 97% rename from src/pocketdb/models/dto/AccountSetting.cpp rename to src/pocketdb/models/dto/account/Setting.cpp index 7caba0164..987919e08 100644 --- a/src/pocketdb/models/dto/AccountSetting.cpp +++ b/src/pocketdb/models/dto/account/Setting.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/AccountSetting.h" +#include "pocketdb/models/dto/account/Setting.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/AccountSetting.h b/src/pocketdb/models/dto/account/Setting.h similarity index 94% rename from src/pocketdb/models/dto/AccountSetting.h rename to src/pocketdb/models/dto/account/Setting.h index ce3faa3ae..a628f17c0 100644 --- a/src/pocketdb/models/dto/AccountSetting.h +++ b/src/pocketdb/models/dto/account/Setting.h @@ -9,7 +9,7 @@ namespace PocketTx { - class AccountSetting : public PocketTx::Transaction + class AccountSetting : public Transaction { public: AccountSetting(); diff --git a/src/pocketdb/models/dto/User.cpp b/src/pocketdb/models/dto/account/User.cpp similarity index 99% rename from src/pocketdb/models/dto/User.cpp rename to src/pocketdb/models/dto/account/User.cpp index c7d94f4ac..901bc0124 100644 --- a/src/pocketdb/models/dto/User.cpp +++ b/src/pocketdb/models/dto/account/User.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/User.h" +#include "pocketdb/models/dto/account/User.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/User.h b/src/pocketdb/models/dto/account/User.h similarity index 100% rename from src/pocketdb/models/dto/User.h rename to src/pocketdb/models/dto/account/User.h diff --git a/src/pocketdb/models/dto/Blocking.cpp b/src/pocketdb/models/dto/action/Blocking.cpp similarity index 98% rename from src/pocketdb/models/dto/Blocking.cpp rename to src/pocketdb/models/dto/action/Blocking.cpp index 4fea1d28b..f0b752891 100644 --- a/src/pocketdb/models/dto/Blocking.cpp +++ b/src/pocketdb/models/dto/action/Blocking.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Blocking.h" +#include "pocketdb/models/dto/action/Blocking.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Blocking.h b/src/pocketdb/models/dto/action/Blocking.h similarity index 100% rename from src/pocketdb/models/dto/Blocking.h rename to src/pocketdb/models/dto/action/Blocking.h diff --git a/src/pocketdb/models/dto/BlockingCancel.cpp b/src/pocketdb/models/dto/action/BlockingCancel.cpp similarity index 92% rename from src/pocketdb/models/dto/BlockingCancel.cpp rename to src/pocketdb/models/dto/action/BlockingCancel.cpp index 2321fba6c..72134d7a5 100644 --- a/src/pocketdb/models/dto/BlockingCancel.cpp +++ b/src/pocketdb/models/dto/action/BlockingCancel.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/BlockingCancel.h" +#include "pocketdb/models/dto/action/BlockingCancel.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/BlockingCancel.h b/src/pocketdb/models/dto/action/BlockingCancel.h similarity index 91% rename from src/pocketdb/models/dto/BlockingCancel.h rename to src/pocketdb/models/dto/action/BlockingCancel.h index cca0b67ff..5afc4dc35 100644 --- a/src/pocketdb/models/dto/BlockingCancel.h +++ b/src/pocketdb/models/dto/action/BlockingCancel.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_BLOCKING_CANCEL_H #define POCKETTX_BLOCKING_CANCEL_H -#include "pocketdb/models/dto/Blocking.h" +#include "pocketdb/models/dto/action/Blocking.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/BoostContent.cpp b/src/pocketdb/models/dto/action/BoostContent.cpp similarity index 97% rename from src/pocketdb/models/dto/BoostContent.cpp rename to src/pocketdb/models/dto/action/BoostContent.cpp index 411dc2e25..29fa54e21 100644 --- a/src/pocketdb/models/dto/BoostContent.cpp +++ b/src/pocketdb/models/dto/action/BoostContent.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/BoostContent.h" +#include "pocketdb/models/dto/action/BoostContent.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/BoostContent.h b/src/pocketdb/models/dto/action/BoostContent.h similarity index 100% rename from src/pocketdb/models/dto/BoostContent.h rename to src/pocketdb/models/dto/action/BoostContent.h diff --git a/src/pocketdb/models/dto/Complain.cpp b/src/pocketdb/models/dto/action/Complain.cpp similarity index 97% rename from src/pocketdb/models/dto/Complain.cpp rename to src/pocketdb/models/dto/action/Complain.cpp index 93c0ad792..0b14e5450 100644 --- a/src/pocketdb/models/dto/Complain.cpp +++ b/src/pocketdb/models/dto/action/Complain.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Complain.h" +#include "pocketdb/models/dto/action/Complain.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Complain.h b/src/pocketdb/models/dto/action/Complain.h similarity index 100% rename from src/pocketdb/models/dto/Complain.h rename to src/pocketdb/models/dto/action/Complain.h diff --git a/src/pocketdb/models/dto/ScoreComment.cpp b/src/pocketdb/models/dto/action/ScoreComment.cpp similarity index 97% rename from src/pocketdb/models/dto/ScoreComment.cpp rename to src/pocketdb/models/dto/action/ScoreComment.cpp index 0650ada8a..9b7d97b96 100644 --- a/src/pocketdb/models/dto/ScoreComment.cpp +++ b/src/pocketdb/models/dto/action/ScoreComment.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/ScoreComment.h" +#include "pocketdb/models/dto/action/ScoreComment.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/ScoreComment.h b/src/pocketdb/models/dto/action/ScoreComment.h similarity index 100% rename from src/pocketdb/models/dto/ScoreComment.h rename to src/pocketdb/models/dto/action/ScoreComment.h diff --git a/src/pocketdb/models/dto/ScoreContent.cpp b/src/pocketdb/models/dto/action/ScoreContent.cpp similarity index 97% rename from src/pocketdb/models/dto/ScoreContent.cpp rename to src/pocketdb/models/dto/action/ScoreContent.cpp index 06e9b1f05..f93907ad1 100644 --- a/src/pocketdb/models/dto/ScoreContent.cpp +++ b/src/pocketdb/models/dto/action/ScoreContent.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/ScoreContent.h" +#include "pocketdb/models/dto/action/ScoreContent.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/ScoreContent.h b/src/pocketdb/models/dto/action/ScoreContent.h similarity index 100% rename from src/pocketdb/models/dto/ScoreContent.h rename to src/pocketdb/models/dto/action/ScoreContent.h diff --git a/src/pocketdb/models/dto/Subscribe.cpp b/src/pocketdb/models/dto/action/Subscribe.cpp similarity index 97% rename from src/pocketdb/models/dto/Subscribe.cpp rename to src/pocketdb/models/dto/action/Subscribe.cpp index d2cfdf5ba..1ffe9adcf 100644 --- a/src/pocketdb/models/dto/Subscribe.cpp +++ b/src/pocketdb/models/dto/action/Subscribe.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Subscribe.h" +#include "pocketdb/models/dto/action/Subscribe.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Subscribe.h b/src/pocketdb/models/dto/action/Subscribe.h similarity index 100% rename from src/pocketdb/models/dto/Subscribe.h rename to src/pocketdb/models/dto/action/Subscribe.h diff --git a/src/pocketdb/models/dto/SubscribeCancel.cpp b/src/pocketdb/models/dto/action/SubscribeCancel.cpp similarity index 92% rename from src/pocketdb/models/dto/SubscribeCancel.cpp rename to src/pocketdb/models/dto/action/SubscribeCancel.cpp index 8021ebf96..0d95845c3 100644 --- a/src/pocketdb/models/dto/SubscribeCancel.cpp +++ b/src/pocketdb/models/dto/action/SubscribeCancel.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/SubscribeCancel.h" +#include "pocketdb/models/dto/action/SubscribeCancel.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/SubscribeCancel.h b/src/pocketdb/models/dto/action/SubscribeCancel.h similarity index 91% rename from src/pocketdb/models/dto/SubscribeCancel.h rename to src/pocketdb/models/dto/action/SubscribeCancel.h index d02d3e734..0e23ecac7 100644 --- a/src/pocketdb/models/dto/SubscribeCancel.h +++ b/src/pocketdb/models/dto/action/SubscribeCancel.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_SUBSCRIBE_CANCEL_H #define POCKETTX_SUBSCRIBE_CANCEL_H -#include "pocketdb/models/dto/Subscribe.h" +#include "pocketdb/models/dto/action/Subscribe.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/SubscribePrivate.cpp b/src/pocketdb/models/dto/action/SubscribePrivate.cpp similarity index 92% rename from src/pocketdb/models/dto/SubscribePrivate.cpp rename to src/pocketdb/models/dto/action/SubscribePrivate.cpp index 69b31080c..88e6bae44 100644 --- a/src/pocketdb/models/dto/SubscribePrivate.cpp +++ b/src/pocketdb/models/dto/action/SubscribePrivate.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/SubscribePrivate.h" +#include "pocketdb/models/dto/action/SubscribePrivate.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/SubscribePrivate.h b/src/pocketdb/models/dto/action/SubscribePrivate.h similarity index 91% rename from src/pocketdb/models/dto/SubscribePrivate.h rename to src/pocketdb/models/dto/action/SubscribePrivate.h index 9f9721c67..2a9de8b1b 100644 --- a/src/pocketdb/models/dto/SubscribePrivate.h +++ b/src/pocketdb/models/dto/action/SubscribePrivate.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_SUBSCRIBE_PRIVATE_H #define POCKETTX_SUBSCRIBE_PRIVATE_H -#include "pocketdb/models/dto/Subscribe.h" +#include "pocketdb/models/dto/action/Subscribe.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Article.cpp b/src/pocketdb/models/dto/content/Article.cpp similarity index 90% rename from src/pocketdb/models/dto/Article.cpp rename to src/pocketdb/models/dto/content/Article.cpp index 6402fe0a1..11db29d7b 100644 --- a/src/pocketdb/models/dto/Article.cpp +++ b/src/pocketdb/models/dto/content/Article.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Article.h" +#include "pocketdb/models/dto/content/Article.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Article.h b/src/pocketdb/models/dto/content/Article.h similarity index 90% rename from src/pocketdb/models/dto/Article.h rename to src/pocketdb/models/dto/content/Article.h index 425c9447b..2eaf4a4ea 100644 --- a/src/pocketdb/models/dto/Article.h +++ b/src/pocketdb/models/dto/content/Article.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_ARTICLE_H #define POCKETTX_ARTICLE_H -#include "pocketdb/models/dto/Post.h" +#include "pocketdb/models/dto/content/Post.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Comment.cpp b/src/pocketdb/models/dto/content/Comment.cpp similarity index 98% rename from src/pocketdb/models/dto/Comment.cpp rename to src/pocketdb/models/dto/content/Comment.cpp index b9aab6a47..e820e189e 100644 --- a/src/pocketdb/models/dto/Comment.cpp +++ b/src/pocketdb/models/dto/content/Comment.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Comment.h" +#include "pocketdb/models/dto/content/Comment.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Comment.h b/src/pocketdb/models/dto/content/Comment.h similarity index 100% rename from src/pocketdb/models/dto/Comment.h rename to src/pocketdb/models/dto/content/Comment.h diff --git a/src/pocketdb/models/dto/CommentDelete.cpp b/src/pocketdb/models/dto/content/CommentDelete.cpp similarity index 95% rename from src/pocketdb/models/dto/CommentDelete.cpp rename to src/pocketdb/models/dto/content/CommentDelete.cpp index 25cdf2ed0..dfcdbab59 100644 --- a/src/pocketdb/models/dto/CommentDelete.cpp +++ b/src/pocketdb/models/dto/content/CommentDelete.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/CommentDelete.h" +#include "pocketdb/models/dto/content/CommentDelete.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/CommentDelete.h b/src/pocketdb/models/dto/content/CommentDelete.h similarity index 92% rename from src/pocketdb/models/dto/CommentDelete.h rename to src/pocketdb/models/dto/content/CommentDelete.h index 514d2aeb1..768a867b4 100644 --- a/src/pocketdb/models/dto/CommentDelete.h +++ b/src/pocketdb/models/dto/content/CommentDelete.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_COMMENT_DELETE_H #define POCKETTX_COMMENT_DELETE_H -#include "pocketdb/models/dto/Comment.h" +#include "pocketdb/models/dto/content/Comment.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/CommentEdit.cpp b/src/pocketdb/models/dto/content/CommentEdit.cpp similarity index 90% rename from src/pocketdb/models/dto/CommentEdit.cpp rename to src/pocketdb/models/dto/content/CommentEdit.cpp index 9e27a1f32..886a31980 100644 --- a/src/pocketdb/models/dto/CommentEdit.cpp +++ b/src/pocketdb/models/dto/content/CommentEdit.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/CommentEdit.h" +#include "pocketdb/models/dto/content/CommentEdit.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/CommentEdit.h b/src/pocketdb/models/dto/content/CommentEdit.h similarity index 90% rename from src/pocketdb/models/dto/CommentEdit.h rename to src/pocketdb/models/dto/content/CommentEdit.h index d8c0d9329..eb3e4126c 100644 --- a/src/pocketdb/models/dto/CommentEdit.h +++ b/src/pocketdb/models/dto/content/CommentEdit.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_COMMENT_EDIT_H #define POCKETTX_COMMENT_EDIT_H -#include "pocketdb/models/dto/Comment.h" +#include "pocketdb/models/dto/content/Comment.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Content.cpp b/src/pocketdb/models/dto/content/Content.cpp similarity index 94% rename from src/pocketdb/models/dto/Content.cpp rename to src/pocketdb/models/dto/content/Content.cpp index 12bcb2d52..8e569d353 100644 --- a/src/pocketdb/models/dto/Content.cpp +++ b/src/pocketdb/models/dto/content/Content.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Content.h" +#include "pocketdb/models/dto/content/Content.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Content.h b/src/pocketdb/models/dto/content/Content.h similarity index 100% rename from src/pocketdb/models/dto/Content.h rename to src/pocketdb/models/dto/content/Content.h diff --git a/src/pocketdb/models/dto/ContentDelete.cpp b/src/pocketdb/models/dto/content/ContentDelete.cpp similarity index 97% rename from src/pocketdb/models/dto/ContentDelete.cpp rename to src/pocketdb/models/dto/content/ContentDelete.cpp index eb7c1718d..ad8fccd81 100644 --- a/src/pocketdb/models/dto/ContentDelete.cpp +++ b/src/pocketdb/models/dto/content/ContentDelete.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/ContentDelete.h" +#include "pocketdb/models/dto/content/ContentDelete.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/ContentDelete.h b/src/pocketdb/models/dto/content/ContentDelete.h similarity index 94% rename from src/pocketdb/models/dto/ContentDelete.h rename to src/pocketdb/models/dto/content/ContentDelete.h index bb4637790..a15df00ad 100644 --- a/src/pocketdb/models/dto/ContentDelete.h +++ b/src/pocketdb/models/dto/content/ContentDelete.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_CONTENT_DELETE_H #define POCKETTX_CONTENT_DELETE_H -#include "pocketdb/models/dto/Content.h" +#include "pocketdb/models/dto/content/Content.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Post.cpp b/src/pocketdb/models/dto/content/Post.cpp similarity index 99% rename from src/pocketdb/models/dto/Post.cpp rename to src/pocketdb/models/dto/content/Post.cpp index 2c166d8f5..d1df4a589 100644 --- a/src/pocketdb/models/dto/Post.cpp +++ b/src/pocketdb/models/dto/content/Post.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Post.h" +#include "pocketdb/models/dto/content/Post.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Post.h b/src/pocketdb/models/dto/content/Post.h similarity index 96% rename from src/pocketdb/models/dto/Post.h rename to src/pocketdb/models/dto/content/Post.h index f95d39bc2..486682f68 100644 --- a/src/pocketdb/models/dto/Post.h +++ b/src/pocketdb/models/dto/content/Post.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_POST_H #define POCKETTX_POST_H -#include "pocketdb/models/dto/Content.h" +#include "pocketdb/models/dto/content/Content.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Video.cpp b/src/pocketdb/models/dto/content/Video.cpp similarity index 90% rename from src/pocketdb/models/dto/Video.cpp rename to src/pocketdb/models/dto/content/Video.cpp index 5e9562c22..c2c2518f9 100644 --- a/src/pocketdb/models/dto/Video.cpp +++ b/src/pocketdb/models/dto/content/Video.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Video.h" +#include "pocketdb/models/dto/content/Video.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Video.h b/src/pocketdb/models/dto/content/Video.h similarity index 90% rename from src/pocketdb/models/dto/Video.h rename to src/pocketdb/models/dto/content/Video.h index 4b12ad82d..a57392993 100644 --- a/src/pocketdb/models/dto/Video.h +++ b/src/pocketdb/models/dto/content/Video.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_VIDEO_H #define POCKETTX_VIDEO_H -#include "pocketdb/models/dto/Post.h" +#include "pocketdb/models/dto/content/Post.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Coinbase.cpp b/src/pocketdb/models/dto/money/Coinbase.cpp similarity index 90% rename from src/pocketdb/models/dto/Coinbase.cpp rename to src/pocketdb/models/dto/money/Coinbase.cpp index 1ec426a1d..9e1f073b4 100644 --- a/src/pocketdb/models/dto/Coinbase.cpp +++ b/src/pocketdb/models/dto/money/Coinbase.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Coinbase.h" +#include "pocketdb/models/dto/money/Coinbase.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Coinbase.h b/src/pocketdb/models/dto/money/Coinbase.h similarity index 90% rename from src/pocketdb/models/dto/Coinbase.h rename to src/pocketdb/models/dto/money/Coinbase.h index 45f8a070b..a463c6286 100644 --- a/src/pocketdb/models/dto/Coinbase.h +++ b/src/pocketdb/models/dto/money/Coinbase.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_COINBASE_H #define POCKETTX_COINBASE_H -#include "pocketdb/models/dto/Default.h" +#include "pocketdb/models/dto/money/Default.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Coinstake.cpp b/src/pocketdb/models/dto/money/Coinstake.cpp similarity index 90% rename from src/pocketdb/models/dto/Coinstake.cpp rename to src/pocketdb/models/dto/money/Coinstake.cpp index f151ab1b1..50da8ddd0 100644 --- a/src/pocketdb/models/dto/Coinstake.cpp +++ b/src/pocketdb/models/dto/money/Coinstake.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Coinstake.h" +#include "pocketdb/models/dto/money/Coinstake.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Coinstake.h b/src/pocketdb/models/dto/money/Coinstake.h similarity index 90% rename from src/pocketdb/models/dto/Coinstake.h rename to src/pocketdb/models/dto/money/Coinstake.h index 10a8dc388..835ac932e 100644 --- a/src/pocketdb/models/dto/Coinstake.h +++ b/src/pocketdb/models/dto/money/Coinstake.h @@ -5,7 +5,7 @@ #ifndef POCKETTX_COINSTAKE_H #define POCKETTX_COINSTAKE_H -#include "pocketdb/models/dto/Default.h" +#include "pocketdb/models/dto/money/Default.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Default.cpp b/src/pocketdb/models/dto/money/Default.cpp similarity index 93% rename from src/pocketdb/models/dto/Default.cpp rename to src/pocketdb/models/dto/money/Default.cpp index f8972317b..d205fb143 100644 --- a/src/pocketdb/models/dto/Default.cpp +++ b/src/pocketdb/models/dto/money/Default.cpp @@ -3,7 +3,7 @@ // https://www.apache.org/licenses/LICENSE-2.0 #include -#include "pocketdb/models/dto/Default.h" +#include "pocketdb/models/dto/money/Default.h" namespace PocketTx { diff --git a/src/pocketdb/models/dto/Default.h b/src/pocketdb/models/dto/money/Default.h similarity index 100% rename from src/pocketdb/models/dto/Default.h rename to src/pocketdb/models/dto/money/Default.h diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index 2acf893bd..abf22439e 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -403,6 +403,48 @@ namespace PocketDb return result; } + bool ConsensusRepository::ExistsInMempool(const string& string1, const vector& types) + { + return ExistsInMempool(string1, "", types); + } + + bool ConsensusRepository::ExistsInMempool(const string& string1, const string& string2, const vector& types) + { + bool result = false; + + string sql = R"sql( + select 1 + from Transactions indexed by Transactions_Type_String1_String2_Height + where Type in ( )sql" + join(vector(types.size(), "?"), ",") + R"sql( ) + )sql"; + + if (string1 != "") + sql += " and String1 = ?"; + + if (string2 != "") + sql += " and String2 = ?"; + + TryTransactionStep(__func__, [&]() + { + auto stmt = SetupSqlStatement(sql); + + int i = 1; + for (const auto& type: types) + TryBindStatementInt(stmt, i++, type); + if (string1 != "") + TryBindStatementText(stmt, i++, string1); + if (string2 != "") + TryBindStatementText(stmt, i++, string2); + + if (sqlite3_step(*stmt) == SQLITE_ROW) + result = true; + + FinalizeSqlStatement(*stmt); + }); + + return result; + } + bool ConsensusRepository::ExistsNotDeleted(const string& txHash, const string& address, const vector& types) { bool result = false; diff --git a/src/pocketdb/repositories/ConsensusRepository.h b/src/pocketdb/repositories/ConsensusRepository.h index 23cea5ecf..b1e29df4e 100644 --- a/src/pocketdb/repositories/ConsensusRepository.h +++ b/src/pocketdb/repositories/ConsensusRepository.h @@ -123,6 +123,8 @@ namespace PocketDb bool ExistsUserRegistrations(vector& addresses, bool mempool); bool ExistsAnotherByName(const string& address, const string& name); bool Exists(const string& txHash, const vector& types, bool inChain); + bool ExistsInMempool(const string& string1, const vector& types); + bool ExistsInMempool(const string& string1, const string& string2, const vector& types); bool ExistsNotDeleted(const string& txHash, const string& address, const vector& types); // get counts in "mempool" - Height is null diff --git a/src/pocketdb/repositories/TransactionRepository.h b/src/pocketdb/repositories/TransactionRepository.h index b9fad462b..5bc836d23 100644 --- a/src/pocketdb/repositories/TransactionRepository.h +++ b/src/pocketdb/repositories/TransactionRepository.h @@ -14,9 +14,6 @@ #include "pocketdb/models/base/TransactionOutput.h" #include "pocketdb/models/base/Rating.h" #include "pocketdb/models/base/DtoModels.h" -#include "pocketdb/models/dto/User.h" -#include "pocketdb/models/dto/ScoreContent.h" -#include "pocketdb/models/dto/ScoreComment.h" namespace PocketDb { diff --git a/src/pocketdb/services/Serializer.h b/src/pocketdb/services/Serializer.h index 49b539158..c19a03842 100644 --- a/src/pocketdb/services/Serializer.h +++ b/src/pocketdb/services/Serializer.h @@ -9,21 +9,6 @@ #include "pocketdb/models/base/Transaction.h" #include "pocketdb/models/base/TransactionOutput.h" -#include "pocketdb/models/dto/Coinbase.h" -#include "pocketdb/models/dto/Coinstake.h" -#include "pocketdb/models/dto/Default.h" -#include "pocketdb/models/dto/User.h" -#include "pocketdb/models/dto/Post.h" -#include "pocketdb/models/dto/Video.h" -#include "pocketdb/models/dto/Blocking.h" -#include "pocketdb/models/dto/BlockingCancel.h" -#include "pocketdb/models/dto/Comment.h" -#include "pocketdb/models/dto/ScoreContent.h" -#include "pocketdb/models/dto/ScoreComment.h" -#include "pocketdb/models/dto/Subscribe.h" -#include "pocketdb/models/dto/SubscribePrivate.h" -#include "pocketdb/models/dto/SubscribeCancel.h" -#include "pocketdb/models/dto/Complain.h" #include "key_io.h" #include "streams.h" diff --git a/src/pocketdb/web/PocketTransactionRpc.cpp b/src/pocketdb/web/PocketTransactionRpc.cpp index 5ebb3b875..6afdad3ed 100644 --- a/src/pocketdb/web/PocketTransactionRpc.cpp +++ b/src/pocketdb/web/PocketTransactionRpc.cpp @@ -10,7 +10,7 @@ #include "script/signingprovider.h" #include "util/rbf.h" #include "rpc/rawtransaction_util.h" -#include "pocketdb/consensus/social/User.hpp" +#include "pocketdb/consensus/social/AccountUser.hpp" namespace PocketWeb::PocketWebRpc { @@ -53,12 +53,12 @@ namespace PocketWeb::PocketWebRpc // Set required fields ptx->SetString1(address); - // TODO (team): TEMPORARY + // TODO (0.21.0): TEMPORARY // Temporary check for UserConsensus_checkpoint_login_limitation checkpoint // Remove this after 1647000 in main net if (*ptx->GetType() == ACCOUNT_USER) { - std::shared_ptr accountUserConsensus = std::make_shared(ChainActive().Height()); + std::shared_ptr accountUserConsensus = std::make_shared(ChainActive().Height()); if (auto[ok, result] = accountUserConsensus->Check(tx, static_pointer_cast(ptx)); !ok) throw JSONRPCError((int)result, strprintf("Failed SocialConsensusHelper::Check with result %d\n", (int)result)); } From d100eb59fc6bc322e660b50b46b4838c47ab784f Mon Sep 17 00:00:00 2001 From: brangr Date: Fri, 9 Sep 2022 17:49:37 +0300 Subject: [PATCH 03/49] Fix check height in ExistsInMempool --- .../repositories/ConsensusRepository.cpp | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index abf22439e..d6a7116af 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -405,25 +405,51 @@ namespace PocketDb bool ConsensusRepository::ExistsInMempool(const string& string1, const vector& types) { - return ExistsInMempool(string1, "", types); + assert(string1 != ""); + bool result = false; + + string sql = R"sql( + select 1 + from Transactions indexed by Transactions_Type_String1_Height_Time_Int1 + where Type in ( )sql" + join(vector(types.size(), "?"), ",") + R"sql( ) + and String1 = ? + and Height is null + limit 1 + )sql"; + + TryTransactionStep(__func__, [&]() + { + auto stmt = SetupSqlStatement(sql); + + int i = 1; + for (const auto& type: types) + TryBindStatementInt(stmt, i++, type); + TryBindStatementText(stmt, i++, string1); + + if (sqlite3_step(*stmt) == SQLITE_ROW) + result = true; + + FinalizeSqlStatement(*stmt); + }); + + return result; } bool ConsensusRepository::ExistsInMempool(const string& string1, const string& string2, const vector& types) { + assert(string1 != ""); + assert(string2 != ""); bool result = false; string sql = R"sql( select 1 from Transactions indexed by Transactions_Type_String1_String2_Height where Type in ( )sql" + join(vector(types.size(), "?"), ",") + R"sql( ) + and String1 = ? + and String2 = ? + and Height is null )sql"; - if (string1 != "") - sql += " and String1 = ?"; - - if (string2 != "") - sql += " and String2 = ?"; - TryTransactionStep(__func__, [&]() { auto stmt = SetupSqlStatement(sql); @@ -431,10 +457,8 @@ namespace PocketDb int i = 1; for (const auto& type: types) TryBindStatementInt(stmt, i++, type); - if (string1 != "") - TryBindStatementText(stmt, i++, string1); - if (string2 != "") - TryBindStatementText(stmt, i++, string2); + TryBindStatementText(stmt, i++, string1); + TryBindStatementText(stmt, i++, string2); if (sqlite3_step(*stmt) == SQLITE_ROW) result = true; From f1a4ec523083b10fd9b5d5e0bab9750eeab9cd74 Mon Sep 17 00:00:00 2001 From: brangr Date: Sat, 10 Sep 2022 21:28:12 +0300 Subject: [PATCH 04/49] Refactoring account editing --- src/pocketdb/consensus/social/AccountUser.hpp | 88 ++----------- src/pocketdb/models/base/PocketTypes.h | 9 +- src/pocketdb/repositories/ChainRepository.cpp | 117 ++++++++++++------ src/pocketdb/repositories/ChainRepository.h | 1 + .../repositories/ConsensusRepository.cpp | 58 +++------ .../repositories/ConsensusRepository.h | 5 +- .../repositories/web/ExplorerRepository.cpp | 4 +- .../repositories/web/NotifierRepository.cpp | 16 +-- .../repositories/web/WebRepository.cpp | 2 +- .../repositories/web/WebRpcRepository.cpp | 14 +-- 10 files changed, 134 insertions(+), 180 deletions(-) diff --git a/src/pocketdb/consensus/social/AccountUser.hpp b/src/pocketdb/consensus/social/AccountUser.hpp index 9471d42ff..74f02c384 100644 --- a/src/pocketdb/consensus/social/AccountUser.hpp +++ b/src/pocketdb/consensus/social/AccountUser.hpp @@ -24,9 +24,9 @@ namespace PocketConsensus AccountUserConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const UserRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; + // Check payload size + if (auto[ok, code] = ValidatePayloadSize(ptx); !ok) + return {false, code}; // Duplicate name if (ConsensusRepoInst.ExistsAnotherByName(*ptx->GetAddress(), *ptx->GetPayloadName())) @@ -35,11 +35,12 @@ namespace PocketConsensus return {false, SocialConsensusResult_NicknameDouble}; } - // Check payload size - if (auto[ok, code] = ValidatePayloadSize(ptx); !ok) - return {false, code}; + // The deleted account cannot be restored + if (auto[ok, type] = ConsensusRepoInst.GetLastAccountType(*ptx->GetAddress()); ok) + if (type == TxType::ACCOUNT_DELETE) + return {false, SocialConsensusResult_NotFound}; - return ValidateEdit(ptx); + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const UserRef& ptx) override { @@ -110,33 +111,6 @@ namespace PocketConsensus return {}; } - virtual ConsensusValidateResult ValidateEdit(const UserRef& ptx) - { - // First user account transaction allowed without next checks - if (auto[ok, prevTxHeight] = ConsensusRepoInst.GetLastAccountHeight(*ptx->GetAddress()); !ok) - return Success; - - // Check editing limits - if (auto[ok, code] = ValidateEditLimit(ptx); !ok) - return {false, code}; - - return Success; - } - - virtual ConsensusValidateResult ValidateEditLimit(const UserRef& ptx) - { - // First user account transaction allowed without next checks - auto[prevOk, prevTime] = ConsensusRepoInst.GetLastAccountTime(*ptx->GetAddress()); - if (!prevOk) - return Success; - - // We allow edit profile only with delay - if ((*ptx->GetTime() - prevTime) <= GetConsensusLimit(ConsensusLimit_edit_user_depth)) - return {false, SocialConsensusResult_ChangeInfoLimit}; - - return Success; - } - virtual int GetChainCount(const UserRef& ptx) { return 0; @@ -181,40 +155,11 @@ namespace PocketConsensus } }; - /******************************************************************************************************************* - * Start checkpoint at 1180000 block - *******************************************************************************************************************/ - class AccountUserConsensus_checkpoint_1180000 : public AccountUserConsensus - { - public: - AccountUserConsensus_checkpoint_1180000(int height) : AccountUserConsensus(height) {} - protected: - ConsensusValidateResult ValidateEditLimit(const UserRef& ptx) override - { - // First user account transaction allowed without next checks - auto[ok, prevTxHeight] = ConsensusRepoInst.GetLastAccountHeight(*ptx->GetAddress()); - if (!ok) return Success; - - // We allow edit profile only with delay - if ((Height - prevTxHeight) <= GetConsensusLimit(ConsensusLimit_edit_user_depth)) - return {false, SocialConsensusResult_ChangeInfoLimit}; - - return Success; - } - }; - - /******************************************************************************************************************* - * Start checkpoint at 1381841 block - *******************************************************************************************************************/ - class AccountUserConsensus_checkpoint_1381841 : public AccountUserConsensus_checkpoint_1180000 + class AccountUserConsensus_checkpoint_chain_count : public AccountUserConsensus { public: - AccountUserConsensus_checkpoint_1381841(int height) : AccountUserConsensus_checkpoint_1180000(height) {} + AccountUserConsensus_checkpoint_chain_count(int height) : AccountUserConsensus(height) {} protected: - ConsensusValidateResult ValidateEditLimit(const UserRef& ptx) override - { - return Success; - } int GetChainCount(const UserRef& ptx) override { return ConsensusRepoInst.CountChainAccount( @@ -225,13 +170,10 @@ namespace PocketConsensus } }; - /******************************************************************************************************************* - * Limitations for username - *******************************************************************************************************************/ - class AccountUserConsensus_checkpoint_login_limitation : public AccountUserConsensus_checkpoint_1381841 + class AccountUserConsensus_checkpoint_login_limitation : public AccountUserConsensus_checkpoint_chain_count { public: - AccountUserConsensus_checkpoint_login_limitation(int height) : AccountUserConsensus_checkpoint_1381841(height) {} + AccountUserConsensus_checkpoint_login_limitation(int height) : AccountUserConsensus_checkpoint_chain_count(height) {} protected: ConsensusValidateResult CheckLogin(const UserRef& ptx) override @@ -280,16 +222,12 @@ namespace PocketConsensus }; - /******************************************************************************************************************* - * Factory for select actual rules version - *******************************************************************************************************************/ class AccountUserConsensusFactory { private: const vector> m_rules = { { 0, -1, [](int height) { return make_shared(height); }}, - { 1180000, 0, [](int height) { return make_shared(height); }}, - { 1381841, 162000, [](int height) { return make_shared(height); }}, + { 1381841, 162000, [](int height) { return make_shared(height); }}, { 1647000, 650000, [](int height) { return make_shared(height); }}, // ~ 03/25/2022 }; public: diff --git a/src/pocketdb/models/base/PocketTypes.h b/src/pocketdb/models/base/PocketTypes.h index f0ab8c700..6088aec7a 100644 --- a/src/pocketdb/models/base/PocketTypes.h +++ b/src/pocketdb/models/base/PocketTypes.h @@ -142,9 +142,12 @@ namespace PocketTx bool IsAccount() const { return Type == TxType::ACCOUNT_USER || - Type == TxType::ACCOUNT_VIDEO_SERVER || - Type == TxType::ACCOUNT_MESSAGE_SERVER || - Type == TxType::ACCOUNT_SETTING; + Type == TxType::ACCOUNT_DELETE; + } + + bool IsAccountSetting() const + { + return Type == TxType::ACCOUNT_SETTING; } bool IsContent() const diff --git a/src/pocketdb/repositories/ChainRepository.cpp b/src/pocketdb/repositories/ChainRepository.cpp index a44472f6b..c92fa1f95 100644 --- a/src/pocketdb/repositories/ChainRepository.cpp +++ b/src/pocketdb/repositories/ChainRepository.cpp @@ -27,6 +27,9 @@ namespace PocketDb if (txInfo.IsAccount()) IndexAccount(txInfo.Hash); + if (txInfo.IsAccountSetting()) + IndexAccountSetting(txInfo.Hash); + if (txInfo.IsContent()) IndexContent(txInfo.Hash); @@ -59,41 +62,6 @@ namespace PocketDb }); } - bool ChainRepository::ClearDatabase() - { - LogPrintf("Full reindexing database. This can take several days.\n"); - - LogPrintf("Deleting database indexes..\n"); - m_database.DropIndexes(); - - LogPrintf("Rollback to first block..\n"); - RollbackHeight(0); - - m_database.CreateStructure(); - - return true; - } - - bool ChainRepository::Rollback(int height) - { - try - { - // Update transactions - TryTransactionStep(__func__, [&]() - { - RestoreOldLast(height); - RollbackHeight(height); - }); - - return true; - } - catch (std::exception& ex) - { - LogPrintf("Error: Rollback to height %d failed with message: %s\n", height, ex.what()); - return false; - } - } - tuple ChainRepository::ExistsBlock(const string& blockHash, int height) { bool exists = false; @@ -127,6 +95,7 @@ namespace PocketDb return {exists, last}; } + void ChainRepository::UpdateTransactionHeight(const string& blockHash, int blockNumber, int height, const string& txHash) { auto stmt = SetupSqlStatement(R"sql( @@ -171,6 +140,7 @@ namespace PocketDb } } + void ChainRepository::IndexBalances(int height) { // Generate new balance records @@ -237,9 +207,43 @@ namespace PocketDb ( select a.Id from Transactions a indexed by Transactions_Type_Last_String1_Height_Id - where a.Type in (Transactions.Type) + where a.Type in (100,170) + and a.Last = 1 + and a.String1 = Transactions.String1 + and a.Height is not null + limit 1 + ), + ifnull( + -- new record + ( + select max( a.Id ) + 1 + from Transactions a indexed by Transactions_Id + ), + 0 -- for first record + ) + ), + Last = 1 + WHERE Hash = ? + )sql"); + TryBindStatementText(setIdStmt, 1, txHash); + TryStepStatement(setIdStmt); + + // Clear old last records for set new last + ClearOldLast(txHash); + } + + void ChainRepository::IndexAccountSetting(const string& txHash) + { + // Get new ID or copy previous + auto setIdStmt = SetupSqlStatement(R"sql( + UPDATE Transactions SET + Id = ifnull( + -- copy self Id + ( + select a.Id + from Transactions a indexed by Transactions_Type_Last_String1_Height_Id + where a.Type in (103) and a.Last = 1 - -- String1 = AddressHash and a.String1 = Transactions.String1 and a.Height is not null limit 1 @@ -309,7 +313,7 @@ namespace PocketDb ( select max( c.Id ) from Transactions c indexed by Transactions_Type_Last_String2_Height - where c.Type in (204, 205, 206) + where c.Type in (204,205,206) and c.Last = 1 -- String2 = RootTxHash and c.String2 = Transactions.String2 @@ -470,6 +474,42 @@ namespace PocketDb TryStepStatement(stmt); } + + bool ChainRepository::ClearDatabase() + { + LogPrintf("Full reindexing database. This can take several days.\n"); + + LogPrintf("Deleting database indexes..\n"); + m_database.DropIndexes(); + + LogPrintf("Rollback to first block..\n"); + RollbackHeight(0); + + m_database.CreateStructure(); + + return true; + } + + bool ChainRepository::Rollback(int height) + { + try + { + // Update transactions + TryTransactionStep(__func__, [&]() + { + RestoreOldLast(height); + RollbackHeight(height); + }); + + return true; + } + catch (std::exception& ex) + { + LogPrintf("Error: Rollback to height %d failed with message: %s\n", height, ex.what()); + return false; + } + } + void ChainRepository::ClearOldLast(const string& txHash) { auto stmt = SetupSqlStatement(R"sql( @@ -489,7 +529,6 @@ namespace PocketDb TryStepStatement(stmt); } - void ChainRepository::RestoreOldLast(int height) { int64_t nTime0 = GetTimeMicros(); diff --git a/src/pocketdb/repositories/ChainRepository.h b/src/pocketdb/repositories/ChainRepository.h index c1dde9623..72ba4dc5f 100644 --- a/src/pocketdb/repositories/ChainRepository.h +++ b/src/pocketdb/repositories/ChainRepository.h @@ -58,6 +58,7 @@ namespace PocketDb void UpdateTransactionOutputs(const TransactionIndexingInfo& txInfo, int height); void IndexAccount(const string& txHash); + void IndexAccountSetting(const string& txHash); void IndexContent(const string& txHash); void IndexComment(const string& txHash); void IndexBlocking(const string& txHash); diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index d6a7116af..2a1c6d12e 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -22,7 +22,7 @@ namespace PocketDb select count(*) from Payload ap indexed by Payload_String2_nocase_TxHash cross join Transactions t indexed by Transactions_Hash_Height - on t.Type in (100, 101, 102) and t.Hash = ap.TxHash and t.Height is not null and t.Last = 1 + on t.Type = 100 and t.Hash = ap.TxHash and t.Height is not null and t.Last = 1 where ap.String2 like ? escape '\' and t.String1 != ? )sql"); @@ -152,7 +152,7 @@ namespace PocketDb string sql = R"sql( select count(distinct(String1)) from Transactions - where Type in (100, 101, 102) + where Type = 100 and String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) )sql" + (mempool ? "" : " and Height is not null ") + R"sql( )sql"; @@ -537,7 +537,7 @@ namespace PocketDb select r.Value from Ratings r where r.Type = 0 - and r.Id = (SELECT u.Id FROM Transactions u WHERE u.Type in (100, 101, 102) and u.Height is not null and u.Last = 1 and u.String1 = ? LIMIT 1) + and r.Id = (SELECT u.Id FROM Transactions u WHERE u.Type = 100 and u.Height is not null and u.Last = 1 and u.String1 = ? LIMIT 1) and r.Last = 1 )sql"; @@ -590,7 +590,7 @@ namespace PocketDb string sql = R"sql( select min(Height) from Transactions - where Type in (100, 101, 102) + where Type in (100) and Id = ? )sql"; @@ -720,7 +720,7 @@ namespace PocketDb -- Score Address join Transactions sa indexed by Transactions_Type_Last_String1_Height_Id - on sa.Type in (100,101,102) and sa.Height > 0 and sa.String1 = s.String1 and sa.Last = 1 + on sa.Type in (100) and sa.Height > 0 and sa.String1 = s.String1 and sa.Last = 1 -- Content join Transactions c indexed by Transactions_Hash_Height @@ -728,7 +728,7 @@ namespace PocketDb -- Content Address join Transactions ca indexed by Transactions_Type_Last_String1_Height_Id - on ca.Type in (100,101,102) and ca.Height > 0 and ca.String1 = c.String1 and ca.Last = 1 + on ca.Type in (100) and ca.Height > 0 and ca.String1 = c.String1 and ca.Last = 1 where s.Hash = ? )sql"; @@ -779,10 +779,10 @@ namespace PocketDb string sql = R"sql( select u.String1, u.String2 from Transactions u - where u.Type in (100, 101, 102) + where u.Type in (100) and u.Height is not null and u.Height >= ? - and u.Height = (select min(u1.Height) from Transactions u1 where u1.Type in (100, 101, 102) and u1.Height is not null and u1.String1=u.String1) + and u.Height = (select min(u1.Height) from Transactions u1 where u1.Type in (100) and u1.Height is not null and u1.String1=u.String1) and u.String2 is not null )sql"; @@ -955,43 +955,17 @@ namespace PocketDb return result; } - tuple ConsensusRepository::GetLastAccountTime(const string& address) + tuple ConsensusRepository::GetLastAccountType(const string& address) { - tuple result = {false, 0}; + tuple result = {false, TxType::ACCOUNT_DELETE}; TryTransactionStep(__func__, [&]() { auto stmt = SetupSqlStatement(R"sql( - select Time - from Transactions indexed by Transactions_Type_Last_String1_Height_Id - where Type in (100, 101, 102) - and String1 = ? - and Last = 1 - and Height is not null - )sql"); - - TryBindStatementText(stmt, 1, address); - - if (sqlite3_step(*stmt) == SQLITE_ROW) - if (auto[ok, value] = TryGetColumnInt64(*stmt, 0); ok) - result = {true, value}; - - FinalizeSqlStatement(*stmt); - }); - - return result; - } - - tuple ConsensusRepository::GetLastAccountHeight(const string& address) - { - tuple result = {false, 0}; - - TryTransactionStep(__func__, [&]() - { - auto stmt = SetupSqlStatement(R"sql( - select Height + select + Type from Transactions indexed by Transactions_Type_Last_String1_Height_Id - where Type in (100, 101, 102) + where Type in (100,170) and String1 = ? and Last = 1 and Height is not null @@ -1000,8 +974,10 @@ namespace PocketDb TryBindStatementText(stmt, 1, address); if (sqlite3_step(*stmt) == SQLITE_ROW) - if (auto[ok, value] = TryGetColumnInt64(*stmt, 0); ok) - result = {true, value}; + { + if (auto[ok, type] = TryGetColumnInt64(*stmt, 0); ok) + result = {true, (TxType)type}; + } FinalizeSqlStatement(*stmt); }); diff --git a/src/pocketdb/repositories/ConsensusRepository.h b/src/pocketdb/repositories/ConsensusRepository.h index b1e29df4e..e0a3eff65 100644 --- a/src/pocketdb/repositories/ConsensusRepository.h +++ b/src/pocketdb/repositories/ConsensusRepository.h @@ -83,11 +83,8 @@ namespace PocketDb tuple GetFirstContent(const string& rootHash); tuple GetLastContent(const string& rootHash, const vector& types); - - tuple GetLastAccountTime(const string& address); - tuple GetLastAccountHeight(const string& address); + tuple GetLastAccountType(const string& address); tuple GetTransactionHeight(const string& hash); - tuple GetLastBlockingType(const string& address, const string& addressTo); bool ExistBlocking(const string& address, const string& addressTo, const string& addressesTo); tuple GetLastSubscribeType(const string& address, const string& addressTo); diff --git a/src/pocketdb/repositories/web/ExplorerRepository.cpp b/src/pocketdb/repositories/web/ExplorerRepository.cpp index 39ea5863b..41ba52f28 100644 --- a/src/pocketdb/repositories/web/ExplorerRepository.cpp +++ b/src/pocketdb/repositories/web/ExplorerRepository.cpp @@ -262,9 +262,9 @@ namespace PocketDb { TryTransactionStep(__func__, [&]() { auto stmt = SetupSqlStatement(R"sql( - select t.Type, count()Count + select t.Type, count() from Transactions t indexed by Transactions_Type_Last_Height_Id - where t.Type in (100,101,102,200,201,202,208) + where t.Type in (100,200,201,202,208) and t.Last = 1 and t.Height > 0 group by t.Type diff --git a/src/pocketdb/repositories/web/NotifierRepository.cpp b/src/pocketdb/repositories/web/NotifierRepository.cpp index c24088d8e..72e4ca489 100644 --- a/src/pocketdb/repositories/web/NotifierRepository.cpp +++ b/src/pocketdb/repositories/web/NotifierRepository.cpp @@ -20,7 +20,7 @@ namespace PocketDb p.String3 as Avatar from Transactions u indexed by Transactions_Type_Last_String1_Height_Id cross join Payload p on p.TxHash = u.Hash - where u.Type in (100,101,102) + where u.Type in (100) and u.Last=1 and u.Last=1 and u.Height is not null @@ -168,7 +168,7 @@ namespace PocketDb join Payload p on p.TxHash = u.Hash where tRepost.Type in (200, 201, 202, 203) and tRepost.Hash = ? - and u.Type in (100,101,102) + and u.Type in (100) and u.Last = 1 and u.Height is not null )sql"; @@ -209,7 +209,7 @@ namespace PocketDb and s.Last = 1 and s.Height is not null and s.String2 = ? - and u.Type in (100,101,102) + and u.Type in (100) and u.Last=1 and u.Height is not null )sql"; @@ -250,7 +250,7 @@ namespace PocketDb where r.Type in (100) and r.String2 is not null and r.Hash = ? - and u.Type in (100,101,102) + and u.Type in (100) and u.Last=1 and u.Height is not null )sql"; @@ -290,7 +290,7 @@ namespace PocketDb join Payload p on p.TxHash = u.Hash where score.Type in (300) and score.Hash = ? - and u.Type in (100,101,102) + and u.Type in (100) and u.Last=1 and u.Height is not null )sql"; @@ -329,7 +329,7 @@ namespace PocketDb join Payload p on p.TxHash = u.Hash where s.Type in (302, 303, 304) and s.Hash = ? - and u.Type in (100,101,102) + and u.Type in (100) and u.Last=1 and u.Height is not null )sql"; @@ -369,7 +369,7 @@ namespace PocketDb join Transactions u indexed by Transactions_Type_Last_String1_Height_Id on u.String1 = score.String1 join Payload p on p.TxHash = u.Hash where score.Hash = ? - and u.Type in (100,101,102) + and u.Type in (100) and u.Last=1 and u.Height is not null )sql"; @@ -422,7 +422,7 @@ namespace PocketDb on answer.Type in (204, 205) and answer.Last = 1 and answer.String2 = comment.String5 WHERE comment.Type in (204, 205) and comment.Hash = ? - and u.Type in (100,101,102) + and u.Type in (100) and u.Last=1 and u.Height is not null )sql"; diff --git a/src/pocketdb/repositories/web/WebRepository.cpp b/src/pocketdb/repositories/web/WebRepository.cpp index 4db42900f..2531e0bc4 100644 --- a/src/pocketdb/repositories/web/WebRepository.cpp +++ b/src/pocketdb/repositories/web/WebRepository.cpp @@ -121,7 +121,7 @@ namespace PocketDb from Transactions t indexed by Transactions_BlockHash join Payload p on p.TxHash = t.Hash where t.BlockHash = ? - and t.Type in (100, 101, 102, 200, 201, 202, 204, 205) + and t.Type in (100, 200, 201, 202, 204, 205) )sql"; TryTransactionStep(__func__, [&]() diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 6ad999a53..457a64c4f 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -121,7 +121,7 @@ namespace PocketDb string sql = R"sql( SELECT String1, Id FROM Transactions - WHERE Type in (100, 101, 102) + WHERE Type in (100) and Height is not null and Last = 1 and String1 = ? @@ -152,7 +152,7 @@ namespace PocketDb string sql = R"sql( SELECT String1, Id FROM Transactions - WHERE Type in (100, 101, 102) + WHERE Type in (100) and Height is not null and Last = 1 and Id = ? @@ -186,7 +186,7 @@ namespace PocketDb select p.String2, u.String1 from Payload p indexed by Payload_String2_nocase_TxHash cross join Transactions u indexed by Transactions_Hash_Height - on u.Type in (100, 101, 102) and u.Height > 0 and u.Hash = p.TxHash and u.Last = 1 + on u.Type in (100) and u.Height > 0 and u.Hash = p.TxHash and u.Last = 1 where p.String2 like ? escape '\' limit 1 )sql"; @@ -223,7 +223,7 @@ namespace PocketDb string sql = R"sql( select u.String1, u.Time, u.Hash from Transactions u indexed by Transactions_Type_Last_String1_Height_Id - where u.Type in (100, 101, 102) + where u.Type in (100) and u.Last in (0,1) and u.String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) and u.Height = ( @@ -323,7 +323,7 @@ namespace PocketDb from Transactions u indexed by Transactions_Type_Last_String1_Height_Id - where u.Type in (100, 101, 102) + where u.Type in (100) and u.Height is not null and u.String1 = ? and u.Last = 1 @@ -656,7 +656,7 @@ namespace PocketDb from Transactions u indexed by Transactions_Type_Last_String1_Height_Id cross join Payload p on p.TxHash=u.Hash - where u.Type in (100,101,102) + where u.Type in (100) and u.Last = 1 and u.Height is not null )sql" + where + R"sql( @@ -2176,7 +2176,7 @@ namespace PocketDb p.String3 as avatarFrom from Transactions t cross join Transactions u indexed by Transactions_Type_Last_String1_Height_Id - on u.String1 = t.String1 and u.Type in (100, 101, 102) and u.Last = 1 and u.Height > 0 + on u.String1 = t.String1 and u.Type in (100) and u.Last = 1 and u.Height > 0 cross join Payload p on p.TxHash = u.Hash where t.Type in (200, 201, 202) and t.Last = 1 From 373012277301a97687c3601dea7ff5fe2214972c Mon Sep 17 00:00:00 2001 From: brangr Date: Sat, 10 Sep 2022 21:32:18 +0300 Subject: [PATCH 05/49] Move to base class opReturnCheck --- src/pocketdb/consensus/social/AccountUser.hpp | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/src/pocketdb/consensus/social/AccountUser.hpp b/src/pocketdb/consensus/social/AccountUser.hpp index 74f02c384..d90eb7055 100644 --- a/src/pocketdb/consensus/social/AccountUser.hpp +++ b/src/pocketdb/consensus/social/AccountUser.hpp @@ -65,7 +65,15 @@ namespace PocketConsensus } ConsensusValidateResult CheckOpReturnHash(const CTransactionRef& tx, const UserRef& ptx) override { - return Success; + auto ptxORHash = ptx->BuildHash(); + auto txORHash = TransactionHelper::ExtractOpReturnHash(tx); + if (ptxORHash == txORHash) + return Success; + + if (CheckpointRepoInst.IsOpReturnCheckpoint(*ptx->GetHash(), ptxORHash)) + return Success; + + return {false, SocialConsensusResult_FailedOpReturn}; } protected: @@ -151,6 +159,15 @@ namespace PocketConsensus virtual ConsensusValidateResult ValidateBlockDuplicateName(const UserRef& ptx, const UserRef& blockPtx) { + auto ptxName = *ptx->GetPayloadName(); + boost::algorithm::to_lower(ptxName); + + auto blockPtxName = *blockPtx->GetPayloadName(); + boost::algorithm::to_lower(blockPtxName); + + if (ptxName == blockPtxName) + return {false, SocialConsensusResult_NicknameDouble}; + return Success; } }; @@ -192,33 +209,6 @@ namespace PocketConsensus return Success; } - // TODO (brangr): move to base class after this checkpoint - ConsensusValidateResult ValidateBlockDuplicateName(const UserRef& ptx, const UserRef& blockPtx) override - { - auto ptxName = *ptx->GetPayloadName(); - boost::algorithm::to_lower(ptxName); - - auto blockPtxName = *blockPtx->GetPayloadName(); - boost::algorithm::to_lower(blockPtxName); - - if (ptxName == blockPtxName) - return {false, SocialConsensusResult_NicknameDouble}; - - return Success; - } - // TODO (brangr): move to base class after this checkpoint - ConsensusValidateResult CheckOpReturnHash(const CTransactionRef& tx, const UserRef& ptx) override - { - auto ptxORHash = ptx->BuildHash(); - auto txORHash = TransactionHelper::ExtractOpReturnHash(tx); - if (ptxORHash == txORHash) - return Success; - - if (CheckpointRepoInst.IsOpReturnCheckpoint(*ptx->GetHash(), ptxORHash)) - return Success; - - return {false, SocialConsensusResult_FailedOpReturn}; - } }; @@ -228,7 +218,7 @@ namespace PocketConsensus const vector> m_rules = { { 0, -1, [](int height) { return make_shared(height); }}, { 1381841, 162000, [](int height) { return make_shared(height); }}, - { 1647000, 650000, [](int height) { return make_shared(height); }}, // ~ 03/25/2022 + { 1647000, 650000, [](int height) { return make_shared(height); }}, }; public: shared_ptr Instance(int height) From cae3cea5921471f79b3d9198c4a5d266482389c7 Mon Sep 17 00:00:00 2001 From: brangr Date: Sat, 10 Sep 2022 21:36:57 +0300 Subject: [PATCH 06/49] Squashed commit of the following: commit 84b78aab2b2f7c9baa2009f57eee3f92385aafb3 Merge: 7b7338c8 499f514b Author: Andy Oknen Date: Fri Sep 9 14:37:44 2022 +0300 Merge pull request #408 from pocketnetteam/actualization/0.20 Squashed commit of the following: commit 499f514bf494920d2847225ae31eeef5811f305b Author: Andy Oknen Date: Fri Sep 9 10:50:15 2022 +0300 Squashed commit of the following: commit aca3fe7d05c1f0c8a9ea76bf02eff87cefd47142 Merge: 78065768 1cce975f Author: Andy Oknen Date: Thu Sep 8 18:40:05 2022 +0300 Merge pull request #399 from HiHat/patch-1 Important details regarding address and fixes commit 780657681d2564844a42c24de0938da74777c642 Merge: bfaef570 5ce96412 Author: Andy Oknen Date: Thu Sep 8 15:09:22 2022 +0300 Merge pull request #402 from pocketnetteam/andyoknen-patch-1 Update README.md commit 5ce96412b1cc0f67148aa4933dd74fe3b43f6c29 Author: Andy Oknen Date: Wed Sep 7 10:51:21 2022 +0300 Update README.md commit 1cce975f41f0bc130f58e8004ac35f1f8cfd7179 Author: HiHat Date: Tue Sep 6 19:09:26 2022 +0300 Important details regarding address and fixes commit bfaef57025253beb6564dbe4afd30dfe51e059a4 Author: Pocketnet Team Date: Wed Aug 31 13:23:31 2022 +0300 Create add.tasks.to.project.yml commit 8ad81f1601554be5eb557a5fda204a78fd3d3be3 Author: Pocketnet Team Date: Tue Aug 30 15:00:15 2022 +0300 Set maximum depth 1 month for RPC GetMostCommentedFeed commit c1e5845465970d7bbafe909a9528abe0ac3cfd67 Author: Pocketnet Team Date: Tue Aug 30 14:57:23 2022 +0300 Set fork height for BlockingCancel.hpp commit b8bc0adf5c46dc3fb0d14332f49e34dec6105dd3 Merge: 8383efb4 8abd1bb7 Author: Andy Oknen Date: Tue Aug 30 14:45:32 2022 +0300 Merge pull request #385 from pocketnetteam/fix/wrong-key-threshold fix: wrong map key threshold_shark_reg_depth -> threshold_whale_reg_depth commit 8abd1bb75fb52ea6dff9ad73e560362abfd4b1c5 Author: Andy Oknen Date: Tue Aug 30 14:42:46 2022 +0300 Comment not used now RPC commit fee5e39f227d46ac0259d0b26b5680fb451a3eaa Author: Andy Oknen Date: Tue Aug 30 11:13:50 2022 +0300 Extend height for fork to 1873500 block commit 0ea51a2868b2ad0befb1149c2b5a0270cac7ecd1 Author: Andy Oknen Date: Mon Aug 29 14:14:26 2022 +0300 Fix wrong map key threshold_shark_reg_depth -> threshold_whale_reg_depth commit 8383efb46582ec24455867157474dbf29c0bc4f2 Author: Pocketnet Team Date: Thu Aug 25 00:21:32 2022 +0300 Delete project.add.issues.yml commit 95b97de883e4116a7f6d54af3be842e017e7fd01 Author: Pocketnet Team Date: Thu Aug 25 00:17:56 2022 +0300 Create project.add.issues.yml commit 9693e62933ae1ca02560fba1311dbdd4c88c8a77 Author: Pocketnet Team Date: Thu Aug 25 00:07:19 2022 +0300 Create auto_assign.yml commit 7b7338c801e665435cc429381ff3eb98d2a68f57 Merge: 88af7848 b6b9f45f Author: lostystyg <54471935+lostystyg@users.noreply.github.com> Date: Fri Sep 9 10:41:39 2022 +0300 Merge pull request #302 from lostystyg/feature/events feature: events, push notifications and activities commit 88af7848ba0e56fe22a136715bb7fbca46eda966 Merge: dddb3c6d 6280c078 Author: Andy Oknen Date: Thu Sep 8 18:45:15 2022 +0300 Merge pull request #407 from pocketnetteam/fix/clear-database Fix clear database commit 6280c078ae1e1cf38a1d69e67b6bc2203469eda8 Author: Andy Oknen Date: Thu Sep 8 18:39:43 2022 +0300 Fix clear database commit dddb3c6dd0e6a5088d46bfb70051e5fa95fc08fe Merge: 1a03ee9d 6d1975a2 Author: Andy Oknen Date: Thu Sep 8 15:22:39 2022 +0300 Merge pull request #401 from pocketnetteam/feat/txindex-disable-always feat: disable txindex by default commit 1a03ee9d2340909fbedcc8ded34915efc5c9489f Merge: adce55f2 bc022eca Author: Andy Oknen Date: Thu Sep 8 15:07:28 2022 +0300 Merge pull request #406 from pocketnetteam/fix/full-reindex-lists fix: full reindex lists commit b6b9f45f711821ba98a657b55529ae9a6037abab Author: lostystyg Date: Thu Sep 8 15:55:12 2022 +0400 Fix new line commit 314c1a84137a1bba0f246f0649cbd9334625cc03 Author: lostystyg Date: Thu Sep 8 15:52:07 2022 +0400 Temporarily disable getevents rpc commit bbd05740a461ff9ca4c68cfae216e82f28bf1b8d Merge: 32b0e15f adce55f2 Author: lostystyg Date: Thu Sep 8 15:51:13 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit bc022ecac23e00dfb7236ffffbb2e77e6e995682 Author: Andy Oknen Date: Thu Sep 8 14:40:46 2022 +0300 Logging clean commit 8107ae50a48790d12bb0d0662c1ea2dc21cc3e45 Author: Andy Oknen Date: Thu Sep 8 14:38:53 2022 +0300 Call rollback lists for full reindexing commit 32b0e15f67da6f08069173585fa801f641209d88 Author: lostystyg Date: Thu Sep 8 15:26:58 2022 +0400 Optimized notifications collecting commit 24e63f43b73f38a3b534682ca5c2b864863f7bf2 Author: lostystyg Date: Thu Sep 8 13:13:52 2022 +0400 Filling notification result with account info commit 1344fe5b189542b154f2bf9d9a47d23cbc4e83e9 Author: lostystyg Date: Thu Sep 8 12:29:31 2022 +0400 Language for short account commit 710886c50ae33edfda37472b2265aa2adaf127ce Author: lostystyg Date: Thu Sep 8 12:17:28 2022 +0400 Correctly filling notifications answer commit 6d1975a22e50550ff6ef7b393441e49f2cadbfe4 Author: Andy Oknen Date: Wed Sep 7 10:40:06 2022 +0300 Disable enabling txindex by default commit 5b04354199e527de52c08dd1880a12c1f8225ba5 Author: lostystyg Date: Mon Sep 5 15:33:28 2022 +0400 Removed outdated comment commit 57f275ea9dcd3c7c61a75561c809cef6a97f6937 Author: lostystyg Date: Mon Sep 5 15:04:22 2022 +0400 Cosmetics for blocking query in activities commit 88ed33a8731e61a9364840264b099e7012c659cd Author: lostystyg Date: Mon Sep 5 14:47:08 2022 +0400 Removed number from outputs in activities and notifications commit 24534072f1ece6cf940f9033fa032cd20b7471c7 Author: lostystyg Date: Mon Sep 5 13:04:59 2022 +0400 Reuse height binder in notifications for money commit 77f9e87343e7b691227dd97b5a114460a55df7f2 Author: lostystyg Date: Fri Sep 2 16:41:06 2022 +0400 Order outputs by number for activities and notifications commit 8ef4a5bbdd8aed5b860e73c95504fc9676977bec Merge: 2b3a0164 357d1558 Author: lostystyg Date: Thu Sep 1 22:28:12 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit 2b3a0164de79b2ecf67f87dee0e2842fc8ec22df Author: lostystyg Date: Thu Sep 1 22:24:10 2022 +0400 Removed trash from badge in activities commit 66e9054ae456ebdb6b49a0682a141e6abc76c448 Author: lostystyg Date: Thu Sep 1 22:22:59 2022 +0400 Removed trash from badge field in notification queries commit f8924a6f595da8dbff0fe7f341a39399c1b09a6a Author: lostystyg Date: Thu Sep 1 22:21:18 2022 +0400 Ported notifications from 0.20-based dropped branch commit 6d8148ded4c31ea2019b5384fd8e90714cf5010e Author: lostystyg Date: Thu Sep 1 12:10:41 2022 +0400 Added blockings for notifications commit c23e94c4678ab27c7c4dfd1074b50f306a97e6bf Author: lostystyg Date: Wed Aug 31 13:29:41 2022 +0400 Added optional multiple addresses to shortform commit c29ab129b3c2ceb9da564a2f37649e321b50b869 Author: lostystyg Date: Tue Aug 30 19:06:08 2022 +0400 Removed unnecessary todo commit 736748f798fcbecc1f8e8b9e855ca215c3db5d3d Author: lostystyg Date: Tue Aug 30 19:03:32 2022 +0400 Some todo's commit cabb0603547edb11d29363d19fd9328729a2c7ba Author: lostystyg Date: Tue Aug 30 19:02:08 2022 +0400 All action history for comments and answers in activities commit cf5021c9c4f25c22ada7b59f2c143b953c6ad84b Author: lostystyg Date: Tue Aug 30 18:36:51 2022 +0400 Collect roottxhash in activity queries commit 328a3ecd8cad8cdef92b5baa5173f6516ac4d1de Author: lostystyg Date: Tue Aug 30 17:51:10 2022 +0400 Added root tx hash to shortform commit f6fa4a45ca88a8ce0970aaa0dc0950bce1465790 Author: lostystyg Date: Tue Aug 30 17:42:02 2022 +0400 Full history for notifications commit 077f0f26f5b52cf86229d2418cf73d465dbc0b29 Author: lostystyg Date: Thu Aug 25 09:35:42 2022 +0400 Added blocking shorttype commit e2913158f2226f719242e376b8a846ca660ef26b Author: lostystyg Date: Thu Aug 25 09:33:55 2022 +0400 Removed not up to date todo commit 884893775de6aea42350bddcdd93ec42c47c6d04 Author: lostystyg Date: Wed Aug 24 16:55:14 2022 +0400 Removed reposts from activities commit b5631e70c1e54ef4ae60207f2c25f9a72663d458 Merge: e4c102c3 b7b49914 Author: lostystyg Date: Wed Aug 24 16:21:26 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit e4c102c39cc9ebd7cd3bdf38b5c053841c39ca01 Author: lostystyg Date: Wed Aug 24 15:53:24 2022 +0400 Validate filters for events on rpc level commit ac03dcb727512a5ed29450c2a720c1259bcdd158 Author: lostystyg Date: Wed Aug 24 15:49:33 2022 +0400 Validate filters for activities on rpc level commit fcb2fed45b43c3e510be0dfb33504b680b97d016 Author: lostystyg Date: Wed Aug 24 15:49:10 2022 +0400 Removed pocketnetteam from events and activities commit 876e7b574c9ad099fd00721aa92c79561d3eb2b7 Author: lostystyg Date: Wed Aug 24 15:35:47 2022 +0400 Fixed crash if non-valid filters are specified for notifications/activities/events commit 5732263c174be41fb9be7dbc15b48acef6e1e263 Author: lostystyg Date: Mon Aug 22 23:52:32 2022 +0400 Removed todo for money in activities commit 9c7438fb22ddc857876e4cc734fd3885481e9386 Merge: 99c11087 6e530784 Author: lostystyg Date: Mon Aug 22 15:16:13 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit 99c11087a786a017b7c1e4039cb94615d6e742c2 Author: lostystyg Date: Sat Aug 20 18:02:14 2022 +0400 Fixed typo in query commit 6057f91580b1e35399f7cfbbbf43e57d2cf6f486 Author: lostystyg Date: Sat Aug 20 17:53:37 2022 +0400 Removed commented out queries for notifications commit 35375ed1d01fa436ea83a65f910fdd746a8e1e5b Author: lostystyg Date: Sat Aug 20 16:39:23 2022 +0400 Validating filters for getnotificationssummary commit f1be1700c842a7cd1960665cbf969f97b4fe4892 Author: lostystyg Date: Sat Aug 20 16:38:13 2022 +0400 Optimization and fixed for notifications summary queries commit 1d371a0870f3053d77cf65df7c6a537370ede685 Author: lostystyg Date: Sat Aug 20 16:36:29 2022 +0400 Allow to specify union separator commit fcf526c45eb12f853f4da331398b9cf0dbfb6536 Merge: 46edf275 9df85fb7 Author: lostystyg Date: Fri Aug 19 19:26:37 2022 +0400 Merge remote-tracking branch 'origin/fixes/multiplelocks' into feature/events commit 46edf275c6f5e113be1209bca42b3ecf6962cad7 Author: lostystyg Date: Wed Aug 17 18:09:35 2022 +0400 Notifications summary commit 29164ac17d0da9ad5f8ead8f6d87fa8a9bdf30a3 Author: lostystyg Date: Mon Aug 15 11:22:23 2022 +0400 Fixed help for getnotifications commit c26ddf05be536577ca8334fbd57737a848b74805 Merge: 3a49aa58 1bbe483a Author: lostystyg Date: Fri Aug 12 14:01:39 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit 3a49aa58477b3e5cac571a83eedc95b57106bbaa Merge: 5365be10 8a1b0af6 Author: lostystyg Date: Thu Aug 11 16:27:31 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit 5365be10f9f6df46bf973c15b03e1915062ac75e Author: lostystyg Date: Thu Aug 11 14:52:19 2022 +0400 Correct ordering by original txs in activities commit 3339a738328bbdfeb7517254f017a85a693ddaac Author: lostystyg Date: Thu Aug 11 14:51:32 2022 +0400 Removed unnecessary todos commit 1b256cd1fb3b46266b946dca2b2f3ea7da5bb92a Author: lostystyg Date: Thu Aug 11 14:49:12 2022 +0400 Explicitly set index for account joins in activities commit 3ae1ff87786b593bcd6bdc5652f26bb066d50a0a Author: lostystyg Date: Wed Aug 10 11:30:05 2022 +0400 Fixed address positioning in sql query for activities in ContentScore and CommentScore commit fa8543b5c97ee93b84e997b74336aa55d961fbe8 Merge: a433e3ac cc77fdcb Author: lostystyg Date: Wed Aug 10 10:21:20 2022 +0400 Merge branch '0.21' into feature/events commit a433e3ac5bb2dca719697a913e14594c5f46e2d8 Author: lostystyg Date: Mon Aug 8 10:55:52 2022 +0400 Removed orig height from activities because it breaks pagination commit 67febbef23c006f91886b92bb84e88e6d10fe448 Author: lostystyg Date: Fri Jul 22 10:36:48 2022 +0300 Fixed referals for events commit 9845755c09e0e98380dd4a020db8a08e2e551545 Author: lostystyg Date: Fri Jul 22 10:11:06 2022 +0300 Orig height for activities commit eb5c9e6621d4cd35c82af7a13eaa14cb5a0f8a90 Merge: d60cfd32 c6fa67b4 Author: lostystyg Date: Fri Jul 22 09:03:43 2022 +0300 Merge branch '0.21' into feature/events commit d60cfd32e626356ae728db6f51cb3bb36148ab94 Author: lostystyg Date: Wed Jul 20 18:16:05 2022 +0300 A bit cosmetics for events commit 86e5df5a081973a2b6fd9aa546f12d8033373b33 Author: lostystyg Date: Wed Jul 20 18:01:43 2022 +0300 Full comment text in description for events and activities commit fabcc4e520227c4367a39bf0882097201acd155f Author: lostystyg Date: Wed Jul 20 15:30:28 2022 +0300 Inner join instead of cross for repost in activities commit f782b68e000f9ded107f962e8b82f2e986a828bc Author: lostystyg Date: Wed Jul 20 15:26:48 2022 +0300 Fixed repost queries for activities and events commit 7e865aa4b8a31df75f685bedd7cf0bd6973ffa5c Author: lostystyg Date: Wed Jul 20 14:56:19 2022 +0300 Fixed subscriber in activities commit c01a27472ce995c4d80da691f3ca7b3fef8e2c87 Author: lostystyg Date: Tue Jul 19 18:55:36 2022 +0300 Optimizing activity queries commit 91d85294992c2db69c6def5840b324ecdf2bedf9 Author: lostystyg Date: Mon Jul 18 16:36:03 2022 +0300 Optimizing pocketnetteam notifications commit c137b10912886fffb8f9992990873d77878b69d6 Author: lostystyg Date: Mon Jul 18 16:26:56 2022 +0300 Fixed binds for notifications commit e265c7ff37d4531133e2e792c84b444dd79349ed Author: Andy Oknen Date: Mon Jul 18 13:17:59 2022 +0300 Optimize reposts commit dadabe0f0d15f67e74157652dfab24f16ae5441e Author: Andy Oknen Date: Mon Jul 18 13:12:50 2022 +0300 Fix private content from subscribers (not reposts) commit 8c423e45e86fe237a55873828a574f7885faf73c Author: Andy Oknen Date: Mon Jul 18 13:09:11 2022 +0300 Optimize reposts query commit 814a958f101c6c3f924f6db0977d45294662f197 Author: Andy Oknen Date: Mon Jul 18 12:51:01 2022 +0300 Fix incoming money commit 1d0d17e2a8b5491b421e71f0df2547e08468804f Author: lostystyg Date: Mon Jul 18 12:32:41 2022 +0300 getnotification better todos and fixed index commit e3f474ba52e4a1d234ed1f3910014519f99ac0da Author: lostystyg Date: Fri Jul 15 18:02:37 2022 +0300 Added optional related content (in case of reposts) for pocketnetteam posts and private content for notifications commit 427d320494f6390b921ef26e85d83b67f7a5a7aa Author: lostystyg Date: Fri Jul 15 18:01:45 2022 +0300 Fixed reposts for notifications commit 5c261246ad1117d5c393f6c90511a8dc20bd83a9 Author: lostystyg Date: Fri Jul 15 18:01:06 2022 +0300 Moved pocketnetteam posts for notifications to a specific key in answer commit 5e8b8066d31046beccd717bd6cdcb45357259a60 Author: lostystyg Date: Wed Jul 13 18:11:33 2022 +0300 Fixed var name for events contentscore commit 39b478d611fe69437c45c33535fe9e01be8904aa Author: lostystyg Date: Wed Jul 13 18:10:31 2022 +0300 Ignoring empty avatar for short form account commit 848abcae88f1d0b1d922ed9be7a37c9ac820368f Author: lostystyg Date: Wed Jul 13 13:55:24 2022 +0300 Fixed typo in contentscore for activities commit aaac24ae58a9b176beee95f31dfb425281d26d01 Author: lostystyg Date: Wed Jul 13 13:54:54 2022 +0300 Fixed content description for contentscore in activities commit 5d7e566222d686212ba1d475e5581df78a805ba2 Author: lostystyg Date: Tue Jul 12 11:48:56 2022 +0300 Inner join instead of cross for activities and events commit 5bb78a6f327bcaed0cf07e229613b0d236677bcc Author: lostystyg Date: Tue Jul 12 11:22:39 2022 +0300 Updated activities query commit d3c243d4fce004f2da5fab1a83dd587f472cfb18 Author: lostystyg Date: Fri Jul 8 17:31:35 2022 +0300 Comment score activity commit 0a936ade276adea029a29aa26c645cf7f4c997a8 Author: lostystyg Date: Fri Jul 8 17:22:20 2022 +0300 Subscriber activity commit b5d0c401eb859478bdea99f883523ccb828add98 Author: lostystyg Date: Fri Jul 8 17:14:00 2022 +0300 Added comments for activities commit 638c874a0287ebd69aecbca5b675dcb24d1f7669 Author: lostystyg Date: Fri Jul 8 17:13:39 2022 +0300 Fixed answers request for activities commit f3a202681561a3426be3c37748e353907941b50f Author: lostystyg Date: Fri Jul 8 16:36:07 2022 +0300 Base activities rpc request commit 3665c8076186734a16103f1feda707d9bac0e373 Author: lostystyg Date: Fri Jul 8 14:59:17 2022 +0300 Renamed notifications rpc commit d560b5ad7b34847e8644daf7dc09cc2ef4e45927 Author: lostystyg Date: Wed Jul 6 16:18:08 2022 +0300 Fixed acc's rep for getevents commit 071f6ed8d6e7c0f1ff8ad7777675c64b83aa6c21 Author: lostystyg Date: Wed Jul 6 16:17:48 2022 +0300 Ignore badge fort short account commit 1576c8dc6fb2436f030a5f9b79ddd9db3fe843f4 Author: lostystyg Date: Wed Jul 6 15:50:37 2022 +0300 Only orig entries for notifications + some optimizations commit 60e0489fb1976fe6801ceefbaf72370c913d64d5 Author: lostystyg Date: Tue Jul 5 15:44:20 2022 +0300 Updated getnotifications rpc description commit 5e1740fb58b36c0b36b2f99b1b86d9d4bcbcd729 Author: lostystyg Date: Tue Jul 5 15:38:25 2022 +0300 Updated getevents rpc description commit a66588336365912e73e61f5921f430faf085f6b4 Merge: 6828322d 9b8e4bd6 Author: lostystyg Date: Tue Jul 5 15:11:55 2022 +0300 Merge branch '0.21' into feature/events commit 6828322d0616f5c6c9c846e5558a50eaaa4561f1 Author: lostystyg Date: Mon Jul 4 20:34:34 2022 +0300 Money notification commit b227a1cdc0888f532aaec1f86dbe544909e2c83b Author: lostystyg Date: Mon Jul 4 19:41:35 2022 +0300 Extracted common bind for notifications commit ef325659593eaf1f8faeec91fc405099024c9766 Merge: 16a3455f c0f6636c Author: lostystyg Date: Fri Jul 1 19:34:12 2022 +0300 Merge branch '0.21' into feature/events commit 16a3455f20d79b3028db961c280da0e75cea68e3 Author: lostystyg Date: Fri Jul 1 19:14:10 2022 +0300 Notifications commit 9c8a9b3f0d2d0c47c8a6ebd9de34b3fa576c9320 Author: lostystyg Date: Fri Jul 1 19:14:00 2022 +0300 Fixed ShortAccount commit 061a7ab966fafc41644034bf38a259f47bab9f10 Author: lostystyg Date: Wed Jun 29 17:17:24 2022 +0300 A bit generalization in processing filters for events commit b9f3b6a95832ac38782d9003ab4d8f4ad1af990a Author: lostystyg Date: Wed Jun 29 15:38:07 2022 +0300 Restructured events commit b8f37cbf82b986962ec85674d8859ad150567a9c Merge: f862108d 8465afed Author: lostystyg Date: Tue Jun 28 14:35:03 2022 +0300 Merge remote-tracking branch 'origin/0.21' into feature/events commit f862108dd6ca23059c62cad7b227b4d032e41d9c Merge: 8090d0e8 4429a24f Author: lostystyg Date: Mon Jun 27 13:37:20 2022 +0300 Merge branch '0.21' into feature/events commit 8090d0e8464d9b538c0617cab97cb2c08ac11411 Merge: 21b3c715 5c9755ac Author: lostystyg Date: Mon Jun 27 12:39:57 2022 +0300 Merge branch 'minor_fixes' into feature/events commit 21b3c715ae8ef56cc276e62975bb1a727cfb2cde Merge: 78eb6155 8c9006b4 Author: lostystyg Date: Mon Jun 27 12:39:51 2022 +0300 Merge branch '0.21' into feature/events commit 5c9755ac27adf6801e7936d8fefb218494fbc6a4 Author: lostystyg Date: Fri Jun 24 19:09:19 2022 +0300 Some minor fixes commit 78eb6155d9626dea1de3635f0e1484c643a27af9 Merge: 3207e0fc 97cf205e Author: lostystyg Date: Thu Jun 23 19:09:06 2022 +0300 Merge branch '0.21' into feature/events commit 3207e0fc601d9e099cb0181a1fd4dc784672001d Merge: 156ed36a 67a8917f Author: lostystyg Date: Mon Jun 13 16:15:56 2022 +0300 Merge branch '0.21' into feature/events commit 156ed36a5d4155c1b619a17c484c8587b23bb459 Author: lostystyg Date: Fri Jun 10 16:03:17 2022 +0300 Answer fixes for events commit 854e6f5b9ccba90961633409cbbcd7335857e50a Author: lostystyg Date: Fri Jun 10 14:58:52 2022 +0300 Donate value for comment event commit 576fed8fed67233522eea657f4801aa4519b6351 Author: lostystyg Date: Fri Jun 10 13:50:56 2022 +0300 Fixed events height commit 337c1efcc064e68aee3235d944c19da43b465169 Author: lostystyg Date: Fri Jun 10 13:38:03 2022 +0300 Disabled hight border in related content for events commit 7b2c630c686225e3ca28c40c3d349cc3eb295c48 Author: lostystyg Date: Fri Jun 10 13:27:55 2022 +0300 Events queries formatting commit e4f3666e6ff1aabb65efcc17ace03652209353df Author: lostystyg Date: Fri Jun 10 13:15:34 2022 +0300 Comment answer events fulfilled with data commit 775c8d454364df3d8775b78b891e4810b5fd959b Author: Andy Oknen Date: Fri Jun 10 12:14:10 2022 +0300 index comment answer commit 1b5a4966f75358c3a0140267a2e2a342b73ee755 Author: Andy Oknen Date: Fri Jun 10 11:30:03 2022 +0300 Add height limit for answer comments commit 6d0985262639ec83784ec1df4a9f74b96a5b1060 Author: Andy Oknen Date: Fri Jun 10 11:01:04 2022 +0300 comment commit 7805b8e8f7c600c471126e7304bf28fb380ad9aa Author: Andy Oknen Date: Fri Jun 10 10:54:36 2022 +0300 Sql fixes commit 011f94f29438ad36cb423a2faf6dc4686905902c Author: Andy Oknen Date: Fri Jun 10 09:43:51 2022 +0300 Fix sql typo commit a62fd177da5dfb00260cd13db1572b0824e21742 Author: lostystyg Date: Fri Jun 10 09:05:43 2022 +0300 Fixed select ordering in events commit af47ba0b7bb84185fc78c18c178720f8254281e8 Author: Andy Oknen Date: Fri Jun 10 08:50:18 2022 +0300 Fix comment answers sql index commit c97d7f55ddea43ffcde4b0c591086b8ddb6102b3 Author: lostystyg Date: Mon Jun 6 16:00:19 2022 +0300 Fixed description for scores events commit 134f3095dac5169d58a0213a795002d347c33769 Author: lostystyg Date: Mon Jun 6 15:35:51 2022 +0300 Throwing in case of event reconstructor error commit 0c3319a6878381b2bc528f9a24d8e7e491ce4dff Author: Andy Oknen Date: Mon May 23 14:11:21 2022 +0300 Downgrade likers count for testnet commit 367fa1a7a38cbe3f31ac83c3c6afef57ff1229df Author: Andy Oknen Date: Fri Apr 22 10:36:33 2022 +0300 Formatting commit 0421fbf7bf4af46fbb216517eb6f8867ca39f0a5 Author: lostystyg Date: Mon Jun 6 12:47:01 2022 +0300 Optimizing event queries commit aff9e13fece8167e8f7352c3d13206dbccde94b0 Author: lostystyg Date: Mon Jun 6 12:25:58 2022 +0300 Events fixes commit 423d4f9f91b61283e6878b408fc92ae8120ca467 Merge: 7127a3eb 039f41fb Author: lostystyg Date: Fri Jun 3 00:34:41 2022 +0300 Merge remote-tracking branch 'origin/0.21' into feature/events commit 7127a3ebd2bfff8f469afa7e5f980d5c41ae5ff0 Author: lostystyg Date: Fri Jun 3 00:34:12 2022 +0300 Short forms for events commit b8f13088d20cceb8fc67229bffb8154a00c08a20 Author: lostystyg Date: Fri Jun 3 00:34:02 2022 +0300 Updated short forms commit 03c0bd4a9c52a89d276ca9da219a9a323cb41a8c Author: lostystyg Date: Tue May 31 01:01:20 2022 +0300 ShortTxType for short forms commit dfd80a5a62d32e055cbaeabdf089bc4b1e0dbb4d Author: lostystyg Date: Mon May 30 22:52:28 2022 +0300 Added short forms commit 0b2aca0a697fd47cd0b4aee4264acf99aa57f86d Author: lostystyg Date: Mon May 30 15:26:51 2022 +0300 Raw sql query to get all events at height for each account commit 78681c897118244d758fc40732685ad9ba19c524 Author: lostystyg Date: Fri May 6 17:31:21 2022 +0300 Forgotten finalizing stmt commit 8d23c2e6e401f9a41c41d7a6236be2dc1785c19e Author: lostystyg Date: Fri May 6 17:01:01 2022 +0300 Updated args description for getevents commit 4030e741e98038f7297cccae706ba072beb992c2 Author: lostystyg Date: Fri May 6 16:57:43 2022 +0300 Events for single address commit b7ec0f7f40237ac2a6e12f3394163ba1a05a8c98 Author: lostystyg Date: Fri May 6 16:42:10 2022 +0300 constant depth for events commit 1ae34c266e55cdae51aa5df95d28cae91d5385ee Author: lostystyg Date: Fri May 6 16:40:43 2022 +0300 privatecontent for events commit 086a1fa52778907c63eab88d9e691b62edff5246 Author: lostystyg Date: Fri May 6 16:34:57 2022 +0300 Fixed binding for events commit d77c6b6cf4dda626454170d466345fadcf6b12f9 Author: lostystyg Date: Fri May 6 13:37:39 2022 +0300 Fixed filtering for events commit 19591f2421a9e7d9579fe6034f82314ccaaf4562 Author: lostystyg Date: Thu May 5 23:15:02 2022 +0300 Updated events commit 244a198523d5efe7f9c251e7ccd8111dd26eae0c Author: lostystyg Date: Wed May 4 17:04:33 2022 +0300 Fixed filtering for events commit 3deae2ea8a8dded1f50d3ec7ee9bda2616667e90 Author: lostystyg Date: Wed May 4 16:09:02 2022 +0300 FIlters, height and blocknum for events request commit 2600f314343ec9ce45acbd46774e1f2e4924e6a4 Author: lostystyg Date: Sat Apr 30 14:41:04 2022 +0300 Sorting events by height outside of sqlite commit 7f3d953ecb6c01fdf2e5fb6f1cf2d8cc424098a7 Author: lostystyg Date: Sat Apr 30 00:42:26 2022 +0300 Fixed events rpc description commit 192ad0cab7f3639824fe2c9ed4a3862941c89b2e Author: lostystyg Date: Sat Apr 30 00:41:11 2022 +0300 Events optimization commit 7a51e15cb185f07536ca713eebafd0e5c06111dc Author: lostystyg Date: Mon Apr 25 18:35:32 2022 +0300 Better indexing content from private subscribers event commit 3d8e46bfd1b13af691c876d8c82caf77f6035411 Author: lostystyg Date: Mon Apr 25 18:30:38 2022 +0300 Do not check for last for boost events commit dbea23e6036b2cd141552c408a149562351618cd Merge: af71bdf4 b0497826 Author: lostystyg Date: Mon Apr 25 18:20:24 2022 +0300 Merge remote-tracking branch 'origin/0.21.todo' into feature/events commit af71bdf4fdaaffe602ef6fa70efa63ef35ec5c63 Author: lostystyg Date: Mon Apr 25 18:17:09 2022 +0300 Base events logic commit c0e9504a610807a759cffbd239dd9bd2852ad805 Author: lostystyg Date: Mon Apr 18 17:23:50 2022 +0300 Method to get POCKETNET_TEAM address commit 9722326760ef90af0ccb57bbacc5c5c51d76f7d6 Author: lostystyg Date: Mon Apr 18 17:22:46 2022 +0300 Using network id instead of string for getting pocketnet developers --- .github/workflows/add.tasks.to.project.yml | 21 + README.md | 22 +- src/CMakeLists.txt | 2 + src/Makefile.am | 6 +- src/httpserver.cpp | 1 + src/init.cpp | 9 +- src/pocketdb/helpers/PocketnetHelper.h | 8 +- src/pocketdb/helpers/ShortFormHelper.cpp | 56 +- src/pocketdb/helpers/ShortFormHelper.h | 18 + src/pocketdb/migrations/main.cpp | 3 + .../models/shortform/ShortAccount.cpp | 11 + src/pocketdb/models/shortform/ShortAccount.h | 5 +- src/pocketdb/models/shortform/ShortForm.h | 1 - src/pocketdb/models/shortform/ShortTxData.cpp | 52 +- src/pocketdb/models/shortform/ShortTxData.h | 16 +- .../models/shortform/ShortTxOutput.cpp | 45 + src/pocketdb/models/shortform/ShortTxOutput.h | 44 + src/pocketdb/models/shortform/ShortTxType.h | 3 +- src/pocketdb/repositories/ChainRepository.cpp | 29 +- src/pocketdb/repositories/ChainRepository.h | 1 + .../repositories/web/WebRpcRepository.cpp | 3100 +++++++++++++---- .../repositories/web/WebRpcRepository.h | 26 +- src/pocketdb/web/PocketAccountRpc.cpp | 2 +- src/pocketdb/web/PocketContentRpc.cpp | 270 +- src/pocketdb/web/PocketContentRpc.h | 4 +- src/pocketdb/web/PocketRpc.cpp | 5 +- src/pocketdb/web/PocketTagsRpc.cpp | 4 +- src/pocketdb/web/PocketTransactionRpc.cpp | 14 +- src/pocketdb/web/SearchRpc.cpp | 12 +- src/rest.cpp | 3 +- src/rpc/blockchain.cpp | 4 +- src/rpc/rawtransaction.cpp | 8 +- src/staker.cpp | 7 +- 33 files changed, 3128 insertions(+), 684 deletions(-) create mode 100644 .github/workflows/add.tasks.to.project.yml create mode 100644 src/pocketdb/models/shortform/ShortTxOutput.cpp create mode 100644 src/pocketdb/models/shortform/ShortTxOutput.h diff --git a/.github/workflows/add.tasks.to.project.yml b/.github/workflows/add.tasks.to.project.yml new file mode 100644 index 000000000..017b1a683 --- /dev/null +++ b/.github/workflows/add.tasks.to.project.yml @@ -0,0 +1,21 @@ +name: Add new tasks to project + +on: + issues: + types: + - opened + pull_request: + types: + - opened + +jobs: + add-to-project: + name: Add new task to project + runs-on: ubuntu-latest + steps: + - uses: actions/add-to-project@v0.3.0 + with: + project-url: https://github.com/users/pocketnetteam/projects/3 + github-token: ${{ secrets.AUTO_PROJECT_TOKEN }} + # labeled: bug, needs-triage + # label-operator: OR or AND diff --git a/README.md b/README.md index b84ec1823..487add98b 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ PocketnetCore is distributed in two ways: binary installer and build from source Minimum system requirements: - 2 core x86-64 CPU - 4GB RAM -- 100 GB harddrive +- 150 GB harddrive - 10 Mbps internet connection Recommended System Requirements @@ -75,7 +75,6 @@ $ $ pocketcoin-cli --help $ pocketcoin-tx --help ``` - More information : https://hub.docker.com/r/pocketnetteam/pocketnet.core # First full synchronization @@ -100,9 +99,8 @@ $ pocketcoind --help # Latest snapshot archive https://snapshot.pocketnet.app/latest.tgz - https://snapshot.pocketnet.app/latest.bz2 ``` -4. There must be archive tgz with 5 directories: +3. There must be archive tgz with 5 directories: ```shell blocks\ - ... @@ -141,12 +139,24 @@ $ pocketcoind --help # for bz2 archive $ tar -xjf latest.tgz -C ./ + + # create wallets directory if not exist + $ mkdir wallets ``` -5. Make sure the folders and files inside are not set to "read only" +5. Make sure the folders and files inside are not set to "read only" (grant permissions to all files for current user via ```chmod -R ~/.pocketcoin/``` unix command) 6. Start the node. **VERY IMPORTANT**: save the **wallet.dat** file or **wallets/** files before cleaning the directory. It is recommended to even save these files somewhere for backup. +# Get address (for PKOIN receiving) and private key info (Linux, Docker) +```shell +# get address for PKOIN receiving +$ pocketcoin-cli getnewaddress "node" + +$ +# get private key info for private safe storage +$ pocketcoin-cli dumpprivkey "" +``` # Build from source code See `doc/build-*.md` files for build instructions. @@ -154,7 +164,7 @@ See `doc/build-*.md` files for build instructions. # Help You can get help and useful information from different sources: -- https://pocketnet.app/help +- https://bastyon.com/help - https://github.com/pocketnetteam/pocketnet.core/blob/master/doc/public_access.md - https://github.com/pocketnetteam/pocketnet.core/tree/master/doc/help - https://github.com/pocketnetteam/pocketnet.core/blob/master/share/examples/pocketcoin.conf diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a7908236..e78e4a501 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -640,6 +640,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) diff --git a/src/Makefile.am b/src/Makefile.am index 1325b4efe..9d80f85c2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -225,7 +225,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 = \ @@ -312,7 +313,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 = \ diff --git a/src/httpserver.cpp b/src/httpserver.cpp index aea4844ea..ffc2ba608 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -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); diff --git a/src/init.cpp b/src/init.cpp index cb8ad9cfe..bfbb86e98 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2127,9 +2127,12 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA fFeeEstimatesInitialized = true; // ********************************************************* Step 8: start indexers - // TODO (brangr): maybe not needed? - g_txindex = MakeUnique(nTxIndexCache, false, fReindex); - g_txindex->Start(); + // TODO (brangr): 0.21.0 check need txindex test + if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) + { + g_txindex = MakeUnique(nTxIndexCache, false, fReindex); + g_txindex->Start(); + } for (const auto& filter_type : g_enabled_filter_types) { InitBlockFilterIndex(filter_type, filter_index_cache, false, fReindex); diff --git a/src/pocketdb/helpers/PocketnetHelper.h b/src/pocketdb/helpers/PocketnetHelper.h index a771c4aec..965a197e7 100644 --- a/src/pocketdb/helpers/PocketnetHelper.h +++ b/src/pocketdb/helpers/PocketnetHelper.h @@ -15,8 +15,8 @@ namespace PocketHelpers { using namespace std; - static map> PocketnetDevelopers{ - {"main", { + static map> PocketnetDevelopers{ + {NetworkId::NetworkMain, { "P9EkPPJPPRYxmK541WJkmH8yBM4GuWDn2m", "PUGBtfmivvcg1afnEt9vqVi3yZ7v6S9BcC", "PDtuJDVXaq82HH7fafgwBmcoxbqqWdJ9u9", @@ -28,7 +28,7 @@ namespace PocketHelpers "PMyjUzHtzsmbejB87ATbrcQNatiGsT4NzG", "PHdW4pwWbFdoofVhSEfPSHgradmrvZdbE5" }}, - {"test", { + {NetworkId::NetworkTest, { "TG69Jioc81PiwMAJtRanfZqUmRY4TUG7nt", "TLnfXcFNxxrpEUUzrzZvbW7b9gWFtAcc8x", "TYMo5HRFpc7tqzccaVifx7s2x2ZDqMikCR", @@ -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(); } diff --git a/src/pocketdb/helpers/ShortFormHelper.cpp b/src/pocketdb/helpers/ShortFormHelper.cpp index 316dcfd85..84e1b67ca 100644 --- a/src/pocketdb/helpers/ShortFormHelper.cpp +++ b/src/pocketdb/helpers/ShortFormHelper.cpp @@ -21,6 +21,7 @@ static const std::map& GetTypesMap() { { PocketDb::ShortTxType::PrivateContent, "privatecontent" }, { PocketDb::ShortTxType::Boost, "boost" }, { PocketDb::ShortTxType::Repost, "repost" }, + { PocketDb::ShortTxType::Blocking, "blocking" } }; return typesMap; } @@ -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 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 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 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(); diff --git a/src/pocketdb/helpers/ShortFormHelper.h b/src/pocketdb/helpers/ShortFormHelper.h index d5fa1854b..a00ac3a2f 100644 --- a/src/pocketdb/helpers/ShortFormHelper.h +++ b/src/pocketdb/helpers/ShortFormHelper.h @@ -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 diff --git a/src/pocketdb/migrations/main.cpp b/src/pocketdb/migrations/main.cpp index 234099b74..8fc93a993 100644 --- a/src/pocketdb/migrations/main.cpp +++ b/src/pocketdb/migrations/main.cpp @@ -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); diff --git a/src/pocketdb/models/shortform/ShortAccount.cpp b/src/pocketdb/models/shortform/ShortAccount.cpp index 859279609..d0697decd 100644 --- a/src/pocketdb/models/shortform/ShortAccount.cpp +++ b/src/pocketdb/models/shortform/ShortAccount.cpp @@ -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; } @@ -64,3 +65,13 @@ void PocketDb::ShortAccount::SetReputation(const int64_t& reputation) { m_reputation = reputation; } + +const std::optional& PocketDb::ShortAccount::GetLang() const +{ + return m_lang; +} + +void PocketDb::ShortAccount::SetLang(const std::optional& lang) +{ + m_lang = lang; +} diff --git a/src/pocketdb/models/shortform/ShortAccount.h b/src/pocketdb/models/shortform/ShortAccount.h index 597158110..78ac5f863 100644 --- a/src/pocketdb/models/shortform/ShortAccount.h +++ b/src/pocketdb/models/shortform/ShortAccount.h @@ -8,7 +8,7 @@ #include #include - +#include namespace PocketDb { @@ -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& GetLang() const; + void SetLang(const std::optional& lang); private: std::string m_avatar; std::string m_name; std::string m_badge; + std::optional m_lang; int64_t m_reputation {0}; }; } diff --git a/src/pocketdb/models/shortform/ShortForm.h b/src/pocketdb/models/shortform/ShortForm.h index d343b0550..338d04039 100644 --- a/src/pocketdb/models/shortform/ShortForm.h +++ b/src/pocketdb/models/shortform/ShortForm.h @@ -15,7 +15,6 @@ namespace PocketDb class ShortForm { public: - // TODO tomorrow: serialize me correctly!!! ShortForm(PocketDb::ShortTxType type, ShortTxData txData, std::optional relatedContent); UniValue Serialize() const; diff --git a/src/pocketdb/models/shortform/ShortTxData.cpp b/src/pocketdb/models/shortform/ShortTxData.cpp index ac49a5a74..c449e2710 100644 --- a/src/pocketdb/models/shortform/ShortTxData.cpp +++ b/src/pocketdb/models/shortform/ShortTxData.cpp @@ -10,7 +10,8 @@ PocketDb::ShortTxData::ShortTxData(std::string hash, PocketTx::TxType txType, std::optional address, std::optional height, std::optional blockNum, std::optional account, std::optional val, std::optional description, std::optional commentParentId, - std::optional commentAnswerId + std::optional commentAnswerId, std::optional rootTxHash, + std::optional>>> multipleAddresses ) : m_hash(std::move(hash)), m_txType(txType), @@ -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) @@ -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 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 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; } @@ -81,4 +111,20 @@ const std::optional& PocketDb::ShortTxData::GetCommentParentId() co void PocketDb::ShortTxData::SetCommentAnswerId(const std::optional& commentAnswerId) { m_commentAnswerId = commentAnswerId; } -const std::optional& PocketDb::ShortTxData::GetCommentAnswerId() const { return m_commentAnswerId; } \ No newline at end of file +const std::optional& PocketDb::ShortTxData::GetCommentAnswerId() const { return m_commentAnswerId; } + +void PocketDb::ShortTxData::SetRootTxHash(const std::optional& rootTxHash) { m_rootTxHash = rootTxHash; } + +const std::optional& PocketDb::ShortTxData::GetRootTxHash() const { return m_rootTxHash; } + +void PocketDb::ShortTxData::SetMultipleAddresses(const std::optional>>>& multipleAddresses) { m_multipleAddresses = multipleAddresses; } + +const std::optional>>>& PocketDb::ShortTxData::GetMultipleAddresses() { return m_multipleAddresses; } + +void PocketDb::ShortTxData::SetOutputs(const std::optional>& outputs) { m_outputs = outputs; } + +const std::optional>& PocketDb::ShortTxData::GetOutputs() const { return m_outputs; } + +void PocketDb::ShortTxData::SetInputs(const std::optional>& inputs) { m_inputs = inputs; } + +const std::optional>& PocketDb::ShortTxData::GetInputs() const { return m_inputs; } diff --git a/src/pocketdb/models/shortform/ShortTxData.h b/src/pocketdb/models/shortform/ShortTxData.h index 7447c3273..5f3b9a40a 100644 --- a/src/pocketdb/models/shortform/ShortTxData.h +++ b/src/pocketdb/models/shortform/ShortTxData.h @@ -7,6 +7,7 @@ #include "pocketdb/models/base/PocketTypes.h" #include "pocketdb/models/shortform/ShortAccount.h" +#include "pocketdb/models/shortform/ShortTxOutput.h" #include @@ -23,7 +24,8 @@ namespace PocketDb std::optional height, std::optional blockNum, std::optional account, std::optional val, std::optional description, - std::optional commentParentId, std::optional commentAnswerId); + std::optional commentParentId, std::optional commentAnswerId, + std::optional rootTxHash, std::optional>>> multipleAddresses); ShortTxData(std::string hash, PocketTx::TxType txType); @@ -47,6 +49,14 @@ namespace PocketDb const std::optional& GetCommentParentId() const; void SetCommentAnswerId(const std::optional& commentAnswerId); const std::optional& GetCommentAnswerId() const; + void SetRootTxHash(const std::optional& rootTxHash); + const std::optional& GetRootTxHash() const; + void SetMultipleAddresses(const std::optional>>>& multipleAddresses); + const std::optional>>>& GetMultipleAddresses(); + void SetOutputs(const std::optional>& outputs); + const std::optional>& GetOutputs() const; + void SetInputs(const std::optional>& inputs); + const std::optional>& GetInputs() const; private: std::string m_hash; @@ -55,8 +65,12 @@ namespace PocketDb std::optional 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 m_blockNum; // TODO (losty): probably some filters for these fields std::optional m_account; // Account data associated with address + std::optional>>> m_multipleAddresses; std::optional m_val; + std::optional> m_inputs; + std::optional> m_outputs; std::optional m_description; // Short description of content, e.x. first lines of post's text + std::optional m_rootTxHash; // Special-case fields for comments std::optional m_commentParentId; diff --git a/src/pocketdb/models/shortform/ShortTxOutput.cpp b/src/pocketdb/models/shortform/ShortTxOutput.cpp new file mode 100644 index 000000000..72bc9f9d4 --- /dev/null +++ b/src/pocketdb/models/shortform/ShortTxOutput.cpp @@ -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& txHash) { m_txHash = txHash; } + +const std::optional& PocketDb::ShortTxOutput::GetTxHash() const { return m_txHash; } + +void PocketDb::ShortTxOutput::SetSpentTxHash(const std::optional& spentTxHash) { m_spentTxHash = spentTxHash; } + +const std::optional& PocketDb::ShortTxOutput::GetSpentTxHash() const { return m_spentTxHash; } + +void PocketDb::ShortTxOutput::SetNumber(const std::optional& number) { m_number = number; } + +const std::optional& PocketDb::ShortTxOutput::GetNumber() const { return m_number; } + +void PocketDb::ShortTxOutput::SetAddressHash(const std::optional& addressHash) { m_addressHash = addressHash; } + +const std::optional& PocketDb::ShortTxOutput::GetAddressHash() const { return m_addressHash; } + +void PocketDb::ShortTxOutput::SetScriptPubKey(const std::optional& scriptPubKey) { m_scriptPubKey = scriptPubKey; } + +const std::optional& PocketDb::ShortTxOutput::GetcriptPubKey() const { return m_scriptPubKey; } + +void PocketDb::ShortTxOutput::SetValue(const std::optional& value) { m_value = value; } + +const std::optional& PocketDb::ShortTxOutput::GetValue() const { return m_value; } + diff --git a/src/pocketdb/models/shortform/ShortTxOutput.h b/src/pocketdb/models/shortform/ShortTxOutput.h new file mode 100644 index 000000000..ea1d6d3be --- /dev/null +++ b/src/pocketdb/models/shortform/ShortTxOutput.h @@ -0,0 +1,44 @@ +// 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_SHORTTXOUTPUT_H +#define POCKETDB_SHORTTXOUTPUT_H + +#include "univalue.h" + +#include +#include +#include + +namespace PocketDb +{ + class ShortTxOutput + { + public: + UniValue Serialize() const; + + void SetTxHash(const std::optional& txHash); + const std::optional& GetTxHash() const; + void SetSpentTxHash(const std::optional& spentTxHash); + const std::optional& GetSpentTxHash() const; + void SetNumber(const std::optional& number); + const std::optional& GetNumber() const; + void SetAddressHash(const std::optional& addressHash); + const std::optional& GetAddressHash() const; + void SetScriptPubKey(const std::optional& scriptPubKey); + const std::optional& GetcriptPubKey() const; + void SetValue(const std::optional& value); + const std::optional& GetValue() const; + + private: + std::optional m_txHash; + std::optional m_spentTxHash; + std::optional m_number; + std::optional m_addressHash; + std::optional m_scriptPubKey; + std::optional m_value; + }; +} + +#endif // POCKETDB_SHORTTXOUTPUT_H \ No newline at end of file diff --git a/src/pocketdb/models/shortform/ShortTxType.h b/src/pocketdb/models/shortform/ShortTxType.h index f23fd0430..15caf05c9 100644 --- a/src/pocketdb/models/shortform/ShortTxType.h +++ b/src/pocketdb/models/shortform/ShortTxType.h @@ -19,7 +19,8 @@ namespace PocketDb ContentScore, PrivateContent, Boost, - Repost + Repost, + Blocking }; } diff --git a/src/pocketdb/repositories/ChainRepository.cpp b/src/pocketdb/repositories/ChainRepository.cpp index c92fa1f95..ccb55fdd0 100644 --- a/src/pocketdb/repositories/ChainRepository.cpp +++ b/src/pocketdb/repositories/ChainRepository.cpp @@ -617,13 +617,6 @@ namespace PocketDb int64_t nTime3 = GetTimeMicros(); LogPrint(BCLog::BENCH, " - RestoreOldLast (Balances): %.2fms\n", 0.001 * (nTime3 - nTime2)); - - // ---------------------------------------- - // Rollback blocking list - RollbackBlockingList(height); - - int64_t nTime4 = GetTimeMicros(); - LogPrint(BCLog::BENCH, " - RollbackHeight (Rollback blocking list): %.2fms\n", 0.001 * (nTime4 - nTime3)); } void ChainRepository::RollbackHeight(int height) @@ -701,6 +694,8 @@ namespace PocketDb void ChainRepository::RollbackBlockingList(int height) { + int64_t nTime0 = GetTimeMicros(); + auto delListStmt = SetupSqlStatement(R"sql( delete from BlockingLists where ROWID in ( @@ -721,6 +716,9 @@ namespace PocketDb )sql"); TryBindStatementInt(delListStmt, 1, height); TryStepStatement(delListStmt); + + int64_t nTime1 = GetTimeMicros(); + LogPrint(BCLog::BENCH, " - RollbackList (Delete blocking list): %.2fms\n", 0.001 * (nTime1 - nTime0)); auto insListStmt = SetupSqlStatement(R"sql( insert into BlockingLists @@ -745,7 +743,24 @@ namespace PocketDb )sql"); TryBindStatementInt(insListStmt, 1, height); TryStepStatement(insListStmt); + + int64_t nTime2 = GetTimeMicros(); + LogPrint(BCLog::BENCH, " - RollbackList (Insert blocking list): %.2fms\n", 0.001 * (nTime2 - nTime1)); } + void ChainRepository::ClearBlockingList() + { + int64_t nTime0 = GetTimeMicros(); + + auto stmt = SetupSqlStatement(R"sql( + delete from BlockingLists + )sql"); + TryStepStatement(stmt); + + int64_t nTime1 = GetTimeMicros(); + LogPrint(BCLog::BENCH, " - ClearBlockingList (Delete blocking list): %.2fms\n", 0.001 * (nTime1 - nTime0)); + } + + } // namespace PocketDb diff --git a/src/pocketdb/repositories/ChainRepository.h b/src/pocketdb/repositories/ChainRepository.h index 72ba4dc5f..9e18b80ac 100644 --- a/src/pocketdb/repositories/ChainRepository.h +++ b/src/pocketdb/repositories/ChainRepository.h @@ -51,6 +51,7 @@ namespace PocketDb private: void RollbackBlockingList(int height); + void ClearBlockingList(); void RollbackHeight(int height); void RestoreOldLast(int height); diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 457a64c4f..919a3129b 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -6,14 +6,97 @@ #include "pocketdb/helpers/ShortFormHelper.h" +#include + namespace PocketDb { + class NotificationsResult + { + public: + bool HasData(const std::string& hash) + { + return m_data.find(hash) != m_data.end(); + } + + void InsertData(const PocketDb::ShortForm& shortForm) + { + m_data.insert({shortForm.GetTxData().GetHash(), shortForm}); + } + + void InsertNotifiers(const std::string& hash, std::set addresses) + { + for (const auto& address: addresses) { + m_notifiers[address].insert(hash); + } + } + + std::set GetNotifiersAddresses() const + { + std::set res; + for (const auto& notifierEntry: m_notifiers) { + res.insert(notifierEntry.first); + } + + return res; + } + + UniValue Serialize(const std::map accsData) const + { + std::map> hashToIndexMap; + UniValue data (UniValue::VARR); + std::vector tmp; + tmp.reserve(m_data.size()); + for (const auto& shortForm: m_data) { + hashToIndexMap.insert({shortForm.first, {shortForm.second.GetType(), tmp.size()}}); + tmp.emplace_back(shortForm.second.Serialize()); + } + data.push_backV(tmp); + + UniValue notifiers (UniValue::VOBJ); + notifiers.reserveKVSize(m_notifiers.size()); + for (const auto& notifiersEntry: m_notifiers) { + std::map> txIndicies; + for (const auto& txHash: notifiersEntry.second) { + const auto& txEntry = hashToIndexMap.at(txHash); + txIndicies[txEntry.first].emplace_back(txEntry.second); + } + UniValue e (UniValue::VOBJ); + for (const auto& lol: txIndicies) { + UniValue indicies (UniValue::VARR); + indicies.push_backV(lol.second); + e.pushKV(PocketHelpers::ShortTxTypeConvertor::toString(lol.first), indicies, false); + } + UniValue notifier (UniValue::VOBJ); + notifier.pushKV("e", e); + if (auto acc = accsData.find(notifiersEntry.first); acc != accsData.end()) { + notifier.pushKV("i", acc->second.Serialize()); + } + notifiers.pushKV(notifiersEntry.first, notifier, false); + } + + UniValue result (UniValue::VOBJ); + result.pushKV("data", data); + result.pushKV("notifiers", notifiers); + + return result; + } + + private: + std::map m_data; + std::map> m_notifiers; + }; + class ShortFormParser : public RowAccessor { public: - PocketDb::ShortForm ParseRow(sqlite3_stmt* stmt, const int& startIndex) + void Reset(const int& startIndex) { - int index = startIndex; + m_startIndex = startIndex; + } + + PocketDb::ShortForm ParseFull(sqlite3_stmt* stmt) + { + int index = m_startIndex; auto [ok, type] = TryGetColumnString(stmt, index++); if (!ok) { throw std::runtime_error("Missing row type"); @@ -29,12 +112,31 @@ namespace PocketDb return {PocketHelpers::ShortTxTypeConvertor::strToType(type), *txData, relatedContent}; } + std::string ParseHash(sqlite3_stmt* stmt) + { + auto [ok, hash] = TryGetColumnString(stmt, m_startIndex+1); + if (!ok) { + throw std::runtime_error("Failed to extract tx hash from stmt"); + } + + return hash; + } + + std::optional> ParseOutputs(sqlite3_stmt* stmt) + { + auto [ok, str] = TryGetColumnString(stmt, m_startIndex + 9); + if (ok) { + return _parseOutputs(str); + } + return std::nullopt; + } + protected: std::optional ProcessTxData(sqlite3_stmt* stmt, int& index) { const auto i = index; - static const auto stmtOffset = 13; + static const auto stmtOffset = 17; index += stmtOffset; auto [ok1, hash] = TryGetColumnString(stmt, i); @@ -45,11 +147,15 @@ namespace PocketDb if (auto [ok, val] = TryGetColumnString(stmt, i+2); ok) txData.SetAddress(val); if (auto [ok, val] = TryGetColumnInt64(stmt, i+3); ok) txData.SetHeight(val); if (auto [ok, val] = TryGetColumnInt64(stmt, i+4); ok) txData.SetBlockNum(val); - if (auto [ok, val] = TryGetColumnInt64(stmt, i+5); ok) txData.SetVal(val); - if (auto [ok, val] = TryGetColumnString(stmt, i+6); ok) txData.SetDescription(val); - if (auto [ok, val] = TryGetColumnString(stmt, i+7); ok) txData.SetCommentParentId(val); - if (auto [ok, val] = TryGetColumnString(stmt, i+8); ok) txData.SetCommentAnswerId(val); - txData.SetAccount(_processAccount(stmt, i+9)); + if (auto [ok, val] = TryGetColumnString(stmt, i+5); ok) txData.SetRootTxHash(val); + if (auto [ok, val] = TryGetColumnInt64(stmt, i+6); ok) txData.SetVal(val); + if (auto [ok, val] = TryGetColumnString(stmt, i+7); ok) txData.SetInputs(_parseOutputs(val)); + if (auto [ok, val] = TryGetColumnString(stmt, i+8); ok) txData.SetOutputs(_parseOutputs(val)); + if (auto [ok, val] = TryGetColumnString(stmt, i+9); ok) txData.SetDescription(val); + if (auto [ok, val] = TryGetColumnString(stmt, i+10); ok) txData.SetCommentParentId(val); + if (auto [ok, val] = TryGetColumnString(stmt, i+11); ok) txData.SetCommentAnswerId(val); + txData.SetAccount(_processAccount(stmt, i+12)); + if (auto [ok, val] = TryGetColumnString(stmt, i+16); ok) txData.SetMultipleAddresses(_processMultipleAddresses(val)); return txData; } @@ -67,14 +173,76 @@ namespace PocketDb } return std::nullopt; } + + std::optional> _parseOutputs(const std::string& jsonStr) + { + UniValue json (UniValue::VOBJ); + if (!json.read(jsonStr) || !json.isArray()) return std::nullopt; + std::vector res; + res.reserve(json.size()); + for (int i = 0; i < json.size(); i++) { + const auto& elem = json[i]; + ShortTxOutput output; + + if (elem.exists("TxHash") && elem["TxHash"].isStr()) output.SetTxHash(elem["TxHash"].get_str()); + if (elem.exists("Value") && elem["Value"].isNum()) output.SetValue(elem["Value"].get_int64()); + if (elem.exists("SpentTxHash") && elem["SpentTxHash"].isStr()) output.SetSpentTxHash(elem["SpentTxHash"].get_str()); + if (elem.exists("AddressHash") && elem["AddressHash"].isStr()) output.SetAddressHash(elem["AddressHash"].get_str()); + if (elem.exists("Number") && elem["Number"].isNum()) output.SetNumber(elem["Number"].get_int()); + if (elem.exists("ScriptPubKey") && elem["ScriptPubKey"].isStr()) output.SetScriptPubKey(elem["ScriptPubKey"].get_str()); + + res.emplace_back(std::move(output)); + } + + return res; + } + + std::optional>>> _processMultipleAddresses(const std::string& jsonStr) + { + UniValue json; + if (!json.read(jsonStr) || !json.isArray() || json.size() <= 0) return std::nullopt; + + std::vector>> multipleAddresses; + for (int i = 0; i < json.size(); i++) { + const auto& entry = json[i]; + if (!entry.isObject() || !entry.exists("address") || !entry["address"].isStr()) { + continue; + } + + auto address = entry["address"].get_str(); + std::optional accountData; + if (entry.exists("account")) { + const auto& account = entry["account"]; + if (account["name"].isStr()) { + ShortAccount accData; + accData.SetName(account["name"].get_str()); + if (account["avatar"].isStr()) accData.SetAvatar(account["avatar"].get_str()); + if (account["badge"].isStr()) accData.SetBadge(account["badge"].get_str()); + if (account["reputation"].isNull()) accData.SetReputation(account["reputation"].get_int64()); + accountData = std::move(accData); + } + } + + multipleAddresses.emplace_back(std::make_pair(std::move(address), std::move(accountData))); + } + + return multipleAddresses; + } + + private: + int m_startIndex = 0; }; class EventsReconstructor : public RowAccessor { public: + EventsReconstructor() + { + m_parser.Reset(0); + } void FeedRow(sqlite3_stmt* stmt) { - m_result.emplace_back(std::move(m_parser.ParseRow(stmt, 0))); + m_result.emplace_back(std::move(m_parser.ParseFull(stmt))); } std::vector GetResult() const @@ -89,24 +257,62 @@ namespace PocketDb class NotificationsReconstructor : public RowAccessor { public: + NotificationsReconstructor() { + m_parser.Reset(1); + } + void FeedRow(sqlite3_stmt* stmt) { - auto shortForm = m_parser.ParseRow(stmt, 1); + std::set notifiers; + auto [ok, addressOne] = TryGetColumnString(stmt, 0); + if (ok) { + notifiers.insert(addressOne); + } else { + if (auto outputs = m_parser.ParseOutputs(stmt); outputs) { + for (const auto& output: *outputs) { + if (output.GetAddressHash() && !output.GetAddressHash()->empty()) { + notifiers.insert(*output.GetAddressHash()); + } + } + } + } + if (notifiers.empty()) throw std::runtime_error("Missing address of notifier"); - auto [ok, address] = TryGetColumnString(stmt, 0); - if (!ok) throw std::runtime_error("Missing address of notifier"); + auto txHash = m_parser.ParseHash(stmt); + if (!m_notifications.HasData(txHash)) { + m_notifications.InsertData(m_parser.ParseFull(stmt)); + } + m_notifications.InsertNotifiers(txHash, notifiers); + } + NotificationsResult GetResult() const + { + return m_notifications; + } + private: + ShortFormParser m_parser; + NotificationsResult m_notifications; + }; - m_result[address].emplace_back(std::move(shortForm)); - + class NotificationSummaryReconstructor : public RowAccessor + { + public: + void FeedRow(sqlite3_stmt* stmt) + { + auto [ok1, typeStr] = TryGetColumnString(stmt, 0); + auto [ok2, address] = TryGetColumnString(stmt, 1); + if (!ok1 || !ok2) return; + + if (auto type = PocketHelpers::ShortTxTypeConvertor::strToType(typeStr); type != ShortTxType::NotSet) { + m_result[address][type]++; + } } - WebRpcRepository::NotificationsResult GetResult() const + + auto GetResult() const { return m_result; } private: - ShortFormParser m_parser; - std::map> m_result; - std::vector m_pocketnetteamPosts; + std::map> m_result; }; @@ -3282,24 +3488,12 @@ namespace PocketDb langFilter += " cross join Payload p indexed by Payload_String1_TxHash on p.TxHash = t.Hash and p.String1 = ? "; string sql = R"sql( - select t.Id, - - ( - select count() - from Transactions s --indexed by Transactions_Type_Last_String3_Height - where s.Type in (204, 205) and s.Last = 1 and s.String3 = t.String2 and s.Height is not null - -- exclude commenters blocked by the author of the post - and not exists ( - select 1 - from Transactions b --indexed by Transactions_Type_Last_String1_String2_Height - where b.Type in (305) and b.Last = 1 and b.String1 = t.String1 and b.String2 = s.String1 and b.Height > 0 - ) - ) commentsCount + select t.Id from Transactions t indexed by Transactions_Type_Last_Height_Id - --cross join Ratings cr indexed by Ratings_Type_Id_Last_Value - -- on cr.Type = 2 and cr.Last = 1 and cr.Id = t.Id and cr.Value > 0 + cross join Ratings cr indexed by Ratings_Type_Id_Last_Value + on cr.Type = 2 and cr.Last = 1 and cr.Id = t.Id and cr.Value > 0 )sql" + langFilter + R"sql( @@ -3349,9 +3543,24 @@ namespace PocketDb ) )sql"; } + // sql += " order by cr.Value desc "; + sql += R"sql( + order by ( + select count() + from Transactions s indexed by Transactions_Type_Last_String3_Height + where s.Type in (204, 205) and s.Height is not null and s.String3 = t.String2 and s.Last = 1 + -- exclude commenters blocked by the author of the post + and not exists ( + select 1 + from Transactions b indexed by Transactions_Type_Last_String1_Height_Id + where b.Type in (305) and b.Last = 1 and b.Height > 0 and b.String1 = t.String1 and b.String2 = s.String1 + ) + ) desc + limit ? + )sql"; + // --------------------------------------------- - vector> idswithcomments; vector ids; TryTransactionStep(func, [&]() @@ -3398,38 +3607,24 @@ namespace PocketDb TryBindStatementText(stmt, i++, lang); } + TryBindStatementInt(stmt, i++, countOut); + // --------------------------------------------- while (sqlite3_step(*stmt) == SQLITE_ROW) { auto[ok0, contentId] = TryGetColumnInt64(*stmt, 0); - auto[ok1, commentsCount] = TryGetColumnInt(*stmt, 1); - - idswithcomments.emplace_back(contentId, commentsCount); + ids.push_back(contentId); } FinalizeSqlStatement(*stmt); }); - if (!idswithcomments.empty()) + // Get content data + if (!ids.empty()) { - std::sort(idswithcomments.begin(), idswithcomments.end(), - [] (const auto &x, const auto &y) {return x.second > y.second;}); - - std::transform(idswithcomments.begin(), idswithcomments.end(), std::back_inserter(ids), - [](decltype(idswithcomments)::value_type const &pair) { - return pair.first; - }); - - if (ids.size() > countOut) - ids = {ids.begin(), ids.begin() + countOut}; - - // Get content data - if (!ids.empty()) - { - auto contents = GetContentsData(ids, address); - result.push_backV(contents); - } + auto contents = GetContentsData(ids, address); + result.push_backV(contents); } // Complete! @@ -4714,8 +4909,7 @@ namespace PocketDb result.pushKV("donations",resultDonations); return result; - } - + }; // Choosing predicate for function above based on filters. std::function _choosePredicate(const std::set& filters) { @@ -4733,8 +4927,8 @@ namespace PocketDb static inline auto _constructSelectsBasedOnFilters( const std::set& filters, const std::map&, QueryParams>>& selects, - const std::string& footer) - { + const std::string& footer, const std::string& separator = "union") + { auto predicate = _choosePredicate(filters); // Binds that should be performed to constructed query @@ -4744,10 +4938,14 @@ namespace PocketDb for (const auto& select: selects) { if (predicate(select.first)) { queryElems.emplace_back(select.second.query); - queryElems.emplace_back("union"); + queryElems.emplace_back(separator); binds.emplace_back(select.second.binding); } } + + if (queryElems.empty()) { + throw std::runtime_error("Failed to construct query for requested filters"); + } queryElems.pop_back(); // Dropping last "union" std::stringstream ss; @@ -4760,454 +4958,1948 @@ namespace PocketDb return std::pair { ss.str(), binds }; } - WebRpcRepository::NotificationsResult WebRpcRepository::GetNotifications(int64_t height, const std::set& filters) + std::vector WebRpcRepository::GetActivities(const std::string& address, int64_t heightMax, int64_t heightMin, int64_t blockNumMax, const std::set& filters) { + // This is required because we want static bind functors for optimization so parameters can't be captured there struct QueryParams { // Handling all by reference - const int64_t& height; - } queryParams {height}; - - // Static because it will not be changed for entire node run - - static const auto heightBinder = - [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ - TryBindStatementInt64(stmt, i++, queryParams.height); - }; + const std::string& address; + const int64_t& heightMax; + const int64_t& heightMin; + const int64_t& blockNumMax; + } queryParams{address, heightMax, heightMin, blockNumMax}; static const std::map&, QueryParams>> selects = { { - ShortTxType::Money, { R"sql( - -- Incoming money - select - o.AddressHash, -- TODO (losty): empty str here - (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Money) + R"sql(')TP, - t.Hash, - t.Type, - i.AddressHash, - t.Height as Height, - t.BlockNum as BlockNum, - o.Value, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null + ShortTxType::Answer, { R"sql( + -- My answers to other's comments + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Answer) + R"sql(')TP, + a.Hash, + a.Type, + null, + a.Height as Height, + a.BlockNum as BlockNum, + a.String2, + null, + null, + null, + pa.String1, + a.String4, + a.String5, + null, + null, + null, + null, + null, + c.Hash, + c.Type, + c.String1, + c.Height, + c.BlockNum, + c.String2, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = c.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = c.Hash + and o.TxHeight = c.Height + order by o.Number + ), + pc.String1, + c.String4, + c.String5, + pca.String2, + pca.String3, + null, -- Badge + ifnull(rca.Value,0), + null + + from Transactions c indexed by Transactions_Type_Last_String2_Height -- My comments + + left join Payload pc + on pc.TxHash = c.Hash + + join Transactions a indexed by Transactions_Type_String1_Height_Time_Int1 -- Other answers + on a.Type in (204, 205, 206) + and a.Height > ? + and (a.Height < ? or (a.Height = ? and a.BlockNum < ?)) + and a.String5 = c.String2 + and a.String1 != c.String1 + and a.String1 = ? + + left join Payload pa + on pa.TxHash = a.Hash + + left join Transactions ca indexed by Transactions_Type_Last_String1_Height_Id + on ca.Type = 100 + and ca.Last = 1 + and ca.String1 = c.String1 + and ca.Height > 0 + + left join Payload pca + on pca.TxHash = ca.Hash + + left join Ratings rca indexed by Ratings_Type_Id_Last_Height + on rca.Type = 0 + and rca.Id = ca.Id + and rca.Last = 1 - from Transactions t indexed by Transactions_Height_Type + where c.Type in (204, 205) + and c.Last = 1 + and c.Height > 0 - join TxOutputs o - on t.Hash = o.TxHash - and o.TxHeight = t.Height - and o.AddressHash != '' + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams) { + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } + }}, - join TxOutputs i indexed by TxOutputs_SpentTxHash - on i.SpentTxHash = o.TxHash - and i.Number = (select min(ii.Number) from TxOutputs ii where ii.SpentTxHash = o.TxHash) - and i.AddressHash != o.AddressHash -- TODO (brangr, lostystyg): exclude coinstake first transaction + { + ShortTxType::Comment, { R"sql( + -- Comments for my content + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Comment) + R"sql(')TP, + c.Hash, + c.Type, + null, + c.Height as Height, + c.BlockNum as BlockNum, + c.String2, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = c.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = c.Hash + and o.TxHeight = c.Height + order by o.Number + ), + pc.String1, + c.String4, + c.String5, + null, + null, + null, + null, + null, + p.Hash, + p.Type, + p.String1, + p.Height, + p.BlockNum, + p.String2, + null, + null, + null, + pp.String2, + null, + null, + pap.String2, + pap.String3, + null, + ifnull(rap.Value, 0), + null + + from Transactions p indexed by Transactions_Type_Last_String2_Height + + join Transactions c indexed by Transactions_Type_String1_Height_Time_Int1 + on c.Type in (204, 205, 206) + and c.String3 = p.String2 + and c.String1 != p.String1 + and c.Height > ? + and (c.Height < ? or (c.Height = ? and c.BlockNum < ?)) + and c.String1 = ? + + left join TxOutputs oc indexed by TxOutputs_TxHash_AddressHash_Value + on oc.TxHash = c.Hash and oc.AddressHash = p.String1 and oc.AddressHash != c.String1 -- TODO: c.Hash or c.String2 or clast.Hash??? + + left join Payload pc + on pc.TxHash = c.Hash + + left join Payload pp + on pp.TxHash = p.Hash + + left join Transactions ap indexed by Transactions_Type_Last_String1_Height_Id -- accounts of commentators + on ap.String1 = p.String1 + and ap.Last = 1 + and ap.Type = 100 + and ap.Height > 0 + + left join Payload pap + on pap.TxHash = ap.Hash + + left join Ratings rap indexed by Ratings_Type_Id_Last_Height + on rap.Type = 0 + and rap.Id = ap.Id + and rap.Last = 1 + + where p.Type in (200,201,202) + and p.Last = 1 + and p.Height > 0 - where t.Type in (1,2,3) -- 1 default money transfer, 2 coinbase, 3 coinstake - and t.Height = ? )sql", [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ - TryBindStatementInt64(stmt, i++, queryParams.height); + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); } }}, - // { - // ShortTxType::Referal, { R"sql( - // -- referals - // select - // t.String2, - // (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Referal) + R"sql(')TP, - // t.Hash, - // t.Type, - // t.String1, - // t.Height as Height, - // t.BlockNum as BlockNum, - // null, - // null, - // p.String2, - // p.String3, - // p.String4, - // ifnull(r.Value,0), -- TODO (losty): do we need rating if referal is always a new user? - // null, - // null, - // null, - // null, - // null, - // null, - // null, - // null, - // null, - // null, - // null - - // from Transactions t --indexed by Transactions_Type_Last_String2_Height - - // left join Payload p - // on p.TxHash = t.Hash - - // left join Ratings r indexed by Ratings_Type_Id_Last_Height - // on r.Type = 0 - // and r.Id = t.Id - // and r.Last = 1 - - // where t.Type = 100 - // and t.String2 is not null - // and t.Height = ? - // and (select count(*) from Transactions tt where tt.Id = t.Id) = 1 -- Only original - // )sql", - // heightBinder - // }}, - { - ShortTxType::Answer, { R"sql( - -- Comment answers - select - c.String1, - (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Answer) + R"sql(')TP, - a.Hash, - a.Type, - a.String1, - orig.Height as Height, - a.BlockNum as BlockNum, - null, - pa.String1, - a.String4, - a.String5, - paa.String2, - paa.String3, - paa.String4, - ifnull(ra.Value,0), - post.Hash, - post.Type, - post.String1, - post.Height, - post.BlockNum, - null, - null, - null, - ppost.String2, - papost.String2, - papost.String3, - null, - ifnull(rapost.Value,0) - - from Transactions a indexed by Transactions_Type_Last_Height_String5_String1 -- Other answers + ShortTxType::Subscriber, { R"sql( + -- Subscribers + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Subscriber) + R"sql(')TP, + subs.Hash, + subs.Type, + null, + subs.Height as Height, + subs.BlockNum as BlockNum, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + u.Hash, + u.Type, + u.String1, + u.Height, + u.BlockNum, + null, + null, + null, + null, + null, + null, + null, + pu.String2, + pu.String3, + null, + ifnull(ru.Value,0), + null + + from Transactions subs indexed by Transactions_Type_String1_Height_Time_Int1 - join Transactions c indexed by Transactions_Type_Last_String2_Height -- My comments - on c.Type in (204, 205) - and c.Last = 1 - and c.Height > 0 - and c.String2 = a.String5 - and c.String1 != a.String1 - - left join Transactions post -- Root post - on post.Type in (200, 201, 202) - and post.Last = 1 - and post.String2 = a.String3 + join Transactions u indexed by Transactions_Type_Last_String1_Height_Id + on u.Type in (100) + and u.Last = 1 + and u.String1 = subs.String2 + and u.Height > 0 - left join Payload ppost - on ppost.TxHash = post.Hash + left join Payload pu + on pu.TxHash = u.Hash - left join Transactions apost - on apost.Type = 100 - and apost.Last = 1 - and apost.String1 = post.String1 - - left join Payload papost - on papost.TxHash = apost.Hash - - left join Ratings rapost indexed by Ratings_Type_Id_Last_Height - on rapost.Type = 0 - and rapost.Id = apost.Id - and rapost.Last = 1 + left join Ratings ru indexed by Ratings_Type_Id_Last_Height + on ru.Type = 0 + and ru.Id = u.Id + and ru.Last = 1 - left join Transactions orig - on orig.Hash = a.String2 + where subs.Type in (302, 303, 304) + and subs.String1 = ? + and subs.Height > ? + and (subs.Height < ? or (subs.Height = ? and subs.BlockNum < ?)) - left join Payload pa - on pa.TxHash = a.Hash + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementText(stmt, i++, queryParams.address); + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + } + }}, - left join Transactions aa - on aa.Type = 100 - and aa.Last = 1 + { + ShortTxType::CommentScore, { R"sql( + -- Comment scores + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::CommentScore) + R"sql(')TP, + s.Hash, + s.Type, + null, + s.Height as Height, + s.BlockNum as BlockNum, + null, + s.Int1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + c.Hash, + c.Type, + c.String1, + c.Height, + c.BlockNum, + c.String2, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = c.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = c.Hash + and o.TxHeight = c.Height + order by o.Number + ), + pc.String1, + c.String4, + c.String5, + pac.String2, + pac.String3, + null, + ifnull(rac.Value,0), + null + + from Transactions c indexed by Transactions_Type_Last_String2_Height + + left join Payload pc + on pc.TxHash = c.Hash + + join Transactions s indexed by Transactions_Type_Last_String1_Height_Id + on s.Type = 301 + and s.Last = 0 + and s.String2 = c.String2 + and s.Height > ? + and (s.Height < ? or (s.Height = ? and s.BlockNum < ?)) + and s.String1 = ? + + left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + on ac.Type = 100 + and ac.Last = 1 + and ac.String1 = c.String1 + and ac.Height > 0 + + left join Payload pac + on pac.TxHash = ac.Hash + + left join Ratings rac indexed by Ratings_Type_Id_Last_Height + on rac.Type = 0 + and rac.Id = ac.Id + and rac.Last = 1 + + where c.Type in (204,205) + and c.Last = 1 + and c.Height > 0 + + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } + }}, + + { + ShortTxType::ContentScore, { R"sql( + -- Content scores + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::ContentScore) + R"sql(')TP, + s.Hash, + s.Type, + null, + s.Height as Height, + s.BlockNum as BlockNum, + null, + s.Int1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + c.Hash, + c.Type, + c.String1, + c.Height, + c.BlockNum, + c.String2, + null, + null, + null, + pc.String2, + null, + null, + pac.String2, + pac.String3, + null, + ifnull(rac.Value,0), + null + + from Transactions c indexed by Transactions_Type_Last_String2_Height + + left join Payload pc + on pc.TxHash = c.Hash + + join Transactions s indexed by Transactions_Type_Last_String1_Height_Id + on s.Type = 300 + and s.Last = 0 + and s.String2 = c.String2 + and s.Height > ? + and (s.Height < ? or (s.Height = ? and s.BlockNum < ?)) + and s.String1 = ? + + left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + on ac.Type = 100 + and ac.Last = 1 + and ac.String1 = c.String1 + and ac.Height > 0 + + left join Payload pac + on pac.TxHash = ac.Hash + + left join Ratings rac indexed by Ratings_Type_Id_Last_Height + on rac.Type = 0 + and rac.Id = ac.Id + and rac.Last = 1 + + where c.Type in (200, 201, 202) + and c.Last = 1 + and c.Height > 0 + + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } + }}, + + { + ShortTxType::Boost, { R"sql( + -- Boosts for my content + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Boost) + R"sql(')TP, + tBoost.Hash, + tboost.Type, + null, + tBoost.Height as Height, + tBoost.BlockNum as BlockNum, + null, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = tBoost.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = tBoost.Hash + and o.TxHeight = tBoost.Height + order by o.Number + ), + null, + null, + null, + null, + null, + null, + null, + null, + tContent.Hash, + tContent.Type, + tContent.String1, + tContent.Height, + tContent.BlockNum, + tContent.String2, + null, + null, + null, + pContent.String2, + null, + null, + pac.String2, + pac.String3, + null, + ifnull(rac.Value,0), + null + + from Transactions tBoost indexed by Transactions_Type_Last_String1_Height_Id + + join Transactions tContent indexed by Transactions_Type_Last_String2_Height + on tContent.Type in (200,201,202) + and tContent.Last in (0,1) + and tContent.Height > 0 + and tContent.String2 = tBoost.String2 + + left join Payload pContent + on pContent.TxHash = tContent.Hash + + left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + on ac.String1 = tContent.String1 + and ac.Type = 100 + and ac.Last = 1 + and ac.Height > 0 + + left join Payload pac + on pac.TxHash = ac.Hash + + left join Ratings rac indexed by Ratings_Type_Id_Last_Height + on rac.Type = 0 + and rac.Id = ac.Id + and rac.Last = 1 + + where tBoost.Type in (208) + and tBoost.Last in (0,1) + and tBoost.String1 = ? + and tBoost.Height > ? + and (tBoost.Height < ? or (tBoost.Height = ? and tBoost.BlockNum < ?)) + + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementText(stmt, i++, queryParams.address); + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + } + }}, + + { + ShortTxType::Blocking, { R"sql( + -- My blockings and unblockings + select + ('blocking')TP, + b.Hash, + b.Type, + ac.String1, + b.Height as Height, + b.BlockNum as BlockNum, + null, + null, + null, + null, + null, + null, + null, + pac.String2, + pac.String3, + null, + ifnull(rac.Value,0), + ( + select json_group_array( + json_object( + 'address', mac.String1, + 'account', json_object( + 'name', pmac.String2, + 'avatar', pmac.String3, + 'reputation', ifnull(rmac.Value,0) + ) + ) + ) + from Transactions mac indexed by Transactions_Type_Last_String1_Height_Id + + left join Payload pmac + on pmac.TxHash = mac.Hash + + left join Ratings rmac indexed by Ratings_Type_Id_Last_Height + on rmac.Type = 0 + and rmac.Id = mac.Id + and rmac.Last = 1 + + where mac.String1 in (select value from json_each(b.String3)) + and mac.Type = 100 + and mac.Last = 1 + and mac.Height > 0 + ), + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + + from Transactions b indexed by Transactions_Type_String1_Height_Time_Int1 + + left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + on ac.String1 = b.String2 + and ac.Type = 100 + and ac.Last = 1 + and ac.Height > 0 + + left join Payload pac + on pac.TxHash = ac.Hash + + left join Ratings rac indexed by Ratings_Type_Id_Last_Height + on rac.Type = 0 + and rac.Id = ac.Id + and rac.Last = 1 + + where b.Type in (305,306) + and b.String1 = ? + and b.Height > ? + and (b.Height < ? or (b.Height = ? and b.BlockNum < ?)) + + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementText(stmt, i++, queryParams.address); + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + } + }}, + }; + + static const auto footer = R"sql( + + -- Global order and limit for pagination + order by Height desc, BlockNum desc + limit 10 + + )sql"; + + auto [elem1, elem2] = _constructSelectsBasedOnFilters(filters, selects, footer); + auto& sql = elem1; + auto& binds = elem2; + + EventsReconstructor reconstructor; + TryTransactionStep(__func__, [&]() + { + auto stmt = SetupSqlStatement(sql); + int i = 1; + + for (const auto& bind: binds) { + bind(stmt, i, queryParams); + } + + while (sqlite3_step(*stmt) == SQLITE_ROW) + { + reconstructor.FeedRow(*stmt); + } + + FinalizeSqlStatement(*stmt); + }); + + return reconstructor.GetResult(); + } + + std::map WebRpcRepository::GetShortAccountsForAddresses(const std::set& addresses) + { + auto sql = R"sql( + select + ac.String1, + p.String1, + p.String2, + p.String3, + ifnull(r.Value,0) + + from Transactions ac + + left join Payload p + on p.TxHash = ac.Hash + + left join Ratings r indexed by Ratings_Type_Id_Last_Height + on r.Type = 0 + and r.Id = ac.Id + and r.Last = 1 + + where ac.String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) + and ac.Type = 100 + and ac.Last = 1 + )sql"; + + std::map res; + TryTransactionStep(__func__, [&]() + { + auto stmt = SetupSqlStatement(sql); + int i = 1; + + for (const auto& address: addresses) { + TryBindStatementText(stmt, i, address); + i++; + } + + while (sqlite3_step(*stmt) == SQLITE_ROW) + { + std::string address; + if (auto [ok, val] = TryGetColumnString(*stmt, 0); ok) + address = val; + else + continue; // TODO (losty): error + + ShortAccount acc; + if (auto [ok, val] = TryGetColumnString(*stmt, 1); ok) acc.SetLang(val); + if (auto [ok, val] = TryGetColumnString(*stmt, 2); ok) acc.SetName(val); + if (auto [ok, val] = TryGetColumnString(*stmt, 3); ok) acc.SetAvatar(val); + if (auto [ok, val] = TryGetColumnInt64(*stmt, 4); ok) acc.SetReputation(val); + res.insert({address, acc}); + } + + FinalizeSqlStatement(*stmt); + }); + + return res; + } + + UniValue WebRpcRepository::GetNotifications(int64_t height, const std::set& filters) + { + struct QueryParams { + // Handling all by reference + const int64_t& height; + } queryParams {height}; + + // Static because it will not be changed for entire node run + + static const auto heightBinder = + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.height); + }; + + static const std::map&, QueryParams>> selects = { + { + ShortTxType::Money, { R"sql( + -- Incoming money + select + null, -- Will be filled + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Money) + R"sql(')TP, + t.Hash, + t.Type, + null, + t.Height as Height, + t.BlockNum as BlockNum, + null, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = t.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = t.Hash + and o.TxHeight = t.Height + order by o.Number + ) + + from Transactions t indexed by Transactions_Height_Type + + where t.Type in (1,2,3) -- 1 default money transfer, 2 coinbase, 3 coinstake + and t.Height = ? + )sql", + heightBinder + }}, + + { + ShortTxType::Referal, { R"sql( + -- referals + select + t.String2, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Referal) + R"sql(')TP, + t.Hash, + t.Type, + t.String1, + t.Height as Height, + t.BlockNum as BlockNum, + null, + null, + null, + null, + null, + null, + null, + p.String2, + p.String3, + null, + ifnull(r.Value,0) -- TODO (losty): do we need rating if referal is always a new user? + + from Transactions t indexed by Transactions_Height_Type + + left join Payload p + on p.TxHash = t.Hash + + left join Ratings r indexed by Ratings_Type_Id_Last_Height + on r.Type = 0 + and r.Id = t.Id + and r.Last = 1 + + where t.Type = 100 + and t.String2 is not null + and t.Height = ? + and (select count(*) from Transactions tt indexed by Transactions_Id_Last where tt.Id = t.Id) = 1 -- Only original + )sql", + heightBinder + }}, + + { + ShortTxType::Answer, { R"sql( + -- Comment answers + select + c.String1, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Answer) + R"sql(')TP, + a.Hash, + a.Type, + a.String1, + a.Height as Height, + a.BlockNum as BlockNum, + a.String2, + null, + null, + null, + pa.String1, + a.String4, + a.String5, + paa.String2, + paa.String3, + null, + ifnull(ra.Value,0), + null, + post.Hash, + post.Type, + post.String1, + post.Height, + post.BlockNum, + post.String2, + null, + null, + null, + null, + null, + ppost.String2, + papost.String2, + papost.String3, + null, + ifnull(rapost.Value,0) + + from Transactions a indexed by Transactions_Height_Type -- Other answers + + join Transactions c indexed by Transactions_Type_Last_String2_Height -- My comments + on c.Type in (204, 205) + and c.Last = 1 + and c.Height > 0 + and c.String2 = a.String5 + and c.String1 != a.String1 + + left join Transactions post indexed by Transactions_Type_Last_String2_Height + on post.Type in (200, 201, 202) + and post.Last = 1 + and post.String2 = a.String3 + + left join Payload ppost + on ppost.TxHash = post.Hash + + left join Transactions apost indexed by Transactions_Type_Last_String1_String2_Height + on apost.Type = 100 + and apost.Last = 1 + and apost.String1 = post.String1 + + left join Payload papost + on papost.TxHash = apost.Hash + + left join Ratings rapost indexed by Ratings_Type_Id_Last_Height + on rapost.Type = 0 + and rapost.Id = apost.Id + and rapost.Last = 1 + + left join Payload pa + on pa.TxHash = a.Hash + + left join Transactions aa indexed by Transactions_Type_Last_String1_Height_Id + on aa.Type = 100 + and aa.Last = 1 + and aa.String1 = a.String1 + and aa.Height > 0 + + left join Payload paa + on paa.TxHash = aa.Hash + + left join Ratings ra indexed by Ratings_Type_Id_Last_Height + on ra.Type = 0 + and ra.Id = aa.Id + and ra.Last = 1 + + where a.Type = 204 -- only orig + and a.Height = ? + )sql", + heightBinder + }}, + + { + ShortTxType::Comment, { R"sql( + -- Comments for my content + select + p.String1, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Comment) + R"sql(')TP, + c.Hash, + c.Type, + c.String1, + c.Height as Height, + c.BlockNum as BlockNum, + c.String2, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = c.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = c.Hash + and o.TxHeight = c.Height + order by o.Number + ), + pc.String1, + null, + null, + pac.String2, + pac.String3, + null, + ifnull(rac.Value,0), + null, + p.Hash, + p.Type, + null, + p.Height, + p.BlockNum, + p.String2, + null, + null, + null, + pp.String2 + + from Transactions c indexed by Transactions_Height_Type + + join Transactions p indexed by Transactions_Type_Last_String2_Height + on p.Type in (200,201,202) + and p.Last = 1 + and p.Height > 0 + and p.String2 = c.String3 + and p.String1 != c.String1 + + left join Payload pc + on pC.TxHash = c.Hash + + left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + on ac.String1 = c.String1 + and ac.Last = 1 + and ac.Type = 100 + and ac.Height > 0 + + left join Payload pac + on pac.TxHash = ac.Hash + + left join Ratings rac indexed by Ratings_Type_Id_Last_Height + on rac.Type = 0 + and rac.Id = ac.Id + and rac.Last = 1 + + left join Payload pp + on pp.TxHash = p.Hash + + where c.Type = 204 -- only orig + and c.Height = ? + )sql", + heightBinder + }}, + + { + ShortTxType::Subscriber, { R"sql( + -- Subscribers + select + subs.String2, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Subscriber) + R"sql(')TP, + subs.Hash, + subs.Type, + subs.String1, + subs.Height as Height, + subs.BlockNum as BlockNum, + null, + null, + null, + null, + null, + null, + null, + pu.String2, + pu.String3, + null, + ifnull(ru.Value,0) + + from Transactions subs indexed by Transactions_Height_Type + + left join Transactions u indexed by Transactions_Type_Last_String1_Height_Id + on u.Type in (100) + and u.Last = 1 + and u.String1 = subs.String1 + and u.Height > 0 + + left join Payload pu + on pu.TxHash = u.Hash + + left join Ratings ru indexed by Ratings_Type_Id_Last_Height + on ru.Type = 0 + and ru.Id = u.Id + and ru.Last = 1 + + where subs.Type in (302, 303) -- Ignoring unsubscribers? + and subs.Height = ? + )sql", + heightBinder + }}, + + { + ShortTxType::CommentScore, { R"sql( + -- Comment scores + select + c.String1, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::CommentScore) + R"sql(')TP, + s.Hash, + s.Type, + s.String1, + s.Height as Height, + s.BlockNum as BlockNum, + null, + s.Int1, + null, + null, + null, + null, + null, + pacs.String2, + pacs.String3, + null, + ifnull(racs.Value,0), + null, + c.Hash, + c.Type, + null, + c.Height, -- TODO (losty): original? + c.BlockNum, + c.String2, + null, + null, + null, + ps.String1, + c.String4, + c.String5 + + from Transactions s indexed by Transactions_Height_Type + + join Transactions c indexed by Transactions_Type_Last_String2_Height + on c.Type in (204,205) + and c.Last = 1 + and c.Height > 0 + and c.String2 = s.String2 + + left join Payload ps + on ps.TxHash = c.Hash + + join Transactions acs indexed by Transactions_Type_Last_String1_Height_Id + on acs.Type = 100 + and acs.Last = 1 + and acs.String1 = s.String1 + and acs.Height > 0 + + left join Payload pacs + on pacs.TxHash = acs.Hash + + left join Ratings racs indexed by Ratings_Type_Id_Last_Height + on racs.Type = 0 + and racs.Id = acs.Id + and racs.Last = 1 + + where s.Type = 301 + and s.Height = ? + )sql", + heightBinder + }}, + + { + ShortTxType::ContentScore, { R"sql( + -- Content scores + select + c.String1, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::ContentScore) + R"sql(')TP, + s.Hash, + s.Type, + s.String1, + s.Height as Height, + s.BlockNum as BlockNum, + null, + s.Int1, + null, + null, + null, + null, + null, + pacs.String2, + pacs.String3, + null, + ifnull(racs.Value,0), + null, + c.Hash, + c.Type, + null, + c.Height, -- TODO (losty): original? + c.BlockNum, + c.String2, + null, + null, + null, + ps.String2 + + from Transactions s indexed by Transactions_Height_Type + + join Transactions c indexed by Transactions_Type_Last_String2_Height + on c.Type in (200, 201, 202) + and c.Last = 1 + and c.Height > 0 + and c.String2 = s.String2 + + left join Payload ps + on ps.TxHash = c.Hash + + join Transactions acs indexed by Transactions_Type_Last_String1_Height_Id + on acs.Type = 100 + and acs.Last = 1 + and acs.String1 = s.String1 + and acs.Height > 0 + + left join Payload pacs + on pacs.TxHash = acs.Hash + + left join Ratings racs indexed by Ratings_Type_Id_Last_Height + on racs.Type = 0 + and racs.Id = acs.Id + and racs.Last = 1 + + where s.Type = 300 + and s.Height = ? + )sql", + heightBinder + }}, + + { + ShortTxType::PrivateContent, { R"sql( + -- Content from private subscribers + select + subs.String1, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::PrivateContent) + R"sql(')TP, + c.Hash, + c.Type, + c.String1, + c.Height as Height, + c.BlockNum as BlockNum, + c.String2, + null, + null, + null, + p.String2, + null, + null, + pac.String2, + pac.String3, + null, + ifnull(rac.Value,0), + null, + r.Hash, + r.Type, + r.String1, + r.Height, + r.BlockNum, + r.String2, + null, + null, + null, + pr.String2 + + from Transactions c indexed by Transactions_Height_Type -- content for private subscribers + + join Transactions subs indexed by Transactions_Type_Last_String2_Height -- Subscribers private + on subs.Type = 303 + and subs.Last = 1 + and subs.String2 = c.String1 + and subs.Height > 0 + + left join Transactions r -- related content - possible reposts + on r.String2 = c.String3 + and r.Type in (200,201,202) + and r.Last = 1 + + left join Payload pr + on pr.TxHash = r.Hash + + cross join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + on ac.Type = 100 + and ac.Last = 1 + and ac.String1 = c.String1 + and ac.Height > 0 + + cross join Payload p + on p.TxHash = c.Hash + + cross join Payload pac + on pac.TxHash = ac.Hash + + left join Ratings rac indexed by Ratings_Type_Id_Last_Height + on rac.Type = 0 + and rac.Id = ac.Id + and rac.Last = 1 + + where c.Type in (200,201,202) + and c.Hash = c.String2 -- only orig + and c.Height = ? + )sql", + heightBinder + }}, + + { + ShortTxType::Boost, { R"sql( + -- Boosts for my content + select + tContent.String1, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Boost) + R"sql(')TP, + tBoost.Hash, + tboost.Type, + tBoost.String1, + tBoost.Height as Height, + tBoost.BlockNum as BlockNum, + tBoost.String2, + null, + ( + select json_group_array(json_object( + 'Value', Value, + 'Number', Number, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs i + where i.SpentTxHash = tBoost.Hash + ), + ( + select json_group_array(json_object( + 'Value', Value, + 'AddressHash', AddressHash, + 'ScriptPubKey', ScriptPubKey + )) + from TxOutputs o + where o.TxHash = tBoost.Hash + and o.TxHeight = tBoost.Height + order by o.Number + ), + null, + null, + null, + pac.String2, + pac.String3, + null, + ifnull(rac.Value,0), + null, + tContent.Hash, + tContent.Type, + null, + tContent.Height, + tContent.BlockNum, + tContent.String2, + null, + null, + null, + pContent.String2 + + from Transactions tBoost indexed by Transactions_Type_Last_Height_Id + + left join Transactions tContent indexed by Transactions_Type_Last_String2_Height + on tContent.Type in (200,201,202) + and tContent.Last in (0,1) + and tContent.Height > 0 + and tContent.String2 = tBoost.String2 + + left join Payload pContent + on pContent.TxHash = tContent.Hash + + left join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + on ac.String1 = tBoost.String1 + and ac.Type = 100 + and ac.Last = 1 + and ac.Height > 0 + + left join Payload pac + on pac.TxHash = ac.Hash + + left join Ratings rac indexed by Ratings_Type_Id_Last_Height + on rac.Type = 0 + and rac.Id = ac.Id + and rac.Last = 1 + + where tBoost.Type in (208) + and tBoost.Last in (0,1) + and tBoost.Height = ? + )sql", + heightBinder + }}, + + { + ShortTxType::Repost, { R"sql( + -- Reposts + select + p.String1, + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Repost) + R"sql(')TP, + r.Hash, + r.Type, + r.String1, + r.Height as Height, + r.BlockNum as BlockNum, + r.String2, + null, + null, + null, + pr.String2, + null, + null, + par.String2, + par.String3, + null, + ifnull(rar.Value,0), + null, + p.Hash, + p.Type, + null, + p.Height, + p.BlockNum, + p.String2, + null, + null, + null, + pp.String2 + + from Transactions r + + join Transactions p indexed by Transactions_Type_Last_String2_Height + on p.Type in (200,201,202) + and p.Last = 1 + and p.String2 = r.String3 + and p.Height > 0 + + left join Payload pp + on pp.TxHash = p.Hash + + left join Payload pr + on pr.TxHash = r.Hash + + join Transactions ar indexed by Transactions_Type_Last_String1_Height_Id + on ar.Type = 100 + and ar.Last = 1 + and ar.String1 = r.String1 + and ar.Height > 0 + + left join Payload par + on par.TxHash = ar.Hash + + left join Ratings rar indexed by Ratings_Type_Id_Last_Height + on rar.Type = 0 + and rar.Id = ar.Id + and rar.Last = 1 + + where r.Type in (200,201,202) + and r.Hash = r.String2 -- Only orig + and r.Height = ? + and r.String3 is not null + )sql", + heightBinder + }} + }; + + auto predicate = _choosePredicate(filters); + + NotificationsReconstructor reconstructor; + for(const auto& select: selects) { + if (predicate(select.first)) { + const auto& selectData = select.second; + TryTransactionStep(__func__, [&]() + { + auto stmt = SetupSqlStatement(selectData.query); + + int i = 1; + selectData.binding(stmt, i, queryParams); + + while (sqlite3_step(*stmt) == SQLITE_ROW) + reconstructor.FeedRow(*stmt); + + FinalizeSqlStatement(*stmt); + }); + } + } + + auto notificationResult = reconstructor.GetResult(); + auto accsData = GetShortAccountsForAddresses(notificationResult.GetNotifiersAddresses()); + return notificationResult.Serialize(accsData); + } + + std::vector WebRpcRepository::GetEventsForAddresses(const std::string& address, int64_t heightMax, int64_t heightMin, int64_t blockNumMax, const std::set& filters) + { + // This is required because we want static bind functors for optimization so parameters can't be captured there + struct QueryParams { + // Handling all by reference + const std::string& address; + const int64_t& heightMax; + const int64_t& heightMin; + const int64_t& blockNumMax; + } queryParams {address, heightMax, heightMin, blockNumMax}; + + static const std::map&, QueryParams>> selects = { + { + ShortTxType::Money, { R"sql( + -- Incoming money + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Money) + R"sql(')TP, + t.Hash, + t.Type, + i.AddressHash, + t.Height as Height, + t.BlockNum as BlockNum, + o.Value, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + + from TxOutputs o indexed by TxOutputs_AddressHash_TxHeight_TxHash + + join Transactions t indexed by Transactions_Hash_Type_Height + on t.Hash = o.TxHash + and t.Type in (1,2,3) -- 1 default money transfer, 2 coinbase, 3 coinstake + and t.Height > ? + and (t.Height < ? or (t.Height = ? and t.BlockNum < ?)) + + join TxOutputs i indexed by TxOutputs_SpentTxHash + on i.SpentTxHash = o.TxHash + and i.Number = (select min(ii.Number) from TxOutputs ii where ii.SpentTxHash = o.TxHash) + and i.AddressHash != o.AddressHash -- TODO (brangr, lostystyg): exclude coinstake first transaction + + where o.AddressHash = ? + and o.TxHeight > ? + and o.TxHeight < ? + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + } + }}, + + { + ShortTxType::Referal, { R"sql( + -- referals + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Referal) + R"sql(')TP, + t.Hash, + t.Type, + t.String1, + t.Height as Height, + t.BlockNum as BlockNum, + null, + null, + p.String2, + p.String3, + p.String4, + ifnull(r.Value,0), + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + + from Transactions t indexed by Transactions_Type_Last_String2_Height + + left join Payload p + on p.TxHash = t.Hash + + left join Ratings r indexed by Ratings_Type_Id_Last_Height + on r.Type = 0 + and r.Id = t.Id + and r.Last = 1 + + where t.Type = 100 + and t.Last in (0,1) + and t.String2 = ? + and t.Height > ? + and (t.Height < ? or (t.Height = ? and t.BlockNum < ?)) + and t.ROWID = (select min(tt.ROWID) from Transactions tt where tt.Id = t.Id) + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementText(stmt, i++, queryParams.address); + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + } + }}, + + { + ShortTxType::Answer, { R"sql( + -- Comment answers + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Answer) + R"sql(')TP, + a.Hash, + a.Type, + a.String1, + orig.Height as Height, + a.BlockNum as BlockNum, + null, + pa.String1, + paa.String2, + paa.String3, + paa.String4, + ifnull(ra.Value,0), + c.Hash, + c.Type, + null, + c.Height, + c.BlockNum, + null, + pc.String1, + null, + null, + null, + null + + from Transactions c indexed by Transactions_Type_Last_String1_String2_Height -- My comments + + left join Payload pc + on pc.TxHash = c.Hash + + join Transactions a indexed by Transactions_Type_Last_String5_Height -- Other answers + on a.Type in (204, 205) and a.Last = 1 + and a.Height > ? + and (a.Height < ? or (a.Height = ? and a.BlockNum < ?)) + and a.String5 = c.String2 + and a.String1 != c.String1 + + join Transactions orig indexed by Transactions_Hash_Height + on orig.Hash = a.String2 + + left join Payload pa + on pa.TxHash = a.Hash + + left join Transactions aa + on aa.Type = 100 + and aa.Last = 1 and aa.String1 = a.String1 and aa.Height > 0 - left join Payload paa - on paa.TxHash = aa.Hash + left join Payload paa + on paa.TxHash = aa.Hash + + left join Ratings ra indexed by Ratings_Type_Id_Last_Height + on ra.Type = 0 + and ra.Id = aa.Id + and ra.Last = 1 + + where c.Type in (204, 205) + and c.Last = 1 + and c.String1 = ? + and c.Height > 0 + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } + }}, + + { + ShortTxType::Comment, { R"sql( + -- Comments for my content + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Comment) + R"sql(')TP, + c.Hash, + c.Type, + c.String1, + c.Height as Height, + c.BlockNum as BlockNum, + oc.Value, + pc.String1, + pac.String2, + pac.String3, + pac.String4, + ifnull(rac.Value,0), + p.Hash, + p.Type, + null, + p.Height, + p.BlockNum, + null, + null, + null, + null, + null, + null + + from Transactions p indexed by Transactions_String1_Last_Height + + join Transactions c indexed by Transactions_Type_Last_String3_Height + on c.Type in (204,205) + and c.Last = 1 + and c.String3 = p.String2 + and c.String1 != p.String1 + and c.Hash = c.String2 + and c.Height > ? + and (c.Height < ? or (c.Height = ? and c.BlockNum < ?)) + + left join TxOutputs oc indexed by TxOutputs_TxHash_AddressHash_Value + on oc.TxHash = c.Hash and oc.AddressHash = p.String1 and oc.AddressHash != c.String1 + + left join Payload pc + on pC.TxHash = c.Hash + + join Transactions ac -- accounts of commentators + on ac.String1 = c.String1 + and ac.Last = 1 + and ac.Type = 100 + and ac.Height > 0 + + left join Payload pac + on pac.TxHash = ac.Hash + + left join Ratings rac indexed by Ratings_Type_Id_Last_Height + on rac.Type = 0 + and rac.Id = ac.Id + and rac.Last = 1 + + where p.Type in (200,201,202) + and p.Last = 1 + and p.Height > 0 + and p.String1 = ? + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } + }}, + + { + ShortTxType::Subscriber, { R"sql( + -- Subscribers + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Subscriber) + R"sql(')TP, + subs.Hash, + subs.Type, + subs.String1, + subs.Height as Height, + subs.BlockNum as BlockNum, + null, + null, + pu.String2, + pu.String3, + pu.String4, + ifnull(ru.Value,0), + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + + from Transactions subs --indexed by Transactions_Type_Last_String2_Height + + join Transactions u --indexed by Transactions_Type_Last_String1_Height_Id + on u.Type in (100) + and u.Last = 1 + and u.String1 = subs.String1 + and u.Height > 0 + + left join Payload pu + on pu.TxHash = u.Hash + + left join Ratings ru indexed by Ratings_Type_Id_Last_Height + on ru.Type = 0 + and ru.Id = u.Id + and ru.Last = 1 + + where subs.Type in (302, 303) -- Ignoring unsubscribers? + and subs.Last = 1 + and subs.String2 = ? + and subs.Height > ? + and (subs.Height < ? or (subs.Height = ? and subs.BlockNum < ?)) + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementText(stmt, i++, queryParams.address); + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + } + }}, + + { + ShortTxType::CommentScore, { R"sql( + -- Comment scores + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::CommentScore) + R"sql(')TP, + s.Hash, + s.Type, + s.String1, + s.Height as Height, + s.BlockNum as BlockNum, + s.Int1, + null, + pacs.String2, + pacs.String3, + pacs.String4, + ifnull(racs.Value,0), + c.Hash, + c.Type, + null, + c.Height, -- TODO (losty): original? + c.BlockNum, + null, + ps.String1, + null, + null, + null, + null + + from Transactions c indexed by Transactions_Type_Last_String1_Height_Id - left join Ratings ra indexed by Ratings_Type_Id_Last_Height - on ra.Type = 0 - and ra.Id = aa.Id - and ra.Last = 1 + join Transactions s indexed by Transactions_Type_Last_String2_Height + on s.Type = 301 + and s.Last = 0 + and s.String2 = c.String2 + and s.Height > ? + and (s.Height < ? or (s.Height = ? and s.BlockNum < ?)) - where a.Type = 204 -- only orig - and a.Last in (0,1) - and a.Height = ? + left join Payload ps + on ps.TxHash = c.Hash + + join Transactions acs + on acs.Type = 100 + and acs.Last = 1 + and acs.String1 = s.String1 + and acs.Height > 0 + + left join Payload pacs + on pacs.TxHash = acs.Hash + + left join Ratings racs indexed by Ratings_Type_Id_Last_Height + on racs.Type = 0 + and racs.Id = acs.Id + and racs.Last = 1 + + where c.Type in (204,205) + and c.Last = 1 + and c.Height > 0 + and c.String1 = ? )sql", - heightBinder + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } }}, - // { - // ShortTxType::Comment, { R"sql( - // -- Comments for my content - // select - // p.String1, - // (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Comment) + R"sql(')TP, - // c.Hash, - // c.Type, - // c.String1, - // c.Height as Height, - // c.BlockNum as BlockNum, - // oc.Value, - // pc.String1, - // pac.String2, - // pac.String3, - // pac.String4, - // ifnull(rac.Value,0), -- TODO rep - // p.Hash, - // p.Type, - // null, - // p.Height, - // p.BlockNum, - // null, - // pp.String2, - // null, - // null, - // null, - // null - - // from Transactions c - - // left join Transactions p - // on p.Type in (200,201,202) - // and p.Last = 1 - // and p.Height > 0 - // and p.String2 = c.String3 - // and p.String1 != c.String1 - - // left join TxOutputs oc indexed by TxOutputs_TxHash_AddressHash_Value - // on oc.TxHash = c.Hash and oc.AddressHash = p.String1 and oc.AddressHash != c.String1 - - // left join Payload pc - // on pC.TxHash = c.Hash - - // left join Transactions ac -- accounts of commentators - // on ac.String1 = c.String1 - // and ac.Last = 1 - // and ac.Type = 100 - // and ac.Height > 0 - - // left join Payload pac - // on pac.TxHash = ac.Hash - - // left join Ratings rac indexed by Ratings_Type_Id_Last_Height - // on rac.Type = 0 - // and rac.Id = ac.Id - // and rac.Last = 1 - - // left join Payload pp - // on pp.TxHash = p.Hash + { + ShortTxType::ContentScore, { R"sql( + -- Content scores + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::ContentScore) + R"sql(')TP, + s.Hash, + s.Type, + s.String1, + s.Height as Height, + s.BlockNum as BlockNum, + s.Int1, + null, + pacs.String2, + pacs.String3, + pacs.String4, + ifnull(racs.Value,0), + c.Hash, + c.Type, + null, + c.Height, -- TODO (losty): original? + c.BlockNum, + null, + pc.String2, + null, + null, + null, + null - // where c.Type = 204 -- only orig - // and c.Height = ? - // )sql", - // heightBinder - // }}, + from Transactions c indexed by Transactions_Type_Last_String1_Height_Id - // { - // ShortTxType::Subscriber, { R"sql( - // -- Subscribers - // select - // subs.String2, - // (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Subscriber) + R"sql(')TP, - // subs.Hash, - // subs.Type, - // subs.String1, - // subs.Height as Height, - // subs.BlockNum as BlockNum, - // null, - // null, - // pu.String2, - // pu.String3, - // pu.String4, - // ifnull(ru.Value,0), - // null, - // null, - // null, - // null, - // null, - // null, - // null, - // null, - // null, - // null, - // null - - // from Transactions subs --indexed by Transactions_Type_Last_String2_Height - - // left join Transactions u --indexed by Transactions_Type_Last_String1_Height_Id - // on u.Type in (100) - // and u.Last = 1 - // and u.String1 = subs.String1 - // and u.Height > 0 - - // left join Payload pu - // on pu.TxHash = u.Hash - - // left join Ratings ru indexed by Ratings_Type_Id_Last_Height - // on ru.Type = 0 - // and ru.Id = u.Id - // and ru.Last = 1 - - // where subs.Type in (302, 303) -- Ignoring unsubscribers? - // and subs.Height = ? - // )sql", - // heightBinder - // }}, + join Transactions s indexed by Transactions_Type_Last_String2_Height + on s.Type = 300 + and s.Last = 0 + and s.String2 = c.String2 + and s.Height > ? + and (s.Height < ? or (s.Height = ? and s.BlockNum < ?)) - // { - // ShortTxType::CommentScore, { R"sql( - // -- Comment scores - // select - // c.String1, - // (')sql" + ShortTxTypeConvertor::toString(ShortTxType::CommentScore) + R"sql(')TP, - // s.Hash, - // s.Type, - // s.String1, - // s.Height as Height, - // s.BlockNum as BlockNum, - // s.Int1, - // null, - // pacs.String2, - // pacs.String3, - // pacs.String4, - // ifnull(racs.Value,0), - // c.Hash, - // c.Type, - // null, - // c.Height, -- TODO (losty): original? - // c.BlockNum, - // null, - // ps.String1, - // null, - // null, - // null, - // null - - // from Transactions s indexed by Transactions_Height_Type - - // join Transactions c indexed by Transactions_Type_Last_String2_Height - // on c.Type in (204,205) - // and c.Last = 1 - // and c.Height > 0 - // and c.String2 = s.String2 - - // left join Payload ps - // on ps.TxHash = c.Hash - - // join Transactions acs - // on acs.Type = 100 - // and acs.Last = 1 - // and acs.String1 = s.String1 - // and acs.Height > 0 - - // left join Payload pacs - // on pacs.TxHash = acs.Hash - - // left join Ratings racs indexed by Ratings_Type_Id_Last_Height - // on racs.Type = 0 - // and racs.Id = acs.Id - // and racs.Last = 1 - - // where s.Type = 301 - // and s.Height = ? - // )sql", - // heightBinder - // }}, + left join Payload pc + on pc.TxHash = c.Hash - // { - // ShortTxType::ContentScore, { R"sql( - // -- Content scores - // select - // c.String1, - // (')sql" + ShortTxTypeConvertor::toString(ShortTxType::ContentScore) + R"sql(')TP, - // s.Hash, - // s.Type, - // s.String1, - // s.Height as Height, - // s.BlockNum as BlockNum, - // s.Int1, - // null, - // pacs.String2, - // pacs.String3, - // pacs.String4, - // ifnull(racs.Value,0), - // c.Hash, - // c.Type, - // null, - // c.Height, -- TODO (losty): original? - // c.BlockNum, - // null, - // ps.String2, - // null, - // null, - // null, - // null - - // from Transactions s indexed by Transactions_Height_Type - - // join Transactions c indexed by Transactions_Type_Last_String2_Height - // on c.Type in (200, 201, 202) - // and c.Last = 1 - // and c.Height > 0 - // and c.String2 = s.String2 - - // left join Payload ps - // on ps.TxHash = c.Hash - - // join Transactions acs - // on acs.Type = 100 - // and acs.Last = 1 - // and acs.String1 = s.String1 - // and acs.Height > 0 - - // left join Payload pacs - // on pacs.TxHash = acs.Hash - - // left join Ratings racs indexed by Ratings_Type_Id_Last_Height - // on racs.Type = 0 - // and racs.Id = acs.Id - // and racs.Last = 1 - - // where s.Type = 300 - // and s.Height = ? - // )sql", - // heightBinder - // }}, + join Transactions acs + on acs.Type = 100 + and acs.Last = 1 + and acs.String1 = s.String1 + and acs.Height > 0 + + left join Payload pacs + on pacs.TxHash = acs.Hash + + left join Ratings racs indexed by Ratings_Type_Id_Last_Height + on racs.Type = 0 + and racs.Id = acs.Id + and racs.Last = 1 + + where c.Type in (200, 201, 202) + and c.Last = 1 + and c.Height > 0 + and c.String1 = ? + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } + }}, { ShortTxType::PrivateContent, { R"sql( -- Content from private subscribers select - subs.String1, (')sql" + ShortTxTypeConvertor::toString(ShortTxType::PrivateContent) + R"sql(')TP, c.Hash, c.Type, @@ -5216,71 +6908,67 @@ namespace PocketDb c.BlockNum as BlockNum, null, p.String2, - null, - null, pac.String2, pac.String3, - null, + pac.String4, ifnull(rac.Value,0), - r.Hash, -- TODO (losty): probably reposts here? - r.Type, - r.String1, - r.Height, - r.BlockNum, + null, -- TODO (losty): probably reposts here? + null, + null, + null, + null, null, - pr.String2, null, null, - null, -- TODO (losty): No account info null, null, null - from Transactions c indexed by Transactions_Height_Type -- content for private subscribers - - cross join Transactions subs indexed by Transactions_Type_Last_String2_Height -- Subscribers private - on subs.Type = 303 - and subs.Last = 1 - and subs.String2 = c.String1 - and subs.Height > 0 - - left join Transactions r -- related content - possible reposts - on r.String2 = c.String3 - and r.Type in (200,201,202) - and r.Last = 1 + from Transactions subs indexed by Transactions_Type_Last_String1_Height_Id -- Subscribers private - left join Payload pr - on pr.TxHash = r.Hash + join Transactions c indexed by Transactions_Type_Last_String1_Height_Id -- content for private subscribers + on c.Type in (200,201,202) + and c.Last = 1 -- TODO (losty): last = 1 and c.Hash = c.String2 ????? + and c.String1 = subs.String2 + -- and c.Hash = c.String2 -- TODO (losty): Only first content record + and c.Height > ? + and (c.Height < ? or (c.Height = ? and c.BlockNum < ?)) - cross join Transactions ac indexed by Transactions_Type_Last_String1_Height_Id + left join Payload p + on p.TxHash = c.Hash + + join Transactions ac on ac.Type = 100 and ac.Last = 1 and ac.String1 = c.String1 and ac.Height > 0 - cross join Payload p - on p.TxHash = c.Hash - - cross join Payload pac + left join Payload pac on pac.TxHash = ac.Hash left join Ratings rac indexed by Ratings_Type_Id_Last_Height on rac.Type = 0 and rac.Id = ac.Id and rac.Last = 1 - - where c.Type in (200,201,202) - and c.Hash = c.String2 -- only orig - and c.Height = ? + + where subs.Type = 303 + and subs.Last = 1 + and subs.Height > 0 + and subs.String1 = ? )sql", - heightBinder + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } }}, { ShortTxType::Boost, { R"sql( -- Boosts for my content select - tContent.String1, (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Boost) + R"sql(')TP, tBoost.Hash, tboost.Type, @@ -5289,8 +6977,6 @@ namespace PocketDb tBoost.BlockNum as BlockNum, tBoost.Int1, null, - null, - null, pac.String2, pac.String3, pac.String4, @@ -5305,22 +6991,20 @@ namespace PocketDb null, null, null, - null, - null, null from Transactions tBoost indexed by Transactions_Type_Last_Height_Id - left join Transactions tContent indexed by Transactions_Type_Last_String2_Height + join Transactions tContent indexed by Transactions_Type_Last_String1_String2_Height on tContent.Type in (200,201,202) and tContent.Last in (0,1) and tContent.Height > 0 + and tContent.String1 = ? and tContent.String2 = tBoost.String2 - left join Payload pContent on pContent.TxHash = tContent.Hash - - left join Transactions ac + + join Transactions ac on ac.String1 = tBoost.String1 and ac.Type = 100 and ac.Last = 1 @@ -5336,99 +7020,323 @@ namespace PocketDb where tBoost.Type in (208) and tBoost.Last in (0,1) - and tBoost.Height = ? + and tBoost.Height > ? + and (tBoost.Height < ? or (tBoost.Height = ? and tBoost.BlockNum < ?)) )sql", - heightBinder + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementText(stmt, i++, queryParams.address); + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + } }}, - // { - // ShortTxType::Repost, { R"sql( - // -- Reposts - // select - // p.String1, - // (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Repost) + R"sql(')TP, - // r.Hash, - // r.Type, - // r.String1, - // r.Height as Height, - // r.BlockNum as BlockNum, - // null, - // pr.String2, - // par.String2, - // par.String3, - // par.String4, - // ifnull(rar.Value,0), - // p.Hash, - // p.Type, - // null, - // p.Height, - // p.BlockNum, - // null, - // pp.String2, - // null, - // null, - // null, - // null - - // from Transactions r - - // cross join Transactions p - // on p.Hash = r.String3 - // and p.Type in (200,201,202) - - // left join Payload pp - // on pp.TxHash = p.Hash - - // left join Payload pr - // on pr.TxHash = r.Hash - - // join Transactions ar indexed by Transactions_Type_Last_String1_Height_Id - // on ar.Type = 100 - // and ar.Last = 1 - // and ar.String1 = r.String1 - // and ar.Height > 0 - - // left join Payload par - // on par.TxHash = ar.Hash - - // left join Ratings rar indexed by Ratings_Type_Id_Last_Height - // on rar.Type = 0 - // and rar.Id = ar.Id - // and rar.Last = 1 - - // where r.Type in (200,201,202) - // and r.Hash = r.String2 -- Only orig - // and r.Height = ? - // and r.String3 is not null - - // )sql", - // heightBinder - // }} - }; + { + ShortTxType::Repost, { R"sql( + -- Reposts + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Repost) + R"sql(')TP, + r.Hash, + r.Type, + r.String1, + r.Height as Height, -- TODO (losty): orig height maybe??? + r.BlockNum as BlockNum, + null, + pr.String2, + par.String2, + par.String3, + par.String4, + ifnull(rar.Value,0), + p.Hash, + p.Type, + null, + p.Height, + p.BlockNum, + null, + pp.String2, + null, + null, + null, + null - auto predicate = _choosePredicate(filters); + from Transactions p indexed by Transactions_Type_Last_String1_Height_Id + + join Payload pp + on pp.TxHash = p.Hash + + join Transactions r indexed by Transactions_Type_Last_String3_Height + on r.Type in (200,201,202) + and r.Last = 1 + and r.String3 = p.String2 + and r.Height > ? + and (r.Height < ? or (r.Height = ? and r.BlockNum < ?)) + + left join Payload pr + on pr.TxHash = r.Hash + + join Transactions ar + on ar.Type = 100 + and ar.Last = 1 + and ar.String1 = r.String1 + and ar.Height > 0 + + left join Payload par + on par.TxHash = ar.Hash + + left join Ratings rar indexed by Ratings_Type_Id_Last_Height + on rar.Type = 0 + and rar.Id = ar.Id + and rar.Last = 1 + + where p.Type in (200,201,202) + and p.Last = 1 + and p.Height > 0 + and p.String1 = ? + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + TryBindStatementInt64(stmt, i++, queryParams.blockNumMax); + TryBindStatementText(stmt, i++, queryParams.address); + } + }}}; + + static const auto footer = R"sql( + + -- Global order and limit for pagination + order by Height desc, BlockNum desc + limit 10 + + )sql"; - NotificationsReconstructor reconstructor; - for(const auto& select: selects) { - if (predicate(select.first)) { - const auto& selectData = select.second; - TryTransactionStep(__func__, [&]() - { - auto stmt = SetupSqlStatement(selectData.query); + auto [elem1, elem2] = _constructSelectsBasedOnFilters(filters, selects, footer); + // A bit dirty hack because structure bindings can't be captured by lambda function. + auto& sql = elem1; + auto& binds = elem2; - int i = 1; - selectData.binding(stmt, i, queryParams); + EventsReconstructor reconstructor; + TryTransactionStep(__func__, [&]() + { + auto stmt = SetupSqlStatement(sql); + int i = 1; - while (sqlite3_step(*stmt) == SQLITE_ROW) - { - reconstructor.FeedRow(*stmt); - } + for (const auto& bind: binds) { + bind(stmt, i, queryParams); + } - FinalizeSqlStatement(*stmt); - }); + while (sqlite3_step(*stmt) == SQLITE_ROW) + { + reconstructor.FeedRow(*stmt); } - } + FinalizeSqlStatement(*stmt); + }); + return reconstructor.GetResult(); + } + + + std::map> WebRpcRepository::GetNotificationsSummary(int64_t heightMax, int64_t heightMin, const std::set& addresses, const std::set& filters) + { + struct QueryParams { + // Handling all by reference + const int64_t& heightMax; + const int64_t& heightMin; + const std::set& addresses; + } queryParams {heightMax, heightMin, addresses}; + + const std::map&, QueryParams>> selects = { + { + ShortTxType::Referal, { R"sql( + -- referals + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Referal) + R"sql(')TP, + t.String2 + + from Transactions t indexed by Transactions_Type_Last_String2_Height + + where t.Type = 100 + and t.Last in (0,1) + and t.Height between ? and ? + and t.String2 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) + and t.ROWID = (select min(tt.ROWID) from Transactions tt indexed by Transactions_Id where tt.Id = t.Id) + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + for (const auto& address: queryParams.addresses) { + TryBindStatementText(stmt, i++, address); + } + } + }}, + + { + ShortTxType::Comment, { R"sql( + -- Comments for my content + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Comment) + R"sql(')TP, + p.String1 + + from Transactions c indexed by Transactions_Type_Last_String3_Height + + join Transactions p indexed by Transactions_String1_Last_Height + on p.Type in (200,201,202) + and p.Last = 1 + and p.Height > 0 + and p.String2 = c.String3 + and p.String1 != c.String1 + and p.String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) + + where c.Type = 204 -- only orig + and c.Last in (0,1) + and c.Height between ? and ? + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + for (const auto& address: queryParams.addresses) { + TryBindStatementText(stmt, i++, address); + } + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + } + }}, + + { + ShortTxType::Subscriber, { R"sql( + -- Subscribers + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Subscriber) + R"sql(')TP, + subs.String2 + + from Transactions subs indexed by Transactions_Type_Last_String2_Height + + where subs.Type in (302, 303) -- Ignoring unsubscribers? + and subs.Last in (0,1) + and subs.Height between ? and ? + and subs.String2 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) + + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + for (const auto& address: queryParams.addresses) { + TryBindStatementText(stmt, i++, address); + } + } + }}, + + { + ShortTxType::CommentScore, { R"sql( + -- Comment scores + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::CommentScore) + R"sql(')TP, + c.String1 + + from Transactions s indexed by Transactions_Type_Last_String2_Height + + join Transactions c indexed by Transactions_Type_Last_String1_String2_Height + on c.Type in (204,205) + and c.Last = 1 + and c.Height > 0 + and c.String2 = s.String2 + and c.String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) + + where s.Type = 301 + and s.Last = 0 + and s.Height between ? and ? + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + for (const auto& address: queryParams.addresses) { + TryBindStatementText(stmt, i++, address); + } + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + } + }}, + + { + ShortTxType::ContentScore, { R"sql( + -- Content scores + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::ContentScore) + R"sql(')TP, + c.String1 + + from Transactions s indexed by Transactions_Type_Last_String2_Height + + join Transactions c indexed by Transactions_Type_Last_String1_String2_Height + on c.Type in (200, 201, 202) + and c.Last = 1 + and c.Height > 0 + and c.String2 = s.String2 + and c.String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) + + where s.Type = 300 + and s.Last = 0 + and s.Height between ? and ? + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + for (const auto& address: queryParams.addresses) { + TryBindStatementText(stmt, i++, address); + } + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + } + }}, + + + { + ShortTxType::Repost, { R"sql( + -- Reposts + select + (')sql" + ShortTxTypeConvertor::toString(ShortTxType::Repost) + R"sql(')TP, + p.String1 + + from Transactions r indexed by Transactions_Type_Last_String3_Height + + join Transactions p indexed by Transactions_Type_Last_String1_String2_Height + on p.String2 = r.String3 + and p.Last = 1 + and p.Type in (200,201,202) + and p.String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) + + where r.Type in (200,201,202) + and r.Last in (0,1) + and r.Hash = r.String2 -- Only orig + and r.Height between ? and ? + and r.String3 is not null + + )sql", + [this](std::shared_ptr& stmt, int& i, QueryParams const& queryParams){ + for (const auto& address: queryParams.addresses) { + TryBindStatementText(stmt, i++, address); + } + TryBindStatementInt64(stmt, i++, queryParams.heightMin); + TryBindStatementInt64(stmt, i++, queryParams.heightMax); + } + }} + }; + + auto [elem1, elem2] = _constructSelectsBasedOnFilters(filters, selects, "", "union all"); + auto& sql = elem1; + auto& binds = elem2; + + NotificationSummaryReconstructor reconstructor; + TryTransactionStep(__func__, [&]() + { + auto stmt = SetupSqlStatement(sql); + int i = 1; + + for (const auto& bind: binds) { + bind(stmt, i, queryParams); + } + + while (sqlite3_step(*stmt) == SQLITE_ROW) + { + reconstructor.FeedRow(*stmt); + } + + FinalizeSqlStatement(*stmt); + }); return reconstructor.GetResult(); } -} +} \ No newline at end of file diff --git a/src/pocketdb/repositories/web/WebRpcRepository.h b/src/pocketdb/repositories/web/WebRpcRepository.h index 2ce684515..f0b9c0c50 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.h +++ b/src/pocketdb/repositories/web/WebRpcRepository.h @@ -159,15 +159,35 @@ namespace PocketDb UniValue GetContentActions(const string& postTxHash); - // First - map where keys are addresses and values are ShortForms of events from given block. Second - pocketnetteam posts. - using NotificationsResult = std::map>; + /** + * Returns map where key is address. Value is map, where key - height, value - vector of transactions for this height. + */ + std::vector GetEventsForAddresses(const std::string& address, int64_t heightMax, int64_t heightMin, int64_t blockNum, const std::set& filters); + /** * Get all possible events for all adresses in concrete block * * @param height height of block to search * @param filters */ - NotificationsResult GetNotifications(int64_t height, const std::set& filters); + UniValue GetNotifications(int64_t height, const std::set& filters); + + std::map GetShortAccountsForAddresses(const std::set& addresses); + + /** + * Get all activities (posts, comments, etc) created by address + * + * @param address - address to search activities for + * @param heightMax - height to start search from, including + * @param heightMin - height untill search, excluding + * @param blockNumMax - number of tx in block to start search in heightMax, excluding + * @param filters + * @return vector of activities in ShortForm + */ + std::vector GetActivities(const std::string& address, int64_t heightMax, int64_t heightMin, int64_t blockNumMax, const std::set& filters); + + // TODO (losty): convert return type to class of smth. + docs + std::map> GetNotificationsSummary(int64_t heightMax, int64_t heightMin, const std::set& addresses, const std::set& filters); // TODO (o1q): Remove this two methods when the client gui switches to new methods UniValue GetProfileFeedOld(const string& addressFrom, const string& addressTo, int64_t topContentId, int count, const string& lang, const vector& tags, const vector& contentTypes); diff --git a/src/pocketdb/web/PocketAccountRpc.cpp b/src/pocketdb/web/PocketAccountRpc.cpp index 71af4343d..d51a7c3f1 100644 --- a/src/pocketdb/web/PocketAccountRpc.cpp +++ b/src/pocketdb/web/PocketAccountRpc.cpp @@ -404,7 +404,7 @@ namespace PocketWeb::PocketWebRpc const auto& node = EnsureNodeContext(request.context); // Get exclude inputs already used in mempool vector> mempoolInputs; - // TODO (losty-fur): possible null mempool + CHECK_NONFATAL(node.mempool); node.mempool->GetAllInputs(mempoolInputs); // Get unspents from DB diff --git a/src/pocketdb/web/PocketContentRpc.cpp b/src/pocketdb/web/PocketContentRpc.cpp index 89c62b585..ee7568c7c 100644 --- a/src/pocketdb/web/PocketContentRpc.cpp +++ b/src/pocketdb/web/PocketContentRpc.cpp @@ -407,8 +407,8 @@ namespace PocketWeb::PocketWebRpc if (request.params[0].isNum()) count = request.params[0].get_int(); else if (request.params[0].isStr()) - // TODO (losty-fur): do not ignore result - bool res = ParseInt32(request.params[0].get_str(), &count); + if (!ParseInt32(request.params[0].get_str(), &count)) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to parse int from string"); } // Depth in blocks (default about 3 days) @@ -419,8 +419,8 @@ namespace PocketWeb::PocketWebRpc if (request.params[1].isNum()) depthBlocks = request.params[1].get_int(); else if (request.params[1].isStr()) - // TODO (losty-fur): do not ignore result - bool res = ParseInt32(request.params[1].get_str(), &depthBlocks); + if (!ParseInt32(request.params[1].get_str(), &depthBlocks)) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to parse int from string"); // for old version electron if (depthBlocks == 259200) @@ -441,8 +441,8 @@ namespace PocketWeb::PocketWebRpc } else if (request.params[2].isStr()) { - // TODO (losty-fur): do not ignore result - bool res = ParseInt32(request.params[2].get_str(), &nOffset); + if (!ParseInt32(request.params[2].get_str(), &nOffset)) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to parse int from string"); } nHeightOffset -= nOffset; } @@ -1299,18 +1299,103 @@ namespace PocketWeb::PocketWebRpc }; } + RPCHelpMan GetEvents() + { + return RPCHelpMan{"GetEvents", + "\nGet all events assotiated with addresses. Search depth - 3 months\n", + { + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "address to get events for"}, + {"heightMax", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "max height to start search from, including. Default is current chain height"}, + {"blockNum", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "number of transaction in block to start search from for specified heightMax, excluding. Default is 999999"}, + {"filters", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "filters to specify event's types to search for. Default: search for all events", + { + {ShortTxTypeConvertor::toString(ShortTxType::Money), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "incoming money"}, + {ShortTxTypeConvertor::toString(ShortTxType::Referal), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "registered referals"}, + {ShortTxTypeConvertor::toString(ShortTxType::Answer), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "answers to acc's comments"}, + {ShortTxTypeConvertor::toString(ShortTxType::Comment), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "comments to acc's content"}, + {ShortTxTypeConvertor::toString(ShortTxType::Subscriber), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "subscribers"}, + {ShortTxTypeConvertor::toString(ShortTxType::CommentScore), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "scores to acc's comments"}, + {ShortTxTypeConvertor::toString(ShortTxType::ContentScore), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "scores to acc's content"}, + {ShortTxTypeConvertor::toString(ShortTxType::PrivateContent), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "content from private subscriptions"}, + {ShortTxTypeConvertor::toString(ShortTxType::Boost), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "boosts of acc's content"}, + {ShortTxTypeConvertor::toString(ShortTxType::Repost), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "reposts of acc's content"}, + } + } + }, + { + // TODO (rpc): provide return description + }, + RPCExamples{ + // TODO (rpc) + HelpExampleCli("getevents", "") + + HelpExampleRpc("getevents", "") + }, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue + { + RPCTypeCheck(request.params, {UniValue::VSTR}); + + auto address = request.params[0].get_str(); + + int64_t heightMax = ChainActive().Height(); // TODO (losty): deadlock here wtf + if (request.params.size() > 1 && request.params[1].isNum()) { + heightMax = request.params[1].get_int64(); + } + + int64_t blockNum = 9999999; // Default + if (request.params.size() > 2 && request.params[2].isNum()) { + blockNum = request.params[2].get_int64(); + } + + static const int64_t depth = 129600; // 3 months + int64_t heightMin = heightMax - depth; + if (heightMin < 0) { + heightMin = 0; + } + + std::set filters; + if (request.params.size() > 3 && request.params[3].isArray()) { + const auto& rawFilters = request.params[3].get_array(); + for (int i = 0; i < rawFilters.size(); i++) { + if (rawFilters[i].isStr()) { + const auto& rawFilter = rawFilters[i].get_str(); + auto filter = ShortTxTypeConvertor::strToType(rawFilter); + if (!PocketHelpers::ShortTxFilterValidator::Events::IsFilterAllowed(filter)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Unexpected filter: " + rawFilter); + } + filters.insert(filter); + } + } + } + + auto shortTxs = request.DbConnection()->WebRpcRepoInst->GetEventsForAddresses(address, heightMax, heightMin, blockNum, filters); + UniValue res(UniValue::VARR); + for (const auto& tx: shortTxs) { + res.push_back(tx.Serialize()); + } + + return res; + }, + }; + } + RPCHelpMan GetNotifications() { return RPCHelpMan{"getnotifications", "\nGet all possible notifications for all addresses for concrete block height.\n", { {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "height of block to search in"}, - {"filters", RPCArg::Type::ARR, RPCArg::Optional::NO, "type(s) of notifications. If empty or null - search for all types", + {"filters", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "type(s) of notifications. If empty or null - search for all types", { - {ShortTxTypeConvertor::toString(ShortTxType::Money), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "recieved money"}, - {ShortTxTypeConvertor::toString(ShortTxType::Answer), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "answers to acc's comments"}, - {ShortTxTypeConvertor::toString(ShortTxType::PrivateContent), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "content from acc's private subscriptions`"}, - {ShortTxTypeConvertor::toString(ShortTxType::Boost), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "boosts of acc's content"}, + {ShortTxTypeConvertor::toString(ShortTxType::Money), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new incoming coins"}, + {ShortTxTypeConvertor::toString(ShortTxType::Answer), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new answers to acc's comments"}, + {ShortTxTypeConvertor::toString(ShortTxType::Boost), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new boosts of acc's content"}, + {ShortTxTypeConvertor::toString(ShortTxType::Referal), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new registration with my referal link"}, + {ShortTxTypeConvertor::toString(ShortTxType::Comment), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new comments under acc's content"}, + {ShortTxTypeConvertor::toString(ShortTxType::Subscriber), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new subscribers to acc"}, + {ShortTxTypeConvertor::toString(ShortTxType::CommentScore), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new scores to acc's comments"}, + {ShortTxTypeConvertor::toString(ShortTxType::ContentScore), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new scores to acc's content"}, + {ShortTxTypeConvertor::toString(ShortTxType::PrivateContent), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new content from acc's private subscriptions"}, + {ShortTxTypeConvertor::toString(ShortTxType::Repost), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "new reposts of acc's content"}, } }, }, @@ -1324,15 +1409,6 @@ namespace PocketWeb::PocketWebRpc }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - if (request.fHelp) - throw std::runtime_error( - "getnotifications\n" - "\nGet all possible notifications for all addresses for concrete block height.\n" - "\nArguments:\n" - "1. \"height\" (int) height of block to search in\n" - "2. \"filters\" (array of strings, optional) type(s) of notifications. If empty or null - search for all types\n" - ); - RPCTypeCheck(request.params, {UniValue::VNUM}); auto height = request.params[0].get_int64(); @@ -1354,25 +1430,153 @@ namespace PocketWeb::PocketWebRpc } } - auto shortTxMap = request.DbConnection()->WebRpcRepoInst->GetNotifications(height, filters); + return request.DbConnection()->WebRpcRepoInst->GetNotifications(height, filters); + }, + }; + } + + RPCHelpMan GetActivities() + { + return RPCHelpMan{"GetActivities", + "\nGet all activities created by account. Search depth - 3 months\n", + { + {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "address to get activities for"}, + {"heightMax", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "max height to start search from, including. Default is current chain height"}, + {"blockNum", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "number of transaction in block to start search from for specified heightMax, excluding. Default is 999999"}, + {"filters", RPCArg::Type::ARR, RPCArg::Optional::OMITTED_NAMED_ARG, "filters to specify event's types to search for. Default: search for all activities", + { + {ShortTxTypeConvertor::toString(ShortTxType::Answer), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "acc's answers to comments"}, + {ShortTxTypeConvertor::toString(ShortTxType::Comment), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "acc's comments"}, + {ShortTxTypeConvertor::toString(ShortTxType::Subscriber), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "acc's subscribes"}, + {ShortTxTypeConvertor::toString(ShortTxType::CommentScore), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "acc's comments scores"}, + {ShortTxTypeConvertor::toString(ShortTxType::ContentScore), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "acc's content scores"}, + {ShortTxTypeConvertor::toString(ShortTxType::Boost), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "boosts content done by acc"}, + {ShortTxTypeConvertor::toString(ShortTxType::Blocking), RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "my blockings/unblockings"}, + } + } + }, + { + // TODO (rpc): provide return description + }, + RPCExamples{ + // TODO (rpc) + HelpExampleCli("getactivities", "") + + HelpExampleRpc("getactivities", "") + }, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue + { + RPCTypeCheck(request.params, {UniValue::VSTR}); + + auto address = request.params[0].get_str(); + + int64_t heightMax = ChainActive().Height(); + if (request.params.size() > 1 && request.params[1].isNum()) { + heightMax = request.params[1].get_int64(); + } + + int64_t blockNum = 9999999; // Default + if (request.params.size() > 2 && request.params[2].isNum()) { + blockNum = request.params[2].get_int64(); + } + + static const int64_t depth = 129600; // 3 months + int64_t heightMin = heightMax - depth; + if (heightMin < 0) { + heightMin = 0; + } - UniValue userNotifications {UniValue::VOBJ}; - userNotifications.reserveKVSize(shortTxMap.size()); - for (const auto& addressSpecific: shortTxMap) { - UniValue txs {UniValue::VARR}; - std::vector tmp; - for (const auto& tx: addressSpecific.second) { - tmp.emplace_back(tx.Serialize()); + std::set filters; + if (request.params.size() > 3 && request.params[3].isArray()) { + const auto& rawFilters = request.params[3].get_array(); + for (int i = 0; i < rawFilters.size(); i++) { + if (rawFilters[i].isStr()) { + const auto& rawFilter = rawFilters[i].get_str(); + auto filter = ShortTxTypeConvertor::strToType(rawFilter); + if (!PocketHelpers::ShortTxFilterValidator::Activities::IsFilterAllowed(filter)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Unexpected filter: " + rawFilter); + } + filters.insert(filter); + } } - txs.push_backV(std::move(tmp)); - userNotifications.pushKV(addressSpecific.first, txs, false /*searchDuplicate*/); } - UniValue res {UniValue::VOBJ}; - res.pushKV("users_notifications", userNotifications); + auto shortTxs = request.DbConnection()->WebRpcRepoInst->GetActivities(address, heightMax, heightMin, blockNum, filters); + UniValue res(UniValue::VARR); + for (const auto& tx: shortTxs) { + res.push_back(tx.Serialize()); + } return res; }, - }; + }; + } + + RPCHelpMan GetNotificationsSummary() + { + return RPCHelpMan{"GetNotificationsSummary", + "\\n", // TODO (losty) + { + + }, + { + // TODO (rpc): provide return description + }, + RPCExamples{ + // TODO (rpc) + HelpExampleCli("getnotificationssummary", "") + + HelpExampleRpc("getnotificationssummary", "") + }, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue + { + RPCTypeCheck(request.params, {UniValue::VARR}); + + + std::set addresses; + auto addressesRaw = request.params[0].get_array(); + for (int i = 0; i < addressesRaw.size(); i++) { + addresses.insert(addressesRaw[i].get_str()); + } + + int64_t heightMax = ChainActive().Height(); // TODO (losty): deadlock here wtf + if (request.params.size() > 1 && request.params[1].isNum()) { + heightMax = request.params[1].get_int64(); + } + + + static const int64_t depth = 480; // 8 hours + int64_t heightMin = heightMax - depth; + if (heightMin < 0) { + heightMin = 0; + } + + std::set filters; + if (request.params.size() > 3 && request.params[3].isArray()) { + const auto& rawFilters = request.params[3].get_array(); + for (int i = 0; i < rawFilters.size(); i++) { + if (rawFilters[i].isStr()) { + const auto& rawFilter = rawFilters[i].get_str(); + auto filter = ShortTxTypeConvertor::strToType(rawFilter); + if (!ShortTxFilterValidator::NotificationsSummary::IsFilterAllowed(filter)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Unexpected filter: " + rawFilter); + } + filters.insert(filter); + } + } + } + + auto res = request.DbConnection()->WebRpcRepoInst->GetNotificationsSummary(heightMax, heightMin, addresses, filters); + UniValue response(UniValue::VOBJ); + + for (const auto& addressEntry: res) { + UniValue addressRelated(UniValue::VOBJ); + for (const auto& summaryEntry: addressEntry.second) { + addressRelated.pushKV(PocketHelpers::ShortTxTypeConvertor::toString(summaryEntry.first), summaryEntry.second); + } + response.pushKV(addressEntry.first, addressRelated); + } + + return response; + }, + }; } } diff --git a/src/pocketdb/web/PocketContentRpc.h b/src/pocketdb/web/PocketContentRpc.h index 466bf819f..936cb3e82 100644 --- a/src/pocketdb/web/PocketContentRpc.h +++ b/src/pocketdb/web/PocketContentRpc.h @@ -30,8 +30,10 @@ namespace PocketWeb::PocketWebRpc RPCHelpMan GetContentsStatistic(); RPCHelpMan GetRandomContents(); RPCHelpMan GetContentActions(); + RPCHelpMan GetEvents(); // TODO (losty): probably move to another place RPCHelpMan GetNotifications(); - + RPCHelpMan GetActivities(); + RPCHelpMan GetNotificationsSummary(); } #endif //SRC_POCKETDEBUG_H diff --git a/src/pocketdb/web/PocketRpc.cpp b/src/pocketdb/web/PocketRpc.cpp index d2877f9f9..951afc170 100644 --- a/src/pocketdb/web/PocketRpc.cpp +++ b/src/pocketdb/web/PocketRpc.cpp @@ -69,7 +69,10 @@ static const CRPCCommand commands[] = {"contents", "getcontents", &GetContents, {"address"}}, {"contents", "getrandomcontents", &GetRandomContents, {}}, {"contents", "getcontentactions", &GetContentActions, {"contentHash"}}, - // {"contents", "getnotifications", &GetNotifications, {"height", "filters"}}, + // {"contents", "getevents", &GetEvents, {"address", "height", "blockNum", "filters"}}, + {"contents", "getactivities", &GetActivities, {"address", "height", "blockNum", "filters"}}, + {"contents", "getnotifications", &GetNotifications, {"height", "filters"}}, + {"contents", "getnotificationssummary", &GetNotificationsSummary, {"addresses", "height", "filters"}}, // Tags // {"artifacts", "searchtags", &gettemplate, {"search_string", "count"}}, diff --git a/src/pocketdb/web/PocketTagsRpc.cpp b/src/pocketdb/web/PocketTagsRpc.cpp index 029b71485..39b1f198f 100644 --- a/src/pocketdb/web/PocketTagsRpc.cpp +++ b/src/pocketdb/web/PocketTagsRpc.cpp @@ -30,8 +30,8 @@ namespace PocketWeb::PocketWebRpc int pageSize = 50; if (request.params.size() > 1) - // TODO (losty-fur): do not ignore result - bool res = ParseInt32(request.params[1].get_str(), &pageSize); + if (!ParseInt32(request.params[1].get_str(), &pageSize)) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to parse int from string"); int pageStart = 0; // if (request.params.size() > 2) diff --git a/src/pocketdb/web/PocketTransactionRpc.cpp b/src/pocketdb/web/PocketTransactionRpc.cpp index 6afdad3ed..363381973 100644 --- a/src/pocketdb/web/PocketTransactionRpc.cpp +++ b/src/pocketdb/web/PocketTransactionRpc.cpp @@ -31,6 +31,9 @@ namespace PocketWeb::PocketWebRpc [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { auto& node = EnsureNodeContext(request.context); + if (!node.mempool) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Null mempool"); + } RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VOBJ}); @@ -64,7 +67,7 @@ namespace PocketWeb::PocketWebRpc } // Insert into mempool - return _accept_transaction(tx, ptx, *node.mempool, *node.connman); // TODO (losty-fur): possible null + return _accept_transaction(tx, ptx, *node.mempool, *node.connman); }, }; } @@ -234,8 +237,12 @@ namespace PocketWeb::PocketWebRpc _ptx->SetHash(""); _ptx->DeserializeRpc(txPayload); auto& node = EnsureNodeContext(request.context); - // TODO (losty): probably bad assert like this - assert(node.mempool); + if (!node.mempool) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Null mempool"); + } + if (!node.connman) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Null connman"); + } // Get unspents vector> mempoolInputs; node.mempool->GetAllInputs(mempoolInputs); @@ -312,7 +319,6 @@ namespace PocketWeb::PocketWebRpc // Set required fields ptx->SetString1(address); - // TODO (losty-fur): possible null mempool and connman // Insert into mempool return _accept_transaction(tx, ptx, *node.mempool, *node.connman); //const CTransaction& ctx = *tx; diff --git a/src/pocketdb/web/SearchRpc.cpp b/src/pocketdb/web/SearchRpc.cpp index f818d4d1d..2aa8fabec 100644 --- a/src/pocketdb/web/SearchRpc.cpp +++ b/src/pocketdb/web/SearchRpc.cpp @@ -44,8 +44,8 @@ namespace PocketWeb::PocketWebRpc { try { - // TODO (losty-fur): do not ignore result - bool res = ParseInt32(request.params[2].get_str(), &searchRequest.TopBlock); + if (!ParseInt32(request.params[2].get_str(), &searchRequest.TopBlock)) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to parse int from string"); } catch (...) { } } @@ -55,8 +55,8 @@ namespace PocketWeb::PocketWebRpc { try { - // TODO (losty-fur): do not ignore result - bool res = ParseInt32(request.params[3].get_str(), &searchRequest.PageStart); + if (!ParseInt32(request.params[3].get_str(), &searchRequest.PageStart)) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to parse int from string"); } catch (...) { } } @@ -66,8 +66,8 @@ namespace PocketWeb::PocketWebRpc { try { - // TODO (losty-fur): do not ignore result - bool res = ParseInt32(request.params[4].get_str(), &searchRequest.PageSize); + if (!ParseInt32(request.params[4].get_str(), &searchRequest.PageSize)) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to parse int from string"); } catch (...) { } } diff --git a/src/rest.cpp b/src/rest.cpp index fdf32699f..fb1c6697e 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -935,8 +935,9 @@ static bool debug_index_block(const util::Ref& context, HTTPRequest* req, const { arith_uint256 hashProof; arith_uint256 targetProofOfStake; + CHECK_NONFATAL(node.mempool); CheckProofOfStake(pblockindex->pprev, block.vtx[1], block.nBits, hashProof, hashProofOfStakeSource, - targetProofOfStake, NULL, *node.mempool, false); // TODO (losty-fur): possible null nmempool + targetProofOfStake, NULL, *node.mempool, false); int64_t nReward = GetProofOfStakeReward(pblockindex->nHeight, 0, Params().GetConsensus()); if (!CheckBlockRatingRewards(block, pblockindex->pprev, nReward, hashProofOfStakeSource)) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 4f3f5db52..4c13b3c23 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1515,7 +1515,9 @@ static RPCHelpMan getmempoolinfo() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const auto& node = EnsureNodeContext(request.context); - // TODO (losty-fur): possible null mempool + if (!node.mempool) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Null mempool"); + } UniValue result = mempoolInfoToJSON(*node.mempool); int sqliteMempoolCount = PocketDb::TransRepoInst.MempoolCount(); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index f2456f78a..f25c155c8 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -801,8 +801,12 @@ RPCHelpMan SendRawTransaction() throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); auto& node = EnsureNodeContext(request.context); - assert (node.mempool); - assert (node.connman); // TODO (losty): probably connman is able to be null? + if (!node.mempool) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Null mempool"); + } + if (!node.connman) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Null connman"); + } CTransactionRef tx(MakeTransactionRef(std::move(mtx))); return PocketWeb::PocketWebRpc::_accept_transaction(tx, nullptr, *node.mempool, *node.connman); diff --git a/src/staker.cpp b/src/staker.cpp index 7b0f0b126..2852dea2f 100644 --- a/src/staker.cpp +++ b/src/staker.cpp @@ -116,6 +116,8 @@ void Staker::worker(const util::Ref& context, CChainParams const& chainparams, s util::ThreadRename("coin-staker"); const auto& node = EnsureNodeContext(context); + CHECK_NONFATAL(node.mempool); // Mempool should be always available here + CHECK_NONFATAL(node.chainman); // Same for this bool running = true; int nLastCoinStakeSearchInterval = 0; @@ -173,10 +175,9 @@ void Staker::worker(const util::Ref& context, CChainParams const& chainparams, s } uint64_t nFees = 0; - // TODO (losty-fur): possible null mempool auto assembler = BlockAssembler(*node.mempool, chainparams); - // TODO (losty): passing here nullopt because coinbase script is only usefull for mining blocks + // Nullopt for scriptPubKeyIn because coinbase script is only usefull for mining blocks auto blocktemplate = assembler.CreateNewBlock( nullopt, true, &nFees ); @@ -188,7 +189,7 @@ void Staker::worker(const util::Ref& context, CChainParams const& chainparams, s // Extend pocketBlock with coinStake transaction if (auto[ok, ptx] = PocketServices::Serializer::DeserializeTransaction(block->vtx[1]); ok) blocktemplate->pocketBlock->emplace_back(ptx); - // TODO (losty-fur): possible null chainman + CheckStake(block, blocktemplate->pocketBlock, wallet, chainparams, *node.chainman, *node.mempool); UninterruptibleSleep(std::chrono::milliseconds{500}); } From 2718a6effc98cc84787700a1eaae7e61b13d59fe Mon Sep 17 00:00:00 2001 From: brangr Date: Sat, 10 Sep 2022 21:41:57 +0300 Subject: [PATCH 07/49] Squashed commit of the following: commit 84b78aab2b2f7c9baa2009f57eee3f92385aafb3 Merge: 7b7338c8 499f514b Author: Andy Oknen Date: Fri Sep 9 14:37:44 2022 +0300 Merge pull request #408 from pocketnetteam/actualization/0.20 Squashed commit of the following: commit 499f514bf494920d2847225ae31eeef5811f305b Author: Andy Oknen Date: Fri Sep 9 10:50:15 2022 +0300 Squashed commit of the following: commit aca3fe7d05c1f0c8a9ea76bf02eff87cefd47142 Merge: 78065768 1cce975f Author: Andy Oknen Date: Thu Sep 8 18:40:05 2022 +0300 Merge pull request #399 from HiHat/patch-1 Important details regarding address and fixes commit 780657681d2564844a42c24de0938da74777c642 Merge: bfaef570 5ce96412 Author: Andy Oknen Date: Thu Sep 8 15:09:22 2022 +0300 Merge pull request #402 from pocketnetteam/andyoknen-patch-1 Update README.md commit 5ce96412b1cc0f67148aa4933dd74fe3b43f6c29 Author: Andy Oknen Date: Wed Sep 7 10:51:21 2022 +0300 Update README.md commit 1cce975f41f0bc130f58e8004ac35f1f8cfd7179 Author: HiHat Date: Tue Sep 6 19:09:26 2022 +0300 Important details regarding address and fixes commit bfaef57025253beb6564dbe4afd30dfe51e059a4 Author: Pocketnet Team Date: Wed Aug 31 13:23:31 2022 +0300 Create add.tasks.to.project.yml commit 8ad81f1601554be5eb557a5fda204a78fd3d3be3 Author: Pocketnet Team Date: Tue Aug 30 15:00:15 2022 +0300 Set maximum depth 1 month for RPC GetMostCommentedFeed commit c1e5845465970d7bbafe909a9528abe0ac3cfd67 Author: Pocketnet Team Date: Tue Aug 30 14:57:23 2022 +0300 Set fork height for BlockingCancel.hpp commit b8bc0adf5c46dc3fb0d14332f49e34dec6105dd3 Merge: 8383efb4 8abd1bb7 Author: Andy Oknen Date: Tue Aug 30 14:45:32 2022 +0300 Merge pull request #385 from pocketnetteam/fix/wrong-key-threshold fix: wrong map key threshold_shark_reg_depth -> threshold_whale_reg_depth commit 8abd1bb75fb52ea6dff9ad73e560362abfd4b1c5 Author: Andy Oknen Date: Tue Aug 30 14:42:46 2022 +0300 Comment not used now RPC commit fee5e39f227d46ac0259d0b26b5680fb451a3eaa Author: Andy Oknen Date: Tue Aug 30 11:13:50 2022 +0300 Extend height for fork to 1873500 block commit 0ea51a2868b2ad0befb1149c2b5a0270cac7ecd1 Author: Andy Oknen Date: Mon Aug 29 14:14:26 2022 +0300 Fix wrong map key threshold_shark_reg_depth -> threshold_whale_reg_depth commit 8383efb46582ec24455867157474dbf29c0bc4f2 Author: Pocketnet Team Date: Thu Aug 25 00:21:32 2022 +0300 Delete project.add.issues.yml commit 95b97de883e4116a7f6d54af3be842e017e7fd01 Author: Pocketnet Team Date: Thu Aug 25 00:17:56 2022 +0300 Create project.add.issues.yml commit 9693e62933ae1ca02560fba1311dbdd4c88c8a77 Author: Pocketnet Team Date: Thu Aug 25 00:07:19 2022 +0300 Create auto_assign.yml commit 7b7338c801e665435cc429381ff3eb98d2a68f57 Merge: 88af7848 b6b9f45f Author: lostystyg <54471935+lostystyg@users.noreply.github.com> Date: Fri Sep 9 10:41:39 2022 +0300 Merge pull request #302 from lostystyg/feature/events feature: events, push notifications and activities commit 88af7848ba0e56fe22a136715bb7fbca46eda966 Merge: dddb3c6d 6280c078 Author: Andy Oknen Date: Thu Sep 8 18:45:15 2022 +0300 Merge pull request #407 from pocketnetteam/fix/clear-database Fix clear database commit 6280c078ae1e1cf38a1d69e67b6bc2203469eda8 Author: Andy Oknen Date: Thu Sep 8 18:39:43 2022 +0300 Fix clear database commit dddb3c6dd0e6a5088d46bfb70051e5fa95fc08fe Merge: 1a03ee9d 6d1975a2 Author: Andy Oknen Date: Thu Sep 8 15:22:39 2022 +0300 Merge pull request #401 from pocketnetteam/feat/txindex-disable-always feat: disable txindex by default commit 1a03ee9d2340909fbedcc8ded34915efc5c9489f Merge: adce55f2 bc022eca Author: Andy Oknen Date: Thu Sep 8 15:07:28 2022 +0300 Merge pull request #406 from pocketnetteam/fix/full-reindex-lists fix: full reindex lists commit b6b9f45f711821ba98a657b55529ae9a6037abab Author: lostystyg Date: Thu Sep 8 15:55:12 2022 +0400 Fix new line commit 314c1a84137a1bba0f246f0649cbd9334625cc03 Author: lostystyg Date: Thu Sep 8 15:52:07 2022 +0400 Temporarily disable getevents rpc commit bbd05740a461ff9ca4c68cfae216e82f28bf1b8d Merge: 32b0e15f adce55f2 Author: lostystyg Date: Thu Sep 8 15:51:13 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit bc022ecac23e00dfb7236ffffbb2e77e6e995682 Author: Andy Oknen Date: Thu Sep 8 14:40:46 2022 +0300 Logging clean commit 8107ae50a48790d12bb0d0662c1ea2dc21cc3e45 Author: Andy Oknen Date: Thu Sep 8 14:38:53 2022 +0300 Call rollback lists for full reindexing commit 32b0e15f67da6f08069173585fa801f641209d88 Author: lostystyg Date: Thu Sep 8 15:26:58 2022 +0400 Optimized notifications collecting commit 24e63f43b73f38a3b534682ca5c2b864863f7bf2 Author: lostystyg Date: Thu Sep 8 13:13:52 2022 +0400 Filling notification result with account info commit 1344fe5b189542b154f2bf9d9a47d23cbc4e83e9 Author: lostystyg Date: Thu Sep 8 12:29:31 2022 +0400 Language for short account commit 710886c50ae33edfda37472b2265aa2adaf127ce Author: lostystyg Date: Thu Sep 8 12:17:28 2022 +0400 Correctly filling notifications answer commit 6d1975a22e50550ff6ef7b393441e49f2cadbfe4 Author: Andy Oknen Date: Wed Sep 7 10:40:06 2022 +0300 Disable enabling txindex by default commit 5b04354199e527de52c08dd1880a12c1f8225ba5 Author: lostystyg Date: Mon Sep 5 15:33:28 2022 +0400 Removed outdated comment commit 57f275ea9dcd3c7c61a75561c809cef6a97f6937 Author: lostystyg Date: Mon Sep 5 15:04:22 2022 +0400 Cosmetics for blocking query in activities commit 88ed33a8731e61a9364840264b099e7012c659cd Author: lostystyg Date: Mon Sep 5 14:47:08 2022 +0400 Removed number from outputs in activities and notifications commit 24534072f1ece6cf940f9033fa032cd20b7471c7 Author: lostystyg Date: Mon Sep 5 13:04:59 2022 +0400 Reuse height binder in notifications for money commit 77f9e87343e7b691227dd97b5a114460a55df7f2 Author: lostystyg Date: Fri Sep 2 16:41:06 2022 +0400 Order outputs by number for activities and notifications commit 8ef4a5bbdd8aed5b860e73c95504fc9676977bec Merge: 2b3a0164 357d1558 Author: lostystyg Date: Thu Sep 1 22:28:12 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit 2b3a0164de79b2ecf67f87dee0e2842fc8ec22df Author: lostystyg Date: Thu Sep 1 22:24:10 2022 +0400 Removed trash from badge in activities commit 66e9054ae456ebdb6b49a0682a141e6abc76c448 Author: lostystyg Date: Thu Sep 1 22:22:59 2022 +0400 Removed trash from badge field in notification queries commit f8924a6f595da8dbff0fe7f341a39399c1b09a6a Author: lostystyg Date: Thu Sep 1 22:21:18 2022 +0400 Ported notifications from 0.20-based dropped branch commit 6d8148ded4c31ea2019b5384fd8e90714cf5010e Author: lostystyg Date: Thu Sep 1 12:10:41 2022 +0400 Added blockings for notifications commit c23e94c4678ab27c7c4dfd1074b50f306a97e6bf Author: lostystyg Date: Wed Aug 31 13:29:41 2022 +0400 Added optional multiple addresses to shortform commit c29ab129b3c2ceb9da564a2f37649e321b50b869 Author: lostystyg Date: Tue Aug 30 19:06:08 2022 +0400 Removed unnecessary todo commit 736748f798fcbecc1f8e8b9e855ca215c3db5d3d Author: lostystyg Date: Tue Aug 30 19:03:32 2022 +0400 Some todo's commit cabb0603547edb11d29363d19fd9328729a2c7ba Author: lostystyg Date: Tue Aug 30 19:02:08 2022 +0400 All action history for comments and answers in activities commit cf5021c9c4f25c22ada7b59f2c143b953c6ad84b Author: lostystyg Date: Tue Aug 30 18:36:51 2022 +0400 Collect roottxhash in activity queries commit 328a3ecd8cad8cdef92b5baa5173f6516ac4d1de Author: lostystyg Date: Tue Aug 30 17:51:10 2022 +0400 Added root tx hash to shortform commit f6fa4a45ca88a8ce0970aaa0dc0950bce1465790 Author: lostystyg Date: Tue Aug 30 17:42:02 2022 +0400 Full history for notifications commit 077f0f26f5b52cf86229d2418cf73d465dbc0b29 Author: lostystyg Date: Thu Aug 25 09:35:42 2022 +0400 Added blocking shorttype commit e2913158f2226f719242e376b8a846ca660ef26b Author: lostystyg Date: Thu Aug 25 09:33:55 2022 +0400 Removed not up to date todo commit 884893775de6aea42350bddcdd93ec42c47c6d04 Author: lostystyg Date: Wed Aug 24 16:55:14 2022 +0400 Removed reposts from activities commit b5631e70c1e54ef4ae60207f2c25f9a72663d458 Merge: e4c102c3 b7b49914 Author: lostystyg Date: Wed Aug 24 16:21:26 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit e4c102c39cc9ebd7cd3bdf38b5c053841c39ca01 Author: lostystyg Date: Wed Aug 24 15:53:24 2022 +0400 Validate filters for events on rpc level commit ac03dcb727512a5ed29450c2a720c1259bcdd158 Author: lostystyg Date: Wed Aug 24 15:49:33 2022 +0400 Validate filters for activities on rpc level commit fcb2fed45b43c3e510be0dfb33504b680b97d016 Author: lostystyg Date: Wed Aug 24 15:49:10 2022 +0400 Removed pocketnetteam from events and activities commit 876e7b574c9ad099fd00721aa92c79561d3eb2b7 Author: lostystyg Date: Wed Aug 24 15:35:47 2022 +0400 Fixed crash if non-valid filters are specified for notifications/activities/events commit 5732263c174be41fb9be7dbc15b48acef6e1e263 Author: lostystyg Date: Mon Aug 22 23:52:32 2022 +0400 Removed todo for money in activities commit 9c7438fb22ddc857876e4cc734fd3885481e9386 Merge: 99c11087 6e530784 Author: lostystyg Date: Mon Aug 22 15:16:13 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit 99c11087a786a017b7c1e4039cb94615d6e742c2 Author: lostystyg Date: Sat Aug 20 18:02:14 2022 +0400 Fixed typo in query commit 6057f91580b1e35399f7cfbbbf43e57d2cf6f486 Author: lostystyg Date: Sat Aug 20 17:53:37 2022 +0400 Removed commented out queries for notifications commit 35375ed1d01fa436ea83a65f910fdd746a8e1e5b Author: lostystyg Date: Sat Aug 20 16:39:23 2022 +0400 Validating filters for getnotificationssummary commit f1be1700c842a7cd1960665cbf969f97b4fe4892 Author: lostystyg Date: Sat Aug 20 16:38:13 2022 +0400 Optimization and fixed for notifications summary queries commit 1d371a0870f3053d77cf65df7c6a537370ede685 Author: lostystyg Date: Sat Aug 20 16:36:29 2022 +0400 Allow to specify union separator commit fcf526c45eb12f853f4da331398b9cf0dbfb6536 Merge: 46edf275 9df85fb7 Author: lostystyg Date: Fri Aug 19 19:26:37 2022 +0400 Merge remote-tracking branch 'origin/fixes/multiplelocks' into feature/events commit 46edf275c6f5e113be1209bca42b3ecf6962cad7 Author: lostystyg Date: Wed Aug 17 18:09:35 2022 +0400 Notifications summary commit 29164ac17d0da9ad5f8ead8f6d87fa8a9bdf30a3 Author: lostystyg Date: Mon Aug 15 11:22:23 2022 +0400 Fixed help for getnotifications commit c26ddf05be536577ca8334fbd57737a848b74805 Merge: 3a49aa58 1bbe483a Author: lostystyg Date: Fri Aug 12 14:01:39 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit 3a49aa58477b3e5cac571a83eedc95b57106bbaa Merge: 5365be10 8a1b0af6 Author: lostystyg Date: Thu Aug 11 16:27:31 2022 +0400 Merge remote-tracking branch 'origin/0.21' into feature/events commit 5365be10f9f6df46bf973c15b03e1915062ac75e Author: lostystyg Date: Thu Aug 11 14:52:19 2022 +0400 Correct ordering by original txs in activities commit 3339a738328bbdfeb7517254f017a85a693ddaac Author: lostystyg Date: Thu Aug 11 14:51:32 2022 +0400 Removed unnecessary todos commit 1b256cd1fb3b46266b946dca2b2f3ea7da5bb92a Author: lostystyg Date: Thu Aug 11 14:49:12 2022 +0400 Explicitly set index for account joins in activities commit 3ae1ff87786b593bcd6bdc5652f26bb066d50a0a Author: lostystyg Date: Wed Aug 10 11:30:05 2022 +0400 Fixed address positioning in sql query for activities in ContentScore and CommentScore commit fa8543b5c97ee93b84e997b74336aa55d961fbe8 Merge: a433e3ac cc77fdcb Author: lostystyg Date: Wed Aug 10 10:21:20 2022 +0400 Merge branch '0.21' into feature/events commit a433e3ac5bb2dca719697a913e14594c5f46e2d8 Author: lostystyg Date: Mon Aug 8 10:55:52 2022 +0400 Removed orig height from activities because it breaks pagination commit 67febbef23c006f91886b92bb84e88e6d10fe448 Author: lostystyg Date: Fri Jul 22 10:36:48 2022 +0300 Fixed referals for events commit 9845755c09e0e98380dd4a020db8a08e2e551545 Author: lostystyg Date: Fri Jul 22 10:11:06 2022 +0300 Orig height for activities commit eb5c9e6621d4cd35c82af7a13eaa14cb5a0f8a90 Merge: d60cfd32 c6fa67b4 Author: lostystyg Date: Fri Jul 22 09:03:43 2022 +0300 Merge branch '0.21' into feature/events commit d60cfd32e626356ae728db6f51cb3bb36148ab94 Author: lostystyg Date: Wed Jul 20 18:16:05 2022 +0300 A bit cosmetics for events commit 86e5df5a081973a2b6fd9aa546f12d8033373b33 Author: lostystyg Date: Wed Jul 20 18:01:43 2022 +0300 Full comment text in description for events and activities commit fabcc4e520227c4367a39bf0882097201acd155f Author: lostystyg Date: Wed Jul 20 15:30:28 2022 +0300 Inner join instead of cross for repost in activities commit f782b68e000f9ded107f962e8b82f2e986a828bc Author: lostystyg Date: Wed Jul 20 15:26:48 2022 +0300 Fixed repost queries for activities and events commit 7e865aa4b8a31df75f685bedd7cf0bd6973ffa5c Author: lostystyg Date: Wed Jul 20 14:56:19 2022 +0300 Fixed subscriber in activities commit c01a27472ce995c4d80da691f3ca7b3fef8e2c87 Author: lostystyg Date: Tue Jul 19 18:55:36 2022 +0300 Optimizing activity queries commit 91d85294992c2db69c6def5840b324ecdf2bedf9 Author: lostystyg Date: Mon Jul 18 16:36:03 2022 +0300 Optimizing pocketnetteam notifications commit c137b10912886fffb8f9992990873d77878b69d6 Author: lostystyg Date: Mon Jul 18 16:26:56 2022 +0300 Fixed binds for notifications commit e265c7ff37d4531133e2e792c84b444dd79349ed Author: Andy Oknen Date: Mon Jul 18 13:17:59 2022 +0300 Optimize reposts commit dadabe0f0d15f67e74157652dfab24f16ae5441e Author: Andy Oknen Date: Mon Jul 18 13:12:50 2022 +0300 Fix private content from subscribers (not reposts) commit 8c423e45e86fe237a55873828a574f7885faf73c Author: Andy Oknen Date: Mon Jul 18 13:09:11 2022 +0300 Optimize reposts query commit 814a958f101c6c3f924f6db0977d45294662f197 Author: Andy Oknen Date: Mon Jul 18 12:51:01 2022 +0300 Fix incoming money commit 1d0d17e2a8b5491b421e71f0df2547e08468804f Author: lostystyg Date: Mon Jul 18 12:32:41 2022 +0300 getnotification better todos and fixed index commit e3f474ba52e4a1d234ed1f3910014519f99ac0da Author: lostystyg Date: Fri Jul 15 18:02:37 2022 +0300 Added optional related content (in case of reposts) for pocketnetteam posts and private content for notifications commit 427d320494f6390b921ef26e85d83b67f7a5a7aa Author: lostystyg Date: Fri Jul 15 18:01:45 2022 +0300 Fixed reposts for notifications commit 5c261246ad1117d5c393f6c90511a8dc20bd83a9 Author: lostystyg Date: Fri Jul 15 18:01:06 2022 +0300 Moved pocketnetteam posts for notifications to a specific key in answer commit 5e8b8066d31046beccd717bd6cdcb45357259a60 Author: lostystyg Date: Wed Jul 13 18:11:33 2022 +0300 Fixed var name for events contentscore commit 39b478d611fe69437c45c33535fe9e01be8904aa Author: lostystyg Date: Wed Jul 13 18:10:31 2022 +0300 Ignoring empty avatar for short form account commit 848abcae88f1d0b1d922ed9be7a37c9ac820368f Author: lostystyg Date: Wed Jul 13 13:55:24 2022 +0300 Fixed typo in contentscore for activities commit aaac24ae58a9b176beee95f31dfb425281d26d01 Author: lostystyg Date: Wed Jul 13 13:54:54 2022 +0300 Fixed content description for contentscore in activities commit 5d7e566222d686212ba1d475e5581df78a805ba2 Author: lostystyg Date: Tue Jul 12 11:48:56 2022 +0300 Inner join instead of cross for activities and events commit 5bb78a6f327bcaed0cf07e229613b0d236677bcc Author: lostystyg Date: Tue Jul 12 11:22:39 2022 +0300 Updated activities query commit d3c243d4fce004f2da5fab1a83dd587f472cfb18 Author: lostystyg Date: Fri Jul 8 17:31:35 2022 +0300 Comment score activity commit 0a936ade276adea029a29aa26c645cf7f4c997a8 Author: lostystyg Date: Fri Jul 8 17:22:20 2022 +0300 Subscriber activity commit b5d0c401eb859478bdea99f883523ccb828add98 Author: lostystyg Date: Fri Jul 8 17:14:00 2022 +0300 Added comments for activities commit 638c874a0287ebd69aecbca5b675dcb24d1f7669 Author: lostystyg Date: Fri Jul 8 17:13:39 2022 +0300 Fixed answers request for activities commit f3a202681561a3426be3c37748e353907941b50f Author: lostystyg Date: Fri Jul 8 16:36:07 2022 +0300 Base activities rpc request commit 3665c8076186734a16103f1feda707d9bac0e373 Author: lostystyg Date: Fri Jul 8 14:59:17 2022 +0300 Renamed notifications rpc commit d560b5ad7b34847e8644daf7dc09cc2ef4e45927 Author: lostystyg Date: Wed Jul 6 16:18:08 2022 +0300 Fixed acc's rep for getevents commit 071f6ed8d6e7c0f1ff8ad7777675c64b83aa6c21 Author: lostystyg Date: Wed Jul 6 16:17:48 2022 +0300 Ignore badge fort short account commit 1576c8dc6fb2436f030a5f9b79ddd9db3fe843f4 Author: lostystyg Date: Wed Jul 6 15:50:37 2022 +0300 Only orig entries for notifications + some optimizations commit 60e0489fb1976fe6801ceefbaf72370c913d64d5 Author: lostystyg Date: Tue Jul 5 15:44:20 2022 +0300 Updated getnotifications rpc description commit 5e1740fb58b36c0b36b2f99b1b86d9d4bcbcd729 Author: lostystyg Date: Tue Jul 5 15:38:25 2022 +0300 Updated getevents rpc description commit a66588336365912e73e61f5921f430faf085f6b4 Merge: 6828322d 9b8e4bd6 Author: lostystyg Date: Tue Jul 5 15:11:55 2022 +0300 Merge branch '0.21' into feature/events commit 6828322d0616f5c6c9c846e5558a50eaaa4561f1 Author: lostystyg Date: Mon Jul 4 20:34:34 2022 +0300 Money notification commit b227a1cdc0888f532aaec1f86dbe544909e2c83b Author: lostystyg Date: Mon Jul 4 19:41:35 2022 +0300 Extracted common bind for notifications commit ef325659593eaf1f8faeec91fc405099024c9766 Merge: 16a3455f c0f6636c Author: lostystyg Date: Fri Jul 1 19:34:12 2022 +0300 Merge branch '0.21' into feature/events commit 16a3455f20d79b3028db961c280da0e75cea68e3 Author: lostystyg Date: Fri Jul 1 19:14:10 2022 +0300 Notifications commit 9c8a9b3f0d2d0c47c8a6ebd9de34b3fa576c9320 Author: lostystyg Date: Fri Jul 1 19:14:00 2022 +0300 Fixed ShortAccount commit 061a7ab966fafc41644034bf38a259f47bab9f10 Author: lostystyg Date: Wed Jun 29 17:17:24 2022 +0300 A bit generalization in processing filters for events commit b9f3b6a95832ac38782d9003ab4d8f4ad1af990a Author: lostystyg Date: Wed Jun 29 15:38:07 2022 +0300 Restructured events commit b8f37cbf82b986962ec85674d8859ad150567a9c Merge: f862108d 8465afed Author: lostystyg Date: Tue Jun 28 14:35:03 2022 +0300 Merge remote-tracking branch 'origin/0.21' into feature/events commit f862108dd6ca23059c62cad7b227b4d032e41d9c Merge: 8090d0e8 4429a24f Author: lostystyg Date: Mon Jun 27 13:37:20 2022 +0300 Merge branch '0.21' into feature/events commit 8090d0e8464d9b538c0617cab97cb2c08ac11411 Merge: 21b3c715 5c9755ac Author: lostystyg Date: Mon Jun 27 12:39:57 2022 +0300 Merge branch 'minor_fixes' into feature/events commit 21b3c715ae8ef56cc276e62975bb1a727cfb2cde Merge: 78eb6155 8c9006b4 Author: lostystyg Date: Mon Jun 27 12:39:51 2022 +0300 Merge branch '0.21' into feature/events commit 5c9755ac27adf6801e7936d8fefb218494fbc6a4 Author: lostystyg Date: Fri Jun 24 19:09:19 2022 +0300 Some minor fixes commit 78eb6155d9626dea1de3635f0e1484c643a27af9 Merge: 3207e0fc 97cf205e Author: lostystyg Date: Thu Jun 23 19:09:06 2022 +0300 Merge branch '0.21' into feature/events commit 3207e0fc601d9e099cb0181a1fd4dc784672001d Merge: 156ed36a 67a8917f Author: lostystyg Date: Mon Jun 13 16:15:56 2022 +0300 Merge branch '0.21' into feature/events commit 156ed36a5d4155c1b619a17c484c8587b23bb459 Author: lostystyg Date: Fri Jun 10 16:03:17 2022 +0300 Answer fixes for events commit 854e6f5b9ccba90961633409cbbcd7335857e50a Author: lostystyg Date: Fri Jun 10 14:58:52 2022 +0300 Donate value for comment event commit 576fed8fed67233522eea657f4801aa4519b6351 Author: lostystyg Date: Fri Jun 10 13:50:56 2022 +0300 Fixed events height commit 337c1efcc064e68aee3235d944c19da43b465169 Author: lostystyg Date: Fri Jun 10 13:38:03 2022 +0300 Disabled hight border in related content for events commit 7b2c630c686225e3ca28c40c3d349cc3eb295c48 Author: lostystyg Date: Fri Jun 10 13:27:55 2022 +0300 Events queries formatting commit e4f3666e6ff1aabb65efcc17ace03652209353df Author: lostystyg Date: Fri Jun 10 13:15:34 2022 +0300 Comment answer events fulfilled with data commit 775c8d454364df3d8775b78b891e4810b5fd959b Author: Andy Oknen Date: Fri Jun 10 12:14:10 2022 +0300 index comment answer commit 1b5a4966f75358c3a0140267a2e2a342b73ee755 Author: Andy Oknen Date: Fri Jun 10 11:30:03 2022 +0300 Add height limit for answer comments commit 6d0985262639ec83784ec1df4a9f74b96a5b1060 Author: Andy Oknen Date: Fri Jun 10 11:01:04 2022 +0300 comment commit 7805b8e8f7c600c471126e7304bf28fb380ad9aa Author: Andy Oknen Date: Fri Jun 10 10:54:36 2022 +0300 Sql fixes commit 011f94f29438ad36cb423a2faf6dc4686905902c Author: Andy Oknen Date: Fri Jun 10 09:43:51 2022 +0300 Fix sql typo commit a62fd177da5dfb00260cd13db1572b0824e21742 Author: lostystyg Date: Fri Jun 10 09:05:43 2022 +0300 Fixed select ordering in events commit af47ba0b7bb84185fc78c18c178720f8254281e8 Author: Andy Oknen Date: Fri Jun 10 08:50:18 2022 +0300 Fix comment answers sql index commit c97d7f55ddea43ffcde4b0c591086b8ddb6102b3 Author: lostystyg Date: Mon Jun 6 16:00:19 2022 +0300 Fixed description for scores events commit 134f3095dac5169d58a0213a795002d347c33769 Author: lostystyg Date: Mon Jun 6 15:35:51 2022 +0300 Throwing in case of event reconstructor error commit 0c3319a6878381b2bc528f9a24d8e7e491ce4dff Author: Andy Oknen Date: Mon May 23 14:11:21 2022 +0300 Downgrade likers count for testnet commit 367fa1a7a38cbe3f31ac83c3c6afef57ff1229df Author: Andy Oknen Date: Fri Apr 22 10:36:33 2022 +0300 Formatting commit 0421fbf7bf4af46fbb216517eb6f8867ca39f0a5 Author: lostystyg Date: Mon Jun 6 12:47:01 2022 +0300 Optimizing event queries commit aff9e13fece8167e8f7352c3d13206dbccde94b0 Author: lostystyg Date: Mon Jun 6 12:25:58 2022 +0300 Events fixes commit 423d4f9f91b61283e6878b408fc92ae8120ca467 Merge: 7127a3eb 039f41fb Author: lostystyg Date: Fri Jun 3 00:34:41 2022 +0300 Merge remote-tracking branch 'origin/0.21' into feature/events commit 7127a3ebd2bfff8f469afa7e5f980d5c41ae5ff0 Author: lostystyg Date: Fri Jun 3 00:34:12 2022 +0300 Short forms for events commit b8f13088d20cceb8fc67229bffb8154a00c08a20 Author: lostystyg Date: Fri Jun 3 00:34:02 2022 +0300 Updated short forms commit 03c0bd4a9c52a89d276ca9da219a9a323cb41a8c Author: lostystyg Date: Tue May 31 01:01:20 2022 +0300 ShortTxType for short forms commit dfd80a5a62d32e055cbaeabdf089bc4b1e0dbb4d Author: lostystyg Date: Mon May 30 22:52:28 2022 +0300 Added short forms commit 0b2aca0a697fd47cd0b4aee4264acf99aa57f86d Author: lostystyg Date: Mon May 30 15:26:51 2022 +0300 Raw sql query to get all events at height for each account commit 78681c897118244d758fc40732685ad9ba19c524 Author: lostystyg Date: Fri May 6 17:31:21 2022 +0300 Forgotten finalizing stmt commit 8d23c2e6e401f9a41c41d7a6236be2dc1785c19e Author: lostystyg Date: Fri May 6 17:01:01 2022 +0300 Updated args description for getevents commit 4030e741e98038f7297cccae706ba072beb992c2 Author: lostystyg Date: Fri May 6 16:57:43 2022 +0300 Events for single address commit b7ec0f7f40237ac2a6e12f3394163ba1a05a8c98 Author: lostystyg Date: Fri May 6 16:42:10 2022 +0300 constant depth for events commit 1ae34c266e55cdae51aa5df95d28cae91d5385ee Author: lostystyg Date: Fri May 6 16:40:43 2022 +0300 privatecontent for events commit 086a1fa52778907c63eab88d9e691b62edff5246 Author: lostystyg Date: Fri May 6 16:34:57 2022 +0300 Fixed binding for events commit d77c6b6cf4dda626454170d466345fadcf6b12f9 Author: lostystyg Date: Fri May 6 13:37:39 2022 +0300 Fixed filtering for events commit 19591f2421a9e7d9579fe6034f82314ccaaf4562 Author: lostystyg Date: Thu May 5 23:15:02 2022 +0300 Updated events commit 244a198523d5efe7f9c251e7ccd8111dd26eae0c Author: lostystyg Date: Wed May 4 17:04:33 2022 +0300 Fixed filtering for events commit 3deae2ea8a8dded1f50d3ec7ee9bda2616667e90 Author: lostystyg Date: Wed May 4 16:09:02 2022 +0300 FIlters, height and blocknum for events request commit 2600f314343ec9ce45acbd46774e1f2e4924e6a4 Author: lostystyg Date: Sat Apr 30 14:41:04 2022 +0300 Sorting events by height outside of sqlite commit 7f3d953ecb6c01fdf2e5fb6f1cf2d8cc424098a7 Author: lostystyg Date: Sat Apr 30 00:42:26 2022 +0300 Fixed events rpc description commit 192ad0cab7f3639824fe2c9ed4a3862941c89b2e Author: lostystyg Date: Sat Apr 30 00:41:11 2022 +0300 Events optimization commit 7a51e15cb185f07536ca713eebafd0e5c06111dc Author: lostystyg Date: Mon Apr 25 18:35:32 2022 +0300 Better indexing content from private subscribers event commit 3d8e46bfd1b13af691c876d8c82caf77f6035411 Author: lostystyg Date: Mon Apr 25 18:30:38 2022 +0300 Do not check for last for boost events commit dbea23e6036b2cd141552c408a149562351618cd Merge: af71bdf4 b0497826 Author: lostystyg Date: Mon Apr 25 18:20:24 2022 +0300 Merge remote-tracking branch 'origin/0.21.todo' into feature/events commit af71bdf4fdaaffe602ef6fa70efa63ef35ec5c63 Author: lostystyg Date: Mon Apr 25 18:17:09 2022 +0300 Base events logic commit c0e9504a610807a759cffbd239dd9bd2852ad805 Author: lostystyg Date: Mon Apr 18 17:23:50 2022 +0300 Method to get POCKETNET_TEAM address commit 9722326760ef90af0ccb57bbacc5c5c51d76f7d6 Author: lostystyg Date: Mon Apr 18 17:22:46 2022 +0300 Using network id instead of string for getting pocketnet developers --- src/pocketdb/repositories/ChainRepository.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pocketdb/repositories/ChainRepository.cpp b/src/pocketdb/repositories/ChainRepository.cpp index ccb55fdd0..631f9794b 100644 --- a/src/pocketdb/repositories/ChainRepository.cpp +++ b/src/pocketdb/repositories/ChainRepository.cpp @@ -477,13 +477,14 @@ namespace PocketDb bool ChainRepository::ClearDatabase() { - LogPrintf("Full reindexing database. This can take several days.\n"); + LogPrintf("Full reindexing database..\n"); LogPrintf("Deleting database indexes..\n"); m_database.DropIndexes(); LogPrintf("Rollback to first block..\n"); RollbackHeight(0); + ClearBlockingList(); m_database.CreateStructure(); @@ -498,6 +499,7 @@ namespace PocketDb TryTransactionStep(__func__, [&]() { RestoreOldLast(height); + RollbackBlockingList(height); RollbackHeight(height); }); @@ -509,7 +511,7 @@ namespace PocketDb return false; } } - + void ChainRepository::ClearOldLast(const string& txHash) { auto stmt = SetupSqlStatement(R"sql( @@ -763,4 +765,5 @@ namespace PocketDb + } // namespace PocketDb From 293a1da677c67a774677a02a9c6a115ad9680491 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Mon, 12 Sep 2022 10:48:11 +0300 Subject: [PATCH 08/49] Revert --- .../repositories/web/WebRpcRepository.cpp | 108 +++++++++--------- src/pocketdb/web/PocketTransactionRpc.cpp | 11 +- src/pos.cpp | 4 - src/wallet/wallet.cpp | 10 +- 4 files changed, 65 insertions(+), 68 deletions(-) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 919a3129b..55dc316a3 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -762,6 +762,7 @@ namespace PocketDb u.Hash as AccountHash , u.String1 as Address , u.Id + , u.Type , p.String2 as Name , p.String3 as Avatar , p.String7 as Donations @@ -862,7 +863,7 @@ namespace PocketDb from Transactions u indexed by Transactions_Type_Last_String1_Height_Id cross join Payload p on p.TxHash=u.Hash - where u.Type in (100) + where u.Type in (100, 170) and u.Last = 1 and u.Height is not null )sql" + where + R"sql( @@ -889,69 +890,68 @@ namespace PocketDb auto[ok0, hash] = TryGetColumnString(*stmt, i++); auto[ok1, address] = TryGetColumnString(*stmt, i++); auto[ok2, id] = TryGetColumnInt64(*stmt, i++); + auto[ok3, Type] = TryGetColumnInt(*stmt, i++); + bool isDeleted = (Type==TxType::ACCOUNT_DELETE); record.pushKV("hash", hash); record.pushKV("address", address); record.pushKV("id", id); if (IsDeveloper(address)) record.pushKV("dev", true); + if (isDeleted) record.pushKV("deleted", true); + + if(!isDeleted) { + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("name", value); + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("i", value); + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("b", value); + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("r", value); + if (auto [ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("postcnt", value); + if (auto [ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("dltdcnt", value); + if (auto [ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("reputation", value / 10.0); + if (auto [ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("subscribes_count", value); + if (auto [ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("subscribers_count", value); + if (auto [ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("blockings_count", value); + if (auto [ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("likers_count", value); + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("k", value); + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("a", value); + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("l", value); + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("s", value); + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) record.pushKV("update", value); + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) record.pushKV("regdate", value); + + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) { + UniValue flags(UniValue::VOBJ); + flags.read(value); + record.pushKV("flags", flags); + } - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("name", value); - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("i", value); - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("b", value); - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("r", value); - if (auto[ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("postcnt", value); - if (auto[ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("dltdcnt", value); - if (auto[ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("reputation", value / 10.0); - if (auto[ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("subscribes_count", value); - if (auto[ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("subscribers_count", value); - if (auto[ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("blockings_count", value); - if (auto[ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("likers_count", value); - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("k", value); - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("a", value); - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("l", value); - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) record.pushKV("s", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) record.pushKV("update", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) record.pushKV("regdate", value); + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) { + UniValue flags(UniValue::VOBJ); + flags.read(value); + record.pushKV("firstFlags", flags); + } - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) - { - UniValue flags(UniValue::VOBJ); - flags.read(value); - record.pushKV("flags", flags); - } + if (!shortForm) { - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) - { - UniValue flags(UniValue::VOBJ); - flags.read(value); - record.pushKV("firstFlags", flags); - } + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) { + UniValue subscribes(UniValue::VARR); + subscribes.read(value); + record.pushKV("subscribes", subscribes); + } - if (!shortForm) - { - - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) - { - UniValue subscribes(UniValue::VARR); - subscribes.read(value); - record.pushKV("subscribes", subscribes); - } + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) { + UniValue subscribes(UniValue::VARR); + subscribes.read(value); + record.pushKV("subscribers", subscribes); + } - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) - { - UniValue subscribes(UniValue::VARR); - subscribes.read(value); - record.pushKV("subscribers", subscribes); - } + if (auto [ok, value] = TryGetColumnString(*stmt, i++); ok) { + UniValue subscribes(UniValue::VARR); + subscribes.read(value); + record.pushKV("blocking", subscribes); + } - if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) - { - UniValue subscribes(UniValue::VARR); - subscribes.read(value); - record.pushKV("blocking", subscribes); + if (auto [ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("rc", value); } - - if (auto[ok, value] = TryGetColumnInt(*stmt, i++); ok) record.pushKV("rc", value); } result.emplace_back(address, id, record); @@ -3655,6 +3655,9 @@ namespace PocketDb if (topContentId > 0) contentIdWhere = " and t.Id < ? "; + string accountExistence = " join Transaction ua indexed by Transactions_Type_Last_String1_Height_Id " + " on ua.String1 = t.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null "; + string langFilter; if (!lang.empty()) langFilter += " join Payload p indexed by Payload_String1_TxHash on p.TxHash = t.Hash and p.String1 = ? "; @@ -3697,6 +3700,7 @@ namespace PocketDb string sql = R"sql( select t.Id from Transactions t indexed by Transactions_Type_Last_String1_Height_Id + )sql" + accountExistence + R"sql( )sql" + langFilter + R"sql( where t.Type in )sql" + contentTypesWhere + R"sql( and t.Height > 0 diff --git a/src/pocketdb/web/PocketTransactionRpc.cpp b/src/pocketdb/web/PocketTransactionRpc.cpp index 363381973..438e341e1 100644 --- a/src/pocketdb/web/PocketTransactionRpc.cpp +++ b/src/pocketdb/web/PocketTransactionRpc.cpp @@ -214,6 +214,7 @@ namespace PocketWeb::PocketWebRpc // Get pocketnet transaction type string string txTypeHex = request.params[3].get_str(); + auto txType = PocketHelpers::TransactionHelper::ConvertOpReturnToType(txTypeHex); // Get payload object UniValue txPayload = request.params[4].get_obj(); @@ -225,11 +226,11 @@ namespace PocketWeb::PocketWebRpc // Content Author address string contentAddressValue = ""; - if (request.params[6].isStr() && txPayload.exists("value") && txPayload["value"].isNum()) - contentAddressValue = request.params[6].get_str() + " " + to_string(txPayload["value"].get_int()); + if (txType == ACTION_SCORE_CONTENT || txType == ACTION_SCORE_COMMENT) + if (request.params[6].isStr() && txPayload.exists("value") && txPayload["value"].isNum()) + contentAddressValue = request.params[6].get_str() + " " + to_string(txPayload["value"].get_int()); // Build template for transaction - auto txType = PocketHelpers::TransactionHelper::ConvertOpReturnToType(txTypeHex); shared_ptr _ptx = PocketHelpers::TransactionHelper::CreateInstance(txType); if (!_ptx) throw JSONRPCError(RPC_PARSE_ERROR, "Failed create pocketnet transaction payload"); @@ -252,7 +253,7 @@ namespace PocketWeb::PocketWebRpc int64_t totalAmount = 0; UniValue _inputs(UniValue::VARR); int i = 0; - while (totalAmount <= (fee + outputCount) && i < unsp.size()) + while (totalAmount <= (fee + outputCount + 1000) && i < unsp.size()) { totalAmount += unsp[i]["amountSat"].get_int64(); _inputs.push_back(unsp[i]); @@ -273,7 +274,7 @@ namespace PocketWeb::PocketWebRpc // generate transaction auto _opReturn = CScript() << OP_RETURN << ParseHex(txTypeHex) << ParseHex(_ptx->BuildHash()); - if (contentAddressValue != "") _opReturn = _opReturn << ParseHex(HexStr(contentAddressValue)); + // if (contentAddressValue != "") _opReturn = _opReturn << ParseHex(HexStr(contentAddressValue)); CTxOut _dataOut(0, _opReturn); CMutableTransaction mTx = ConstructPocketnetTransaction(_inputs, _dataOut, _outputs, NullUniValue, NullUniValue); diff --git a/src/pos.cpp b/src/pos.cpp index 8731b6773..292c5b092 100644 --- a/src/pos.cpp +++ b/src/pos.cpp @@ -545,11 +545,7 @@ bool TransactionGetCoinAge(CTransactionRef transaction, uint64_t &nCoinAge, Chai for (auto txin : transaction->vin) { // First try finding the previous transaction in database - - // TODO (losty-critical): can internal fields be null? - LogPrintf("DEBUG: getting transaction from sqlite db"); auto txPrev = PocketDb::TransRepoInst.Get(txin.prevout.hash.ToString(), false, false, true); - if (!txPrev) continue; // previous transaction not in main chain diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8ca784223..4d5243c24 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2545,9 +2545,6 @@ bool CWallet::SignTransaction(CMutableTransaction& tx) const return false; } const CWalletTx& wtx = mi->second; - // TODO (losty-fur): seems good - // Хороший вопрос, нужно тестировать - LogPrintf("CWallet::SignTransaction: DEBUG: creating coin!"); coins[input.prevout] = Coin(wtx.tx->vout[input.prevout.n], wtx.m_confirm.block_height, wtx.IsCoinBase(), wtx.IsCoinStake(), PocketHelpers::TransactionHelper::IsPocketTransaction(wtx.tx)); } std::map input_errors; @@ -4679,7 +4676,9 @@ void CWallet::AvailableCoinsForStaking(std::vector& vCoins, unsigned in vCoins.clear(); { - LOCK(cs_wallet); + // TODO (brangr, team): change LOCK(cs_wallet); to LOCK2(cs_main, cs_wallet); + LOCK(cs_wallet); + // LOCK2(cs_main, cs_wallet); for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; const uint256& wtxid = it->first; @@ -5048,14 +5047,11 @@ tuple CWallet::GetStakeWeight() const { // Choose coins to use int64_t nBalance = GetBalance().m_mine_trusted; - LogPrintf("GetStakeWeight: DEBUG: using mine_trusted coins: %d", nBalance); - if (nBalance <= 0) { return {0, 0}; } std::set > vwtxPrev; - std::set > setCoins; int64_t nValueIn = 0; From 51f4f48f02693b551fccb4722af9a870a55840a2 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Mon, 12 Sep 2022 12:31:33 +0300 Subject: [PATCH 09/49] Fix delete transaction helper --- src/CMakeLists.txt | 2 ++ src/pocketdb/helpers/TransactionHelper.cpp | 31 ++++++++++++++-------- src/pocketdb/helpers/TransactionHelper.h | 16 ++++++----- src/pocketdb/models/dto/account/Delete.cpp | 7 +++++ src/pocketdb/models/dto/account/Delete.h | 2 ++ src/pocketdb/web/PocketTransactionRpc.cpp | 5 +++- src/wallet/wallet.cpp | 2 -- 7 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e78e4a501..0e4fa2512 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -589,6 +589,8 @@ add_library(${POCKETDB} pocketdb/models/dto/account/User.cpp pocketdb/models/dto/account/Setting.h pocketdb/models/dto/account/Setting.cpp + pocketdb/models/dto/account/Delete.h + pocketdb/models/dto/account/Delete.cpp pocketdb/models/dto/content/Content.h pocketdb/models/dto/content/Content.cpp diff --git a/src/pocketdb/helpers/TransactionHelper.cpp b/src/pocketdb/helpers/TransactionHelper.cpp index 3f69c6282..696e23ac3 100644 --- a/src/pocketdb/helpers/TransactionHelper.cpp +++ b/src/pocketdb/helpers/TransactionHelper.cpp @@ -52,14 +52,12 @@ namespace PocketHelpers else if (op == OR_UNSUBSCRIBE) return TxType::ACTION_SUBSCRIBE_CANCEL; - else if (op == OR_ACCOUNT_SETTING) - return TxType::ACCOUNT_SETTING; else if (op == OR_USERINFO) return TxType::ACCOUNT_USER; - else if (op == OR_VIDEO_SERVER) - return TxType::ACCOUNT_VIDEO_SERVER; - else if (op == OR_MESSAGE_SERVER) - return TxType::ACCOUNT_MESSAGE_SERVER; + else if (op == OR_ACCOUNT_SETTING) + return TxType::ACCOUNT_SETTING; + else if (op == OR_ACCOUNT_DELETE) + return TxType::ACCOUNT_DELETE; else if (op == OR_BLOCKING) return TxType::ACTION_BLOCKING; @@ -135,10 +133,12 @@ namespace PocketHelpers // TODO (brangr) (v0.21.0): need remove for next generation serialization switch (*transaction.GetType()) { - case TxType::ACCOUNT_SETTING: - return "AccountSettings"; case TxType::ACCOUNT_USER: return "Users"; + case TxType::ACCOUNT_SETTING: + return "AccountSettings"; + case TxType::ACCOUNT_DELETE: + return "AccountDelete"; case TxType::CONTENT_POST: case TxType::CONTENT_VIDEO: case TxType::CONTENT_ARTICLE: @@ -294,6 +294,9 @@ namespace PocketHelpers case ACCOUNT_SETTING: ptx = make_shared(tx); break; + case ACCOUNT_DELETE: + ptx = make_shared(tx); + break; case ACCOUNT_USER: ptx = make_shared(tx); break; @@ -372,6 +375,9 @@ namespace PocketHelpers case ACCOUNT_SETTING: ptx = make_shared(); break; + case ACCOUNT_DELETE: + ptx = make_shared(); + break; case ACCOUNT_USER: ptx = make_shared(); break; @@ -454,8 +460,6 @@ namespace PocketHelpers return "video"; case CONTENT_ARTICLE: return "article"; - case ACCOUNT_SETTING: - return "accSet"; case ACTION_SCORE_CONTENT: return "upvoteShare"; case ACTION_SUBSCRIBE: @@ -466,6 +470,10 @@ namespace PocketHelpers return "unsubscribe"; case ACCOUNT_USER: return "userInfo"; + case ACCOUNT_SETTING: + return "accSet"; + case ACCOUNT_DELETE: + return "accDel"; case CONTENT_COMMENT: return "comment"; case CONTENT_COMMENT_EDIT: @@ -489,12 +497,13 @@ namespace PocketHelpers 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; - else if (type == "accSet" || type == OR_ACCOUNT_SETTING) return TxType::ACCOUNT_SETTING; else if (type == "upvoteShare" || type == OR_SCORE) return TxType::ACTION_SCORE_CONTENT; else if (type == "subscribe" || type == OR_SUBSCRIBE) return TxType::ACTION_SUBSCRIBE; else if (type == "subscribePrivate" || type == OR_SUBSCRIBEPRIVATE) return TxType::ACTION_SUBSCRIBE_PRIVATE; else if (type == "unsubscribe" || type == OR_UNSUBSCRIBE) return TxType::ACTION_SUBSCRIBE_CANCEL; else if (type == "userInfo" || type == OR_USERINFO) return TxType::ACCOUNT_USER; + else if (type == "accSet" || type == OR_ACCOUNT_SETTING) return TxType::ACCOUNT_SETTING; + else if (type == "accDel" || type == OR_ACCOUNT_DELETE) return TxType::ACCOUNT_DELETE; else if (type == "comment" || type == OR_COMMENT) return TxType::CONTENT_COMMENT; else if (type == "commentEdit" || type == OR_COMMENT_EDIT) return TxType::CONTENT_COMMENT_EDIT; else if (type == "commentDelete" || type == OR_COMMENT_DELETE) return TxType::CONTENT_COMMENT_DELETE; diff --git a/src/pocketdb/helpers/TransactionHelper.h b/src/pocketdb/helpers/TransactionHelper.h index a0134d100..89e848848 100644 --- a/src/pocketdb/helpers/TransactionHelper.h +++ b/src/pocketdb/helpers/TransactionHelper.h @@ -16,27 +16,31 @@ #include "pocketdb/models/base/DtoModels.h" #include "pocketdb/models/base/PocketTypes.h" -#include "pocketdb/models/dto/action/Blocking.h" -#include "pocketdb/models/dto/action/BlockingCancel.h" -#include "pocketdb/models/dto/action/BoostContent.h" #include "pocketdb/models/dto/money/Coinbase.h" #include "pocketdb/models/dto/money/Coinstake.h" #include "pocketdb/models/dto/money/Default.h" + #include "pocketdb/models/dto/content/Post.h" #include "pocketdb/models/dto/content/Video.h" #include "pocketdb/models/dto/content/Article.h" #include "pocketdb/models/dto/content/Comment.h" #include "pocketdb/models/dto/content/CommentEdit.h" #include "pocketdb/models/dto/content/CommentDelete.h" +#include "pocketdb/models/dto/content/ContentDelete.h" + #include "pocketdb/models/dto/action/Subscribe.h" #include "pocketdb/models/dto/action/SubscribeCancel.h" #include "pocketdb/models/dto/action/SubscribePrivate.h" #include "pocketdb/models/dto/action/Complain.h" -#include "pocketdb/models/dto/account/Setting.h" -#include "pocketdb/models/dto/account/User.h" #include "pocketdb/models/dto/action/ScoreContent.h" #include "pocketdb/models/dto/action/ScoreComment.h" -#include "pocketdb/models/dto/content/ContentDelete.h" +#include "pocketdb/models/dto/action/Blocking.h" +#include "pocketdb/models/dto/action/BlockingCancel.h" +#include "pocketdb/models/dto/action/BoostContent.h" + +#include "pocketdb/models/dto/account/Setting.h" +#include "pocketdb/models/dto/account/User.h" +#include "pocketdb/models/dto/account/Delete.h" #include "pocketdb/models/dto/moderation/Flag.h" diff --git a/src/pocketdb/models/dto/account/Delete.cpp b/src/pocketdb/models/dto/account/Delete.cpp index 95740ed3a..743cdb56b 100644 --- a/src/pocketdb/models/dto/account/Delete.cpp +++ b/src/pocketdb/models/dto/account/Delete.cpp @@ -16,5 +16,12 @@ namespace PocketTx { SetType(TxType::ACCOUNT_DELETE); } + + string AccountDelete::BuildHash() + { + std::string data; + return Transaction::GenerateHash(data); + } + } // namespace PocketTx diff --git a/src/pocketdb/models/dto/account/Delete.h b/src/pocketdb/models/dto/account/Delete.h index cf383ac1f..7a2bd982f 100644 --- a/src/pocketdb/models/dto/account/Delete.h +++ b/src/pocketdb/models/dto/account/Delete.h @@ -14,6 +14,8 @@ namespace PocketTx public: AccountDelete(); AccountDelete(const CTransactionRef& tx); + + string BuildHash() override; }; // class AccountDelete } // namespace PocketTx diff --git a/src/pocketdb/web/PocketTransactionRpc.cpp b/src/pocketdb/web/PocketTransactionRpc.cpp index 438e341e1..7676d1829 100644 --- a/src/pocketdb/web/PocketTransactionRpc.cpp +++ b/src/pocketdb/web/PocketTransactionRpc.cpp @@ -260,6 +260,9 @@ namespace PocketWeb::PocketWebRpc i += 1; } + if (totalAmount <= (fee + outputCount + 1000)) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Insufficient funds"); + // Build outputs UniValue _outputs(UniValue::VARR); int64_t returned = totalAmount - fee; @@ -274,7 +277,7 @@ namespace PocketWeb::PocketWebRpc // generate transaction auto _opReturn = CScript() << OP_RETURN << ParseHex(txTypeHex) << ParseHex(_ptx->BuildHash()); - // if (contentAddressValue != "") _opReturn = _opReturn << ParseHex(HexStr(contentAddressValue)); + if (contentAddressValue != "") _opReturn = _opReturn << ParseHex(HexStr(contentAddressValue)); CTxOut _dataOut(0, _opReturn); CMutableTransaction mTx = ConstructPocketnetTransaction(_inputs, _dataOut, _outputs, NullUniValue, NullUniValue); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4d5243c24..d826876e8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4676,9 +4676,7 @@ void CWallet::AvailableCoinsForStaking(std::vector& vCoins, unsigned in vCoins.clear(); { - // TODO (brangr, team): change LOCK(cs_wallet); to LOCK2(cs_main, cs_wallet); LOCK(cs_wallet); - // LOCK2(cs_main, cs_wallet); for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; const uint256& wtxid = it->first; From 04b06f0fa88878594cfd6869cebba0d4e0617a2c Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Mon, 12 Sep 2022 13:22:42 +0300 Subject: [PATCH 10/49] Fix check register deleted account --- src/pocketdb/consensus/Base.h | 1 + src/pocketdb/consensus/Social.h | 12 +++++++++--- src/pocketdb/consensus/social/AccountUser.hpp | 9 +++++++-- src/pocketdb/repositories/ConsensusRepository.cpp | 7 ++++--- src/pocketdb/repositories/ConsensusRepository.h | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/pocketdb/consensus/Base.h b/src/pocketdb/consensus/Base.h index a45f0dab9..1636acd36 100644 --- a/src/pocketdb/consensus/Base.h +++ b/src/pocketdb/consensus/Base.h @@ -82,6 +82,7 @@ namespace PocketConsensus SocialConsensusResult_SelfFlag = 64, SocialConsensusResult_ExceededLimit = 65, SocialConsensusResult_LowReputation = 66, + SocialConsensusResult_AccountDeleted = 67, }; static inline string SocialConsensusResultString(SocialConsensusResult code) diff --git a/src/pocketdb/consensus/Social.h b/src/pocketdb/consensus/Social.h index 044a9f88d..07a98c290 100644 --- a/src/pocketdb/consensus/Social.h +++ b/src/pocketdb/consensus/Social.h @@ -46,11 +46,14 @@ namespace PocketConsensus bool inBlock = false; for (auto& blockTx: *block) { - if (!TransactionHelper::IsIn(*blockTx->GetType(), {ACCOUNT_USER})) + if (!TransactionHelper::IsIn(*blockTx->GetType(), { ACCOUNT_USER, ACCOUNT_DELETE })) continue; if (*blockTx->GetString1() == address) { + if (*blockTx->GetType() == ACCOUNT_DELETE) + return {false, SocialConsensusResult_AccountDeleted}; + inBlock = true; break; } @@ -67,7 +70,7 @@ namespace PocketConsensus // Check registrations in DB if (!addressesForCheck.empty() && - !PocketDb::ConsensusRepoInst.ExistsUserRegistrations(addressesForCheck, false)) + !PocketDb::ConsensusRepoInst.ExistsUserRegistrations(addressesForCheck)) return {false, SocialConsensusResult_NotRegistered}; } @@ -115,7 +118,10 @@ namespace PocketConsensus } // Get addresses from transaction for check registration - virtual vector GetAddressesForCheckRegistration(const shared_ptr& tx) = 0; + virtual vector GetAddressesForCheckRegistration(const shared_ptr& tx) + { + return { *tx->GetAddress() }; + } // Check empty pointer bool IsEmpty(const shared_ptr& ptr) const diff --git a/src/pocketdb/consensus/social/AccountUser.hpp b/src/pocketdb/consensus/social/AccountUser.hpp index d90eb7055..d8ef81f20 100644 --- a/src/pocketdb/consensus/social/AccountUser.hpp +++ b/src/pocketdb/consensus/social/AccountUser.hpp @@ -22,6 +22,7 @@ namespace PocketConsensus { public: AccountUserConsensus(int height) : SocialConsensus(height) {} + ConsensusValidateResult Validate(const CTransactionRef& tx, const UserRef& ptx, const PocketBlockRef& block) override { // Check payload size @@ -38,10 +39,11 @@ namespace PocketConsensus // The deleted account cannot be restored if (auto[ok, type] = ConsensusRepoInst.GetLastAccountType(*ptx->GetAddress()); ok) if (type == TxType::ACCOUNT_DELETE) - return {false, SocialConsensusResult_NotFound}; + return {false, SocialConsensusResult_AccountDeleted}; return SocialConsensus::Validate(tx, ptx, block); } + ConsensusValidateResult Check(const CTransactionRef& tx, const UserRef& ptx) override { if (auto[baseCheck, baseCheckCode] = SocialConsensus::Check(tx, ptx); !baseCheck) @@ -63,6 +65,7 @@ namespace PocketConsensus return Success; } + ConsensusValidateResult CheckOpReturnHash(const CTransactionRef& tx, const UserRef& ptx) override { auto ptxORHash = ptx->BuildHash(); @@ -77,6 +80,7 @@ namespace PocketConsensus } protected: + ConsensusValidateResult ValidateBlock(const UserRef& ptx, const PocketBlockRef& block) override { // Only one transaction allowed in block @@ -104,6 +108,7 @@ namespace PocketConsensus return Success; } + ConsensusValidateResult ValidateMempool(const UserRef& ptx) override { if (ConsensusRepoInst.CountMempoolUser(*ptx->GetAddress()) > 0) @@ -116,7 +121,7 @@ namespace PocketConsensus } vector GetAddressesForCheckRegistration(const UserRef& ptx) override { - return {}; + return { }; } virtual int GetChainCount(const UserRef& ptx) diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index 2a1c6d12e..70248611a 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -141,7 +141,7 @@ namespace PocketDb return {tx != nullptr, tx}; } - bool ConsensusRepository::ExistsUserRegistrations(vector& addresses, bool mempool) + bool ConsensusRepository::ExistsUserRegistrations(vector& addresses) { auto result = false; @@ -151,10 +151,11 @@ namespace PocketDb // Build sql string string sql = R"sql( select count(distinct(String1)) - from Transactions + from Transactions indexed by Transactions_Type_Last_String1_Height_Id where Type = 100 + and Last = 1 and String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) - )sql" + (mempool ? "" : " and Height is not null ") + R"sql( + and Height is not null )sql"; // Execute diff --git a/src/pocketdb/repositories/ConsensusRepository.h b/src/pocketdb/repositories/ConsensusRepository.h index e0a3eff65..c9e31a59e 100644 --- a/src/pocketdb/repositories/ConsensusRepository.h +++ b/src/pocketdb/repositories/ConsensusRepository.h @@ -117,7 +117,7 @@ namespace PocketDb // Exists bool ExistsComplain(const string& postHash, const string& address, bool mempool); bool ExistsScore(const string& address, const string& contentHash, TxType type, bool mempool); - bool ExistsUserRegistrations(vector& addresses, bool mempool); + bool ExistsUserRegistrations(vector& addresses); bool ExistsAnotherByName(const string& address, const string& name); bool Exists(const string& txHash, const vector& types, bool inChain); bool ExistsInMempool(const string& string1, const vector& types); From 4a4999f9e743efca9a3a862bf23261c760a36cc3 Mon Sep 17 00:00:00 2001 From: only1question Date: Mon, 12 Sep 2022 15:40:34 +0300 Subject: [PATCH 11/49] Deleted account does not have payload --- .../repositories/web/WebRpcRepository.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 55dc316a3..333c1a70d 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -763,9 +763,9 @@ namespace PocketDb , u.String1 as Address , u.Id , u.Type - , p.String2 as Name - , p.String3 as Avatar - , p.String7 as Donations + , ifnull(p.String2,'') as Name + , ifnull(p.String3,'') as Avatar + , ifnull(p.String7,'') as Donations , ifnull(u.String2,'') as Referrer , ifnull(( @@ -810,10 +810,10 @@ namespace PocketDb where lkr.Type in (111,112,113) and lkr.Id = u.Id and lkr.Last = 1 ),0) as Likers - , p.String6 as Pubkey - , p.String4 as About - , p.String1 as Lang - , p.String5 as Url + , ifnull(p.String6,'') as Pubkey + , ifnull(p.String4,'') as About + , ifnull(p.String1,'') as Lang + , ifnull(p.String5,'') as Url , u.Time , ( @@ -861,7 +861,7 @@ namespace PocketDb )sql" + fullProfileSql + R"sql( from Transactions u indexed by Transactions_Type_Last_String1_Height_Id - cross join Payload p on p.TxHash=u.Hash + left join Payload p on p.TxHash=u.Hash where u.Type in (100, 170) and u.Last = 1 From b846cc139effad1de6cbf44a92f79d878126c1a2 Mon Sep 17 00:00:00 2001 From: only1question Date: Mon, 12 Sep 2022 16:43:25 +0300 Subject: [PATCH 12/49] Fixed typo in GetProfileFeed --- src/pocketdb/repositories/web/WebRpcRepository.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 333c1a70d..a77f52c62 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -3655,7 +3655,7 @@ namespace PocketDb if (topContentId > 0) contentIdWhere = " and t.Id < ? "; - string accountExistence = " join Transaction ua indexed by Transactions_Type_Last_String1_Height_Id " + string accountExistence = " join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id " " on ua.String1 = t.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null "; string langFilter; From ef795173cbd610af70acc002768c3636a312d55e Mon Sep 17 00:00:00 2001 From: only1question Date: Mon, 12 Sep 2022 19:18:47 +0300 Subject: [PATCH 13/49] Remove data from deleted account in last comments --- src/pocketdb/repositories/web/WebRpcRepository.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index a77f52c62..0d1164954 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -1033,6 +1033,9 @@ namespace PocketDb from Transactions c indexed by Transactions_Height_Id + cross join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id + on ua.String1 = t.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null + cross join Transactions p indexed by Transactions_Type_Last_String2_Height on p.Type in (200,201,202) and p.Last = 1 and p.Height > 0 and p.String2 = c.String3 @@ -1162,6 +1165,9 @@ namespace PocketDb from Transactions c1 indexed by Transactions_Type_Last_String3_Height + cross join Transactions uac indexed by Transactions_Type_Last_String1_Height_Id + on uac.String1 = c1.String1 and uac.Type = 100 and uac.Last = 1 and uac.Height is not null + left join TxOutputs o indexed by TxOutputs_TxHash_AddressHash_Value on o.TxHash = c1.Hash and o.AddressHash = t.String1 and o.AddressHash != c1.String1 and o.Value > ? @@ -1186,6 +1192,9 @@ namespace PocketDb from Transactions t indexed by Transactions_Last_Id_Height + cross join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id + on ua.String1 = t.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null + where t.Type in (200,201,202,207) and t.Last = 1 and t.Height is not null From 79b5121ccf5debe7f3ef4c7695aa95665da74198 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Tue, 13 Sep 2022 15:02:29 +0300 Subject: [PATCH 14/49] Fix begin/commit/abort sql transaction --- src/pocketdb/repositories/BaseRepository.h | 58 ++++++++----------- .../repositories/web/WebRpcRepository.cpp | 2 +- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/pocketdb/repositories/BaseRepository.h b/src/pocketdb/repositories/BaseRepository.h index 8ddc6b79b..bd0db308b 100644 --- a/src/pocketdb/repositories/BaseRepository.h +++ b/src/pocketdb/repositories/BaseRepository.h @@ -46,38 +46,6 @@ namespace PocketDb class BaseRepository : protected RowAccessor { private: - - template - void TryTransactionStepSince(const string& func, T sql) - { - if (!m_database.BeginTransaction()) - throw std::runtime_error(strprintf("%s: can't begin transaction\n", func)); - - sql(); - - if (!m_database.CommitTransaction()) - throw std::runtime_error(strprintf("%s: can't commit transaction\n", func)); - } - - template - void TryTransactionStepTimeoutSince(const string& func, T sql) - { - auto timeoutValue = chrono::seconds(gArgs.GetArg("-sqltimeout", 10)); - - run_with_timeout( - [&]() - { - TryTransactionStepSince(func, sql); - }, - timeoutValue, - [&]() - { - m_database.InterruptQuery(); - LogPrintf("Function `%s` failed with execute timeout\n", func); - } - ); - } - protected: SQLiteDatabase& m_database; @@ -99,11 +67,33 @@ namespace PocketDb { int64_t nTime1 = GetTimeMicros(); + if (!m_database.BeginTransaction()) + throw std::runtime_error(strprintf("%s: can't begin transaction\n", func)); + // We are running SQL logic with timeout only for read-only connections if (m_database.IsReadOnly()) - TryTransactionStepTimeoutSince(func, sql); + { + auto timeoutValue = chrono::seconds(gArgs.GetArg("-sqltimeout", 10)); + run_with_timeout( + [&]() + { + sql(); + }, + timeoutValue, + [&]() + { + m_database.InterruptQuery(); + LogPrintf("Function `%s` failed with execute timeout\n", func); + } + ); + } else - TryTransactionStepSince(func, sql); + { + sql(); + } + + if (!m_database.CommitTransaction()) + throw std::runtime_error(strprintf("%s: can't commit transaction\n", func)); int64_t nTime2 = GetTimeMicros(); diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index a77f52c62..b0f7e1f81 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -3655,7 +3655,7 @@ namespace PocketDb if (topContentId > 0) contentIdWhere = " and t.Id < ? "; - string accountExistence = " join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id " + string accountExistence = " join Transaction1s ua indexed by Transactions_Type_Last_String1_Height_Id " " on ua.String1 = t.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null "; string langFilter; From 2c54bc0c5435aca42e9491dcc2370eb6dad244a5 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Tue, 13 Sep 2022 15:27:53 +0300 Subject: [PATCH 15/49] refact --- src/pocketdb/consensus/social/Comment.hpp | 5 +---- src/pocketdb/repositories/ConsensusRepository.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/pocketdb/consensus/social/Comment.hpp b/src/pocketdb/consensus/social/Comment.hpp index 7dc5312ff..290e22026 100644 --- a/src/pocketdb/consensus/social/Comment.hpp +++ b/src/pocketdb/consensus/social/Comment.hpp @@ -42,10 +42,7 @@ namespace PocketConsensus if (!IsEmpty(ptx->GetAnswerTxHash())) { // TODO (brangr): replace to check exists not deleted comment - auto[ok, answerTx] = ConsensusRepoInst.GetLastContent( - *ptx->GetAnswerTxHash(), - { CONTENT_COMMENT, CONTENT_COMMENT_EDIT } - ); + auto[ok, answerTx] = ConsensusRepoInst.GetLastContent(*ptx->GetAnswerTxHash(), { CONTENT_COMMENT, CONTENT_COMMENT_EDIT }); if (!ok) return {false, SocialConsensusResult_InvalidParentComment}; diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index 70248611a..600490a4f 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -96,7 +96,7 @@ namespace PocketDb TryTransactionStep(__func__, [&]() { string sql = R"sql( - SELECT + select t.Type, t.Hash, t.Time, @@ -116,12 +116,12 @@ namespace PocketDb p.String5 pString5, p.String6 pString6, p.String7 pString7 - FROM Transactions t indexed by Transactions_Type_Last_String2_Height - LEFT JOIN Payload p on t.Hash = p.TxHash - WHERE t.Type in ( )sql" + join(vector(types.size(), "?"), ",") + R"sql( ) - and t.String2 = ? - and t.Last = 1 - and t.Height is not null + from Transactions t indexed by Transactions_Type_Last_String2_Height + left join Payload p on t.Hash = p.TxHash + where t.Type in ( )sql" + join(vector(types.size(), "?"), ",") + R"sql( ) + and t.String2 = ? + and t.Last = 1 + and t.Height is not null )sql"; auto stmt = SetupSqlStatement(sql); From f9a61cb9d53b0caf3dc3df48413a23c441a71a64 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Tue, 13 Sep 2022 15:44:53 +0300 Subject: [PATCH 16/49] wallet log clean --- src/wallet/scriptpubkeyman.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 20940d468..61e1bfe14 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -1299,7 +1299,7 @@ void LegacyScriptPubKeyMan::KeepDestination(int64_t nIndex, const OutputType& ty assert(have_pk); LearnRelatedScripts(pubkey, type); m_index_to_reserved_key.erase(nIndex); - WalletLogPrintf("keypool keep %d\n", nIndex); + LogPrint(BCLog::WALLET, "keypool keep %d\n", nIndex); } void LegacyScriptPubKeyMan::ReturnDestination(int64_t nIndex, bool fInternal, const CTxDestination&) @@ -1384,7 +1384,7 @@ bool LegacyScriptPubKeyMan::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& key assert(m_index_to_reserved_key.count(nIndex) == 0); m_index_to_reserved_key[nIndex] = keypool.vchPubKey.GetID(); m_pool_key_to_index.erase(keypool.vchPubKey.GetID()); - WalletLogPrintf("keypool reserve %d\n", nIndex); + LogPrint(BCLog::WALLET, "keypool reserve %d\n", nIndex); } NotifyCanGetAddressesChanged(); return true; From 3988d12f27f866585590ea12dd3c2a8682de301d Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Tue, 13 Sep 2022 15:51:34 +0300 Subject: [PATCH 17/49] Clean logs --- src/policy/fees.cpp | 2 +- src/wallet/scriptpubkeyman.cpp | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 7cb85e531..6c30ba80b 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -799,7 +799,7 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation if (confTarget == 1) confTarget = 2; unsigned int maxUsableEstimate = MaxUsableEstimate(); - printf("%u\n", maxUsableEstimate); + LogPrint(BCLog::WALLET, "%u\n", maxUsableEstimate); if ((unsigned int)confTarget > maxUsableEstimate) { confTarget = maxUsableEstimate; } diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 61e1bfe14..5dfdf3566 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -329,9 +329,9 @@ bool LegacyScriptPubKeyMan::TopUpInactiveHDChain(const CKeyID seed_id, int64_t i GenerateNewKey(batch, chain, internal); } if (internal) { - WalletLogPrintf("inactive seed with id %s added %d internal keys\n", HexStr(seed_id), missing); + LogPrint(BCLog::WALLET, "inactive seed with id %s added %d internal keys\n", HexStr(seed_id), missing); } else { - WalletLogPrintf("inactive seed with id %s added %d keys\n", HexStr(seed_id), missing); + LogPrint(BCLog::WALLET, "inactive seed with id %s added %d keys\n", HexStr(seed_id), missing); } } return true; @@ -344,11 +344,11 @@ void LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript& script) for (const auto& keyid : GetAffectedKeys(script, *this)) { std::map::const_iterator mi = m_pool_key_to_index.find(keyid); if (mi != m_pool_key_to_index.end()) { - WalletLogPrintf("%s: Detected a used keypool key, mark all keypool keys up to this key as used\n", __func__); + LogPrint(BCLog::WALLET, "%s: Detected a used keypool key, mark all keypool keys up to this key as used\n", __func__); MarkReserveKeysAsUsed(mi->second); if (!TopUp()) { - WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", __func__); + LogPrint(BCLog::WALLET, "%s: Topping up keypool failed (locked wallet)\n", __func__); } } @@ -362,7 +362,7 @@ void LegacyScriptPubKeyMan::MarkUnusedAddresses(const CScript& script) int64_t index = meta.key_origin.path[2] & ~BIP32_HARDENED_KEY_LIMIT; if (!TopUpInactiveHDChain(meta.hd_seed_id, index, internal)) { - WalletLogPrintf("%s: Adding inactive seed keys failed\n", __func__); + LogPrint(BCLog::WALLET, "%s: Adding inactive seed keys failed\n", __func__); } } } @@ -445,7 +445,7 @@ bool LegacyScriptPubKeyMan::Upgrade(int prev_version, int new_version, bilingual bool hd_upgrade = false; bool split_upgrade = false; if (IsFeatureSupported(new_version, FEATURE_HD) && !IsHDEnabled()) { - WalletLogPrintf("Upgrading wallet to HD\n"); + LogPrint(BCLog::WALLET, "Upgrading wallet to HD\n"); m_storage.SetMinVersion(FEATURE_HD); // generate a new master key @@ -455,7 +455,7 @@ bool LegacyScriptPubKeyMan::Upgrade(int prev_version, int new_version, bilingual } // Upgrade to HD chain split if necessary if (!IsFeatureSupported(prev_version, FEATURE_HD_SPLIT) && IsFeatureSupported(new_version, FEATURE_HD_SPLIT)) { - WalletLogPrintf("Upgrading wallet to use HD chain split\n"); + LogPrint(BCLog::WALLET, "Upgrading wallet to use HD chain split\n"); m_storage.SetMinVersion(FEATURE_PRE_SPLIT_KEYPOOL); split_upgrade = FEATURE_HD_SPLIT > prev_version; // Upgrade the HDChain @@ -743,7 +743,7 @@ bool LegacyScriptPubKeyMan::LoadCScript(const CScript& redeemScript) if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { std::string strAddr = EncodeDestination(ScriptHash(redeemScript)); - WalletLogPrintf("%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr); + LogPrint(BCLog::WALLET, "%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr); return true; } @@ -1222,7 +1222,7 @@ bool LegacyScriptPubKeyMan::NewKeyPool() if (!TopUp()) { return false; } - WalletLogPrintf("LegacyScriptPubKeyMan::NewKeyPool rewrote keypool\n"); + LogPrint(BCLog::WALLET, "LegacyScriptPubKeyMan::NewKeyPool rewrote keypool\n"); } return true; } @@ -1266,7 +1266,7 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize) AddKeypoolPubkeyWithDB(pubkey, internal, batch); } if (missingInternal + missingExternal > 0) { - WalletLogPrintf("keypool added %d keys (%d internal), size=%u (%u internal)\n", missingInternal + missingExternal, missingInternal, setInternalKeyPool.size() + setExternalKeyPool.size() + set_pre_split_keypool.size(), setInternalKeyPool.size()); + LogPrint(BCLog::WALLET, "keypool added %d keys (%d internal), size=%u (%u internal)\n", missingInternal + missingExternal, missingInternal, setInternalKeyPool.size() + setExternalKeyPool.size() + set_pre_split_keypool.size(), setInternalKeyPool.size()); } } NotifyCanGetAddressesChanged(); @@ -1319,7 +1319,7 @@ void LegacyScriptPubKeyMan::ReturnDestination(int64_t nIndex, bool fInternal, co m_index_to_reserved_key.erase(nIndex); NotifyCanGetAddressesChanged(); } - WalletLogPrintf("keypool return %d\n", nIndex); + LogPrint(BCLog::WALLET, "keypool return %d\n", nIndex); } bool LegacyScriptPubKeyMan::GetKeyFromPool(CPubKey& result, const OutputType type, bool internal) @@ -1426,7 +1426,7 @@ void LegacyScriptPubKeyMan::MarkReserveKeysAsUsed(int64_t keypool_id) } LearnAllRelatedScripts(keypool.vchPubKey); batch.ErasePool(index); - WalletLogPrintf("keypool index %d removed\n", index); + LogPrint(BCLog::WALLET, "keypool index %d removed\n", index); it = setKeyPool->erase(it); } } @@ -1494,7 +1494,7 @@ bool LegacyScriptPubKeyMan::ImportScripts(const std::set scripts, int64 for (const auto& entry : scripts) { CScriptID id(entry); if (HaveCScript(id)) { - WalletLogPrintf("Already have script %s, skipping\n", HexStr(entry)); + LogPrint(BCLog::WALLET, "Already have script %s, skipping\n", HexStr(entry)); continue; } if (!AddCScriptWithDB(batch, entry)) { @@ -1522,7 +1522,7 @@ bool LegacyScriptPubKeyMan::ImportPrivKeys(const std::map& privkey assert(key.VerifyPubKey(pubkey)); // Skip if we already have the key if (HaveKey(id)) { - WalletLogPrintf("Already have key with pubkey %s, skipping\n", HexStr(pubkey)); + LogPrint(BCLog::WALLET, "Already have key with pubkey %s, skipping\n", HexStr(pubkey)); continue; } mapKeyMetadata[id].nCreateTime = timestamp; @@ -1550,7 +1550,7 @@ bool LegacyScriptPubKeyMan::ImportPubKeys(const std::vector& ordered_pub CPubKey temp; if (GetPubKey(id, temp)) { // Already have pubkey, skipping - WalletLogPrintf("Already have pubkey %s, skipping\n", HexStr(temp)); + LogPrint(BCLog::WALLET, "Already have pubkey %s, skipping\n", HexStr(temp)); continue; } if (!AddWatchOnlyWithDB(batch, GetScriptForRawPubKey(pubkey), timestamp)) { @@ -1833,11 +1833,11 @@ void DescriptorScriptPubKeyMan::MarkUnusedAddresses(const CScript& script) if (IsMine(script)) { int32_t index = m_map_script_pub_keys[script]; if (index >= m_wallet_descriptor.next_index) { - WalletLogPrintf("%s: Detected a used keypool item at index %d, mark all keypool items up to this item as used\n", __func__, index); + LogPrint(BCLog::WALLET, "%s: Detected a used keypool item at index %d, mark all keypool items up to this item as used\n", __func__, index); m_wallet_descriptor.next_index = index + 1; } if (!TopUp()) { - WalletLogPrintf("%s: Topping up keypool failed (locked wallet)\n", __func__); + LogPrint(BCLog::WALLET, "%s: Topping up keypool failed (locked wallet)\n", __func__); } } } From a7b17d25c11ed3120759670659b4a5b25ce32f01 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Tue, 13 Sep 2022 16:28:22 +0300 Subject: [PATCH 18/49] Fix check register block --- src/pocketdb/consensus/Social.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pocketdb/consensus/Social.h b/src/pocketdb/consensus/Social.h index 07a98c290..75ab27e3a 100644 --- a/src/pocketdb/consensus/Social.h +++ b/src/pocketdb/consensus/Social.h @@ -51,9 +51,6 @@ namespace PocketConsensus if (*blockTx->GetString1() == address) { - if (*blockTx->GetType() == ACCOUNT_DELETE) - return {false, SocialConsensusResult_AccountDeleted}; - inBlock = true; break; } From 07b58dc30344d867a4890120a5a2d8f032b40ee2 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Tue, 13 Sep 2022 16:29:51 +0300 Subject: [PATCH 19/49] Clean logs --- src/net.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index c3a1184a5..17ad0f97c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -400,10 +400,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo // Look for an existing connection CNode* pnode = FindNode(static_cast(addrConnect)); if (pnode) - { - LogPrintf("Failed to open new connection, already connected\n"); return nullptr; - } } /// debug print @@ -430,7 +427,6 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo if (pnode) { pnode->MaybeSetAddrName(std::string(pszDest)); - LogPrintf("Failed to open new connection, already connected\n"); return nullptr; } } From ea6f8fb8bd222bd710529d5a3a169818dca3d9c5 Mon Sep 17 00:00:00 2001 From: only1question Date: Tue, 13 Sep 2022 16:36:03 +0300 Subject: [PATCH 20/49] Remove data from deleted account in all feeds --- src/pocketdb/repositories/web/WebRpcRepository.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 2083127b5..589685988 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -3212,6 +3212,8 @@ namespace PocketDb where scr.Type = 300 and scr.Last in (0,1) and scr.Height is not null and scr.String1 = ? and scr.String2 = t.String2),0) as MyScore from Transactions t indexed by Transactions_Last_Id_Height + cross join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id + on ua.String1 = t.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null left join Payload p on t.Hash = p.TxHash where t.Height is not null and t.Last = 1 @@ -3869,6 +3871,9 @@ namespace PocketDb from Transactions cnt indexed by Transactions_Type_Last_String1_Height_Id + cross join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id + on ua.String1 = cnt.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null + )sql" + langFilter + R"sql( join Transactions subs indexed by Transactions_Type_Last_String1_String2_Height From de9a7a0cc4dc63deda8fa09303992dd5264f8eff Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Tue, 13 Sep 2022 16:48:16 +0300 Subject: [PATCH 21/49] Fix debug typo --- src/pocketdb/repositories/web/WebRpcRepository.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 589685988..ffce283e1 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -3666,7 +3666,7 @@ namespace PocketDb if (topContentId > 0) contentIdWhere = " and t.Id < ? "; - string accountExistence = " join Transaction1s ua indexed by Transactions_Type_Last_String1_Height_Id " + string accountExistence = " join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id " " on ua.String1 = t.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null "; string langFilter; From bb7cd8e714ca0d80dd0ff45b2ed2a9a5d7dd524a Mon Sep 17 00:00:00 2001 From: only1question Date: Tue, 13 Sep 2022 16:55:46 +0300 Subject: [PATCH 22/49] Fixed typo in GetLastComments --- src/pocketdb/repositories/web/WebRpcRepository.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index ffce283e1..d9895844c 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -1034,7 +1034,7 @@ namespace PocketDb from Transactions c indexed by Transactions_Height_Id cross join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id - on ua.String1 = t.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null + on ua.String1 = c.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null cross join Transactions p indexed by Transactions_Type_Last_String2_Height on p.Type in (200,201,202) and p.Last = 1 and p.Height > 0 and p.String2 = c.String3 From fd4b1b584061949de2180c8b443f697cfe426f91 Mon Sep 17 00:00:00 2001 From: only1question Date: Tue, 13 Sep 2022 17:34:18 +0300 Subject: [PATCH 23/49] Added flag if account deleted in GetAccountState --- .../repositories/web/WebRpcRepository.cpp | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index d9895844c..0dc19bc91 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -502,6 +502,7 @@ namespace PocketDb select u.Id as AddressId, u.String1 as Address, + u.Type, (select count() from Transactions p indexed by Transactions_Type_String1_Height_Time_Int1 where p.Type in (200) and p.Hash=p.String2 and p.String1=u.String1 and (p.Height>=? or p.Height isnull)) as PostSpent, @@ -529,7 +530,7 @@ namespace PocketDb from Transactions u indexed by Transactions_Type_Last_String1_Height_Id - where u.Type in (100) + where u.Type in (100, 170) and u.Height is not null and u.String1 = ? and u.Last = 1 @@ -555,15 +556,25 @@ namespace PocketDb if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("address_id", value); if (auto[ok, value] = TryGetColumnString(*stmt, i++); ok) result.pushKV("address", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("post_spent", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("video_spent", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("article_spent", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("comment_spent", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("score_spent", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("comment_score_spent", value); - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("complain_spent", value); - - if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("mod_flag_spent", value); + bool isDeleted = false; + if (auto[ok, Type] = TryGetColumnInt(*stmt, i++); ok) + { + isDeleted = (Type==TxType::ACCOUNT_DELETE); + if (isDeleted) result.pushKV("deleted", true); + } + + if (!isDeleted) { + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("post_spent", value); + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("video_spent", value); + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("article_spent", value); + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("comment_spent", value); + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("score_spent", value); + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) + result.pushKV("comment_score_spent", value); + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("complain_spent", value); + + if (auto [ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.pushKV("mod_flag_spent", value); + } } FinalizeSqlStatement(*stmt); From ec47a955895fe35aeb99419374af51c98fa68e2d Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Tue, 13 Sep 2022 17:44:23 +0300 Subject: [PATCH 24/49] // TODO (brangr): delete --- src/pocketdb/consensus/Social.h | 4 ++++ src/pocketdb/consensus/social/AccountDelete.hpp | 9 ++++++--- src/pocketdb/repositories/ChainRepository.cpp | 4 ++++ src/pocketdb/repositories/ConsensusRepository.cpp | 12 ++++++++++-- src/pocketdb/repositories/MigrationRepository.cpp | 1 + 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/pocketdb/consensus/Social.h b/src/pocketdb/consensus/Social.h index 75ab27e3a..d0576b68a 100644 --- a/src/pocketdb/consensus/Social.h +++ b/src/pocketdb/consensus/Social.h @@ -51,6 +51,10 @@ namespace PocketConsensus if (*blockTx->GetString1() == address) { + // TODO (brangr): delete - подумать для всех ли подходит + if (*blockTx->GetType() == ACCOUNT_DELETE) + return {false, SocialConsensusResult_AccountDeleted}; + inBlock = true; break; } diff --git a/src/pocketdb/consensus/social/AccountDelete.hpp b/src/pocketdb/consensus/social/AccountDelete.hpp index e63fb9cbe..73791ed66 100644 --- a/src/pocketdb/consensus/social/AccountDelete.hpp +++ b/src/pocketdb/consensus/social/AccountDelete.hpp @@ -21,6 +21,8 @@ namespace PocketConsensus public: AccountDeleteConsensus(int height) : SocialConsensus(height) {} + // TODO (brangr): delete - validate exists not deleted account + ConsensusValidateResult Check(const CTransactionRef& tx, const AccountDeleteRef& ptx) override { if (IsEmpty(ptx->GetAddress())) @@ -36,8 +38,9 @@ namespace PocketConsensus // Only one transaction allowed in block for (auto& blockTx : *block) { - if (!TransactionHelper::IsIn(*blockTx->GetType(), { ACCOUNT_USER, ACCOUNT_SETTING, ACCOUNT_DELETE })) - continue; + // TODO (brangr): delete - любая транзакция несовместима с операцией удаления + // if (!TransactionHelper::IsIn(*blockTx->GetType(), { ACCOUNT_USER, ACCOUNT_SETTING, ACCOUNT_DELETE })) + // continue; auto blockPtx = static_pointer_cast(blockTx); if (*blockPtx->GetHash() == *ptx->GetHash()) @@ -60,7 +63,7 @@ namespace PocketConsensus vector GetAddressesForCheckRegistration(const AccountDeleteRef& ptx) override { - return { *ptx->GetAddress() }; + return { }; } }; diff --git a/src/pocketdb/repositories/ChainRepository.cpp b/src/pocketdb/repositories/ChainRepository.cpp index 631f9794b..751738860 100644 --- a/src/pocketdb/repositories/ChainRepository.cpp +++ b/src/pocketdb/repositories/ChainRepository.cpp @@ -374,6 +374,7 @@ namespace PocketDb TryBindStatementText(setLastStmt, 1, txHash); TryStepStatement(setLastStmt); + // TODO (brangr): delete auto insListStmt = SetupSqlStatement(R"sql( insert into BlockingLists (IdSource, IdTarget) select @@ -392,6 +393,7 @@ namespace PocketDb TryBindStatementText(insListStmt, 1, txHash); TryStepStatement(insListStmt); + // TODO (brangr): delete auto delListStmt = SetupSqlStatement(R"sql( delete from BlockingLists where exists @@ -698,6 +700,7 @@ namespace PocketDb { int64_t nTime0 = GetTimeMicros(); + // TODO (brangr): delete auto delListStmt = SetupSqlStatement(R"sql( delete from BlockingLists where ROWID in ( @@ -722,6 +725,7 @@ namespace PocketDb int64_t nTime1 = GetTimeMicros(); LogPrint(BCLog::BENCH, " - RollbackList (Delete blocking list): %.2fms\n", 0.001 * (nTime1 - nTime0)); + // TODO (brangr): delete auto insListStmt = SetupSqlStatement(R"sql( insert into BlockingLists ( diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index 600490a4f..2d836021f 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -211,6 +211,7 @@ namespace PocketDb return {blockingExists, blockingType}; } + // TODO (brangr): delete bool ConsensusRepository::ExistBlocking(const string& address, const string& addressTo, const string& addressesTo) { bool blockingExists = false; @@ -530,6 +531,7 @@ namespace PocketDb return result; } + // TODO (brangr): delete int ConsensusRepository::GetUserReputation(const string& address) { int result = 0; @@ -538,7 +540,7 @@ namespace PocketDb select r.Value from Ratings r where r.Type = 0 - and r.Id = (SELECT u.Id FROM Transactions u WHERE u.Type = 100 and u.Height is not null and u.Last = 1 and u.String1 = ? LIMIT 1) + and r.Id = (select u.Id from Transactions u where u.Type = 100 and u.Height is not null and u.Last = 1 and u.String1 = ? limit 1) and r.Last = 1 )sql"; @@ -584,6 +586,7 @@ namespace PocketDb return result; } + // TODO (brangr): delete int ConsensusRepository::GetAccountRegistrationHeight(int addressId) { int result = 0; @@ -610,6 +613,7 @@ namespace PocketDb return result; } + // TODO (brangr): delete int64_t ConsensusRepository::GetAccountRegistrationTime(int addressId) { int64_t result = 0; @@ -639,6 +643,7 @@ namespace PocketDb return result; } + // TODO (brangr): delete AccountData ConsensusRepository::GetAccountData(const string& address) { AccountData result = {address,-1,0,0,0,0,0}; @@ -729,7 +734,7 @@ namespace PocketDb -- Content Address join Transactions ca indexed by Transactions_Type_Last_String1_Height_Id - on ca.Type in (100) and ca.Height > 0 and ca.String1 = c.String1 and ca.Last = 1 + on ca.Type in (100,170) and ca.Height > 0 and ca.String1 = c.String1 and ca.Last = 1 where s.Hash = ? )sql"; @@ -769,6 +774,7 @@ namespace PocketDb } // Select many referrers + // TODO (brangr): delete - где используется shared_ptr> ConsensusRepository::GetReferrers(const vector& addresses, int minHeight) { shared_ptr> result = make_shared>(); @@ -814,6 +820,7 @@ namespace PocketDb } // Select referrer for one account + // TODO (brangr): delete - где используется tuple ConsensusRepository::GetReferrer(const string& address) { bool result = false; @@ -1585,6 +1592,7 @@ namespace PocketDb return result; } + // TODO (brangr): delete - нужна еще? int ConsensusRepository::CountMempoolUser(const string& address) { int result = 0; diff --git a/src/pocketdb/repositories/MigrationRepository.cpp b/src/pocketdb/repositories/MigrationRepository.cpp index 2afc13902..80d18329d 100644 --- a/src/pocketdb/repositories/MigrationRepository.cpp +++ b/src/pocketdb/repositories/MigrationRepository.cpp @@ -8,6 +8,7 @@ namespace PocketDb { + // TODO (brangr): delete bool MigrationRepository::CreateBlockingList() { bool result = false; From 2ae9b3dd65bd7241ac78a24c08f5828d07cd5e12 Mon Sep 17 00:00:00 2001 From: only1question Date: Tue, 13 Sep 2022 23:44:35 +0300 Subject: [PATCH 25/49] Include deleted accounts in block lists --- src/pocketdb/repositories/ChainRepository.cpp | 24 +++++++++---------- .../repositories/ConsensusRepository.cpp | 6 ++--- .../repositories/MigrationRepository.cpp | 10 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/pocketdb/repositories/ChainRepository.cpp b/src/pocketdb/repositories/ChainRepository.cpp index 751738860..e2698f934 100644 --- a/src/pocketdb/repositories/ChainRepository.cpp +++ b/src/pocketdb/repositories/ChainRepository.cpp @@ -374,7 +374,7 @@ namespace PocketDb TryBindStatementText(setLastStmt, 1, txHash); TryStepStatement(setLastStmt); - // TODO (brangr): delete + // TODO (brangr): delete - Done(o1q) auto insListStmt = SetupSqlStatement(R"sql( insert into BlockingLists (IdSource, IdTarget) select @@ -382,9 +382,9 @@ namespace PocketDb ut.Id from Transactions b join Transactions us indexed by Transactions_Type_Last_String1_Height_Id - on us.Type in (100) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 + on us.Type in (100, 170) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 join Transactions ut indexed by Transactions_Type_Last_String1_Height_Id - on ut.Type in (100) and ut.Last = 1 + on ut.Type in (100, 170) and ut.Last = 1 and ut.String1 in (select b.String2 union select value from json_each(b.String3)) and ut.Height > 0 where b.Type in (305) and b.Hash = ? @@ -393,7 +393,7 @@ namespace PocketDb TryBindStatementText(insListStmt, 1, txHash); TryStepStatement(insListStmt); - // TODO (brangr): delete + // TODO (brangr): delete - Done(o1q) auto delListStmt = SetupSqlStatement(R"sql( delete from BlockingLists where exists @@ -401,9 +401,9 @@ namespace PocketDb 1 from Transactions b join Transactions us indexed by Transactions_Type_Last_String1_Height_Id - on us.Type in (100) and us.Last = 1 and us.String1 = b.String1 and us.Id = BlockingLists.IdSource and us.Height > 0 + on us.Type in (100, 170) and us.Last = 1 and us.String1 = b.String1 and us.Id = BlockingLists.IdSource and us.Height > 0 join Transactions ut indexed by Transactions_Type_Last_String1_Height_Id - on ut.Type in (100) and ut.Last = 1 and ut.String1 = b.String2 and ut.Id = BlockingLists.IdTarget and ut.Height > 0 + on ut.Type in (100, 170) and ut.Last = 1 and ut.String1 = b.String2 and ut.Id = BlockingLists.IdTarget and ut.Height > 0 where b.Type in (306) and b.Hash = ? ) )sql"); @@ -700,18 +700,18 @@ namespace PocketDb { int64_t nTime0 = GetTimeMicros(); - // TODO (brangr): delete + // TODO (brangr): delete - Done(o1q) auto delListStmt = SetupSqlStatement(R"sql( delete from BlockingLists where ROWID in ( select bl.ROWID from Transactions b indexed by Transactions_Type_Last_String1_Height_Id join Transactions us indexed by Transactions_Type_Last_String1_Height_Id - on us.Type in (100) and us.Last = 1 + on us.Type in (100, 170) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 join Transactions ut indexed by Transactions_Type_Last_String1_Height_Id - on ut.Type in (100) and ut.Last = 1 + on ut.Type in (100, 170) and ut.Last = 1 and ut.String1 in (select b.String2 union select value from json_each(b.String3)) and ut.Height > 0 join BlockingLists bl on bl.IdSource = us.Id and bl.IdTarget = ut.Id @@ -725,7 +725,7 @@ namespace PocketDb int64_t nTime1 = GetTimeMicros(); LogPrint(BCLog::BENCH, " - RollbackList (Delete blocking list): %.2fms\n", 0.001 * (nTime1 - nTime0)); - // TODO (brangr): delete + // TODO (brangr): delete - Done(o1q) auto insListStmt = SetupSqlStatement(R"sql( insert into BlockingLists ( @@ -737,9 +737,9 @@ namespace PocketDb ut.Id from Transactions b indexed by Transactions_Type_Last_String1_Height_Id join Transactions us indexed by Transactions_Type_Last_String1_Height_Id - on us.Type in (100) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 + on us.Type in (100, 170) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 join Transactions ut indexed by Transactions_Type_Last_String1_Height_Id - on ut.Type in (100) and ut.Last = 1 + on ut.Type in (100, 170) and ut.Last = 1 --and ut.String1 = b.String2 and ut.String1 in (select b.String2 union select value from json_each(b.String3)) and ut.Height > 0 diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index 2d836021f..b3f8ccea6 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -211,7 +211,7 @@ namespace PocketDb return {blockingExists, blockingType}; } - // TODO (brangr): delete + // TODO (brangr): delete - Done(o1q) bool ConsensusRepository::ExistBlocking(const string& address, const string& addressTo, const string& addressesTo) { bool blockingExists = false; @@ -222,9 +222,9 @@ namespace PocketDb SELECT 1 FROM BlockingLists b JOIN Transactions us indexed by Transactions_Type_Last_String1_Height_Id - ON us.Last = 1 and us.Id = b.IdSource and us.Type = 100 and us.Height is not null + ON us.Last = 1 and us.Id = b.IdSource and us.Type in (100, 170) and us.Height is not null JOIN Transactions ut indexed by Transactions_Type_Last_String1_Height_Id - ON ut.Last = 1 and ut.Id = b.IdTarget and ut.Type = 100 and ut.Height is not null + ON ut.Last = 1 and ut.Id = b.IdTarget and ut.Type in (100, 170) and ut.Height is not null WHERE us.String1 = ? and ut.String1 in (select ? union select value from json_each(?)) LIMIT 1 diff --git a/src/pocketdb/repositories/MigrationRepository.cpp b/src/pocketdb/repositories/MigrationRepository.cpp index 80d18329d..e88c1fec3 100644 --- a/src/pocketdb/repositories/MigrationRepository.cpp +++ b/src/pocketdb/repositories/MigrationRepository.cpp @@ -8,7 +8,7 @@ namespace PocketDb { - // TODO (brangr): delete + // TODO (brangr): delete - Done(o1q) bool MigrationRepository::CreateBlockingList() { bool result = false; @@ -37,9 +37,9 @@ namespace PocketDb ut.Id from Transactions b indexed by Transactions_Type_Last_String1_Height_Id join Transactions us indexed by Transactions_Type_Last_String1_Height_Id - on us.Type in (100) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 + on us.Type in (100, 170) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 join Transactions ut indexed by Transactions_Type_Last_String1_Height_Id - on ut.Type in (100) and ut.Last = 1 + on ut.Type in (100, 170) and ut.Last = 1 --and ut.String1 = b.String2 and ut.String1 in (select b.String2 union select value from json_each(b.String3)) and ut.Height > 0 @@ -70,9 +70,9 @@ namespace PocketDb select 1 from Transactions b indexed by Transactions_Type_Last_String1_Height_Id join Transactions us indexed by Transactions_Type_Last_String1_Height_Id - on us.Type in (100) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 + on us.Type in (100, 170) and us.Last = 1 and us.String1 = b.String1 and us.Height > 0 join Transactions ut indexed by Transactions_Type_Last_String1_Height_Id - on ut.Type in (100) and ut.Last = 1 + on ut.Type in (100, 170) and ut.Last = 1 --and ut.String1 = b.String2 and ut.String1 in (select b.String2 union select value from json_each(b.String3)) and ut.Height > 0 From b9521ffb7073798e6558d0d5ddc8e9b956c9ac1e Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Wed, 14 Sep 2022 13:11:07 +0300 Subject: [PATCH 26/49] Add 170 for get user account data --- src/pocketdb/consensus/Social.h | 6 +++--- src/pocketdb/consensus/social/AccountDelete.hpp | 7 ------- src/pocketdb/consensus/social/Comment.hpp | 2 -- src/pocketdb/consensus/social/CommentEdit.hpp | 5 ----- src/pocketdb/consensus/social/Video.hpp | 1 - src/pocketdb/repositories/ChainRepository.cpp | 4 ---- src/pocketdb/repositories/ConsensusRepository.cpp | 12 +++++++++--- 7 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/pocketdb/consensus/Social.h b/src/pocketdb/consensus/Social.h index d0576b68a..a60258543 100644 --- a/src/pocketdb/consensus/Social.h +++ b/src/pocketdb/consensus/Social.h @@ -51,9 +51,9 @@ namespace PocketConsensus if (*blockTx->GetString1() == address) { - // TODO (brangr): delete - подумать для всех ли подходит - if (*blockTx->GetType() == ACCOUNT_DELETE) - return {false, SocialConsensusResult_AccountDeleted}; + // TODO (brangr): delete - в один блок пусть с удалением пролазят - проверитЬ! + // if (*blockTx->GetType() == ACCOUNT_DELETE) + // return {false, SocialConsensusResult_AccountDeleted}; inBlock = true; break; diff --git a/src/pocketdb/consensus/social/AccountDelete.hpp b/src/pocketdb/consensus/social/AccountDelete.hpp index 73791ed66..2977cdb15 100644 --- a/src/pocketdb/consensus/social/AccountDelete.hpp +++ b/src/pocketdb/consensus/social/AccountDelete.hpp @@ -21,8 +21,6 @@ namespace PocketConsensus public: AccountDeleteConsensus(int height) : SocialConsensus(height) {} - // TODO (brangr): delete - validate exists not deleted account - ConsensusValidateResult Check(const CTransactionRef& tx, const AccountDeleteRef& ptx) override { if (IsEmpty(ptx->GetAddress())) @@ -60,11 +58,6 @@ namespace PocketConsensus return Success; } - - vector GetAddressesForCheckRegistration(const AccountDeleteRef& ptx) override - { - return { }; - } }; // todo (0.21): set minimum height for this transaction diff --git a/src/pocketdb/consensus/social/Comment.hpp b/src/pocketdb/consensus/social/Comment.hpp index 290e22026..9b97682e8 100644 --- a/src/pocketdb/consensus/social/Comment.hpp +++ b/src/pocketdb/consensus/social/Comment.hpp @@ -31,7 +31,6 @@ namespace PocketConsensus // Parent comment if (!IsEmpty(ptx->GetParentTxHash())) { - // TODO (brangr): replace to check exists not deleted comment auto[ok, parentTx] = ConsensusRepoInst.GetLastContent(*ptx->GetParentTxHash(), { CONTENT_COMMENT, CONTENT_COMMENT_EDIT }); if (!ok) @@ -41,7 +40,6 @@ namespace PocketConsensus // Answer comment if (!IsEmpty(ptx->GetAnswerTxHash())) { - // TODO (brangr): replace to check exists not deleted comment auto[ok, answerTx] = ConsensusRepoInst.GetLastContent(*ptx->GetAnswerTxHash(), { CONTENT_COMMENT, CONTENT_COMMENT_EDIT }); if (!ok) diff --git a/src/pocketdb/consensus/social/CommentEdit.hpp b/src/pocketdb/consensus/social/CommentEdit.hpp index d6aac0d69..cd1d2cf84 100644 --- a/src/pocketdb/consensus/social/CommentEdit.hpp +++ b/src/pocketdb/consensus/social/CommentEdit.hpp @@ -57,7 +57,6 @@ namespace PocketConsensus if (!origParentTxHash.empty()) { - // TODO (brangr): replace to check exists not deleted comment if (auto[ok, origParentTx] = ConsensusRepoInst.GetLastContent( origParentTxHash, { CONTENT_COMMENT, CONTENT_COMMENT_EDIT }); !ok) return {false, SocialConsensusResult_InvalidParentComment}; @@ -74,7 +73,6 @@ namespace PocketConsensus if (!origAnswerTxHash.empty()) { - // TODO (brangr): replace to check exists not deleted comment if (auto[ok, origAnswerTx] = ConsensusRepoInst.GetLastContent( origAnswerTxHash, { CONTENT_COMMENT, CONTENT_COMMENT_EDIT }); !ok) return {false, SocialConsensusResult_InvalidAnswerComment}; @@ -94,9 +92,6 @@ namespace PocketConsensus if (*contentTx->GetType() == CONTENT_DELETE) return {false, SocialConsensusResult_CommentDeletedContent}; - - // TODO (brangr): convert to Content base class - // Check Blocking if (auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType( diff --git a/src/pocketdb/consensus/social/Video.hpp b/src/pocketdb/consensus/social/Video.hpp index 21d9da2e3..408a16d0c 100644 --- a/src/pocketdb/consensus/social/Video.hpp +++ b/src/pocketdb/consensus/social/Video.hpp @@ -119,7 +119,6 @@ namespace PocketConsensus virtual ConsensusValidateResult ValidateEdit(const VideoRef& ptx) { - // TODO (brangr): change with check deleted content auto[lastContentOk, lastContent] = PocketDb::ConsensusRepoInst.GetLastContent( *ptx->GetRootTxHash(), { CONTENT_POST, CONTENT_VIDEO, CONTENT_DELETE } diff --git a/src/pocketdb/repositories/ChainRepository.cpp b/src/pocketdb/repositories/ChainRepository.cpp index e2698f934..052df5640 100644 --- a/src/pocketdb/repositories/ChainRepository.cpp +++ b/src/pocketdb/repositories/ChainRepository.cpp @@ -374,7 +374,6 @@ namespace PocketDb TryBindStatementText(setLastStmt, 1, txHash); TryStepStatement(setLastStmt); - // TODO (brangr): delete - Done(o1q) auto insListStmt = SetupSqlStatement(R"sql( insert into BlockingLists (IdSource, IdTarget) select @@ -393,7 +392,6 @@ namespace PocketDb TryBindStatementText(insListStmt, 1, txHash); TryStepStatement(insListStmt); - // TODO (brangr): delete - Done(o1q) auto delListStmt = SetupSqlStatement(R"sql( delete from BlockingLists where exists @@ -700,7 +698,6 @@ namespace PocketDb { int64_t nTime0 = GetTimeMicros(); - // TODO (brangr): delete - Done(o1q) auto delListStmt = SetupSqlStatement(R"sql( delete from BlockingLists where ROWID in ( @@ -725,7 +722,6 @@ namespace PocketDb int64_t nTime1 = GetTimeMicros(); LogPrint(BCLog::BENCH, " - RollbackList (Delete blocking list): %.2fms\n", 0.001 * (nTime1 - nTime0)); - // TODO (brangr): delete - Done(o1q) auto insListStmt = SetupSqlStatement(R"sql( insert into BlockingLists ( diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index b3f8ccea6..cb57eff94 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -211,7 +211,6 @@ namespace PocketDb return {blockingExists, blockingType}; } - // TODO (brangr): delete - Done(o1q) bool ConsensusRepository::ExistBlocking(const string& address, const string& addressTo, const string& addressesTo) { bool blockingExists = false; @@ -531,7 +530,6 @@ namespace PocketDb return result; } - // TODO (brangr): delete int ConsensusRepository::GetUserReputation(const string& address) { int result = 0; @@ -540,7 +538,15 @@ namespace PocketDb select r.Value from Ratings r where r.Type = 0 - and r.Id = (select u.Id from Transactions u where u.Type = 100 and u.Height is not null and u.Last = 1 and u.String1 = ? limit 1) + and r.Id = ( + select u.Id + from Transactions u indexed by Transactions_Type_Last_String1_Height_Id + where u.Type in (100,170) + and u.Last = 1 + and u.String1 = ? + and u.Height is not null + limit 1 + ) and r.Last = 1 )sql"; From f169c83584ac9c45424e11be10f8c311950549da Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Wed, 14 Sep 2022 13:21:40 +0300 Subject: [PATCH 27/49] Complete check deleted account --- .../consensus/social/AccountDelete.hpp | 7 +- src/pocketdb/consensus/social/AccountUser.hpp | 2 +- .../repositories/ConsensusRepository.cpp | 99 ++++++------------- .../repositories/ConsensusRepository.h | 3 - .../repositories/MigrationRepository.cpp | 1 - 5 files changed, 34 insertions(+), 78 deletions(-) diff --git a/src/pocketdb/consensus/social/AccountDelete.hpp b/src/pocketdb/consensus/social/AccountDelete.hpp index 2977cdb15..dd72346d2 100644 --- a/src/pocketdb/consensus/social/AccountDelete.hpp +++ b/src/pocketdb/consensus/social/AccountDelete.hpp @@ -36,9 +36,8 @@ namespace PocketConsensus // Only one transaction allowed in block for (auto& blockTx : *block) { - // TODO (brangr): delete - любая транзакция несовместима с операцией удаления - // if (!TransactionHelper::IsIn(*blockTx->GetType(), { ACCOUNT_USER, ACCOUNT_SETTING, ACCOUNT_DELETE })) - // continue; + if (!TransactionHelper::IsIn(*blockTx->GetType(), { ACCOUNT_USER, ACCOUNT_DELETE })) + continue; auto blockPtx = static_pointer_cast(blockTx); if (*blockPtx->GetHash() == *ptx->GetHash()) @@ -53,7 +52,7 @@ namespace PocketConsensus ConsensusValidateResult ValidateMempool(const AccountDeleteRef& ptx) override { - if (ConsensusRepoInst.ExistsInMempool(*ptx->GetAddress(), { ACCOUNT_USER, ACCOUNT_SETTING, ACCOUNT_DELETE })) + if (ConsensusRepoInst.ExistsInMempool(*ptx->GetAddress(), { ACCOUNT_USER, ACCOUNT_DELETE })) return {false, SocialConsensusResult_ManyTransactions}; return Success; diff --git a/src/pocketdb/consensus/social/AccountUser.hpp b/src/pocketdb/consensus/social/AccountUser.hpp index d8ef81f20..0b1a2713a 100644 --- a/src/pocketdb/consensus/social/AccountUser.hpp +++ b/src/pocketdb/consensus/social/AccountUser.hpp @@ -111,7 +111,7 @@ namespace PocketConsensus ConsensusValidateResult ValidateMempool(const UserRef& ptx) override { - if (ConsensusRepoInst.CountMempoolUser(*ptx->GetAddress()) > 0) + if (ConsensusRepoInst.ExistsInMempool(*ptx->GetAddress(), { ACCOUNT_USER, ACCOUNT_DELETE })) return {false, SocialConsensusResult_ChangeInfoDoubleInMempool}; if (GetChainCount(ptx) > GetConsensusLimit(ConsensusLimit_edit_user_daily_count)) diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index cb57eff94..9da76a1bb 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -592,34 +592,7 @@ namespace PocketDb return result; } - // TODO (brangr): delete - int ConsensusRepository::GetAccountRegistrationHeight(int addressId) - { - int result = 0; - - string sql = R"sql( - select min(Height) - from Transactions - where Type in (100) - and Id = ? - )sql"; - - TryTransactionStep(__func__, [&]() - { - auto stmt = SetupSqlStatement(sql); - TryBindStatementInt(stmt, 1, addressId); - - if (sqlite3_step(*stmt) == SQLITE_ROW) - if (auto[ok, value] = TryGetColumnInt(*stmt, 0); ok) - result = value; - - FinalizeSqlStatement(*stmt); - }); - - return result; - } - - // TODO (brangr): delete + // TODO (brangr): maybe remove in future? int64_t ConsensusRepository::GetAccountRegistrationTime(int addressId) { int64_t result = 0; @@ -627,7 +600,7 @@ namespace PocketDb string sql = R"sql( select Time from Transactions indexed by Transactions_Id - where Type in (100) + where Type in (100, 170) and Height is not null and Id = ? order by Height asc @@ -649,7 +622,6 @@ namespace PocketDb return result; } - // TODO (brangr): delete AccountData ConsensusRepository::GetAccountData(const string& address) { AccountData result = {address,-1,0,0,0,0,0}; @@ -669,15 +641,27 @@ namespace PocketDb ifnull(lca.Value,0)LikersCommentAnswer from Transactions u indexed by Transactions_Type_Last_String1_Height_Id + cross join Transactions reg indexed by Transactions_Id on reg.Id = u.Id and reg.Height = (select min(reg1.Height) from Transactions reg1 indexed by Transactions_Id where reg1.Id = reg.Id) - left join Balances b indexed by Balances_AddressHash_Last on b.AddressHash = u.String1 and b.Last = 1 - left join Ratings r indexed by Ratings_Type_Id_Last_Value on r.Type = 0 and r.Id = u.Id and r.Last = 1 - left join Ratings lp indexed by Ratings_Type_Id_Last_Value on lp.Type = 111 and lp.Id = u.Id and lp.Last = 1 - left join Ratings lc indexed by Ratings_Type_Id_Last_Value on lc.Type = 112 and lc.Id = u.Id and lc.Last = 1 - left join Ratings lca indexed by Ratings_Type_Id_Last_Value on lca.Type = 113 and lca.Id = u.Id and lca.Last = 1 - where u.Type in (100) + left join Balances b indexed by Balances_AddressHash_Last + on b.AddressHash = u.String1 and b.Last = 1 + + left join Ratings r indexed by Ratings_Type_Id_Last_Value + on r.Type = 0 and r.Id = u.Id and r.Last = 1 + + left join Ratings lp indexed by Ratings_Type_Id_Last_Value + on lp.Type = 111 and lp.Id = u.Id and lp.Last = 1 + + left join Ratings lc indexed by Ratings_Type_Id_Last_Value + on lc.Type = 112 and lc.Id = u.Id and lc.Last = 1 + + left join Ratings lca indexed by Ratings_Type_Id_Last_Value + on lca.Type = 113 and lca.Id = u.Id and lca.Last = 1 + + + where u.Type in (100, 170) and u.Last = 1 and u.String1 = ? and u.Height > 0 @@ -780,7 +764,6 @@ namespace PocketDb } // Select many referrers - // TODO (brangr): delete - где используется shared_ptr> ConsensusRepository::GetReferrers(const vector& addresses, int minHeight) { shared_ptr> result = make_shared>(); @@ -792,10 +775,16 @@ namespace PocketDb string sql = R"sql( select u.String1, u.String2 from Transactions u - where u.Type in (100) + where u.Type in (100, 170) and u.Height is not null and u.Height >= ? - and u.Height = (select min(u1.Height) from Transactions u1 where u1.Type in (100) and u1.Height is not null and u1.String1=u.String1) + and u.Height = ( + select min(u1.Height) + from Transactions u1 indexed by Transactions_Type_String1_Height_Time_Int1 + where u1.Type in (100, 170) + and u1.Height is not null + and u1.String1 = u.String1 + ) and u.String2 is not null )sql"; @@ -826,7 +815,6 @@ namespace PocketDb } // Select referrer for one account - // TODO (brangr): delete - где используется tuple ConsensusRepository::GetReferrer(const string& address) { bool result = false; @@ -835,9 +823,9 @@ namespace PocketDb string sql = R"sql( select String2 from Transactions indexed by Transactions_Type_String1_Height_Time_Int1 - where Type in (100) - and Height is not null + where Type in (100, 170) and String1 = ? + and Height is not null order by Height asc limit 1 )sql"; @@ -1598,33 +1586,6 @@ namespace PocketDb return result; } - // TODO (brangr): delete - нужна еще? - int ConsensusRepository::CountMempoolUser(const string& address) - { - int result = 0; - - TryTransactionStep(__func__, [&]() - { - auto stmt = SetupSqlStatement(R"sql( - select count(*) - from Transactions - where Type in (100) - and Height is null - and String1 = ? - )sql"); - - TryBindStatementText(stmt, 1, address); - - if (sqlite3_step(*stmt) == SQLITE_ROW) - if (auto[ok, value] = TryGetColumnInt(*stmt, 0); ok) - result = value; - - FinalizeSqlStatement(*stmt); - }); - - return result; - } - int ConsensusRepository::CountMempoolAccountSetting(const string& address) { int result = 0; diff --git a/src/pocketdb/repositories/ConsensusRepository.h b/src/pocketdb/repositories/ConsensusRepository.h index c9e31a59e..559be0c72 100644 --- a/src/pocketdb/repositories/ConsensusRepository.h +++ b/src/pocketdb/repositories/ConsensusRepository.h @@ -93,7 +93,6 @@ namespace PocketDb int64_t GetUserBalance(const string& address); int GetUserReputation(const string& addressId); int GetUserReputation(int addressId); - int GetAccountRegistrationHeight(int addressId); int64_t GetAccountRegistrationTime(int addressId); AccountData GetAccountData(const string& address); @@ -154,8 +153,6 @@ namespace PocketDb int CountChainScoreContentTime(const string& address, int64_t time); int CountChainScoreContentHeight(const string& address, int height); - int CountMempoolUser(const string& address); - int CountMempoolAccountSetting(const string& address); int CountChainAccountSetting(const string& address, int height); diff --git a/src/pocketdb/repositories/MigrationRepository.cpp b/src/pocketdb/repositories/MigrationRepository.cpp index e88c1fec3..3a6afd75b 100644 --- a/src/pocketdb/repositories/MigrationRepository.cpp +++ b/src/pocketdb/repositories/MigrationRepository.cpp @@ -8,7 +8,6 @@ namespace PocketDb { - // TODO (brangr): delete - Done(o1q) bool MigrationRepository::CreateBlockingList() { bool result = false; From a8178b41906feda829ae826551873c162ee0e4b6 Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Wed, 14 Sep 2022 13:23:09 +0300 Subject: [PATCH 28/49] consensus add deleted account check 2 --- src/pocketdb/repositories/ConsensusRepository.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp index 9da76a1bb..8851817ce 100644 --- a/src/pocketdb/repositories/ConsensusRepository.cpp +++ b/src/pocketdb/repositories/ConsensusRepository.cpp @@ -22,7 +22,7 @@ namespace PocketDb select count(*) from Payload ap indexed by Payload_String2_nocase_TxHash cross join Transactions t indexed by Transactions_Hash_Height - on t.Type = 100 and t.Hash = ap.TxHash and t.Height is not null and t.Last = 1 + on t.Type in (100) and t.Hash = ap.TxHash and t.Height is not null and t.Last = 1 where ap.String2 like ? escape '\' and t.String1 != ? )sql"); @@ -152,7 +152,7 @@ namespace PocketDb string sql = R"sql( select count(distinct(String1)) from Transactions indexed by Transactions_Type_Last_String1_Height_Id - where Type = 100 + where Type in (100) and Last = 1 and String1 in ( )sql" + join(vector(addresses.size(), "?"), ",") + R"sql( ) and Height is not null @@ -716,7 +716,7 @@ namespace PocketDb -- Score Address join Transactions sa indexed by Transactions_Type_Last_String1_Height_Id - on sa.Type in (100) and sa.Height > 0 and sa.String1 = s.String1 and sa.Last = 1 + on sa.Type in (100,170) and sa.Height > 0 and sa.String1 = s.String1 and sa.Last = 1 -- Content join Transactions c indexed by Transactions_Hash_Height From f6fbe7a4de7a30fd6791890bc3919c2537427252 Mon Sep 17 00:00:00 2001 From: only1question Date: Wed, 14 Sep 2022 14:29:01 +0300 Subject: [PATCH 29/49] Remove comments from deleted accounts in GetCommentsByPost --- src/pocketdb/repositories/web/WebRpcRepository.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pocketdb/repositories/web/WebRpcRepository.cpp b/src/pocketdb/repositories/web/WebRpcRepository.cpp index 0dc19bc91..3a2d4b099 100644 --- a/src/pocketdb/repositories/web/WebRpcRepository.cpp +++ b/src/pocketdb/repositories/web/WebRpcRepository.cpp @@ -1308,6 +1308,9 @@ namespace PocketDb ( select count(1) from Transactions s indexed by Transactions_Type_Last_String4_Height + -- exclude deleted accounts + cross join Transactions uac indexed by Transactions_Type_Last_String1_Height_Id + on uac.String1 = s.String1 and uac.Type = 100 and uac.Last = 1 and uac.Height is not null where s.Type in (204, 205) and s.Height is not null and s.String4 = c.String2 @@ -1326,6 +1329,10 @@ namespace PocketDb from Transactions c indexed by Transactions_Type_Last_String3_Height + -- exclude deleted accounts + cross join Transactions ua indexed by Transactions_Type_Last_String1_Height_Id + on ua.String1 = c.String1 and ua.Type = 100 and ua.Last = 1 and ua.Height is not null + join Transactions r ON c.String2 = r.Hash join Payload pl ON pl.TxHash = c.Hash From 98abc0b4f7f3d20e77223aed346f5d94b29f0ecf Mon Sep 17 00:00:00 2001 From: Andy Oknen Date: Wed, 14 Sep 2022 15:33:47 +0300 Subject: [PATCH 30/49] refactoring --- src/init.cpp | 1 + src/pocketdb/consensus/social/AccountDelete.hpp | 5 ++++- src/pocketdb/consensus/social/AccountSetting.hpp | 6 +----- src/pocketdb/consensus/social/Article.hpp | 6 +----- src/pocketdb/consensus/social/Blocking.hpp | 6 +----- src/pocketdb/consensus/social/BlockingCancel.hpp | 6 +----- src/pocketdb/consensus/social/BoostContent.hpp | 6 +----- src/pocketdb/consensus/social/Comment.hpp | 6 +----- src/pocketdb/consensus/social/CommentDelete.hpp | 6 +----- src/pocketdb/consensus/social/CommentEdit.hpp | 9 ++++----- src/pocketdb/consensus/social/Complain.hpp | 6 +----- src/pocketdb/consensus/social/ContentDelete.hpp | 6 +----- src/pocketdb/consensus/social/Post.hpp | 6 +----- src/pocketdb/consensus/social/ScoreComment.hpp | 6 +----- src/pocketdb/consensus/social/ScoreContent.hpp | 6 +----- src/pocketdb/consensus/social/Subscribe.hpp | 6 +----- src/pocketdb/consensus/social/SubscribeCancel.hpp | 6 +----- src/pocketdb/consensus/social/SubscribePrivate.hpp | 6 +----- src/pocketdb/consensus/social/Video.hpp | 6 +----- src/pocketdb/repositories/ChainRepository.cpp | 3 --- src/pocketdb/web/PocketTransactionRpc.cpp | 2 -- 21 files changed, 25 insertions(+), 91 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index bfbb86e98..3b24ddae4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -485,6 +485,7 @@ void SetupServerArgs(NodeContext& node) argsman.AddArg("-skip-validation=", "Skip consensus check and validation before N block logic if running with -reindex or -reindex-chainstate", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-reindex-start", "Start block for -reindex logic (Deafult: 0)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-mempoolclean", "Clean mempool on loading and delete or non blocked transactions from sqlite db", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + argsman.AddArg("-disconnectlast", "Disconnect latest blocks up to the specified height (Default: -1)", false, OptionsCategory::COMMANDS); #if HAVE_SYSTEM argsman.AddArg("-startupnotify=", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); diff --git a/src/pocketdb/consensus/social/AccountDelete.hpp b/src/pocketdb/consensus/social/AccountDelete.hpp index dd72346d2..8c2dcaca4 100644 --- a/src/pocketdb/consensus/social/AccountDelete.hpp +++ b/src/pocketdb/consensus/social/AccountDelete.hpp @@ -23,10 +23,13 @@ namespace PocketConsensus ConsensusValidateResult Check(const CTransactionRef& tx, const AccountDeleteRef& ptx) override { + if (auto[baseCheck, baseCheckCode] = SocialConsensus::Check(tx, ptx); !baseCheck) + return {false, baseCheckCode}; + if (IsEmpty(ptx->GetAddress())) return {false, SocialConsensusResult_Failed}; - return SocialConsensus::Check(tx, ptx); + return Success; } protected: diff --git a/src/pocketdb/consensus/social/AccountSetting.hpp b/src/pocketdb/consensus/social/AccountSetting.hpp index 3ade87d85..036d1273c 100644 --- a/src/pocketdb/consensus/social/AccountSetting.hpp +++ b/src/pocketdb/consensus/social/AccountSetting.hpp @@ -22,15 +22,11 @@ namespace PocketConsensus AccountSettingConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const AccountSettingRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Check payload size if (auto[ok, code] = ValidatePayloadSize(ptx); !ok) return {false, code}; - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const AccountSettingRef& ptx) override { diff --git a/src/pocketdb/consensus/social/Article.hpp b/src/pocketdb/consensus/social/Article.hpp index ff59427bd..9344acee7 100644 --- a/src/pocketdb/consensus/social/Article.hpp +++ b/src/pocketdb/consensus/social/Article.hpp @@ -23,10 +23,6 @@ namespace PocketConsensus ArticleConsensus(int height) : SocialConsensus
(height) {} tuple Validate(const CTransactionRef& tx, const ArticleRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Check payload size if (auto[ok, code] = ValidatePayloadSize(ptx); !ok) return {false, code}; @@ -34,7 +30,7 @@ namespace PocketConsensus if (ptx->IsEdit()) return ValidateEdit(ptx); - return Success; + return SocialConsensus::Validate(tx, ptx, block); } tuple Check(const CTransactionRef& tx, const ArticleRef& ptx) override { diff --git a/src/pocketdb/consensus/social/Blocking.hpp b/src/pocketdb/consensus/social/Blocking.hpp index 83cbc49e3..9e1d64f2f 100644 --- a/src/pocketdb/consensus/social/Blocking.hpp +++ b/src/pocketdb/consensus/social/Blocking.hpp @@ -22,10 +22,6 @@ namespace PocketConsensus BlockingConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const BlockingRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Double blocking in chain if (auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType( *ptx->GetAddress(), @@ -36,7 +32,7 @@ namespace PocketConsensus return {false, SocialConsensusResult_DoubleBlocking}; } - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const BlockingRef& ptx) override { diff --git a/src/pocketdb/consensus/social/BlockingCancel.hpp b/src/pocketdb/consensus/social/BlockingCancel.hpp index 705897814..0534df750 100644 --- a/src/pocketdb/consensus/social/BlockingCancel.hpp +++ b/src/pocketdb/consensus/social/BlockingCancel.hpp @@ -22,10 +22,6 @@ namespace PocketConsensus BlockingCancelConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const BlockingCancelRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - if (auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType( *ptx->GetAddress(), *ptx->GetAddressTo() @@ -35,7 +31,7 @@ namespace PocketConsensus return {false, SocialConsensusResult_InvalidBlocking}; } - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const BlockingCancelRef& ptx) override { diff --git a/src/pocketdb/consensus/social/BoostContent.hpp b/src/pocketdb/consensus/social/BoostContent.hpp index 41ad6f815..95665f15d 100644 --- a/src/pocketdb/consensus/social/BoostContent.hpp +++ b/src/pocketdb/consensus/social/BoostContent.hpp @@ -23,10 +23,6 @@ namespace PocketConsensus ConsensusValidateResult Validate(const CTransactionRef& tx, const BoostContentRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Check exists content transaction auto[contentOk, contentTx] = PocketDb::ConsensusRepoInst.GetLastContent(*ptx->GetContentTxHash(), { CONTENT_POST, CONTENT_VIDEO, CONTENT_ARTICLE, CONTENT_DELETE }); if (!contentOk) @@ -39,7 +35,7 @@ namespace PocketConsensus if (auto[ok, result] = ValidateBlocking(*contentTx->GetString1(), ptx); !ok) return {false, result}; - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const BoostContentRef& ptx) override { diff --git a/src/pocketdb/consensus/social/Comment.hpp b/src/pocketdb/consensus/social/Comment.hpp index 9b97682e8..bf85e4a10 100644 --- a/src/pocketdb/consensus/social/Comment.hpp +++ b/src/pocketdb/consensus/social/Comment.hpp @@ -24,10 +24,6 @@ namespace PocketConsensus CommentConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const CommentRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Parent comment if (!IsEmpty(ptx->GetParentTxHash())) { @@ -69,7 +65,7 @@ namespace PocketConsensus if (auto[ok, code] = ValidatePayloadSize(ptx); !ok) return {false, code}; - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const CommentRef& ptx) override { diff --git a/src/pocketdb/consensus/social/CommentDelete.hpp b/src/pocketdb/consensus/social/CommentDelete.hpp index b1fc39e95..7f881295c 100644 --- a/src/pocketdb/consensus/social/CommentDelete.hpp +++ b/src/pocketdb/consensus/social/CommentDelete.hpp @@ -23,10 +23,6 @@ namespace PocketConsensus ConsensusValidateResult Validate(const CTransactionRef& tx, const CommentDeleteRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Actual comment not deleted auto[actuallTxOk, actuallTx] = ConsensusRepoInst.GetLastContent( *ptx->GetRootTxHash(), @@ -80,7 +76,7 @@ namespace PocketConsensus if (auto[ok, result] = CheckAuthor(ptx, originalPtx, contentTx); !ok) return {false, result}; - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const CommentDeleteRef& ptx) override { diff --git a/src/pocketdb/consensus/social/CommentEdit.hpp b/src/pocketdb/consensus/social/CommentEdit.hpp index cd1d2cf84..bc51ce159 100644 --- a/src/pocketdb/consensus/social/CommentEdit.hpp +++ b/src/pocketdb/consensus/social/CommentEdit.hpp @@ -24,10 +24,6 @@ namespace PocketConsensus CommentEditConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const CommentEditRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Actual comment not deleted auto[actuallTxOk, actuallTx] = ConsensusRepoInst.GetLastContent( *ptx->GetRootTxHash(), @@ -104,7 +100,10 @@ namespace PocketConsensus return {false, code}; // Check edit limit - return ValidateEditOneLimit(ptx); + if (auto[checkResult, checkCode] = ValidateEditOneLimit(ptx); !checkResult) + return {false, checkCode}; + + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const CommentEditRef& ptx) override { diff --git a/src/pocketdb/consensus/social/Complain.hpp b/src/pocketdb/consensus/social/Complain.hpp index f5581a15e..565c5f896 100644 --- a/src/pocketdb/consensus/social/Complain.hpp +++ b/src/pocketdb/consensus/social/Complain.hpp @@ -23,10 +23,6 @@ namespace PocketConsensus ComplainConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const ComplainRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Author or post must be exists auto[lastContentOk, lastContent] = PocketDb::ConsensusRepoInst.GetLastContent( *ptx->GetPostTxHash(), @@ -63,7 +59,7 @@ namespace PocketConsensus if (PocketDb::ConsensusRepoInst.ExistsComplain(*ptx->GetPostTxHash(), *ptx->GetAddress(), false)) return {false, SocialConsensusResult_DoubleComplain}; - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const ComplainRef& ptx) override { diff --git a/src/pocketdb/consensus/social/ContentDelete.hpp b/src/pocketdb/consensus/social/ContentDelete.hpp index 2a9b5821a..e20c1757a 100644 --- a/src/pocketdb/consensus/social/ContentDelete.hpp +++ b/src/pocketdb/consensus/social/ContentDelete.hpp @@ -22,10 +22,6 @@ namespace PocketConsensus ContentDeleteConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const ContentDeleteRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Actual content not deleted auto[ok, actuallTx] = ConsensusRepoInst.GetLastContent( *ptx->GetRootTxHash(), @@ -43,7 +39,7 @@ namespace PocketConsensus if (*ptx->GetAddress() != *actuallTx->GetString1()) return {false, SocialConsensusResult_ContentDeleteUnauthorized}; - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const ContentDeleteRef& ptx) override { diff --git a/src/pocketdb/consensus/social/Post.hpp b/src/pocketdb/consensus/social/Post.hpp index eca08d63e..6e673ef39 100644 --- a/src/pocketdb/consensus/social/Post.hpp +++ b/src/pocketdb/consensus/social/Post.hpp @@ -26,10 +26,6 @@ namespace PocketConsensus PostConsensus(int height) : SocialConsensus(height) {} tuple Validate(const CTransactionRef& tx, const PostRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Check if this post relay another if (!IsEmpty(ptx->GetRelayTxHash())) { @@ -60,7 +56,7 @@ namespace PocketConsensus if (ptx->IsEdit()) return ValidateEdit(ptx); - return Success; + return SocialConsensus::Validate(tx, ptx, block); } tuple Check(const CTransactionRef& tx, const PostRef& ptx) override { diff --git a/src/pocketdb/consensus/social/ScoreComment.hpp b/src/pocketdb/consensus/social/ScoreComment.hpp index de3133a58..bc6bc4394 100644 --- a/src/pocketdb/consensus/social/ScoreComment.hpp +++ b/src/pocketdb/consensus/social/ScoreComment.hpp @@ -24,10 +24,6 @@ namespace PocketConsensus ConsensusValidateResult Validate(const CTransactionRef& tx, const ScoreCommentRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Check already scored content if (PocketDb::ConsensusRepoInst.ExistsScore( *ptx->GetAddress(), *ptx->GetCommentTxHash(), ACTION_SCORE_COMMENT, false)) @@ -86,7 +82,7 @@ namespace PocketConsensus return {false, SocialConsensusResult_FailedOpReturn}; } - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const ScoreCommentRef& ptx) override { diff --git a/src/pocketdb/consensus/social/ScoreContent.hpp b/src/pocketdb/consensus/social/ScoreContent.hpp index ae3a3047f..931e69483 100644 --- a/src/pocketdb/consensus/social/ScoreContent.hpp +++ b/src/pocketdb/consensus/social/ScoreContent.hpp @@ -24,10 +24,6 @@ namespace PocketConsensus ConsensusValidateResult Validate(const CTransactionRef& tx, const ScoreContentRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Check already scored content if (PocketDb::ConsensusRepoInst.ExistsScore(*ptx->GetAddress(), *ptx->GetContentTxHash(), ACTION_SCORE_CONTENT, false)) return {false, SocialConsensusResult_DoubleScore}; @@ -79,7 +75,7 @@ namespace PocketConsensus return {false, SocialConsensusResult_FailedOpReturn}; } - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const ScoreContentRef& ptx) override { diff --git a/src/pocketdb/consensus/social/Subscribe.hpp b/src/pocketdb/consensus/social/Subscribe.hpp index 38d8a3069..fcadd1cd1 100644 --- a/src/pocketdb/consensus/social/Subscribe.hpp +++ b/src/pocketdb/consensus/social/Subscribe.hpp @@ -23,10 +23,6 @@ namespace PocketConsensus SubscribeConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const SubscribeRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - auto[subscribeExists, subscribeType] = PocketDb::ConsensusRepoInst.GetLastSubscribeType( *ptx->GetAddress(), *ptx->GetAddressTo()); @@ -41,7 +37,7 @@ namespace PocketConsensus if (auto[ok, result] = ValidateBlocking(ptx); !ok) return {false, result}; - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const SubscribeRef& ptx) override { diff --git a/src/pocketdb/consensus/social/SubscribeCancel.hpp b/src/pocketdb/consensus/social/SubscribeCancel.hpp index a27ce0f48..5eef40df8 100644 --- a/src/pocketdb/consensus/social/SubscribeCancel.hpp +++ b/src/pocketdb/consensus/social/SubscribeCancel.hpp @@ -23,10 +23,6 @@ namespace PocketConsensus SubscribeCancelConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const SubscribeCancelRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Last record not valid subscribe auto[subscribeExists, subscribeType] = PocketDb::ConsensusRepoInst.GetLastSubscribeType( *ptx->GetAddress(), @@ -38,7 +34,7 @@ namespace PocketConsensus return {false, SocialConsensusResult_InvalideSubscribe}; } - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const SubscribeCancelRef& ptx) override { diff --git a/src/pocketdb/consensus/social/SubscribePrivate.hpp b/src/pocketdb/consensus/social/SubscribePrivate.hpp index a89357db4..fcf29b234 100644 --- a/src/pocketdb/consensus/social/SubscribePrivate.hpp +++ b/src/pocketdb/consensus/social/SubscribePrivate.hpp @@ -22,10 +22,6 @@ namespace PocketConsensus SubscribePrivateConsensus(int height) : SocialConsensus(height) {} ConsensusValidateResult Validate(const CTransactionRef& tx, const SubscribePrivateRef& ptx, const PocketBlockRef& block) override { - // Base validation with calling block or mempool check - if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate) - return {false, baseValidateCode}; - // Check double subscribe auto[subscribeExists, subscribeType] = PocketDb::ConsensusRepoInst.GetLastSubscribeType( *ptx->GetAddress(), @@ -41,7 +37,7 @@ namespace PocketConsensus if (auto[ok, result] = ValidateBlocking(ptx); !ok) return {false, result}; - return Success; + return SocialConsensus::Validate(tx, ptx, block); } ConsensusValidateResult Check(const CTransactionRef& tx, const SubscribePrivateRef& ptx) override { diff --git a/src/pocketdb/consensus/social/Video.hpp b/src/pocketdb/consensus/social/Video.hpp index 408a16d0c..e77441d5b 100644 --- a/src/pocketdb/consensus/social/Video.hpp +++ b/src/pocketdb/consensus/social/Video.hpp @@ -23,10 +23,6 @@ namespace PocketConsensus VideoConsensus(int height) : SocialConsensus