From 28876ce201cc5a2ebd5608c99b73dd2f01b52a0a Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Mon, 25 Mar 2019 14:13:01 -0700 Subject: [PATCH 1/2] Revert "Tokens that fail to redeem due to network errors should be added to a queue and retried" This reverts commit 706f67c5a921b1d63cd538ef573d40d564f2bc0d. --- vendor/bat-native-ads/BUILD.gn | 1 - .../include/bat/ads/confirmation_type.h | 37 +- .../src/bat/ads/confirmation_type.cc | 69 --- .../src/bat/ads/internal/ads_impl.cc | 29 +- .../src/bat/ads/notification_info.cc | 40 +- vendor/bat-native-confirmations/BUILD.gn | 4 - .../bat/confirmations/confirmation_type.h | 37 +- .../bat/confirmations/confirmation_type.cc | 69 --- .../internal/confirmation_info.cc | 30 -- .../internal/confirmation_info.h | 37 -- .../internal/confirmations_impl.cc | 408 +++--------------- .../internal/confirmations_impl.h | 27 +- .../internal/create_confirmation_request.cc | 29 +- .../confirmations/internal/redeem_token.cc | 264 +++++------- .../bat/confirmations/internal/redeem_token.h | 28 +- .../confirmations/internal/security_helper.cc | 2 +- .../confirmations/internal/static_values.h | 3 - .../internal/unblinded_tokens.cc | 6 +- .../src/bat/ledger/internal/ledger_impl.cc | 3 +- 19 files changed, 311 insertions(+), 812 deletions(-) delete mode 100644 vendor/bat-native-ads/src/bat/ads/confirmation_type.cc delete mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/confirmation_type.cc delete mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.cc delete mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.h diff --git a/vendor/bat-native-ads/BUILD.gn b/vendor/bat-native-ads/BUILD.gn index fe37ab993dbc..a23bd61785d6 100644 --- a/vendor/bat-native-ads/BUILD.gn +++ b/vendor/bat-native-ads/BUILD.gn @@ -83,7 +83,6 @@ source_set("ads") { "src/bat/ads/bundle_state.cc", "src/bat/ads/client_info.cc", "src/bat/ads/issuer_info.cc", - "src/bat/ads/confirmation_type.cc", "src/bat/ads/issuers_info.cc", "src/bat/ads/notification_info.cc", "src/bat/ads/internal/ads_impl.cc", diff --git a/vendor/bat-native-ads/include/bat/ads/confirmation_type.h b/vendor/bat-native-ads/include/bat/ads/confirmation_type.h index a8d7aca8ee41..d59834388877 100644 --- a/vendor/bat-native-ads/include/bat/ads/confirmation_type.h +++ b/vendor/bat-native-ads/include/bat/ads/confirmation_type.h @@ -6,34 +6,19 @@ #ifndef BAT_ADS_CONFIRMATION_TYPE_H_ #define BAT_ADS_CONFIRMATION_TYPE_H_ -#include - namespace ads { -class ConfirmationType { - public: - enum Value : int { - UNKNOWN, - CLICK, - DISMISS, - VIEW, - LANDED - }; - - ConfirmationType() = default; - constexpr ConfirmationType(const Value value) : value_(value) {} - explicit ConfirmationType(const std::string& value); - - bool IsSupported() const; - - int value() const; - operator std::string() const; - - bool operator==(ConfirmationType type) const; - bool operator!=(ConfirmationType type) const; - - private: - Value value_; +static char kConfirmationTypeClick[] = "click"; +static char kConfirmationTypeDismiss[] = "dismiss"; +static char kConfirmationTypeView[] = "view"; +static char kConfirmationTypeLanded[] = "landed"; + +enum class ConfirmationType { + UNKNOWN, + CLICK, + DISMISS, + VIEW, + LANDED }; } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/confirmation_type.cc b/vendor/bat-native-ads/src/bat/ads/confirmation_type.cc deleted file mode 100644 index 33cf42b56df1..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/confirmation_type.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* 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/ads/confirmation_type.h" - -namespace ads { - -static const char kConfirmationTypeClick[] = "click"; -static const char kConfirmationTypeDismiss[] = "dismiss"; -static const char kConfirmationTypeView[] = "view"; -static const char kConfirmationTypeLanded[] = "landed"; - -ConfirmationType::ConfirmationType(const std::string& value) { - if (value == kConfirmationTypeClick) { - value_ = CLICK; - } else if (value == kConfirmationTypeDismiss) { - value_ = DISMISS; - } else if (value == kConfirmationTypeView) { - value_ = VIEW; - } else if (value == kConfirmationTypeLanded) { - value_ = LANDED; - } else { - value_ = UNKNOWN; - } -} - -bool ConfirmationType::IsSupported() const { - return value_ != UNKNOWN; -} - -int ConfirmationType::value() const { - return value_; -} - -ConfirmationType::operator std::string() const { - switch (value_) { - case UNKNOWN: { - return ""; - } - - case CLICK: { - return kConfirmationTypeClick; - } - - case DISMISS: { - return kConfirmationTypeDismiss; - } - - case VIEW: { - return kConfirmationTypeView; - } - - case LANDED: { - return kConfirmationTypeLanded; - } - } -} - -bool ConfirmationType::operator==(ConfirmationType type) const { - return value_ == type.value_; -} - -bool ConfirmationType::operator!=(ConfirmationType type) const { - return value_ != type.value_; -} - -} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc index 8b513f7fd7e5..673c859f4bea 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc @@ -1289,8 +1289,35 @@ void AdsImpl::GenerateAdReportingConfirmationEvent( writer.String("notificationId"); writer.String(info.uuid.c_str()); + std::string type; + switch (info.type) { + case ConfirmationType::UNKNOWN: { + DCHECK(false) << "Invalid confirmation type"; + break; + } + + case ConfirmationType::CLICK: { + type = kConfirmationTypeClick; + break; + } + + case ConfirmationType::DISMISS: { + type = kConfirmationTypeDismiss; + break; + } + + case ConfirmationType::VIEW: { + type = kConfirmationTypeView; + break; + } + + case ConfirmationType::LANDED: { + type = kConfirmationTypeLanded; + break; + } + } + writer.String("notificationType"); - auto type = std::string(info.type); writer.String(type.c_str()); writer.EndObject(); diff --git a/vendor/bat-native-ads/src/bat/ads/notification_info.cc b/vendor/bat-native-ads/src/bat/ads/notification_info.cc index c2b2559e94b7..31b485cc5c2f 100644 --- a/vendor/bat-native-ads/src/bat/ads/notification_info.cc +++ b/vendor/bat-native-ads/src/bat/ads/notification_info.cc @@ -78,7 +78,17 @@ Result NotificationInfo::FromJson( if (document.HasMember("confirmation_type")) { std::string confirmation_type = document["confirmation_type"].GetString(); - type = ConfirmationType(confirmation_type); + if (confirmation_type == kConfirmationTypeClick) { + type = ConfirmationType::CLICK; + } else if (confirmation_type == kConfirmationTypeDismiss) { + type = ConfirmationType::DISMISS; + } else if (confirmation_type == kConfirmationTypeView) { + type = ConfirmationType::VIEW; + } else if (confirmation_type == kConfirmationTypeLanded) { + type = ConfirmationType::LANDED; + } else { + type = ConfirmationType::UNKNOWN; + } } return SUCCESS; @@ -106,8 +116,32 @@ void SaveToJson(JsonWriter* writer, const NotificationInfo& info) { writer->String(info.uuid.c_str()); writer->String("confirmation_type"); - auto type = std::string(info.type); - writer->String(type.c_str()); + switch (info.type) { + case ConfirmationType::UNKNOWN: { + writer->String(""); + break; + } + + case ConfirmationType::CLICK: { + writer->String(kConfirmationTypeClick); + break; + } + + case ConfirmationType::DISMISS: { + writer->String(kConfirmationTypeDismiss); + break; + } + + case ConfirmationType::VIEW: { + writer->String(kConfirmationTypeView); + break; + } + + case ConfirmationType::LANDED: { + writer->String(kConfirmationTypeLanded); + break; + } + } writer->EndObject(); } diff --git a/vendor/bat-native-confirmations/BUILD.gn b/vendor/bat-native-confirmations/BUILD.gn index c3509f74c7ba..4e6a570c044a 100644 --- a/vendor/bat-native-confirmations/BUILD.gn +++ b/vendor/bat-native-confirmations/BUILD.gn @@ -37,7 +37,6 @@ source_set("bat-native-confirmations") { ] sources = [ - "include/bat/confirmations/confirmation_type.h", "include/bat/confirmations/confirmations_client.h", "include/bat/confirmations/confirmations.h", "include/bat/confirmations/export.h", @@ -45,7 +44,6 @@ source_set("bat-native-confirmations") { "include/bat/confirmations/issuers_info.h", "include/bat/confirmations/notification_info.h", "include/bat/confirmations/wallet_info.h", - "src/bat/confirmations/confirmation_type.cc", "src/bat/confirmations/confirmations.cc", "src/bat/confirmations/issuer_info.cc", "src/bat/confirmations/issuers_info.cc", @@ -53,8 +51,6 @@ source_set("bat-native-confirmations") { "src/bat/confirmations/wallet_info.cc", "src/bat/confirmations/internal/ads_serve_helper.cc", "src/bat/confirmations/internal/ads_serve_helper.h", - "src/bat/confirmations/internal/confirmation_info.cc", - "src/bat/confirmations/internal/confirmation_info.h", "src/bat/confirmations/internal/confirmations_impl.cc", "src/bat/confirmations/internal/confirmations_impl.h", "src/bat/confirmations/internal/create_confirmation_request.cc", diff --git a/vendor/bat-native-confirmations/include/bat/confirmations/confirmation_type.h b/vendor/bat-native-confirmations/include/bat/confirmations/confirmation_type.h index 64ec851e82f9..0bdf524e0e1f 100644 --- a/vendor/bat-native-confirmations/include/bat/confirmations/confirmation_type.h +++ b/vendor/bat-native-confirmations/include/bat/confirmations/confirmation_type.h @@ -6,34 +6,19 @@ #ifndef BAT_CONFIRMATIONS_CONFIRMATION_TYPE_H_ #define BAT_CONFIRMATIONS_CONFIRMATION_TYPE_H_ -#include - namespace confirmations { -class ConfirmationType { - public: - enum Value : int { - UNKNOWN, - CLICK, - DISMISS, - VIEW, - LANDED - }; - - ConfirmationType() = default; - constexpr ConfirmationType(const Value value) : value_(value) {} - explicit ConfirmationType(const std::string& value); - - bool IsSupported() const; - - int value() const; - operator std::string() const; - - bool operator==(ConfirmationType type) const; - bool operator!=(ConfirmationType type) const; - - private: - Value value_; +static char kConfirmationTypeClick[] = "click"; +static char kConfirmationTypeDismiss[] = "dismiss"; +static char kConfirmationTypeView[] = "view"; +static char kConfirmationTypeLanded[] = "landed"; + +enum class ConfirmationType { + UNKNOWN, + CLICK, + DISMISS, + VIEW, + LANDED }; } // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/confirmation_type.cc b/vendor/bat-native-confirmations/src/bat/confirmations/confirmation_type.cc deleted file mode 100644 index eba081133836..000000000000 --- a/vendor/bat-native-confirmations/src/bat/confirmations/confirmation_type.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* 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/confirmation_type.h" - -namespace confirmations { - -static const char kConfirmationTypeClick[] = "click"; -static const char kConfirmationTypeDismiss[] = "dismiss"; -static const char kConfirmationTypeView[] = "view"; -static const char kConfirmationTypeLanded[] = "landed"; - -ConfirmationType::ConfirmationType(const std::string& value) { - if (value == kConfirmationTypeClick) { - value_ = CLICK; - } else if (value == kConfirmationTypeDismiss) { - value_ = DISMISS; - } else if (value == kConfirmationTypeView) { - value_ = VIEW; - } else if (value == kConfirmationTypeLanded) { - value_ = LANDED; - } else { - value_ = UNKNOWN; - } -} - -bool ConfirmationType::IsSupported() const { - return value_ != UNKNOWN; -} - -int ConfirmationType::value() const { - return value_; -} - -ConfirmationType::operator std::string() const { - switch (value_) { - case UNKNOWN: { - return ""; - } - - case CLICK: { - return kConfirmationTypeClick; - } - - case DISMISS: { - return kConfirmationTypeDismiss; - } - - case VIEW: { - return kConfirmationTypeView; - } - - case LANDED: { - return kConfirmationTypeLanded; - } - } -} - -bool ConfirmationType::operator==(ConfirmationType type) const { - return value_ == type.value_; -} - -bool ConfirmationType::operator!=(ConfirmationType type) const { - return value_ != type.value_; -} - -} // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.cc deleted file mode 100644 index 3db4ff19f731..000000000000 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* 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/confirmation_info.h" - -namespace confirmations { - -ConfirmationInfo::ConfirmationInfo() : - id(""), - creative_instance_id(""), - type(ConfirmationType::UNKNOWN), - token_info(TokenInfo()), - payment_token(nullptr), - blinded_payment_token(nullptr), - credential("") {} - -ConfirmationInfo::ConfirmationInfo(const ConfirmationInfo& info) : - id(info.id), - creative_instance_id(info.creative_instance_id), - type(info.type), - token_info(info.token_info), - payment_token(info.payment_token), - blinded_payment_token(info.blinded_payment_token), - credential(info.credential) {} - -ConfirmationInfo::~ConfirmationInfo() {} - -} // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.h deleted file mode 100644 index 00df164845e5..000000000000 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/confirmation_info.h +++ /dev/null @@ -1,37 +0,0 @@ -/* 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_CONFIRMATION_INFO_H_ -#define BAT_CONFIRMATIONS_INTERNAL_CONFIRMATION_INFO_H_ - -#include - -#include "bat/confirmations/confirmation_type.h" -#include "bat/confirmations/internal/token_info.h" - -#include "wrapper.hpp" // NOLINT - -using challenge_bypass_ristretto::Token; -using challenge_bypass_ristretto::BlindedToken; - -namespace confirmations { - -struct ConfirmationInfo { - ConfirmationInfo(); - explicit ConfirmationInfo(const ConfirmationInfo& info); - ~ConfirmationInfo(); - - std::string id; - std::string creative_instance_id; - ConfirmationType type; - TokenInfo token_info; - Token payment_token; - BlindedToken blinded_payment_token; - std::string credential; -}; - -} // namespace confirmations - -#endif // BAT_CONFIRMATIONS_INTERNAL_CONFIRMATION_INFO_H_ 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 b4a78ec68dc9..4e962ba3d4cf 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 @@ -31,7 +31,6 @@ namespace confirmations { ConfirmationsImpl::ConfirmationsImpl( ConfirmationsClient* confirmations_client) : is_initialized_(false), - retry_failed_confirmations_timer_id_(0), unblinded_tokens_(std::make_unique(this)), unblinded_payment_tokens_(std::make_unique(this)), retry_getting_signed_tokens_timer_id_(0), @@ -51,7 +50,6 @@ ConfirmationsImpl::~ConfirmationsImpl() { BLOG(INFO) << "Deinitializing Confirmations"; StopRetryingToGetRefillSignedTokens(); - StopRetryingFailedConfirmations(); StopPayingOutRedeemedTokens(); } @@ -84,8 +82,6 @@ void ConfirmationsImpl::CheckReady() { auto start_timer_in = CalculateTokenRedemptionTimeInSeconds(); StartPayingOutRedeemedTokens(start_timer_in); - RetryFailedConfirmations(); - RefillTokensIfNecessary(); } @@ -106,10 +102,6 @@ std::string ConfirmationsImpl::ToJSON() const { dictionary.SetKey("next_token_redemption_date_in_seconds", base::Value( std::to_string(next_token_redemption_date_in_seconds_))); - // Confirmations - auto confirmations = GetConfirmationsAsDictionary(confirmations_); - dictionary.SetKey("confirmations", base::Value(std::move(confirmations))); - // Transaction history auto transaction_history = GetTransactionHistoryAsDictionary(transaction_history_); @@ -154,52 +146,6 @@ base::Value ConfirmationsImpl::GetCatalogIssuersAsDictionary( return dictionary; } -base::Value ConfirmationsImpl::GetConfirmationsAsDictionary( - const std::vector& confirmations) const { - base::Value dictionary(base::Value::Type::DICTIONARY); - - base::Value list(base::Value::Type::LIST); - for (const auto& confirmation : confirmations) { - base::Value confirmation_dictionary(base::Value::Type::DICTIONARY); - - confirmation_dictionary.SetKey("id", base::Value(confirmation.id)); - - confirmation_dictionary.SetKey("creative_instance_id", - base::Value(confirmation.creative_instance_id)); - - std::string type = std::string(confirmation.type); - confirmation_dictionary.SetKey("type", base::Value(type)); - - base::Value token_info_dictionary(base::Value::Type::DICTIONARY); - auto unblinded_token_base64 = - confirmation.token_info.unblinded_token.encode_base64(); - token_info_dictionary.SetKey("unblinded_token", - base::Value(unblinded_token_base64)); - auto public_key = confirmation.token_info.public_key; - token_info_dictionary.SetKey("public_key", base::Value(public_key)); - confirmation_dictionary.SetKey("token_info", - base::Value(std::move(token_info_dictionary))); - - auto payment_token_base64 = confirmation.payment_token.encode_base64(); - confirmation_dictionary.SetKey("payment_token", - base::Value(payment_token_base64)); - - auto blinded_payment_token_base64 = - confirmation.blinded_payment_token.encode_base64(); - confirmation_dictionary.SetKey("blinded_payment_token", - base::Value(blinded_payment_token_base64)); - - confirmation_dictionary.SetKey("credential", - base::Value(confirmation.credential)); - - list.GetList().push_back(std::move(confirmation_dictionary)); - } - - dictionary.SetKey("failed_confirmations", base::Value(std::move(list))); - - return dictionary; -} - base::Value ConfirmationsImpl::GetTransactionHistoryAsDictionary( const std::vector& transaction_history) const { base::Value dictionary(base::Value::Type::DICTIONARY); @@ -234,28 +180,23 @@ bool ConfirmationsImpl::FromJSON(const std::string& json) { return false; } - if (!GetCatalogIssuersFromJSON(dictionary)) { + // Catalog issuers + if (!GetCatalogIssuersFromJSON(dictionary.get())) { BLOG(WARNING) << "Failed to get catalog issuers from JSON: " << json; } - if (!GetNextTokenRedemptionDateInSecondsFromJSON(dictionary)) { - BLOG(WARNING) << - "Failed to get next token redemption date from JSON: " << json; - } - - if (!GetConfirmationsFromJSON(dictionary)) { - BLOG(WARNING) << "Failed to get confirmations from JSON: " << json; - } - - if (!GetTransactionHistoryFromJSON(dictionary)) { + // Transaction history + if (!GetTransactionHistoryFromJSON(dictionary.get())) { BLOG(WARNING) << "Failed to get transaction history from JSON: " << json; } - if (!GetUnblindedTokensFromJSON(dictionary)) { + // Unblinded tokens + if (!GetUnblindedTokensFromJSON(dictionary.get())) { BLOG(WARNING) << "Failed to get unblinded tokens from JSON: " << json; } - if (!GetUnblindedPaymentTokensFromJSON(dictionary)) { + // Unblinded payment tokens + if (!GetUnblindedPaymentTokensFromJSON(dictionary.get())) { BLOG(WARNING) << "Failed to get unblinded payment tokens from JSON: " << json; } @@ -277,7 +218,7 @@ bool ConfirmationsImpl::GetCatalogIssuersFromJSON( std::string public_key; std::map catalog_issuers; - if (!GetCatalogIssuersFromDictionary(catalog_issuers_dictionary, &public_key, + if (!GetCatalogIssuersFromDictionary(dictionary, &public_key, &catalog_issuers)) { return false; } @@ -337,184 +278,6 @@ bool ConfirmationsImpl::GetCatalogIssuersFromDictionary( return true; } -bool ConfirmationsImpl::GetNextTokenRedemptionDateInSecondsFromJSON( - base::DictionaryValue* dictionary) { - auto* next_token_redemption_date_in_seconds_value = - dictionary->FindKey("next_token_redemption_date_in_seconds"); - if (!next_token_redemption_date_in_seconds_value) { - return false; - } - - next_token_redemption_date_in_seconds_ = - std::stoull(next_token_redemption_date_in_seconds_value->GetString()); - - return true; -} - -bool ConfirmationsImpl::GetConfirmationsFromJSON( - base::DictionaryValue* dictionary) { - auto* confirmations_value = dictionary->FindKey("confirmations"); - if (!confirmations_value) { - return false; - } - - base::DictionaryValue* confirmations_dictionary; - if (!confirmations_value->GetAsDictionary( - &confirmations_dictionary)) { - return false; - } - - std::vector confirmations; - if (!GetConfirmationsFromDictionary(confirmations_dictionary, - &confirmations)) { - return false; - } - - confirmations_ = confirmations; - - return true; -} - -bool ConfirmationsImpl::GetConfirmationsFromDictionary( - base::DictionaryValue* dictionary, - std::vector* confirmations) { - DCHECK(dictionary); - DCHECK(confirmations); - - // Confirmations - auto* confirmations_value = dictionary->FindKey("failed_confirmations"); - if (!confirmations_value) { - DCHECK(false) << "Confirmations dictionary missing confirmations"; - return false; - } - - confirmations->clear(); - base::ListValue confirmations_list_value(confirmations_value->GetList()); - for (auto& confirmation_value : confirmations_list_value) { - base::DictionaryValue* confirmation_dictionary; - if (!confirmation_value.GetAsDictionary(&confirmation_dictionary)) { - DCHECK(false) << "Confirmation should be a dictionary"; - continue; - } - - ConfirmationInfo confirmation_info; - - // Id - auto* id_value = confirmation_dictionary->FindKey("id"); - if (id_value) { - confirmation_info.id = id_value->GetString(); - } else { - // Id missing, skip confirmation - DCHECK(false) << "Confirmation missing id"; - continue; - } - - // Creative instance id - auto* creative_instance_id_value = - confirmation_dictionary->FindKey("creative_instance_id"); - if (creative_instance_id_value) { - confirmation_info.creative_instance_id = - creative_instance_id_value->GetString(); - } else { - // Creative instance id missing, skip confirmation - DCHECK(false) << "Confirmation missing creative_instance_id"; - continue; - } - - // Type - auto* type_value = confirmation_dictionary->FindKey("type"); - if (type_value) { - ConfirmationType type(type_value->GetString()); - if (!type.IsSupported()) { - // Unsupported type, skip confirmation - DCHECK(false) << "Unsupported confirmation type: " << std::string(type); - continue; - } - - confirmation_info.type = type; - } else { - // Type missing, skip confirmation - DCHECK(false) << "Confirmation missing type"; - continue; - } - - // Token info - auto* token_info_value = confirmation_dictionary->FindKey("token_info"); - if (!token_info_value) { - DCHECK(false) << "Confirmation missing token_info"; - continue; - } - - base::DictionaryValue* token_info_dictionary; - if (!token_info_value->GetAsDictionary(&token_info_dictionary)) { - DCHECK(false) << "Token info should be a dictionary"; - continue; - } - - auto* unblinded_token_value = - token_info_dictionary->FindKey("unblinded_token"); - if (unblinded_token_value) { - auto unblinded_token_base64 = unblinded_token_value->GetString(); - confirmation_info.token_info.unblinded_token = - UnblindedToken::decode_base64(unblinded_token_base64); - } else { - // Unblinded token missing, skip confirmation - DCHECK(false) << "Token info missing unblinded_token"; - continue; - } - - auto* public_key_value = token_info_dictionary->FindKey("public_key"); - if (public_key_value) { - confirmation_info.token_info.public_key = public_key_value->GetString(); - } else { - // Public key missing, skip confirmation - DCHECK(false) << "Token info missing public_key"; - continue; - } - - // Payment token - auto* payment_token_value = - confirmation_dictionary->FindKey("payment_token"); - if (payment_token_value) { - auto payment_token_base64 = payment_token_value->GetString(); - confirmation_info.payment_token = - Token::decode_base64(payment_token_base64); - } else { - // Payment token missing, skip confirmation - DCHECK(false) << "Confirmation missing payment_token"; - continue; - } - - // Blinded payment token - auto* blinded_payment_token_value = - confirmation_dictionary->FindKey("blinded_payment_token"); - if (blinded_payment_token_value) { - auto blinded_payment_token_base64 = - blinded_payment_token_value->GetString(); - confirmation_info.blinded_payment_token = - BlindedToken::decode_base64(blinded_payment_token_base64); - } else { - // Blinded payment token missing, skip confirmation - DCHECK(false) << "Confirmation missing blinded_payment_token"; - continue; - } - - // Credential - auto* credential_value = confirmation_dictionary->FindKey("credential"); - if (credential_value) { - confirmation_info.credential = credential_value->GetString(); - } else { - // Credential missing, skip confirmation - DCHECK(false) << "Confirmation missing credential"; - continue; - } - - confirmations->push_back(confirmation_info); - } - - return true; -} - bool ConfirmationsImpl::GetTransactionHistoryFromJSON( base::DictionaryValue* dictionary) { auto* transaction_history_value = dictionary->FindKey("transaction_history"); @@ -592,8 +355,7 @@ bool ConfirmationsImpl::GetTransactionHistoryFromDictionary( info.confirmation_type = confirmation_type_value->GetString(); } else { // confirmation type missing, fallback to default - ConfirmationType type(ConfirmationType::VIEW); - info.confirmation_type = std::string(type); + info.confirmation_type = kConfirmationTypeView; } transaction_history->push_back(info); @@ -754,37 +516,6 @@ bool ConfirmationsImpl::IsValidPublicKeyForCatalogIssuers( return true; } -void ConfirmationsImpl::AppendConfirmationToQueue( - const ConfirmationInfo& confirmation_info) { - confirmations_.push_back(confirmation_info); - - SaveState(); -} - -bool ConfirmationsImpl::RemoveConfirmationFromQueue( - const ConfirmationInfo& confirmation_info) { - auto id = confirmation_info.id; - - auto it = std::find_if(confirmations_.begin(), confirmations_.end(), - [=](const ConfirmationInfo& info) { - return (info.id == id); - }); - - if (it == confirmations_.end()) { - return false; - } - - BLOG(INFO) << "Removed " << confirmation_info.creative_instance_id - << " creative instance id for " << std::string(confirmation_info.type) - << " from the confirmation queue"; - - confirmations_.erase(it); - - SaveState(); - - return true; -} - void ConfirmationsImpl::GetTransactionHistory( const uint64_t from_timestamp_in_seconds, const uint64_t to_timestamp_in_seconds, @@ -824,13 +555,39 @@ double ConfirmationsImpl::GetEstimatedRedemptionValue( return estimated_redemption_value; } -void ConfirmationsImpl::AppendTransactionToHistory( +void ConfirmationsImpl::AppendTransactionToTransactionHistory( const double estimated_redemption_value, const ConfirmationType confirmation_type) { TransactionInfo info; info.timestamp_in_seconds = Time::NowInSeconds(); info.estimated_redemption_value = estimated_redemption_value; - info.confirmation_type = std::string(confirmation_type); + + switch (confirmation_type) { + case ConfirmationType::UNKNOWN: { + DCHECK(false) << "Invalid confirmation type"; + break; + } + + case ConfirmationType::CLICK: { + info.confirmation_type = kConfirmationTypeClick; + break; + } + + case ConfirmationType::DISMISS: { + info.confirmation_type = kConfirmationTypeDismiss; + break; + } + + case ConfirmationType::VIEW: { + info.confirmation_type = kConfirmationTypeView; + break; + } + + case ConfirmationType::LANDED: { + info.confirmation_type = kConfirmationTypeLanded; + break; + } + } transaction_history_.push_back(info); @@ -841,13 +598,38 @@ void ConfirmationsImpl::AppendTransactionToHistory( void ConfirmationsImpl::ConfirmAd(std::unique_ptr info) { BLOG(INFO) << "ConfirmAd:"; - BLOG(INFO) << " creative_set_id: " << info->creative_set_id; + BLOG(INFO) << " creativeSetId: " << info->creative_set_id; BLOG(INFO) << " category: " << info->category; - BLOG(INFO) << " url: " << info->url; - BLOG(INFO) << " text: " << info->text; + BLOG(INFO) << " notificationUrl: " << info->url; + BLOG(INFO) << " notificationText: " << info->text; BLOG(INFO) << " advertiser: " << info->advertiser; BLOG(INFO) << " uuid: " << info->uuid; - BLOG(INFO) << " type: " << std::string(info->type); + switch (info->type) { + case ConfirmationType::UNKNOWN: { + DCHECK(false) << "Invalid confirmation type"; + break; + } + + case ConfirmationType::CLICK: { + BLOG(INFO) << " confirmationType: click"; + break; + } + + case ConfirmationType::DISMISS: { + BLOG(INFO) << " confirmationType: dismiss"; + break; + } + + case ConfirmationType::VIEW: { + BLOG(INFO) << " confirmationType: view"; + break; + } + + case ConfirmationType::LANDED: { + BLOG(INFO) << " confirmationType: landed"; + break; + } + } redeem_token_->Redeem(info->uuid, info->type); } @@ -864,9 +646,6 @@ bool ConfirmationsImpl::OnTimer(const uint32_t timer_id) { if (timer_id == retry_getting_signed_tokens_timer_id_) { RetryGettingRefillSignedTokens(); return true; - } else if (timer_id == retry_failed_confirmations_timer_id_) { - RetryFailedConfirmations(); - return true; } else if (timer_id == payout_redeemed_tokens_timer_id_) { PayoutRedeemedTokens(); return true; @@ -885,7 +664,7 @@ uint64_t ConfirmationsImpl::CalculateTokenRedemptionTimeInSeconds() { uint64_t start_timer_in; if (_is_debug) { - if (next_token_redemption_date_in_seconds_ - now_in_seconds >= + if (now_in_seconds - next_token_redemption_date_in_seconds_ >= kDebugNextTokenRedemptionAfterSeconds) { UpdateNextTokenRedemptionDate(); SaveState(); @@ -922,57 +701,6 @@ void ConfirmationsImpl::UpdateNextTokenRedemptionDate() { } } -void ConfirmationsImpl::StartRetryingFailedConfirmations( - const uint64_t start_timer_in) { - if (confirmations_.size() == 0) { - BLOG(INFO) << "No failed confirmations to retry"; - return; - } - - StopRetryingFailedConfirmations(); - - confirmations_client_->SetTimer(start_timer_in, - &retry_failed_confirmations_timer_id_); - if (retry_failed_confirmations_timer_id_ == 0) { - BLOG(ERROR) << "Failed to start retrying failed confirmations " - << "due to an invalid timer"; - - return; - } - - BLOG(INFO) << "Start retrying failed confirmations in " << start_timer_in - << " seconds"; -} - -void ConfirmationsImpl::RetryFailedConfirmations() const { - if (confirmations_.size() == 0) { - BLOG(INFO) << "No failed confirmations to retry"; - return; - } - - ConfirmationInfo confirmation_info(confirmations_.front()); - redeem_token_->Redeem(confirmation_info); -} - -void ConfirmationsImpl::StopRetryingFailedConfirmations() { - if (!IsRetryingFailedConfirmations()) { - return; - } - - BLOG(INFO) << "Stopped retrying failed confirmations"; - - confirmations_client_->KillTimer(retry_failed_confirmations_timer_id_); - retry_failed_confirmations_timer_id_ = 0; -} - -bool ConfirmationsImpl::IsRetryingFailedConfirmations() const { - if (retry_failed_confirmations_timer_id_ == 0) { - return false; - } - - return true; -} - 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 fb89f38d675c..6b639942a4f1 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 @@ -16,7 +16,6 @@ #include "bat/confirmations/confirmations_client.h" #include "bat/confirmations/notification_info.h" #include "bat/confirmations/issuers_info.h" -#include "bat/confirmations/internal/confirmation_info.h" #include "base/values.h" @@ -43,17 +42,12 @@ class ConfirmationsImpl : public Confirmations { bool IsValidPublicKeyForCatalogIssuers(const std::string& public_key) const; double GetEstimatedRedemptionValue(const std::string& public_key) const; - // Confirmations - void AppendConfirmationToQueue(const ConfirmationInfo& confirmation_info); - bool RemoveConfirmationFromQueue(const ConfirmationInfo& confirmation_info); - void StartRetryingFailedConfirmations(const uint64_t start_timer_in); - // Transaction history void GetTransactionHistory( const uint64_t from_timestamp_in_seconds, const uint64_t to_timestamp_in_seconds, OnGetTransactionHistoryCallback callback) override; - void AppendTransactionToHistory( + void AppendTransactionToTransactionHistory( const double estimated_redemption_value, const ConfirmationType confirmation_type); @@ -86,13 +80,6 @@ class ConfirmationsImpl : public Confirmations { // Catalog issuers std::map catalog_issuers_; - // Confirmations - uint32_t retry_failed_confirmations_timer_id_; - void RetryFailedConfirmations() const; - void StopRetryingFailedConfirmations(); - bool IsRetryingFailedConfirmations() const; - std::vector confirmations_; - // Transaction history std::vector transaction_history_; @@ -136,9 +123,6 @@ class ConfirmationsImpl : public Confirmations { const std::string& public_key, const std::map& issuers) const; - base::Value GetConfirmationsAsDictionary( - const std::vector& confirmations) const; - base::Value GetTransactionHistoryAsDictionary( const std::vector& transaction_history) const; @@ -151,15 +135,6 @@ class ConfirmationsImpl : public Confirmations { std::string* public_key, std::map* issuers) const; - bool GetNextTokenRedemptionDateInSecondsFromJSON( - base::DictionaryValue* dictionary); - - bool GetConfirmationsFromJSON( - base::DictionaryValue* dictionary); - bool GetConfirmationsFromDictionary( - base::DictionaryValue* dictionary, - std::vector* confirmations); - bool GetTransactionHistoryFromJSON( base::DictionaryValue* dictionary); bool GetTransactionHistoryFromDictionary( diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.cc index c11e1309528d..73fb49e8d88d 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/create_confirmation_request.cc @@ -78,7 +78,34 @@ std::string CreateConfirmationRequest::CreateConfirmationRequestDTO( auto token_base64 = token.encode_base64(); payload.SetKey("blindedPaymentToken", base::Value(token_base64)); - auto type = std::string(confirmation_type); + std::string type; + switch (confirmation_type) { + case ConfirmationType::UNKNOWN: { + DCHECK(false) << "Invalid confirmation type"; + break; + } + + case ConfirmationType::CLICK: { + type = kConfirmationTypeClick; + break; + } + + case ConfirmationType::DISMISS: { + type = kConfirmationTypeDismiss; + break; + } + + case ConfirmationType::VIEW: { + type = kConfirmationTypeView; + break; + } + + case ConfirmationType::LANDED: { + type = kConfirmationTypeLanded; + break; + } + } + payload.SetKey("type", base::Value(type)); std::string json; diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.cc index 46de30951175..f02af03cce67 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.cc @@ -9,7 +9,6 @@ #include "bat/confirmations/internal/logging.h" #include "bat/confirmations/internal/ads_serve_helper.h" #include "bat/confirmations/internal/security_helper.h" -#include "bat/confirmations/internal/static_values.h" #include "bat/confirmations/internal/confirmations_impl.h" #include "bat/confirmations/internal/unblinded_tokens.h" #include "bat/confirmations/internal/create_confirmation_request.h" @@ -18,7 +17,6 @@ #include "base/logging.h" #include "base/guid.h" #include "base/json/json_reader.h" -#include "base/rand_util.h" #include "base/values.h" using std::placeholders::_1; @@ -63,34 +61,48 @@ void RedeemToken::Redeem( CreateConfirmation(creative_instance_id, token_info, confirmation_type); } -void RedeemToken::Redeem( - const ConfirmationInfo& confirmation_info) { - CreateConfirmation(confirmation_info); -} - /////////////////////////////////////////////////////////////////////////////// void RedeemToken::CreateConfirmation( - const ConfirmationInfo& confirmation_info) { + const std::string& creative_instance_id, + const TokenInfo& token_info, + const ConfirmationType confirmation_type) { + DCHECK(!creative_instance_id.empty()); + BLOG(INFO) << "CreateConfirmation"; + if (!unblinded_tokens_->TokenExists(token_info)) { + BLOG(ERROR) << "Failed to redeem token " + << token_info.unblinded_token.encode_base64() + << " as unblinded token could not be found"; + OnRedeem(FAILED, token_info); + return; + } + BLOG(INFO) << "POST /v1/confirmation/{confirmation_id}/{credential}"; CreateConfirmationRequest request; + auto payment_tokens = helper::Security::GenerateTokens(1); + auto payment_token = payment_tokens.front(); + + auto blinded_payment_tokens = helper::Security::BlindTokens(payment_tokens); + auto blinded_payment_token = blinded_payment_tokens.front(); + + auto confirmation_id = base::GenerateGUID(); + + auto payload = request.CreateConfirmationRequestDTO(creative_instance_id, + blinded_payment_token, confirmation_type); + + auto credential = request.CreateCredential(token_info, payload); + BLOG(INFO) << "URL Request:"; - auto url = request.BuildUrl(confirmation_info.id, - confirmation_info.credential); + auto url = request.BuildUrl(confirmation_id, credential); BLOG(INFO) << " URL: " << url; auto method = request.GetMethod(); - auto confirmation_request_dto = request.CreateConfirmationRequestDTO( - confirmation_info.creative_instance_id, - confirmation_info.blinded_payment_token, - confirmation_info.type); - - auto body = request.BuildBody(confirmation_request_dto); + auto body = request.BuildBody(payload); BLOG(INFO) << " Body: " << body; auto headers = request.BuildHeaders(); @@ -103,55 +115,24 @@ void RedeemToken::CreateConfirmation( BLOG(INFO) << " Content_type: " << content_type; auto callback = std::bind(&RedeemToken::OnCreateConfirmation, - this, url, _1, _2, _3, confirmation_info); + this, url, _1, _2, _3, confirmation_type, confirmation_id, payment_token, + blinded_payment_token, token_info); confirmations_client_->LoadURL(url, headers, body, content_type, method, callback); } -void RedeemToken::CreateConfirmation( - const std::string& creative_instance_id, - const TokenInfo& token_info, - const ConfirmationType confirmation_type) { - DCHECK(!creative_instance_id.empty()); - DCHECK(unblinded_tokens_->TokenExists(token_info)); - - ConfirmationInfo confirmation_info; - - confirmation_info.id = base::GenerateGUID(); - - confirmation_info.creative_instance_id = creative_instance_id; - - confirmation_info.type = confirmation_type; - - confirmation_info.token_info = token_info; - - auto payment_tokens = helper::Security::GenerateTokens(1); - confirmation_info.payment_token = payment_tokens.front(); - - auto blinded_payment_tokens = helper::Security::BlindTokens(payment_tokens); - auto blinded_payment_token = blinded_payment_tokens.front(); - confirmation_info.blinded_payment_token = blinded_payment_token; - - CreateConfirmationRequest request; - - auto confirmation_request_dto = - request.CreateConfirmationRequestDTO(creative_instance_id, - blinded_payment_token, confirmation_type); - - confirmation_info.credential = - request.CreateCredential(token_info, confirmation_request_dto); - - CreateConfirmation(confirmation_info); -} - void RedeemToken::OnCreateConfirmation( const std::string& url, const int response_status_code, const std::string& response, const std::map& headers, - const ConfirmationInfo& confirmation_info) { - DCHECK(!confirmation_info.id.empty()); + const ConfirmationType confirmation_type, + const std::string& confirmation_id, + const Token& payment_token, + const BlindedToken& blinded_payment_token, + const TokenInfo& token_info) { + DCHECK(!confirmation_id.empty()); BLOG(INFO) << "OnCreateConfirmation"; @@ -164,46 +145,52 @@ void RedeemToken::OnCreateConfirmation( BLOG(INFO) << " " << header.first << ": " << header.second; } - if (response_status_code != 201 && response_status_code != 400) { + if (response_status_code != 201) { BLOG(ERROR) << "Failed to create confirmation"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } - if (response_status_code != 400) { - // Parse JSON response - base::Optional dictionary = base::JSONReader::Read(response); - if (!dictionary || !dictionary->is_dict()) { - BLOG(ERROR) << "Failed to parse response: " << response; - OnRedeem(FAILED, confirmation_info); - return; - } + // Parse JSON response + std::unique_ptr dictionary = + base::DictionaryValue::From(base::JSONReader::Read(response)); - // Get id - auto* id_value = dictionary->FindKey("id"); - if (!id_value) { - BLOG(ERROR) << "Response missing id"; - OnRedeem(FAILED, confirmation_info); - return; - } + if (!dictionary) { + BLOG(ERROR) << "Failed to parse response: " << response; + OnRedeem(FAILED, token_info); + return; + } - auto id = id_value->GetString(); + // Get id + auto* id_value = dictionary->FindKey("id"); + if (!id_value) { + BLOG(ERROR) << "Response missing id"; + OnRedeem(FAILED, token_info); + return; + } - // Validate id - if (id != confirmation_info.id) { - BLOG(ERROR) << "Response id: " << id - << " does not match confirmation id: " << confirmation_info.id; - OnRedeem(FAILED, confirmation_info); - return; - } + auto id = id_value->GetString(); + + // Validate id + if (id != confirmation_id) { + BLOG(ERROR) << "Response id: " << id << " does not match confirmation id: " + << confirmation_id; + OnRedeem(FAILED, token_info); + return; } // Fetch payment token - FetchPaymentToken(confirmation_info); + FetchPaymentToken(confirmation_type, confirmation_id, payment_token, + blinded_payment_token, token_info); } -void RedeemToken::FetchPaymentToken(const ConfirmationInfo& confirmation_info) { - DCHECK(!confirmation_info.id.empty()); +void RedeemToken::FetchPaymentToken( + const ConfirmationType confirmation_type, + const std::string& confirmation_id, + const Token& payment_token, + const BlindedToken& blinded_payment_token, + const TokenInfo& token_info) { + DCHECK(!confirmation_id.empty()); BLOG(INFO) << "FetchPaymentToken"; @@ -212,13 +199,14 @@ void RedeemToken::FetchPaymentToken(const ConfirmationInfo& confirmation_info) { BLOG(INFO) << "URL Request:"; - auto url = request.BuildUrl(confirmation_info.id); + auto url = request.BuildUrl(confirmation_id); BLOG(INFO) << " URL: " << url; auto method = request.GetMethod(); auto callback = std::bind(&RedeemToken::OnFetchPaymentToken, - this, url, _1, _2, _3, confirmation_info); + this, url, _1, _2, _3, confirmation_type, payment_token, + blinded_payment_token, token_info); confirmations_client_->LoadURL(url, {}, "", "", method, callback); } @@ -228,7 +216,10 @@ void RedeemToken::OnFetchPaymentToken( const int response_status_code, const std::string& response, const std::map& headers, - const ConfirmationInfo& confirmation_info) { + const ConfirmationType confirmation_type, + const Token& payment_token, + const BlindedToken& blinded_payment_token, + const TokenInfo& token_info) { BLOG(INFO) << "OnFetchPaymentToken"; BLOG(INFO) << "URL Request Response:"; @@ -242,7 +233,7 @@ void RedeemToken::OnFetchPaymentToken( if (response_status_code != 200) { BLOG(ERROR) << "Failed to fetch payment token"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } @@ -252,7 +243,7 @@ void RedeemToken::OnFetchPaymentToken( if (!dictionary) { BLOG(ERROR) << "Failed to parse response: " << response; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } @@ -260,7 +251,7 @@ void RedeemToken::OnFetchPaymentToken( auto* id_value = dictionary->FindKey("id"); if (!id_value) { BLOG(ERROR) << "Response missing id"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } @@ -270,7 +261,7 @@ void RedeemToken::OnFetchPaymentToken( auto* payment_token_value = dictionary->FindKey("paymentToken"); if (!payment_token_value) { BLOG(ERROR) << "Response missing paymentToken"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } @@ -278,7 +269,7 @@ void RedeemToken::OnFetchPaymentToken( base::DictionaryValue* payment_token_dictionary; if (!payment_token_value->GetAsDictionary(&payment_token_dictionary)) { BLOG(ERROR) << "Response missing paymentToken dictionary"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } @@ -286,7 +277,7 @@ void RedeemToken::OnFetchPaymentToken( auto* public_key_value = payment_token_dictionary->FindKey("publicKey"); if (!public_key_value) { BLOG(ERROR) << "Response missing publicKey in paymentToken dictionary"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } auto public_key_base64 = public_key_value->GetString(); @@ -296,7 +287,7 @@ void RedeemToken::OnFetchPaymentToken( if (!confirmations_->IsValidPublicKeyForCatalogIssuers(public_key_base64)) { BLOG(ERROR) << "Response public_key: " << public_key_base64 << " was not found in the catalog issuers"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } @@ -304,7 +295,7 @@ void RedeemToken::OnFetchPaymentToken( auto* batch_proof_value = payment_token_dictionary->FindKey("batchProof"); if (!batch_proof_value) { BLOG(ERROR) << "Response missing batchProof in paymentToken dictionary"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } @@ -315,14 +306,14 @@ void RedeemToken::OnFetchPaymentToken( auto* signed_tokens_value = payment_token_dictionary->FindKey("signedTokens"); if (!signed_tokens_value) { BLOG(ERROR) << "Response missing signedTokens in paymentToken dictionary"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } base::ListValue signed_token_base64_values(signed_tokens_value->GetList()); if (signed_token_base64_values.GetSize() != 1) { BLOG(ERROR) << "Too many signedTokens"; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } @@ -334,8 +325,8 @@ void RedeemToken::OnFetchPaymentToken( } // Verify and unblind payment token - auto payment_tokens = {confirmation_info.payment_token}; - auto blinded_payment_tokens = {confirmation_info.blinded_payment_token}; + auto payment_tokens = {payment_token}; + auto blinded_payment_tokens = {blinded_payment_token}; auto unblinded_payment_tokens = batch_proof.verify_and_unblind( payment_tokens, blinded_payment_tokens, signed_tokens, public_key); @@ -346,13 +337,12 @@ void RedeemToken::OnFetchPaymentToken( BLOG(ERROR) << " Batch proof: " << batch_proof_base64; BLOG(ERROR) << " Payment tokens (" << payment_tokens.size() << "):"; - auto payment_token_base64 = confirmation_info.payment_token.encode_base64(); + auto payment_token_base64 = payment_token.encode_base64(); BLOG(ERROR) << " " << payment_token_base64; BLOG(ERROR) << " Blinded payment tokens (" << blinded_payment_tokens.size() << "):"; - auto blinded_payment_token_base64 = - confirmation_info.blinded_payment_token.encode_base64(); + auto blinded_payment_token_base64 = blinded_payment_token.encode_base64(); BLOG(ERROR) << " " << blinded_payment_token_base64; BLOG(ERROR) << " Signed tokens (" << signed_tokens.size() << "):"; @@ -363,21 +353,16 @@ void RedeemToken::OnFetchPaymentToken( BLOG(ERROR) << " Public key: " << public_key_base64; - OnRedeem(FAILED, confirmation_info); + OnRedeem(FAILED, token_info); return; } // Add unblinded payment token TokenInfo unblinded_payment_token_info; - unblinded_payment_token_info.unblinded_token - = unblinded_payment_tokens.front(); + unblinded_payment_token_info.unblinded_token = + unblinded_payment_tokens.front(); unblinded_payment_token_info.public_key = public_key_base64; - if (unblinded_payment_tokens_->TokenExists(unblinded_payment_token_info)) { - OnRedeem(FAILED, confirmation_info, false); - return; - } - std::vector tokens = {unblinded_payment_token_info}; unblinded_payment_tokens_->AddTokens(tokens); @@ -391,68 +376,31 @@ void RedeemToken::OnFetchPaymentToken( << " " << estimated_redemption_value << " BAT, you now have " << unblinded_payment_tokens_->Count() << " unblinded payment tokens"; - confirmations_->AppendTransactionToHistory( - estimated_redemption_value, confirmation_info.type); + confirmations_->AppendTransactionToTransactionHistory( + estimated_redemption_value, confirmation_type); - OnRedeem(SUCCESS, confirmation_info); + OnRedeem(SUCCESS, token_info); } void RedeemToken::OnRedeem( const Result result, - const ConfirmationInfo& confirmation_info, - const bool should_retry) { - auto was_removed = - confirmations_->RemoveConfirmationFromQueue(confirmation_info); - + const TokenInfo& token_info) { if (result != SUCCESS) { - BLOG(WARNING) << "Failed to redeem token with " - << confirmation_info.creative_instance_id - << " creative instance id for " - << std::string(confirmation_info.type); - - if (should_retry) { - if (was_removed) { - BLOG(INFO) << "Moved " << confirmation_info.creative_instance_id - << " creative instance id for " - << std::string(confirmation_info.type) - << " to the back of the confirmations queue"; - } else { - BLOG(INFO) << "Added " << confirmation_info.creative_instance_id - << " creative instance id for " - << std::string(confirmation_info.type) - << " to the confirmations queue"; - } - - confirmations_->AppendConfirmationToQueue(confirmation_info); - } + BLOG(ERROR) << "Failed to redeem token"; } else { - BLOG(INFO) << "Successfully redeemed token with " - << confirmation_info.creative_instance_id - << " creative instance id for " << std::string(confirmation_info.type); + BLOG(INFO) << "Successfully redeemed token"; } - if (unblinded_tokens_->RemoveToken(confirmation_info.token_info)) { - BLOG(INFO) << "Removed " << - confirmation_info.token_info.unblinded_token.encode_base64() + if (!unblinded_tokens_->RemoveToken(token_info)) { + BLOG(ERROR) << "Failed to remove unblinded token " + << token_info.unblinded_token.encode_base64() + << " as unblinded token could not be found"; + } else { + BLOG(INFO) << "Removed " << token_info.unblinded_token.encode_base64() << " unblinded token"; } - ScheduleNextRetryForFailedConfirmations(); - confirmations_->RefillTokensIfNecessary(); } -void RedeemToken::ScheduleNextRetryForFailedConfirmations() const { - auto start_timer_in = CalculateTimerForNextRetryForFailedConfirmations(); - confirmations_->StartRetryingFailedConfirmations(start_timer_in); -} - -uint64_t RedeemToken::CalculateTimerForNextRetryForFailedConfirmations() const { - auto start_timer_in = kRetryFailedConfirmationsAfterSeconds; - auto rand_delay = base::RandInt(0, start_timer_in / 10); - start_timer_in += rand_delay; - - return start_timer_in; -} - } // namespace confirmations diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.h index 4daf284b5053..3f03fd5772fa 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/redeem_token.h @@ -12,7 +12,6 @@ #include "bat/confirmations/confirmations_client.h" #include "bat/confirmations/internal/token_info.h" -#include "bat/confirmations/internal/confirmation_info.h" #include "bat/confirmations/confirmation_type.h" #include "wrapper.hpp" // NOLINT @@ -38,12 +37,8 @@ class RedeemToken { void Redeem( const std::string& creative_instance_id, const ConfirmationType confirmation_type); - void Redeem( - const ConfirmationInfo& confirmation_info); private: - void CreateConfirmation( - const ConfirmationInfo& confirmation_info); void CreateConfirmation( const std::string& creative_instance_id, const TokenInfo& token_info, @@ -53,24 +48,31 @@ class RedeemToken { const int response_status_code, const std::string& response, const std::map& headers, - const ConfirmationInfo& confirmation_info); + const ConfirmationType confirmation_type, + const std::string& confirmation_id, + const Token& payment_token, + const BlindedToken& blinded_payment_token, + const TokenInfo& token_info); void FetchPaymentToken( - const ConfirmationInfo& confirmation_info); + const ConfirmationType confirmation_type, + const std::string& confirmation_id, + const Token& payment_token, + const BlindedToken& blinded_payment_token, + const TokenInfo& token_info); void OnFetchPaymentToken( const std::string& url, const int response_status_code, const std::string& response, const std::map& headers, - const ConfirmationInfo& confirmation_info); + const ConfirmationType confirmation_type, + const Token& payment_token, + const BlindedToken& blinded_payment_token, + const TokenInfo& token_info); void OnRedeem( const Result result, - const ConfirmationInfo& confirmation_info, - const bool should_retry = true); - - void ScheduleNextRetryForFailedConfirmations() const; - uint64_t CalculateTimerForNextRetryForFailedConfirmations() const; + const TokenInfo& token_info); ConfirmationsImpl* confirmations_; // NOT OWNED ConfirmationsClient* confirmations_client_; // NOT OWNED diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/security_helper.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/security_helper.cc index 76caf7a3e005..78c98d48478a 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/security_helper.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/security_helper.cc @@ -60,7 +60,7 @@ std::string Security::Sign( } std::vector Security::GenerateTokens(const int count) { - DCHECK_GT(count, 0); + DCHECK_NE(count, 0); std::vector tokens; 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 a39185f25579..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 @@ -26,9 +26,6 @@ static const uint64_t kNextTokenRedemptionAfterSeconds = static const uint64_t kDebugNextTokenRedemptionAfterSeconds = 25 * base::Time::kSecondsPerMinute; -static const uint64_t kRetryFailedConfirmationsAfterSeconds = - 5 * base::Time::kSecondsPerMinute; - } // namespace confirmations #endif // BAT_CONFIRMATIONS_INTERNAL_STATIC_VALUES_H_ diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/unblinded_tokens.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/unblinded_tokens.cc index 741e412f7c04..ad208e506d6e 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/unblinded_tokens.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/unblinded_tokens.cc @@ -114,7 +114,8 @@ bool UnblindedTokens::RemoveToken(const TokenInfo& token) { auto it = std::find_if(tokens_.begin(), tokens_.end(), [=](const TokenInfo& info) { - return (info.unblinded_token == unblinded_token); + return (info.unblinded_token == unblinded_token && + info.public_key == public_key); }); if (it == tokens_.end()) { @@ -140,7 +141,8 @@ bool UnblindedTokens::TokenExists(const TokenInfo& token) { auto it = std::find_if(tokens_.begin(), tokens_.end(), [=](const TokenInfo& info) { - return (info.unblinded_token == unblinded_token); + return (info.unblinded_token == unblinded_token && + info.public_key == public_key); }); if (it == tokens_.end()) { 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 2d9fc7497f32..13d212d159a5 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 @@ -1331,8 +1331,7 @@ void LedgerImpl::ConfirmAd(const std::string& info) { notification_info->text = notification_info_ads.text; notification_info->url = notification_info_ads.url; notification_info->uuid = notification_info_ads.uuid; - - switch (notification_info_ads.type.value()) { + switch (notification_info_ads.type) { case ads::ConfirmationType::UNKNOWN: { notification_info->type = confirmations::ConfirmationType::UNKNOWN; break; From 5376b400f3803115b8dd05fbd1262106924a88fb Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Mon, 25 Mar 2019 14:13:36 -0700 Subject: [PATCH 2/2] Revert "Change payment token redemption timing" This reverts commit 69386e0c105be10359f96deafc2e02eacdc2900f. --- .../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 - .../src/bat/ads/internal/ads_serve.cc | 3 - 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 | 63 +++---------------- .../internal/confirmations_impl.h | 3 - .../confirmations/internal/payout_tokens.cc | 29 +++------ .../confirmations/internal/payout_tokens.h | 3 +- .../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 - 21 files changed, 49 insertions(+), 253 deletions(-) delete mode 100644 vendor/bat-native-confirmations/src/bat/confirmations/internal/time.cc delete 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 29663e6802f5..3c59f4dbf8e5 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -383,41 +383,6 @@ 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 @@ -459,42 +424,36 @@ 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,debug=true,short-retries=true,reconcile-interval=10"); + "staging=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=,debug=,shortretries=true,reconcile-interval"); + "staging=,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 1a19d062e781..e9a5d2adcae7 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -401,8 +401,6 @@ void RewardsServiceImpl::StartLedger() { #endif SetProduction(isProduction); - SetDebug(false); - const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); @@ -2446,20 +2444,6 @@ 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); @@ -2564,10 +2548,6 @@ 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 699d476c9596..0ea39ec8fd96 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -66,7 +66,6 @@ class PublisherInfoDatabase; class RewardsNotificationServiceImpl; using GetProductionCallback = base::Callback; -using GetDebugCallback = base::Callback; using GetReconcileTimeCallback = base::Callback; using GetShortRetriesCallback = base::Callback; @@ -177,8 +176,6 @@ 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 009c65d236db..96fed480ec0c 100644 --- a/components/services/bat_ledger/bat_ledger_service_impl.cc +++ b/components/services/bat_ledger/bat_ledger_service_impl.cc @@ -17,10 +17,6 @@ bool testing() { return ledger::is_testing; } -bool debug() { - return ledger::is_debug; -} - } namespace bat_ledger { @@ -48,11 +44,6 @@ 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; @@ -71,10 +62,6 @@ 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 298006690acd..08e93fdb0e16 100644 --- a/components/services/bat_ledger/bat_ledger_service_impl.h +++ b/components/services/bat_ledger/bat_ledger_service_impl.h @@ -1,10 +1,9 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public +/* 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 COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ -#define COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ +#ifndef BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ +#define BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ #include @@ -14,33 +13,31 @@ 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 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); + 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); }; -} // namespace bat_ledger +} // namespace bat_ledger -#endif // COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ +#endif // BRAVE_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 2a2f90b31b52..c3a33902adfe 100644 --- a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom +++ b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom @@ -9,13 +9,11 @@ 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-ads/src/bat/ads/internal/ads_serve.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc index c570baf7d4cd..d0b24517036a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc @@ -199,9 +199,6 @@ void AdsServe::RetryDownloadingCatalog() { next_retry_start_timer_in_ *= 2; } - auto rand_delay = base::RandInt(0, next_retry_start_timer_in_ / 10); - next_retry_start_timer_in_ += rand_delay; - ads_->StartCollectingActivity(next_retry_start_timer_in_); } diff --git a/vendor/bat-native-confirmations/BUILD.gn b/vendor/bat-native-confirmations/BUILD.gn index 4e6a570c044a..e98230594957 100644 --- a/vendor/bat-native-confirmations/BUILD.gn +++ b/vendor/bat-native-confirmations/BUILD.gn @@ -74,8 +74,6 @@ 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 297ca2608c07..bd81cad4d7d1 100644 --- a/vendor/bat-native-confirmations/README.md +++ b/vendor/bat-native-confirmations/README.md @@ -131,12 +131,6 @@ 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 b7c93ce991ce..aa8ea66cc14f 100644 --- a/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h +++ b/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h @@ -23,9 +23,6 @@ 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 76476cb16495..abef0178bbac 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc @@ -10,7 +10,6 @@ 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 4e962ba3d4cf..e1c67de4da00 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,9 +14,7 @@ #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" @@ -41,7 +39,6 @@ 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) { } @@ -79,9 +76,7 @@ void ConfirmationsImpl::CheckReady() { is_initialized_ = true; BLOG(INFO) << "Successfully initialized"; - auto start_timer_in = CalculateTokenRedemptionTimeInSeconds(); - StartPayingOutRedeemedTokens(start_timer_in); - + PayoutRedeemedTokens(); RefillTokensIfNecessary(); } @@ -98,10 +93,6 @@ 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_); @@ -334,7 +325,9 @@ bool ConfirmationsImpl::GetTransactionHistoryFromDictionary( std::stoull(timestamp_in_seconds_value->GetString()); } else { // timestamp missing, fallback to default - info.timestamp_in_seconds = Time::NowInSeconds(); + auto now = base::Time::Now(); + info.timestamp_in_seconds = + static_cast((now - base::Time()).InSeconds()); } // Estimated redemption value @@ -558,8 +551,11 @@ 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 = Time::NowInSeconds(); + info.timestamp_in_seconds = now_in_seconds; info.estimated_redemption_value = estimated_redemption_value; switch (confirmation_type) { @@ -658,49 +654,6 @@ 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 (next_token_redemption_date_in_seconds_ == 0) { - 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 6b639942a4f1..0f16c24de359 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,8 +62,6 @@ 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 @@ -105,7 +103,6 @@ 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 a06c900de9d6..6b527aceadbf 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 @@ -22,7 +22,6 @@ PayoutTokens::PayoutTokens( ConfirmationsImpl* confirmations, ConfirmationsClient* confirmations_client, UnblindedTokens* unblinded_payment_tokens) : - next_retry_start_timer_in_(0), confirmations_(confirmations), confirmations_client_(confirmations_client), unblinded_payment_tokens_(unblinded_payment_tokens) { @@ -116,38 +115,26 @@ void PayoutTokens::OnRedeemPaymentTokens( void PayoutTokens::OnPayout(const Result result) { if (result != SUCCESS) { BLOG(ERROR) << "Failed to payout tokens"; - - RetryNextPayout(); } else { unblinded_payment_tokens_->RemoveAllTokens(); BLOG(INFO) << "Successfully paid out tokens"; - - ScheduleNextPayout(); } + + ScheduleNextPayout(); } void PayoutTokens::ScheduleNextPayout() const { - confirmations_->UpdateNextTokenRedemptionDate(); - confirmations_->SaveState(); - - auto start_timer_in = confirmations_->CalculateTokenRedemptionTimeInSeconds(); + auto start_timer_in = CalculateTimerForNextPayout(); confirmations_->StartPayingOutRedeemedTokens(start_timer_in); } -void PayoutTokens::RetryNextPayout() { - BLOG(INFO) << "Retry next payout"; - - if (next_retry_start_timer_in_ == 0) { - next_retry_start_timer_in_ = 2 * base::Time::kSecondsPerMinute; - } else { - next_retry_start_timer_in_ *= 2; - } - - auto rand_delay = base::RandInt(0, next_retry_start_timer_in_ / 10); - next_retry_start_timer_in_ += rand_delay; +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; - confirmations_->StartPayingOutRedeemedTokens(next_retry_start_timer_in_); + return 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 f56e67842d06..92ae27625fae 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,8 +42,7 @@ class PayoutTokens { void OnPayout(const Result result); void ScheduleNextPayout() const; - uint64_t next_retry_start_timer_in_; - void RetryNextPayout(); + 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 3508f7e22d28..7eaf379b0b87 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,11 +20,8 @@ static const int kMaximumUnblindedTokens = 50; static const uint64_t kRetryGettingRefillSignedTokensAfterSeconds = 15; -static const uint64_t kNextTokenRedemptionAfterSeconds = - base::Time::kMicrosecondsPerWeek / base::Time::kMicrosecondsPerSecond; - -static const uint64_t kDebugNextTokenRedemptionAfterSeconds = - 25 * base::Time::kSecondsPerMinute; +static const uint64_t kPayoutAfterSeconds = + base::Time::kSecondsPerHour * base::Time::kHoursPerDay; } // 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 deleted file mode 100644 index 29e5a96e28a3..000000000000 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/time.cc +++ /dev/null @@ -1,17 +0,0 @@ -/* 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 deleted file mode 100644 index b5e420a763df..000000000000 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/time.h +++ /dev/null @@ -1,20 +0,0 @@ -/* 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 52231ef7d39b..e2a461ffa038 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/ledger.h +++ b/vendor/bat-native-ledger/include/bat/ledger/ledger.h @@ -22,7 +22,6 @@ 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 13d212d159a5..02df3f7ac1c8 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,7 +247,6 @@ 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 eb117dc66e40..85cb17cbdce7 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc @@ -14,7 +14,6 @@ namespace ledger { bool is_production = true; -bool is_debug = false; bool is_testing = false; int reconcile_time = 0; // minutes bool short_retries = false;