Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Claim vg (uplift to 1.5.x) #4921

Merged
merged 2 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,36 @@ bool DatabaseUnblindedToken::DeleteRecordsForPromotion(
return statement.Run();
}

ledger::UnblindedTokenList DatabaseUnblindedToken::GetRecordsByPromotionType(
sql::Database* db,
const std::vector<ledger::PromotionType>& promotion_types) {
std::vector<std::string> in_case;

for (const auto& type : promotion_types) {
in_case.push_back(std::to_string(static_cast<int>(type)));
}

const std::string query = base::StringPrintf(
"SELECT u.token_id, u.token_value, u.public_key, u.value FROM %s as u "
"INNER JOIN promotion as p ON p.promotion_id = u.promotion_id "
"WHERE p.type IN (%s)",
table_name_,
base::JoinString(in_case, ",").c_str());

sql::Statement statement(db->GetUniqueStatement(query.c_str()));

ledger::UnblindedTokenList list;
while (statement.Step()) {
auto info = ledger::UnblindedToken::New();
info->id = statement.ColumnInt64(0);
info->token_value = statement.ColumnString(1);
info->public_key = statement.ColumnString(2);
info->value = statement.ColumnDouble(3);

list.push_back(std::move(info));
}

return list;
}

} // namespace brave_rewards
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class DatabaseUnblindedToken: public DatabaseTable {
sql::Database* db,
const std::string& promotion_id);

ledger::UnblindedTokenList GetRecordsByPromotionType(
sql::Database* db,
const std::vector<ledger::PromotionType>& promotion_types);

private:
bool CreateTableV10(sql::Database* db);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ bool PublisherInfoDatabase::DeleteUnblindedTokensForPromotion(
promotion_id);
}

ledger::UnblindedTokenList
PublisherInfoDatabase::GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types) {
return unblinded_token_->GetRecordsByPromotionType(&GetDB(), promotion_types);
}

