From babcde8c76e8b8237f34506bb6bad532669e332c Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 Jun 2024 18:01:59 +0300 Subject: [PATCH] Log if receive unexpected transaction fields. --- td/telegram/StarManager.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/td/telegram/StarManager.cpp b/td/telegram/StarManager.cpp index eff287937..d64748088 100644 --- a/td/telegram/StarManager.cpp +++ b/td/telegram/StarManager.cpp @@ -25,6 +25,7 @@ #include "td/utils/buffer.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/ScopeGuard.h" namespace td { @@ -136,13 +137,23 @@ class GetStarsTransactionsQuery final : public Td::ResultHandler { case telegram_api::starsTransactionPeerFragment::ID: { auto state = [&]() -> td_api::object_ptr { if (transaction->transaction_date_ > 0) { + SCOPE_EXIT { + transaction->transaction_date_ = 0; + transaction->transaction_url_.clear(); + }; return td_api::make_object(transaction->transaction_date_, transaction->transaction_url_); } if (transaction->pending_) { + SCOPE_EXIT { + transaction->pending_ = false; + }; return td_api::make_object(); } if (transaction->failed_) { + SCOPE_EXIT { + transaction->failed_ = false; + }; return td_api::make_object(); } if (!transaction->refund_) { @@ -156,6 +167,9 @@ class GetStarsTransactionsQuery final : public Td::ResultHandler { DialogId dialog_id( static_cast(transaction->peer_.get())->peer_); if (dialog_id.get_type() == DialogType::User) { + SCOPE_EXIT { + bot_payload.clear(); + }; return td_api::make_object( td_->user_manager_->get_user_id_object(dialog_id.get_user_id(), "starTransactionPartnerUser"), std::move(product_info), bot_payload); @@ -173,9 +187,22 @@ class GetStarsTransactionsQuery final : public Td::ResultHandler { UNREACHABLE(); } }(); - transactions.push_back(td_api::make_object( + auto star_transaction = td_api::make_object( transaction->id_, StarManager::get_star_count(transaction->stars_, true), transaction->refund_, - transaction->date_, std::move(partner))); + transaction->date_, std::move(partner)); + if (star_transaction->partner_->get_id() != td_api::starTransactionPartnerUnsupported::ID) { + if (product_info != nullptr) { + LOG(ERROR) << "Receive product info with " << to_string(star_transaction); + } + if (!bot_payload.empty()) { + LOG(ERROR) << "Receive bot payload with " << to_string(star_transaction); + } + if (transaction->transaction_date_ || !transaction->transaction_url_.empty() || transaction->pending_ || + transaction->failed_) { + LOG(ERROR) << "Receive withdrawal state with " << to_string(star_transaction); + } + } + transactions.push_back(std::move(star_transaction)); } promise_.set_value(td_api::make_object(