From 409bce616dd60f910940fc37ed3f54181801a495 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Thu, 14 Mar 2019 03:41:32 +0000 Subject: [PATCH] Change payment token redemption timing --- .../browser/rewards_service_browsertest.cc | 45 ++++++++++++- .../browser/rewards_service_impl.cc | 20 ++++++ .../browser/rewards_service_impl.h | 3 + .../bat_ledger/bat_ledger_service_impl.cc | 13 ++++ .../bat_ledger/bat_ledger_service_impl.h | 59 +++++++++-------- .../public/interfaces/bat_ledger.mojom | 2 + vendor/bat-native-confirmations/BUILD.gn | 2 + vendor/bat-native-confirmations/README.md | 6 ++ .../include/bat/confirmations/confirmations.h | 3 + .../src/bat/confirmations/confirmations.cc | 1 + .../internal/confirmations_impl.cc | 65 +++++++++++++++++-- .../internal/confirmations_impl.h | 3 + .../confirmations/internal/payout_tokens.cc | 15 ++--- .../confirmations/internal/payout_tokens.h | 1 - .../confirmations/internal/static_values.h | 7 +- .../src/bat/confirmations/internal/time.cc | 17 +++++ .../src/bat/confirmations/internal/time.h | 20 ++++++ .../include/bat/ledger/ledger.h | 1 + .../src/bat/ledger/internal/ledger_impl.cc | 1 + .../src/bat/ledger/ledger.cc | 1 + 20 files changed, 236 insertions(+), 49 deletions(-) create mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/time.cc create mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/time.h diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index 3c59f4dbf8e5..29663e6802f5 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -383,6 +383,41 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { GetProduction(); RunUntilIdle(); + // SetDebug(true) + EXPECT_CALL(*this, OnGetDebug(true)); + // Debug - true and 1 + EXPECT_CALL(*this, OnGetDebug(false)).Times(2); + // Debug - false and random + EXPECT_CALL(*this, OnGetDebug(true)).Times(2); + + rewards_service()->SetDebug(true); + GetDebug(); + RunUntilIdle(); + + // Debug - true + rewards_service()->SetDebug(true); + rewards_service()->HandleFlags("debug=true"); + GetDebug(); + RunUntilIdle(); + + // Debug - 1 + rewards_service()->SetDebug(true); + rewards_service()->HandleFlags("debug=1"); + GetDebug(); + RunUntilIdle(); + + // Debug - false + rewards_service()->SetDebug(false); + rewards_service()->HandleFlags("debug=false"); + GetDebug(); + RunUntilIdle(); + + // Debug - random + rewards_service()->SetDebug(false); + rewards_service()->HandleFlags("debug=werwe"); + GetDebug(); + RunUntilIdle(); + // positive number EXPECT_CALL(*this, OnGetReconcileTime(10)); // negative number and string @@ -424,36 +459,42 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsMultipleFlags) { EXPECT_CALL(*this, OnGetProduction(false)); + EXPECT_CALL(*this, OnGetDebug(false)); EXPECT_CALL(*this, OnGetReconcileTime(10)); EXPECT_CALL(*this, OnGetShortRetries(true)); rewards_service()->SetProduction(true); + rewards_service()->SetDebug(true); rewards_service()->SetReconcileTime(0); rewards_service()->SetShortRetries(false); rewards_service()->HandleFlags( - "staging=true,short-retries=true,reconcile-interval=10"); + "staging=true,debug=true,short-retries=true,reconcile-interval=10"); GetReconcileTime(); GetShortRetries(); GetProduction(); + GetDebug(); RunUntilIdle(); } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsWrongInput) { EXPECT_CALL(*this, OnGetProduction(true)); + EXPECT_CALL(*this, OnGetDebug(true)); EXPECT_CALL(*this, OnGetReconcileTime(0)); EXPECT_CALL(*this, OnGetShortRetries(false)); rewards_service()->SetProduction(true); + rewards_service()->SetDebug(true); rewards_service()->SetReconcileTime(0); rewards_service()->SetShortRetries(false); rewards_service()->HandleFlags( - "staging=,shortretries=true,reconcile-interval"); + "staging=,debug=,shortretries=true,reconcile-interval"); GetReconcileTime(); GetShortRetries(); GetProduction(); + GetDebug(); RunUntilIdle(); } diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 5f5b9270b7e5..495b4bcdf10d 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -401,6 +401,8 @@ void RewardsServiceImpl::StartLedger() { #endif SetProduction(isProduction); + SetDebug(false); + const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); @@ -2448,6 +2450,20 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) { continue; } + if (name == "debug") { + bool is_debug; + std::string lower = base::ToLowerASCII(value); + + if (lower == "true" || lower == "1") { + is_debug = true; + } else { + is_debug = false; + } + + SetDebug(is_debug); + continue; + } + if (name == "reconcile-interval") { int reconcile_int; bool success = base::StringToInt(value, &reconcile_int); @@ -2552,6 +2568,10 @@ void RewardsServiceImpl::SetProduction(bool production) { bat_ledger_service_->SetProduction(production); } +void RewardsServiceImpl::SetDebug(bool debug) { + bat_ledger_service_->SetDebug(debug); +} + void RewardsServiceImpl::SetReconcileTime(int32_t time) { bat_ledger_service_->SetReconcileTime(time); } diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index 2b8012c4bc4d..ab1d81e83098 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -66,6 +66,7 @@ class PublisherInfoDatabase; class RewardsNotificationServiceImpl; using GetProductionCallback = base::Callback; +using GetDebugCallback = base::Callback; using GetReconcileTimeCallback = base::Callback; using GetShortRetriesCallback = base::Callback; @@ -174,6 +175,8 @@ class RewardsServiceImpl : public RewardsService, void HandleFlags(const std::string& options); void SetProduction(bool production); void GetProduction(const GetProductionCallback& callback); + void SetDebug(bool debug); + void GetDebug(const GetDebugCallback& callback); void SetReconcileTime(int32_t time); void GetReconcileTime(const GetReconcileTimeCallback& callback); void SetShortRetries(bool short_retries); diff --git a/components/services/bat_ledger/bat_ledger_service_impl.cc b/components/services/bat_ledger/bat_ledger_service_impl.cc index 96fed480ec0c..009c65d236db 100644 --- a/components/services/bat_ledger/bat_ledger_service_impl.cc +++ b/components/services/bat_ledger/bat_ledger_service_impl.cc @@ -17,6 +17,10 @@ bool testing() { return ledger::is_testing; } +bool debug() { + return ledger::is_debug; +} + } namespace bat_ledger { @@ -44,6 +48,11 @@ void BatLedgerServiceImpl::SetProduction(bool is_production) { ledger::is_production = is_production; } +void BatLedgerServiceImpl::SetDebug(bool is_debug) { + DCHECK(!initialized_ || debug()); + ledger::is_debug = is_debug; +} + void BatLedgerServiceImpl::SetReconcileTime(int32_t time) { DCHECK(!initialized_ || testing()); ledger::reconcile_time = time; @@ -62,6 +71,10 @@ void BatLedgerServiceImpl::GetProduction(GetProductionCallback callback) { std::move(callback).Run(ledger::is_production); } +void BatLedgerServiceImpl::GetDebug(GetDebugCallback callback) { + std::move(callback).Run(ledger::is_debug); +} + void BatLedgerServiceImpl::GetReconcileTime(GetReconcileTimeCallback callback) { std::move(callback).Run(ledger::reconcile_time); } diff --git a/components/services/bat_ledger/bat_ledger_service_impl.h b/components/services/bat_ledger/bat_ledger_service_impl.h index 08e93fdb0e16..298006690acd 100644 --- a/components/services/bat_ledger/bat_ledger_service_impl.h +++ b/components/services/bat_ledger/bat_ledger_service_impl.h @@ -1,9 +1,10 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 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_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ -#define BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ +#ifndef COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ +#define COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ #include @@ -13,31 +14,33 @@ namespace bat_ledger { class BatLedgerServiceImpl : public mojom::BatLedgerService { - public: - explicit BatLedgerServiceImpl( - std::unique_ptr service_ref); - ~BatLedgerServiceImpl() override; - - // bat_ledger::mojom::BatLedgerService - void Create(mojom::BatLedgerClientAssociatedPtrInfo client_info, - mojom::BatLedgerAssociatedRequest bat_ledger) override; - - void SetProduction(bool isProduction) override; - void SetReconcileTime(int32_t time) override; - void SetShortRetries(bool short_retries) override; - void SetTesting() override; - - void GetProduction(GetProductionCallback callback) override; - void GetReconcileTime(GetReconcileTimeCallback callback) override; - void GetShortRetries(GetShortRetriesCallback callback) override; - - private: - const std::unique_ptr service_ref_; - bool initialized_; - - DISALLOW_COPY_AND_ASSIGN(BatLedgerServiceImpl); + public: + explicit BatLedgerServiceImpl( + std::unique_ptr service_ref); + ~BatLedgerServiceImpl() override; + + // bat_ledger::mojom::BatLedgerService + void Create(mojom::BatLedgerClientAssociatedPtrInfo client_info, + mojom::BatLedgerAssociatedRequest bat_ledger) override; + + void SetProduction(bool isProduction) override; + void SetDebug(bool isDebug) override; + void SetReconcileTime(int32_t time) override; + void SetShortRetries(bool short_retries) override; + void SetTesting() override; + + void GetProduction(GetProductionCallback callback) override; + void GetDebug(GetDebugCallback callback) override; + void GetReconcileTime(GetReconcileTimeCallback callback) override; + void GetShortRetries(GetShortRetriesCallback callback) override; + + private: + const std::unique_ptr service_ref_; + bool initialized_; + + DISALLOW_COPY_AND_ASSIGN(BatLedgerServiceImpl); }; -} // namespace bat_ledger +} // namespace bat_ledger -#endif // BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ +#endif // COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ diff --git a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom index 3f64d50f429e..932ade284f1a 100644 --- a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom +++ b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom @@ -9,11 +9,13 @@ interface BatLedgerService { Create(associated BatLedgerClient bat_ledger_client, associated BatLedger& bat_ledger); SetProduction(bool isProduction); + SetDebug(bool isDebug); SetReconcileTime(int32 time); SetShortRetries(bool short_retries); SetTesting(); GetProduction() => (bool production); + GetDebug() => (bool debug); GetReconcileTime() => (int32 time); GetShortRetries() => (bool short_retries); }; diff --git a/vendor/bat-native-confirmations/BUILD.gn b/vendor/bat-native-confirmations/BUILD.gn index e98230594957..4e6a570c044a 100644 --- a/vendor/bat-native-confirmations/BUILD.gn +++ b/vendor/bat-native-confirmations/BUILD.gn @@ -74,6 +74,8 @@ source_set("bat-native-confirmations") { "src/bat/confirmations/internal/security_helper.h", "src/bat/confirmations/internal/string_helper.cc", "src/bat/confirmations/internal/string_helper.h", + "src/bat/confirmations/internal/time.cc", + "src/bat/confirmations/internal/time.h", "src/bat/confirmations/internal/token_info.cc", "src/bat/confirmations/internal/token_info.h", "src/bat/confirmations/internal/unblinded_tokens.cc", diff --git a/vendor/bat-native-confirmations/README.md b/vendor/bat-native-confirmations/README.md index bd81cad4d7d1..297ca2608c07 100644 --- a/vendor/bat-native-confirmations/README.md +++ b/vendor/bat-native-confirmations/README.md @@ -131,6 +131,12 @@ Use staging Ads Serve as defined by `STAGING_SERVER` in `static_values.h`. Defau --rewards=staging=true ``` +Use shorter timers to help with testing token redemption as defined by `kDebugNextTokenRedemptionAfterSeconds` in `static_values.h`. + +``` +--rewards=debug=true +``` + Enable diagnostic logging, where `#` should set to a minimum log level. Valid values are from 0 to 3 where INFO = 0, WARNING = 1, ERROR = 2 and FATAL = 3. So if you want INFO, WARNING and ERROR you would choose 2 ``` diff --git a/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h b/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h index aa8ea66cc14f..b7c93ce991ce 100644 --- a/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h +++ b/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h @@ -23,6 +23,9 @@ namespace confirmations { // Determines whether to use the staging or production Ad Serve extern bool _is_production; +// Determines whether to enable or disable debugging +extern bool _is_debug; + extern const char _confirmations_name[]; using TransactionInfo = ::ledger::TransactionInfo; diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc b/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc index abef0178bbac..76476cb16495 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc @@ -10,6 +10,7 @@ namespace confirmations { bool _is_production = false; +bool _is_debug = false; const char _confirmations_name[] = "confirmations.json"; diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.cc index 474bd903d5e2..b9f241230aeb 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.cc @@ -14,7 +14,9 @@ #include "bat/confirmations/internal/redeem_token.h" #include "bat/confirmations/internal/payout_tokens.h" #include "bat/confirmations/internal/unblinded_tokens.h" +#include "bat/confirmations/internal/time.h" +#include "base/rand_util.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/time/time.h" @@ -39,6 +41,7 @@ ConfirmationsImpl::ConfirmationsImpl( payout_redeemed_tokens_timer_id_(0), payout_tokens_(std::make_unique(this, confirmations_client, unblinded_payment_tokens_.get())), + next_token_redemption_date_in_seconds_(0), state_has_loaded_(false), confirmations_client_(confirmations_client) { } @@ -76,7 +79,9 @@ void ConfirmationsImpl::CheckReady() { is_initialized_ = true; BLOG(INFO) << "Successfully initialized"; - PayoutRedeemedTokens(); + auto start_timer_in = CalculateTokenRedemptionTimeInSeconds(); + StartPayingOutRedeemedTokens(start_timer_in); + RefillTokensIfNecessary(); } @@ -93,6 +98,10 @@ std::string ConfirmationsImpl::ToJSON() const { GetCatalogIssuersAsDictionary(public_key_, catalog_issuers_); dictionary.SetKey("catalog_issuers", base::Value(std::move(catalog_issuers))); + // Next token redemption date + dictionary.SetKey("next_token_redemption_date_in_seconds", base::Value( + std::to_string(next_token_redemption_date_in_seconds_))); + // Transaction history auto transaction_history = GetTransactionHistoryAsDictionary(transaction_history_); @@ -189,6 +198,17 @@ bool ConfirmationsImpl::FromJSON(const std::string& json) { return false; } + // Next token redemption date + auto* next_token_redemption_date_in_seconds_value = + dictionary->FindKey("next_token_redemption_date_in_seconds"); + if (next_token_redemption_date_in_seconds_value) { + next_token_redemption_date_in_seconds_ = + std::stoull(next_token_redemption_date_in_seconds_value->GetString()); + } else { + // Initial token redemption date + UpdateNextTokenRedemptionDate(); + } + // Transaction history auto* transaction_history_value = dictionary->FindKey("transaction_history"); if (!transaction_history_value) { @@ -502,11 +522,8 @@ double ConfirmationsImpl::GetEstimatedRedemptionValue( void ConfirmationsImpl::AppendTransactionToTransactionHistory( const double estimated_redemption_value, const ConfirmationType confirmation_type) { - auto now = base::Time::Now(); - auto now_in_seconds = (now - base::Time()).InSeconds(); - TransactionInfo info; - info.timestamp_in_seconds = now_in_seconds; + info.timestamp_in_seconds = Time::NowInSeconds(); info.estimated_redemption_value = estimated_redemption_value; switch (confirmation_type) { @@ -605,6 +622,44 @@ void ConfirmationsImpl::RefillTokensIfNecessary() const { refill_tokens_->Refill(wallet_info_, public_key_); } +uint64_t ConfirmationsImpl::CalculateTokenRedemptionTimeInSeconds() { + auto now_in_seconds = Time::NowInSeconds(); + + uint64_t start_timer_in; + + if (_is_debug) { + if (now_in_seconds - next_token_redemption_date_in_seconds_ >= + kDebugNextTokenRedemptionAfterSeconds) { + UpdateNextTokenRedemptionDate(); + SaveState(); + } + } + + if (now_in_seconds >= next_token_redemption_date_in_seconds_) { + // Browser was launched after the token redemption date + start_timer_in = base::RandInt(0, 5 * base::Time::kSecondsPerMinute); + } else { + start_timer_in = next_token_redemption_date_in_seconds_ - now_in_seconds; + } + + auto rand_delay = base::RandInt(0, start_timer_in / 10); + start_timer_in += rand_delay; + + return start_timer_in; +} + +void ConfirmationsImpl::UpdateNextTokenRedemptionDate() { + next_token_redemption_date_in_seconds_ = Time::NowInSeconds(); + + if (!_is_debug) { + next_token_redemption_date_in_seconds_ += + kNextTokenRedemptionAfterSeconds; + } else { + next_token_redemption_date_in_seconds_ += + kDebugNextTokenRedemptionAfterSeconds; + } +} + void ConfirmationsImpl::StartPayingOutRedeemedTokens( const uint64_t start_timer_in) { StopPayingOutRedeemedTokens(); diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.h index 6c773c31439b..e7ad33c1b6f8 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmations_impl.h @@ -62,6 +62,8 @@ class ConfirmationsImpl : public Confirmations { void ConfirmAd(std::unique_ptr info) override; // Payout redeemed tokens + void UpdateNextTokenRedemptionDate(); + uint64_t CalculateTokenRedemptionTimeInSeconds(); void StartPayingOutRedeemedTokens(const uint64_t start_timer_in); // State @@ -103,6 +105,7 @@ class ConfirmationsImpl : public Confirmations { void StopPayingOutRedeemedTokens(); bool IsPayingOutRedeemedTokens() const; std::unique_ptr payout_tokens_; + uint64_t next_token_redemption_date_in_seconds_; // State void OnStateSaved(const Result result); diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/payout_tokens.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/payout_tokens.cc index 6b527aceadbf..b2cdb1d9d64c 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/payout_tokens.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/payout_tokens.cc @@ -10,8 +10,6 @@ #include "bat/confirmations/internal/unblinded_tokens.h" #include "bat/confirmations/internal/redeem_payment_tokens_request.h" -#include "base/rand_util.h" - using std::placeholders::_1; using std::placeholders::_2; using std::placeholders::_3; @@ -125,16 +123,11 @@ void PayoutTokens::OnPayout(const Result result) { } void PayoutTokens::ScheduleNextPayout() const { - auto start_timer_in = CalculateTimerForNextPayout(); - confirmations_->StartPayingOutRedeemedTokens(start_timer_in); -} + confirmations_->UpdateNextTokenRedemptionDate(); + confirmations_->SaveState(); -uint64_t PayoutTokens::CalculateTimerForNextPayout() const { - auto start_timer_in = kPayoutAfterSeconds; - auto rand_delay = base::RandInt(0, start_timer_in / 10); - start_timer_in += rand_delay; - - return start_timer_in; + auto start_timer_in = confirmations_->CalculateTokenRedemptionTimeInSeconds(); + confirmations_->StartPayingOutRedeemedTokens(start_timer_in); } } // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/payout_tokens.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/payout_tokens.h index 92ae27625fae..25385d6dd87a 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/payout_tokens.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/payout_tokens.h @@ -42,7 +42,6 @@ class PayoutTokens { void OnPayout(const Result result); void ScheduleNextPayout() const; - uint64_t CalculateTimerForNextPayout() const; ConfirmationsImpl* confirmations_; // NOT OWNED ConfirmationsClient* confirmations_client_; // NOT OWNED diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h index 7eaf379b0b87..3508f7e22d28 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h @@ -20,8 +20,11 @@ static const int kMaximumUnblindedTokens = 50; static const uint64_t kRetryGettingRefillSignedTokensAfterSeconds = 15; -static const uint64_t kPayoutAfterSeconds = - base::Time::kSecondsPerHour * base::Time::kHoursPerDay; +static const uint64_t kNextTokenRedemptionAfterSeconds = + base::Time::kMicrosecondsPerWeek / base::Time::kMicrosecondsPerSecond; + +static const uint64_t kDebugNextTokenRedemptionAfterSeconds = + 25 * base::Time::kSecondsPerMinute; } // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/time.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/time.cc new file mode 100644 index 000000000000..29e5a96e28a3 --- /dev/null +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/time.cc @@ -0,0 +1,17 @@ +/* Copyright (c) 2019 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/confirmations/internal/time.h" + +#include "base/time/time.h" + +namespace confirmations { + +uint64_t Time::NowInSeconds() { + auto now = base::Time::Now(); + return static_cast((now - base::Time()).InSeconds()); +} + +} // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/time.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/time.h new file mode 100644 index 000000000000..b5e420a763df --- /dev/null +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/time.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2019 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 BAT_CONFIRMATIONS_INTERNAL_TIME_H_ +#define BAT_CONFIRMATIONS_INTERNAL_TIME_H_ + +#include + +namespace confirmations { + +class Time { + public: + static uint64_t NowInSeconds(); +}; + +} // namespace confirmations + +#endif // BAT_CONFIRMATIONS_INTERNAL_TIME_H_ diff --git a/vendor/bat-native-ledger/include/bat/ledger/ledger.h b/vendor/bat-native-ledger/include/bat/ledger/ledger.h index d2ecef4a8832..a9f407be34dd 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/ledger.h +++ b/vendor/bat-native-ledger/include/bat/ledger/ledger.h @@ -22,6 +22,7 @@ namespace ledger { extern bool is_production; +extern bool is_debug; extern bool is_testing; extern int reconcile_time; // minutes extern bool short_retries; diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc index 714fe3ea0e13..73d665d8bf30 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc @@ -247,6 +247,7 @@ void LedgerImpl::SetConfirmationsWalletInfo( const braveledger_bat_helper::WALLET_INFO_ST& wallet_info) { if (!bat_confirmations_) { confirmations::_is_production = ledger::is_production; + confirmations::_is_debug = ledger::is_debug; bat_confirmations_.reset( confirmations::Confirmations::CreateInstance(ledger_client_)); diff --git a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc index 85cb17cbdce7..eb117dc66e40 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc @@ -14,6 +14,7 @@ namespace ledger { bool is_production = true; +bool is_debug = false; bool is_testing = false; int reconcile_time = 0; // minutes bool short_retries = false;