/**
*
* GENERAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class PublisherInfoDatabase {
const std::string& contribution_id,
const std::string& publisher_key);

ledger::UnblindedTokenList GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types);

// Vacuums the database. This will cause sqlite to defragment and collect
// unused space in the file. It can be VERY SLOW.
void Vacuum();
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/rewards_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void RewardsService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
#endif
registry->RegisterUint64Pref(prefs::kStatePromotionLastFetchStamp, 0ull);
registry->RegisterBooleanPref(prefs::kStatePromotionCorruptedMigrated, false);
registry->RegisterBooleanPref(prefs::kStateAnonTransferChecked, false);
}

} // namespace brave_rewards
35 changes: 33 additions & 2 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4304,7 +4304,7 @@ ledger::UnblindedTokenList GetAllUnblindedTokensOnFileTaskRunner(
}

void RewardsServiceImpl::GetAllUnblindedTokens(
ledger::GetAllUnblindedTokensCallback callback) {
ledger::GetUnblindedTokenListCallback callback) {
base::PostTaskAndReplyWithResult(
file_task_runner_.get(),
FROM_HERE,
Expand All @@ -4316,7 +4316,7 @@ void RewardsServiceImpl::GetAllUnblindedTokens(
}

void RewardsServiceImpl::OnGetAllUnblindedTokens(
ledger::GetAllUnblindedTokensCallback callback,
ledger::GetUnblindedTokenListCallback callback,
ledger::UnblindedTokenList list) {
callback(std::move(list));
}
Expand Down Expand Up @@ -4749,4 +4749,35 @@ void RewardsServiceImpl::ReconcileStampReset() {
}
}

ledger::UnblindedTokenList GetUnblindedTokensByPromotionTypeOnFileTaskRunner(
PublisherInfoDatabase* backend,
const std::vector<ledger::PromotionType>& promotion_types) {
DCHECK(backend);
if (!backend) {
return {};
}

return backend->GetUnblindedTokensByPromotionType(promotion_types);
}

void RewardsServiceImpl::GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types,
ledger::GetUnblindedTokenListCallback callback) {
base::PostTaskAndReplyWithResult(
file_task_runner_.get(),
FROM_HERE,
base::BindOnce(&GetUnblindedTokensByPromotionTypeOnFileTaskRunner,
publisher_info_backend_.get(),
promotion_types),
base::BindOnce(&RewardsServiceImpl::OnGetUnblindedTokensByPromotionType,
AsWeakPtr(),
callback));
}

void RewardsServiceImpl::OnGetUnblindedTokensByPromotionType(
ledger::GetUnblindedTokenListCallback callback,
ledger::UnblindedTokenList list) {
callback(std::move(list));
}

} // namespace brave_rewards
12 changes: 10 additions & 2 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class RewardsServiceImpl : public RewardsService,
ledger::ResultCallback callback) override;

void GetAllUnblindedTokens(
ledger::GetAllUnblindedTokensCallback callback) override;
ledger::GetUnblindedTokenListCallback callback) override;

void DeleteUnblindedTokens(
const std::vector<std::string>& id_list,
Expand Down Expand Up @@ -779,6 +779,10 @@ class RewardsServiceImpl : public RewardsService,

void ReconcileStampReset() override;

void GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types,
ledger::GetUnblindedTokenListCallback callback) override;

// end ledger::LedgerClient

// Mojo Proxy methods
Expand Down Expand Up @@ -830,7 +834,7 @@ class RewardsServiceImpl : public RewardsService,
ledger::PromotionPtr info);

void OnGetAllUnblindedTokens(
ledger::GetAllUnblindedTokensCallback callback,
ledger::GetUnblindedTokenListCallback callback,
ledger::UnblindedTokenList list);

void OnGetAllPromotions(
Expand Down Expand Up @@ -877,6 +881,10 @@ class RewardsServiceImpl : public RewardsService,
ledger::GetContributionInfoCallback callback,
ledger::ContributionInfoPtr info);

void OnGetUnblindedTokensByPromotionType(
ledger::GetUnblindedTokenListCallback callback,
ledger::UnblindedTokenList list);

#if defined(OS_ANDROID)
ledger::Environment GetServerEnvironmentForAndroid();
void CreateWalletAttestationResult(
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ const char kStatePromotionLastFetchStamp[] =
"brave.rewards.promotion_last_fetch_stamp";
const char kStatePromotionCorruptedMigrated[] =
"brave.rewards.promotion_corrupted_migrated";
const char kStateAnonTransferChecked[] = "brave.rewards.anon_transfer_checked";
} // namespace prefs
} // namespace brave_rewards
1 change: 1 addition & 0 deletions components/brave_rewards/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern const char kStateServerPublisherListStamp[];
extern const char kStateUpholdAnonAddress[];
extern const char kStatePromotionLastFetchStamp[];
extern const char kStatePromotionCorruptedMigrated[];
extern const char kStateAnonTransferChecked[];

extern const char kUseRewardsStagingServer[];
} // namespace prefs
Expand Down
19 changes: 17 additions & 2 deletions components/services/bat_ledger/bat_ledger_client_mojo_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1011,13 +1011,13 @@ void BatLedgerClientMojoProxy::SaveUnblindedTokenList(
}

void OnGetAllUnblindedTokens(
const ledger::GetAllUnblindedTokensCallback& callback,
const ledger::GetUnblindedTokenListCallback& callback,
ledger::UnblindedTokenList list) {
callback(std::move(list));
}

void BatLedgerClientMojoProxy::GetAllUnblindedTokens(
ledger::GetAllUnblindedTokensCallback callback) {
ledger::GetUnblindedTokenListCallback callback) {
bat_ledger_client_->GetAllUnblindedTokens(
base::BindOnce(&OnGetAllUnblindedTokens, std::move(callback)));
}
Expand Down Expand Up @@ -1146,4 +1146,19 @@ void BatLedgerClientMojoProxy::ReconcileStampReset() {
bat_ledger_client_->ReconcileStampReset();
}

void OnGetUnblindedTokensByPromotionType(
ledger::GetUnblindedTokenListCallback callback,
ledger::UnblindedTokenList list) {
callback(std::move(list));
}

void BatLedgerClientMojoProxy::GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types,
ledger::GetUnblindedTokenListCallback callback) {
bat_ledger_client_->GetUnblindedTokensByPromotionType(
promotion_types,
base::BindOnce(&OnGetUnblindedTokensByPromotionType,
std::move(callback)));
}

} // namespace bat_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,
ledger::ResultCallback callback) override;

void GetAllUnblindedTokens(
ledger::GetAllUnblindedTokensCallback callback) override;
ledger::GetUnblindedTokenListCallback callback) override;

void DeleteUnblindedTokens(
const std::vector<std::string>& id_list,
Expand Down Expand Up @@ -268,6 +268,10 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,

void ReconcileStampReset() override;

void GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types,
ledger::GetUnblindedTokenListCallback callback) override;

private:
bool Connected() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,4 +1391,31 @@ void LedgerClientMojoProxy::ReconcileStampReset() {
ledger_client_->ReconcileStampReset();
}

// static
void LedgerClientMojoProxy::OnGetUnblindedTokensByPromotionType(
CallbackHolder<GetUnblindedTokensByPromotionTypeCallback>* holder,
ledger::UnblindedTokenList list) {
DCHECK(holder);
if (holder->is_valid()) {
std::move(holder->get()).Run(std::move(list));
}
delete holder;
}

void LedgerClientMojoProxy::GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types,
GetUnblindedTokensByPromotionTypeCallback callback) {
auto* holder =
new CallbackHolder<GetUnblindedTokensByPromotionTypeCallback>(
AsWeakPtr(),
std::move(callback));
ledger_client_->GetUnblindedTokensByPromotionType(
promotion_types,
std::bind(
LedgerClientMojoProxy::OnGetUnblindedTokensByPromotionType,
holder,
_1));
}


} // namespace bat_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ class LedgerClientMojoProxy : public mojom::BatLedgerClient,

void ReconcileStampReset() override;

void GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types,
GetUnblindedTokensByPromotionTypeCallback callback) override;

private:
// workaround to pass base::OnceCallback into std::bind
// also serves as a wrapper for passing ledger::LedgerCallbackHandler*
Expand Down Expand Up @@ -528,6 +532,10 @@ class LedgerClientMojoProxy : public mojom::BatLedgerClient,
CallbackHolder<UpdateContributionInfoContributedAmountCallback>* holder,
const ledger::Result result);

static void OnGetUnblindedTokensByPromotionType(
CallbackHolder<GetUnblindedTokensByPromotionTypeCallback>* holder,
ledger::UnblindedTokenList list);

ledger::LedgerClient* ledger_client_;

DISALLOW_COPY_AND_ASSIGN(LedgerClientMojoProxy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,6 @@ interface BatLedgerClient {
UpdateContributionInfoContributedAmount(string contribution_id, string publisher_key) => (ledger.mojom.Result result);

ReconcileStampReset();

GetUnblindedTokensByPromotionType(array<ledger.mojom.PromotionType> types) => (array<ledger.mojom.UnblindedToken> list);
};
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ test("brave_unit_tests") {
sources += [
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unblinded_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/phase_two_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/helper_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/reddit_unittest.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class MockConfirmationsClient : public ConfirmationsClient {
ledger::ResultCallback callback));

MOCK_METHOD1(GetAllUnblindedTokens, void(
ledger::GetAllUnblindedTokensCallback callback));
ledger::GetUnblindedTokenListCallback callback));

MOCK_METHOD2(DeleteUnblindedTokens, void(
const std::vector<std::string>& id_list,
Expand Down Expand Up @@ -407,6 +407,10 @@ class MockConfirmationsClient : public ConfirmationsClient {
ledger::ResultCallback callback));

MOCK_METHOD0(ReconcileStampReset, void());

MOCK_METHOD2(GetUnblindedTokensByPromotionType, void(
const std::vector<ledger::PromotionType>& promotion_types,
ledger::GetUnblindedTokenListCallback callback));
};

} // namespace confirmations
Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-ledger/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ source_set("ledger") {
"src/bat/ledger/internal/media/youtube.cc",
"src/bat/ledger/internal/promotion/promotion.cc",
"src/bat/ledger/internal/promotion/promotion.h",
"src/bat/ledger/internal/promotion/promotion_transfer.cc",
"src/bat/ledger/internal/promotion/promotion_transfer.h",
"src/bat/ledger/internal/promotion/promotion_util.cc",
"src/bat/ledger/internal/promotion/promotion_util.h",
"src/bat/ledger/internal/properties/ballot_properties.cc",
Expand Down
8 changes: 6 additions & 2 deletions vendor/bat-native-ledger/include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ using ResultCallback = std::function<void(const Result)>;
using GetFirstContributionQueueCallback =
std::function<void(ContributionQueuePtr)>;
using GetPromotionCallback = std::function<void(PromotionPtr)>;
using GetAllUnblindedTokensCallback = std::function<void(UnblindedTokenList)>;
using GetUnblindedTokenListCallback = std::function<void(UnblindedTokenList)>;
using GetAllPromotionsCallback = std::function<void(PromotionMap)>;

using GetTransactionReportCallback =
Expand Down Expand Up @@ -322,7 +322,7 @@ class LEDGER_EXPORT LedgerClient {
ledger::ResultCallback callback) = 0;

virtual void GetAllUnblindedTokens(
ledger::GetAllUnblindedTokensCallback callback) = 0;
ledger::GetUnblindedTokenListCallback callback) = 0;

virtual void DeleteUnblindedTokens(
const std::vector<std::string>& id_list,
Expand Down Expand Up @@ -365,6 +365,10 @@ class LEDGER_EXPORT LedgerClient {
ResultCallback callback) = 0;

virtual void ReconcileStampReset() = 0;

virtual void GetUnblindedTokensByPromotionType(
const std::vector<ledger::PromotionType>& promotion_types,
ledger::GetUnblindedTokenListCallback callback) = 0;
};

} // namespace ledger
Expand Down
Loading