From 5326c21b164d57ef4a9e325324930a1aefc2127b Mon Sep 17 00:00:00 2001 From: zenparsing Date: Tue, 23 Feb 2021 16:09:18 -0500 Subject: [PATCH] Add support for BAP reporting endpoint --- .../brave_rewards/browser/rewards_service.cc | 1 + .../browser/rewards_service_impl.cc | 3 + .../common/rewards_browsertest_response.cc | 6 + .../browser/test/rewards_browsertest.cc | 33 +++++ components/brave_rewards/common/pref_names.cc | 1 + components/brave_rewards/common/pref_names.h | 1 + vendor/bat-native-ledger/BUILD.gn | 4 + .../include/bat/ledger/option_keys.h | 7 +- .../ledger/internal/promotion/bap_reporter.cc | 115 ++++++++++++++++++ .../ledger/internal/promotion/bap_reporter.h | 49 ++++++++ .../promotion/bap_reporter_endpoint.cc | 92 ++++++++++++++ .../promotion/bap_reporter_endpoint.h | 57 +++++++++ .../ledger/internal/promotion/promotion.cc | 23 ++-- .../bat/ledger/internal/promotion/promotion.h | 8 +- .../src/bat/ledger/internal/state/state.cc | 9 ++ .../src/bat/ledger/internal/state/state.h | 9 +- .../bat/ledger/internal/state/state_keys.h | 7 +- vendor/brave-ios/Ledger/BATBraveLedger.mm | 5 +- 18 files changed, 409 insertions(+), 21 deletions(-) create mode 100644 vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter.cc create mode 100644 vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter.h create mode 100644 vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter_endpoint.cc create mode 100644 vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter_endpoint.h diff --git a/components/brave_rewards/browser/rewards_service.cc b/components/brave_rewards/browser/rewards_service.cc index 417feee1c791..331028a5f329 100644 --- a/components/brave_rewards/browser/rewards_service.cc +++ b/components/brave_rewards/browser/rewards_service.cc @@ -92,6 +92,7 @@ void RewardsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { registry->RegisterStringPref(prefs::kParametersMonthlyTipChoices, ""); registry->RegisterBooleanPref(prefs::kFetchOldBalance, true); registry->RegisterBooleanPref(prefs::kEmptyBalanceChecked, false); + registry->RegisterBooleanPref(prefs::kBAPReported, false); registry->RegisterStringPref(prefs::kWalletBrave, ""); registry->RegisterStringPref(prefs::kWalletUphold, ""); } diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 269622c09f18..a4c84069c003 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -1498,6 +1498,9 @@ bool RewardsServiceImpl::GetBooleanOption(const std::string& name) const { return false; } + if (name == ledger::option::kShouldReportBAPAmount) + return OnlyAnonWallet(); + const auto it = kBoolOptions.find(name); DCHECK(it != kBoolOptions.end()); diff --git a/components/brave_rewards/browser/test/common/rewards_browsertest_response.cc b/components/brave_rewards/browser/test/common/rewards_browsertest_response.cc index f7fcefcf6eb6..3aff69ee3668 100644 --- a/components/brave_rewards/browser/test/common/rewards_browsertest_response.cc +++ b/components/brave_rewards/browser/test/common/rewards_browsertest_response.cc @@ -258,6 +258,12 @@ void RewardsBrowserTestResponse::Get( return; } + if (url.find("/v1/promotions/report-bap") != std::string::npos) { + *response = ""; + *response_status_code = net::HTTP_OK; + return; + } + if (url.find("/v1/captchas") != std::string::npos) { *response = captcha_; } diff --git a/components/brave_rewards/browser/test/rewards_browsertest.cc b/components/brave_rewards/browser/test/rewards_browsertest.cc index bc4043130872..0bb3227b6552 100644 --- a/components/brave_rewards/browser/test/rewards_browsertest.cc +++ b/components/brave_rewards/browser/test/rewards_browsertest.cc @@ -22,6 +22,7 @@ #include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_promotion.h" #include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_response.h" #include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_util.h" +#include "brave/components/brave_rewards/common/pref_names.h" #include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/testing_profile.h" @@ -522,4 +523,36 @@ IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, BAPPopup) { EXPECT_TRUE(popup_shown); } +IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, BAPReporting) { + rewards_browsertest_util::StartProcess(rewards_service_); + rewards_browsertest_util::CreateWallet(rewards_service_); + rewards_service_->FetchPromotions(); + promotion_->WaitForPromotionInitialization(); + promotion_->ClaimPromotionViaCode(); + + rewards_browsertest_util::WaitForLedgerStop(rewards_service_); + + rewards_browsertest_util::StartProcess(rewards_service_); + auto* prefs = browser()->profile()->GetPrefs(); + rewards_browsertest_util::WaitForLedgerStop(rewards_service_); + + EXPECT_FALSE(prefs->GetBoolean(brave_rewards::prefs::kBAPReported)); + + prefs->SetInteger(country_codes::kCountryIDAtInstall, 19024); + + base::RunLoop run_loop; + PrefChangeRegistrar prefs_listener; + prefs_listener.Init(browser()->profile()->GetPrefs()); + prefs_listener.Add(brave_rewards::prefs::kBAPReported, + base::BindLambdaForTesting( + [&run_loop](const std::string&) { run_loop.Quit(); })); + + // Start the ledger process and wait for pref to be set, indicating that the + // reporting completed successfully. + rewards_browsertest_util::StartProcess(rewards_service_); + run_loop.Run(); + + EXPECT_TRUE(prefs->GetBoolean(brave_rewards::prefs::kBAPReported)); +} + } // namespace rewards_browsertest diff --git a/components/brave_rewards/common/pref_names.cc b/components/brave_rewards/common/pref_names.cc index 99fb6c9510e2..eaa767795f72 100644 --- a/components/brave_rewards/common/pref_names.cc +++ b/components/brave_rewards/common/pref_names.cc @@ -64,6 +64,7 @@ const char kFetchOldBalance[] = "brave.rewards.fetch_old_balance"; const char kEmptyBalanceChecked[] = "brave.rewards.empty_balance_checked"; +const char kBAPReported[] = "brave.rewards.bap_reported"; const char kWalletBrave[] = "brave.rewards.wallets.brave"; const char kWalletUphold[] = diff --git a/components/brave_rewards/common/pref_names.h b/components/brave_rewards/common/pref_names.h index a4884f1eae2f..d6e5e164ab9a 100644 --- a/components/brave_rewards/common/pref_names.h +++ b/components/brave_rewards/common/pref_names.h @@ -52,6 +52,7 @@ extern const char kParametersTipChoices[]; extern const char kParametersMonthlyTipChoices[]; extern const char kFetchOldBalance[]; extern const char kEmptyBalanceChecked[]; +extern const char kBAPReported[]; extern const char kWalletBrave[]; extern const char kWalletUphold[]; diff --git a/vendor/bat-native-ledger/BUILD.gn b/vendor/bat-native-ledger/BUILD.gn index 9dadd0b4e832..6829a323ce40 100644 --- a/vendor/bat-native-ledger/BUILD.gn +++ b/vendor/bat-native-ledger/BUILD.gn @@ -387,6 +387,10 @@ source_set("ledger") { "src/bat/ledger/internal/logging/logging.h", "src/bat/ledger/internal/logging/logging_util.cc", "src/bat/ledger/internal/logging/logging_util.h", + "src/bat/ledger/internal/promotion/bap_reporter.cc", + "src/bat/ledger/internal/promotion/bap_reporter.h", + "src/bat/ledger/internal/promotion/bap_reporter_endpoint.cc", + "src/bat/ledger/internal/promotion/bap_reporter_endpoint.h", "src/bat/ledger/internal/promotion/promotion.cc", "src/bat/ledger/internal/promotion/promotion.h", "src/bat/ledger/internal/promotion/promotion_transfer.cc", diff --git a/vendor/bat-native-ledger/include/bat/ledger/option_keys.h b/vendor/bat-native-ledger/include/bat/ledger/option_keys.h index 1c7fb87bb095..b65bb814d8e0 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/option_keys.h +++ b/vendor/bat-native-ledger/include/bat/ledger/option_keys.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVELEDGER_OPTION_KEYS_H_ -#define BRAVELEDGER_OPTION_KEYS_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_INCLUDE_BAT_LEDGER_OPTION_KEYS_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_INCLUDE_BAT_LEDGER_OPTION_KEYS_H_ #include @@ -15,8 +15,9 @@ const char kPublisherListRefreshInterval[] = "publisher_list_refresh_interval"; const char kClaimUGP[] = "claim_ugp"; const char kContributionsDisabledForBAPMigration[] = "contributions_disabled_for_bap_migration"; +const char kShouldReportBAPAmount[] = "should_report_bap"; } // namespace option } // namespace ledger -#endif // BRAVELEDGER_OPTION_KEYS_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_INCLUDE_BAT_LEDGER_OPTION_KEYS_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter.cc new file mode 100644 index 000000000000..25cb19b71d75 --- /dev/null +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter.cc @@ -0,0 +1,115 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/ledger/internal/promotion/bap_reporter.h" + +#include "base/time/time.h" +#include "bat/ledger/global_constants.h" +#include "bat/ledger/internal/common/time_util.h" +#include "bat/ledger/internal/ledger_impl.h" +#include "bat/ledger/option_keys.h" + +using std::placeholders::_1; +using std::placeholders::_2; + +namespace ledger { +namespace promotion { + +namespace { + +constexpr int64_t kRetryDelay = 24 * base::Time::kSecondsPerHour; +constexpr int64_t kRetryAfterFailureDelay = 10 * base::Time::kSecondsPerMinute; +constexpr int64_t kMaxRetryAfterFailureDelay = 4 * base::Time::kSecondsPerHour; + +} // namespace + +BAPReporter::BAPReporter(LedgerImpl* ledger) + : ledger_(ledger), endpoint_(ledger) { + DCHECK(ledger); +} + +BAPReporter::~BAPReporter() = default; + +void BAPReporter::ReportBAPAmount() { + if (running_) + return; + + timer_.Stop(); + + bool should_report = ledger_->ledger_client()->GetBooleanOption( + option::kShouldReportBAPAmount); + + // Only run this reporter if the user is in a BAP region and we haven't + // successfully reported yet. + if (!should_report || ledger_->state()->GetBAPReported()) + return; + + running_ = true; + + // First, get the user's unspent BAP tokens. + ledger_->database()->GetSpendableUnblindedTokensByBatchTypes( + {type::CredsBatchType::PROMOTION}, + std::bind(&BAPReporter::OnUnblindedTokens, this, _1)); +} + +void BAPReporter::OnUnblindedTokens( + std::vector tokens) { + double amount = 0; + for (const auto& token : tokens) + amount += token->value; + + // If the user has no BAP, then schedule a retry and exit. + if (amount <= 0) { + ScheduleRetryAfterZeroBalance(); + return; + } + + // Send the amount to the server. + endpoint_.Request(amount, + std::bind(&BAPReporter::OnEndpointResponse, this, _1)); +} + +void BAPReporter::OnEndpointResponse(bool success) { + // If the server reported an error, assume a temporary problem and try again + // later. + if (!success) { + ScheduleRetryAfterFailure(); + return; + } + + BLOG(1, "BAP successsfully reported"); + + // Set a flag to indicate that we don't need to report again. + ledger_->state()->SetBAPReported(true); + running_ = false; + retry_count_ = 0; +} + +void BAPReporter::ScheduleRetryAfterZeroBalance() { + running_ = false; + + base::TimeDelta delay = base::TimeDelta::FromSeconds(kRetryDelay); + + BLOG(1, "User has zero balance - rescheduling BAP reporting in " << delay); + timer_.Start( + FROM_HERE, delay, + base::BindOnce(&BAPReporter::ReportBAPAmount, base::Unretained(this))); +} + +void BAPReporter::ScheduleRetryAfterFailure() { + running_ = false; + + base::TimeDelta delay = util::GetRandomizedDelayWithBackoff( + base::TimeDelta::FromSeconds(kRetryAfterFailureDelay), + base::TimeDelta::FromSeconds(kMaxRetryAfterFailureDelay), retry_count_++); + + BLOG(1, "BAP reporting failed - rescheduling in " << delay); + timer_.Start( + FROM_HERE, delay, + base::BindOnce(&BAPReporter::ReportBAPAmount, base::Unretained(this))); +} + +} // namespace promotion +} // namespace ledger diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter.h b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter.h new file mode 100644 index 000000000000..715002ebefed --- /dev/null +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_BAP_REPORTER_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_BAP_REPORTER_H_ + +#include +#include + +#include "base/timer/timer.h" +#include "bat/ledger/internal/promotion/bap_reporter_endpoint.h" +#include "bat/ledger/ledger.h" + +namespace ledger { + +class LedgerImpl; + +namespace promotion { + +class BAPReporter { + public: + explicit BAPReporter(LedgerImpl* ledger); + + BAPReporter(const BAPReporter&) = delete; + BAPReporter& operator=(const BAPReporter&) = delete; + + ~BAPReporter(); + + void ReportBAPAmount(); + + private: + void OnUnblindedTokens(std::vector tokens); + void OnEndpointResponse(bool success); + void ScheduleRetryAfterZeroBalance(); + void ScheduleRetryAfterFailure(); + + LedgerImpl* ledger_; + bool running_ = false; + int retry_count_ = 0; + base::OneShotTimer timer_; + BAPReporterEndpoint endpoint_; +}; + +} // namespace promotion +} // namespace ledger + +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_BAP_REPORTER_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter_endpoint.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter_endpoint.cc new file mode 100644 index 000000000000..a0be27170cda --- /dev/null +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter_endpoint.cc @@ -0,0 +1,92 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/ledger/internal/promotion/bap_reporter_endpoint.h" + +#include +#include +#include + +#include "base/json/json_writer.h" +#include "bat/ledger/internal/common/request_util.h" +#include "bat/ledger/internal/endpoint/promotion/promotions_util.h" +#include "bat/ledger/internal/ledger_impl.h" +#include "net/http/http_status_code.h" + +using std::placeholders::_1; + +namespace ledger { +namespace promotion { + +namespace { + +const char kEndpointPath[] = "/v1/promotions/report-bap"; + +} // namespace + +BAPReporterEndpoint::BAPReporterEndpoint(LedgerImpl* ledger) : ledger_(ledger) { + DCHECK(ledger_); +} + +BAPReporterEndpoint::~BAPReporterEndpoint() = default; + +void BAPReporterEndpoint::Request(double amount, Callback callback) { + const auto wallet = ledger_->wallet()->GetWallet(); + if (!wallet) { + BLOG(0, "Wallet is null"); + callback(false); + return; + } + + base::Value body(base::Value::Type::DICTIONARY); + body.SetDoubleKey("amount", amount); + std::string payload; + base::JSONWriter::Write(body, &payload); + + const std::string sign_url = std::string("post ") + kEndpointPath; + auto headers = util::BuildSignHeaders(sign_url, payload, wallet->payment_id, + wallet->recovery_seed); + + auto request = type::UrlRequest::New(); + request->url = endpoint::promotion::GetServerUrl(kEndpointPath); + request->headers = std::move(headers); + request->content = std::move(payload); + request->content_type = "application/json; charset=utf-8"; + request->method = type::UrlMethod::POST; + ledger_->LoadURL( + std::move(request), + std::bind(&BAPReporterEndpoint::OnFetchCompleted, this, callback, _1)); +} + +void BAPReporterEndpoint::OnFetchCompleted(Callback callback, + const type::UrlResponse& response) { + ledger::LogUrlResponse(__func__, response); + + bool success = false; + switch (response.status_code) { + case net::HTTP_BAD_REQUEST: { + BLOG(0, "Invalid request"); + break; + } + case net::HTTP_INTERNAL_SERVER_ERROR: { + BLOG(0, "Internal server error"); + break; + } + case net::HTTP_OK: + case net::HTTP_CONFLICT: { + success = true; + break; + } + default: { + BLOG(0, "Unexpected reponse code " << response.status_code); + break; + } + } + + callback(success); +} + +} // namespace promotion +} // namespace ledger diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter_endpoint.h b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter_endpoint.h new file mode 100644 index 000000000000..222193eaa5e6 --- /dev/null +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/bap_reporter_endpoint.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_BAP_REPORTER_ENDPOINT_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_BAP_REPORTER_ENDPOINT_H_ + +#include + +#include "base/values.h" +#include "bat/ledger/ledger.h" + +// POST /v1/promotions/report-bap +// +// Request body: +// { +// "amount": +// } +// +// Success code: +// HTTP_OK (200) +// +// Error Codes: +// HTTP_BAD_REQUEST (400) +// HTTP_CONFLICT (409) Endpoint already called for this payment ID +// HTTP_INTERNAL_SERVER_ERROR (500) +// +// Response body: +// { +// "reportBapId": +// } + +namespace ledger { + +class LedgerImpl; + +namespace promotion { + +class BAPReporterEndpoint { + public: + explicit BAPReporterEndpoint(LedgerImpl* ledger); + ~BAPReporterEndpoint(); + + using Callback = std::function; + void Request(double amount, Callback callback); + + private: + void OnFetchCompleted(Callback callback, const type::UrlResponse& response); + + LedgerImpl* ledger_; // NOT OWNED +}; + +} // namespace promotion +} // namespace ledger + +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_BAP_REPORTER_ENDPOINT_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion.cc index 9e39af56c20f..da23d5411565 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion.cc @@ -18,6 +18,7 @@ #include "bat/ledger/internal/credentials/credentials_util.h" #include "bat/ledger/internal/ledger_impl.h" #include "bat/ledger/internal/legacy/wallet_info_properties.h" +#include "bat/ledger/internal/promotion/bap_reporter.h" #include "bat/ledger/internal/promotion/promotion_transfer.h" #include "bat/ledger/internal/promotion/promotion_util.h" #include "bat/ledger/option_keys.h" @@ -74,13 +75,13 @@ void HandleExpiredPromotions( } // namespace -Promotion::Promotion(LedgerImpl* ledger) : - attestation_(std::make_unique - (ledger)), - transfer_(std::make_unique(ledger)), - promotion_server_( - std::make_unique(ledger)), - ledger_(ledger) { +Promotion::Promotion(LedgerImpl* ledger) + : attestation_( + std::make_unique(ledger)), + transfer_(std::make_unique(ledger)), + bap_reporter_(std::make_unique(ledger)), + promotion_server_(std::make_unique(ledger)), + ledger_(ledger) { DCHECK(ledger_); credentials_ = credential::CredentialsFactory::Create( ledger_, @@ -100,6 +101,8 @@ void Promotion::Initialize() { ledger_->database()->GetAllPromotions(check_callback); } + bap_reporter_->ReportBAPAmount(); + auto retry_callback = std::bind(&Promotion::Retry, this, _1); @@ -115,6 +118,12 @@ void Promotion::Fetch(ledger::FetchPromotionCallback callback) { return; } + if (ledger_->state()->GetBAPReported()) { + BLOG(1, "Fetch promotions disabled after BAP reporting"); + callback(type::Result::LEDGER_OK, {}); + return; + } + // If we fetched promotions recently, fulfill this request from the // database instead of querying the server again if (!ledger::is_testing) { diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion.h b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion.h index 6c8170c94559..a529a1b0d147 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVELEDGER_PROMOTION_H_ -#define BRAVELEDGER_PROMOTION_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_PROMOTION_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_PROMOTION_H_ #include #include @@ -24,6 +24,7 @@ class LedgerImpl; namespace promotion { class PromotionTransfer; +class BAPReporter; class Promotion { public: @@ -146,6 +147,7 @@ class Promotion { std::unique_ptr attestation_; std::unique_ptr transfer_; + std::unique_ptr bap_reporter_; std::unique_ptr credentials_; std::unique_ptr promotion_server_; LedgerImpl* ledger_; // NOT OWNED @@ -156,4 +158,4 @@ class Promotion { } // namespace promotion } // namespace ledger -#endif // BRAVELEDGER_PROMOTION_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_PROMOTION_PROMOTION_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state.cc index c602b480ec01..debfd89309ea 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state.cc @@ -367,5 +367,14 @@ bool State::GetAnonTransferChecked() { return ledger_->ledger_client()->GetBooleanState(kAnonTransferChecked); } +bool State::GetBAPReported() { + return ledger_->ledger_client()->GetBooleanState(kBAPReported); +} + +void State::SetBAPReported(bool bap_reported) { + ledger_->database()->SaveEventLog(kBAPReported, std::to_string(bap_reported)); + return ledger_->ledger_client()->SetBooleanState(kBAPReported, bap_reported); +} + } // namespace state } // namespace ledger diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state.h b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state.h index 68faeb05c461..3d138f3d2e51 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVELEDGER_BAT_STATE_STATE_H_ -#define BRAVELEDGER_BAT_STATE_STATE_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_STATE_STATE_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_STATE_STATE_H_ #include #include @@ -111,6 +111,9 @@ class State { bool GetAnonTransferChecked(); + bool GetBAPReported(); + void SetBAPReported(bool bap_reported); + private: LedgerImpl* ledger_; // NOT OWNED std::unique_ptr migration_; @@ -119,4 +122,4 @@ class State { } // namespace state } // namespace ledger -#endif // BRAVELEDGER_BAT_STATE_STATE_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_STATE_STATE_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_keys.h b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_keys.h index faefc3617a44..29c88e5d3212 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_keys.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_keys.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVELEDGER_STATE_STATE_KEYS_H_ -#define BRAVELEDGER_STATE_STATE_KEYS_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_STATE_STATE_KEYS_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_STATE_STATE_KEYS_H_ #include @@ -41,10 +41,11 @@ const char kParametersMonthlyTipChoices[] = "parameters.tip.monthly_choices"; const char kFetchOldBalance[] = "fetch_old_balance"; const char kEmptyBalanceChecked[] = "empty_balance_checked"; +const char kBAPReported[] = "bap_reported"; const char kWalletBrave[] ="wallets.brave"; const char kWalletUphold[] = "wallets.uphold"; } // namespace state } // namespace ledger -#endif // BRAVELEDGER_STATE_STATE_KEYS_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_STATE_STATE_KEYS_H_ diff --git a/vendor/brave-ios/Ledger/BATBraveLedger.mm b/vendor/brave-ios/Ledger/BATBraveLedger.mm index e94704fd05b4..e2f7edfcfceb 100644 --- a/vendor/brave-ios/Ledger/BATBraveLedger.mm +++ b/vendor/brave-ios/Ledger/BATBraveLedger.mm @@ -76,8 +76,9 @@ + (void)__objc_setter:(__type)newValue { ledger::__cpp_var = newValue; } /// Ledger Prefs, keys will be defined in `bat/ledger/option_keys.h` const std::map kBoolOptions = { - {ledger::option::kClaimUGP, true} -}; + {ledger::option::kClaimUGP, true}, + {ledger::option::kContributionsDisabledForBAPMigration, false}, + {ledger::option::kShouldReportBAPAmount, false}}; const std::map kIntegerOptions = {}; const std::map kDoubleOptions = {}; const std::map kStringOptions = {};