From 532145b8d6930fd127bb2637a09129792253a3d5 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Sat, 16 May 2020 09:20:38 +0000 Subject: [PATCH 1/2] Uplift of #5569 (squashed) to beta --- .../ledger/internal/database/database_unblinded_token.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.cc index 9deeb83c30e2..aa7485891a76 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.cc @@ -441,8 +441,8 @@ void DatabaseUnblindedToken::GetRecordsByTriggerIds( const std::string query = base::StringPrintf( "SELECT ut.token_id, ut.token_value, ut.public_key, ut.value, " "ut.creds_id, ut.expires_at FROM %s as ut " - "INNER JOIN creds_batch as cb ON cb.creds_id = ut.creds_id " - "WHERE cb.trigger_id IN (%s)", + "LEFT JOIN creds_batch as cb ON cb.creds_id = ut.creds_id " + "WHERE cb.trigger_id IN (%s) OR ut.creds_id IS NULL", kTableName, GenerateStringInCase(trigger_ids).c_str()); @@ -523,10 +523,10 @@ void DatabaseUnblindedToken::GetSpendableRecordListByBatchTypes( const std::string query = base::StringPrintf( "SELECT ut.token_id, ut.token_value, ut.public_key, ut.value, " "ut.creds_id, ut.expires_at FROM %s as ut " - "INNER JOIN creds_batch as cb ON cb.creds_id = ut.creds_id " + "LEFT JOIN creds_batch as cb ON cb.creds_id = ut.creds_id " "WHERE ut.redeemed_at = 0 AND " "(ut.expires_at > strftime('%%s','now') OR ut.expires_at = 0) AND " - "cb.trigger_type IN (%s)", + "(cb.trigger_type IN (%s) OR ut.creds_id IS NULL)", kTableName, base::JoinString(in_case, ",").c_str()); From a96951970f87d1c77c28618786e3a3f15d1286e5 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 22 May 2020 09:05:48 +0200 Subject: [PATCH 2/2] Only claim not redeemed tokens Resolves https://github.com/brave/brave-browser/issues/9891 --- .../src/bat/ledger/internal/database/database.cc | 4 ++-- .../src/bat/ledger/internal/database/database.h | 2 +- .../bat/ledger/internal/database/database_unblinded_token.cc | 5 +++-- .../bat/ledger/internal/database/database_unblinded_token.h | 2 +- .../bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc | 4 ++-- .../bat-native-ledger/src/bat/ledger/internal/ledger_impl.h | 2 +- .../src/bat/ledger/internal/ledger_impl_mock.h | 2 +- .../src/bat/ledger/internal/promotion/promotion_transfer.cc | 2 +- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database.cc index a83992a88445..e89311432126 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database.cc @@ -509,10 +509,10 @@ void Database::MarkUblindedTokensAsSpent( callback); } -void Database::GetUnblindedTokensByTriggerIds( +void Database::GetSpendableUnblindedTokensByTriggerIds( const std::vector& trigger_ids, ledger::GetUnblindedTokenListCallback callback) { - unblinded_token_->GetRecordsByTriggerIds(trigger_ids, callback); + unblinded_token_->GetSpendableRecordsByTriggerIds(trigger_ids, callback); } void Database::GetSpendableUnblindedTokensByBatchTypes( diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database.h b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database.h index 62574e940890..3e5c7c4f7aa3 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database.h @@ -341,7 +341,7 @@ class Database { const std::string& redeem_id, ledger::ResultCallback callback); - void GetUnblindedTokensByTriggerIds( + void GetSpendableUnblindedTokensByTriggerIds( const std::vector& trigger_ids, ledger::GetUnblindedTokenListCallback callback); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.cc index aa7485891a76..13c3a12ab746 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.cc @@ -428,7 +428,7 @@ void DatabaseUnblindedToken::OnGetRecords( callback(std::move(list)); } -void DatabaseUnblindedToken::GetRecordsByTriggerIds( +void DatabaseUnblindedToken::GetSpendableRecordsByTriggerIds( const std::vector& trigger_ids, ledger::GetUnblindedTokenListCallback callback) { if (trigger_ids.empty()) { @@ -442,7 +442,8 @@ void DatabaseUnblindedToken::GetRecordsByTriggerIds( "SELECT ut.token_id, ut.token_value, ut.public_key, ut.value, " "ut.creds_id, ut.expires_at FROM %s as ut " "LEFT JOIN creds_batch as cb ON cb.creds_id = ut.creds_id " - "WHERE cb.trigger_id IN (%s) OR ut.creds_id IS NULL", + "WHERE ut.redeemed_at = 0 AND " + "(cb.trigger_id IN (%s) OR ut.creds_id IS NULL)", kTableName, GenerateStringInCase(trigger_ids).c_str()); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.h b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.h index d21fd119a1bc..883f2ccd8dd1 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/database/database_unblinded_token.h @@ -24,7 +24,7 @@ class DatabaseUnblindedToken: public DatabaseTable { ledger::UnblindedTokenList list, ledger::ResultCallback callback); - void GetRecordsByTriggerIds( + void GetSpendableRecordsByTriggerIds( const std::vector& trigger_ids, ledger::GetUnblindedTokenListCallback callback); 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 68dbe91ad511..80372c08eec3 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 @@ -1568,10 +1568,10 @@ void LedgerImpl::MarkUblindedTokensAsSpent( callback); } -void LedgerImpl::GetUnblindedTokensByTriggerIds( +void LedgerImpl::GetSpendableUnblindedTokensByTriggerIds( const std::vector& trigger_ids, ledger::GetUnblindedTokenListCallback callback) { - bat_database_->GetUnblindedTokensByTriggerIds(trigger_ids, callback); + bat_database_->GetSpendableUnblindedTokensByTriggerIds(trigger_ids, callback); } ledger::ClientInfoPtr LedgerImpl::GetClientInfo() { diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h index 6e1f9972bb32..9ca98363b59d 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h @@ -573,7 +573,7 @@ class LedgerImpl : public ledger::Ledger { const std::string& redeem_id, ledger::ResultCallback callback); - void GetUnblindedTokensByTriggerIds( + void GetSpendableUnblindedTokensByTriggerIds( const std::vector& trigger_ids, ledger::GetUnblindedTokenListCallback callback); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl_mock.h b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl_mock.h index f1bad7c0adb3..ca0360aa9350 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl_mock.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl_mock.h @@ -526,7 +526,7 @@ class MockLedgerImpl : public LedgerImpl { MOCK_METHOD1(GetAnonWalletStatus, void(ledger::ResultCallback)); - MOCK_METHOD2(GetUnblindedTokensByTriggerIds, void( + MOCK_METHOD2(GetSpendableUnblindedTokensByTriggerIds, void( const std::vector& trigger_ids, ledger::GetUnblindedTokenListCallback)); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion_transfer.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion_transfer.cc index b8d44adf85d9..fdf7fb19170e 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion_transfer.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/promotion/promotion_transfer.cc @@ -93,7 +93,7 @@ void PromotionTransfer::GetEligibleTokens( ids.push_back(promotion->id); } - ledger_->GetUnblindedTokensByTriggerIds( + ledger_->GetSpendableUnblindedTokensByTriggerIds( ids, tokens_callback); }