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

Moves pending contributon into mojom definition #2510

Merged
merged 1 commit into from May 28, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Moves pending contributon into mojom definition

  • Loading branch information
NejcZdovc committed May 28, 2019
commit 574f947b7633e710de64679d1cf289979e7e4d68
@@ -924,17 +924,17 @@ bool PublisherInfoDatabase::InsertPendingContribution
return false;
}

for (const auto& item : list.list_) {
for (const auto& item : list) {
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"INSERT INTO pending_contribution "
"(publisher_id, amount, added_date, viewing_id, category) "
"VALUES (?, ?, ?, ?, ?)"));

statement.BindString(0, item.publisher_key);
statement.BindDouble(1, item.amount);
statement.BindString(0, item->publisher_key);
statement.BindDouble(1, item->amount);
statement.BindInt64(2, now_seconds);
statement.BindString(3, item.viewing_id);
statement.BindInt(4, item.category);
statement.BindString(3, item->viewing_id);
statement.BindInt(4, item->category);
statement.Run();
}

@@ -982,20 +982,20 @@ void PublisherInfoDatabase::GetPendingContributions(
"INNER JOIN publisher_info AS pi ON pc.publisher_id = pi.publisher_id"));

while (info_sql.Step()) {
ledger::PendingContributionInfo info;
info.publisher_key = info_sql.ColumnString(0);
info.name = info_sql.ColumnString(1);
info.url = info_sql.ColumnString(2);
info.favicon_url = info_sql.ColumnString(3);
info.verified = info_sql.ColumnBool(4);
info.provider = info_sql.ColumnString(5);
info.amount = info_sql.ColumnDouble(6);
info.added_date = info_sql.ColumnInt64(7);
info.viewing_id = info_sql.ColumnString(8);
info.category =
auto info = ledger::PendingContributionInfo::New();
info->publisher_key = info_sql.ColumnString(0);
info->name = info_sql.ColumnString(1);
info->url = info_sql.ColumnString(2);
info->favicon_url = info_sql.ColumnString(3);
info->verified = info_sql.ColumnBool(4);
info->provider = info_sql.ColumnString(5);
info->amount = info_sql.ColumnDouble(6);
info->added_date = info_sql.ColumnInt64(7);
info->viewing_id = info_sql.ColumnString(8);
info->category =
static_cast<ledger::REWARDS_CATEGORY>(info_sql.ColumnInt(9));

list->push_back(info);
list->push_back(std::move(info));
}
}

@@ -624,25 +624,26 @@ TEST_F(PublisherInfoDatabaseTest, InsertPendingContribution) {
base::FilePath db_file;
CreateTempDatabase(&temp_dir, &db_file);

ledger::PendingContribution contribution1;
contribution1.publisher_key = "key1";
contribution1.amount = 10;
contribution1.added_date = 10;
contribution1.viewing_id = "fsodfsdnf23r23rn";
contribution1.category = ledger::REWARDS_CATEGORY::AUTO_CONTRIBUTE;

ledger::PendingContribution contribution2;
contribution2.publisher_key = "key2";
contribution2.amount = 20;
contribution2.viewing_id = "aafsofdfsdnf23r23rn";
contribution2.category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP;
auto contribution1 = ledger::PendingContribution::New();
contribution1->publisher_key = "key1";
contribution1->amount = 10;
contribution1->added_date = 10;
contribution1->viewing_id = "fsodfsdnf23r23rn";
contribution1->category = ledger::REWARDS_CATEGORY::AUTO_CONTRIBUTE;

auto contribution2 = ledger::PendingContribution::New();
contribution2->publisher_key = "key2";
contribution2->amount = 20;
contribution2->viewing_id = "aafsofdfsdnf23r23rn";
contribution2->category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP;


ledger::PendingContributionList list;
list.list_.push_back(contribution1);
list.list_.push_back(contribution2);
list.push_back(contribution1->Clone());
list.push_back(contribution2->Clone());

bool success = publisher_info_database_->InsertPendingContribution(
list);
std::move(list));
EXPECT_TRUE(success);

std::string query = "SELECT * FROM pending_contribution";
@@ -652,21 +653,21 @@ TEST_F(PublisherInfoDatabaseTest, InsertPendingContribution) {

// First contribution
EXPECT_TRUE(info_sql.Step());
EXPECT_EQ(info_sql.ColumnString(0), contribution1.publisher_key);
EXPECT_EQ(info_sql.ColumnDouble(1), contribution1.amount);
EXPECT_EQ(info_sql.ColumnString(0), contribution1->publisher_key);
EXPECT_EQ(info_sql.ColumnDouble(1), contribution1->amount);
EXPECT_GE(info_sql.ColumnInt64(2), 20);
EXPECT_EQ(info_sql.ColumnString(3), contribution1.viewing_id);
EXPECT_EQ(info_sql.ColumnString(3), contribution1->viewing_id);
EXPECT_EQ(static_cast<ledger::REWARDS_CATEGORY>(info_sql.ColumnInt(4)),
contribution1.category);
contribution1->category);

// Second contribution
EXPECT_TRUE(info_sql.Step());
EXPECT_EQ(info_sql.ColumnString(0), contribution2.publisher_key);
EXPECT_EQ(info_sql.ColumnDouble(1), contribution2.amount);
EXPECT_EQ(info_sql.ColumnString(0), contribution2->publisher_key);
EXPECT_EQ(info_sql.ColumnDouble(1), contribution2->amount);
EXPECT_GE(info_sql.ColumnInt64(2), 0);
EXPECT_EQ(info_sql.ColumnString(3), contribution2.viewing_id);
EXPECT_EQ(info_sql.ColumnString(3), contribution2->viewing_id);
EXPECT_EQ(static_cast<ledger::REWARDS_CATEGORY>(info_sql.ColumnInt(4)),
contribution2.category);
contribution2->category);
}

TEST_F(PublisherInfoDatabaseTest, GetActivityList) {
@@ -1043,35 +1044,35 @@ void PublisherInfoDatabaseTest::PreparePendingContributions() {
EXPECT_EQ(CountTableRows("publisher_info"), 4);

// Insert some pending contributions
ledger::PendingContribution contribution1;
contribution1.publisher_key = "key1";
contribution1.amount = 10;
contribution1.viewing_id = "fsodfsdnf23r23rn";
contribution1.category = ledger::REWARDS_CATEGORY::AUTO_CONTRIBUTE;

ledger::PendingContribution contribution2;
contribution2.publisher_key = "key2";
contribution2.amount = 20;
contribution2.viewing_id = "aafsoffdffdfsdnf23r23rn";
contribution2.category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP;

ledger::PendingContribution contribution3;
contribution3.publisher_key = "key3";
contribution3.amount = 30;
contribution3.viewing_id = "aafszxfzcofdfsdnf23r23rn";
contribution3.category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP;

ledger::PendingContribution contribution4;
contribution4.publisher_key = "key4";
contribution4.amount = 40;
contribution4.viewing_id = "aafsofdfs12333dnf23r23rn";
contribution4.category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP;
auto contribution1 = ledger::PendingContribution::New();
contribution1->publisher_key = "key1";
contribution1->amount = 10;
contribution1->viewing_id = "fsodfsdnf23r23rn";
contribution1->category = ledger::REWARDS_CATEGORY::AUTO_CONTRIBUTE;

auto contribution2 = ledger::PendingContribution::New();
contribution2->publisher_key = "key2";
contribution2->amount = 20;
contribution2->viewing_id = "aafsoffdffdfsdnf23r23rn";
contribution2->category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP;

auto contribution3 = ledger::PendingContribution::New();
contribution3->publisher_key = "key3";
contribution3->amount = 30;
contribution3->viewing_id = "aafszxfzcofdfsdnf23r23rn";
contribution3->category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP;

auto contribution4 = ledger::PendingContribution::New();
contribution4->publisher_key = "key4";
contribution4->amount = 40;
contribution4->viewing_id = "aafsofdfs12333dnf23r23rn";
contribution4->category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP;

ledger::PendingContributionList list;
list.list_.push_back(contribution1);
list.list_.push_back(contribution2);
list.list_.push_back(contribution3);
list.list_.push_back(contribution4);
list.push_back(std::move(contribution1));
list.push_back(std::move(contribution2));
list.push_back(std::move(contribution3));
list.push_back(std::move(contribution4));

success = publisher_info_database_->InsertPendingContribution(
list);
@@ -1093,12 +1094,12 @@ TEST_F(PublisherInfoDatabaseTest, GetPendingContributions) {
publisher_info_database_->GetPendingContributions(&select_list);
EXPECT_EQ(static_cast<int>(select_list.size()), 4);

EXPECT_EQ(select_list.at(0).publisher_key, "key1");
EXPECT_EQ(select_list.at(1).publisher_key, "key2");
EXPECT_EQ(select_list.at(2).publisher_key, "key3");
EXPECT_EQ(select_list.at(3).publisher_key, "key4");
EXPECT_EQ(select_list.at(0)->publisher_key, "key1");
EXPECT_EQ(select_list.at(1)->publisher_key, "key2");
EXPECT_EQ(select_list.at(2)->publisher_key, "key3");
EXPECT_EQ(select_list.at(3)->publisher_key, "key4");

EXPECT_EQ(select_list.at(0).url, "https://key1.com");
EXPECT_EQ(select_list.at(0)->url, "https://key1.com");
}

TEST_F(PublisherInfoDatabaseTest, RemovePendingContributions) {
@@ -1113,20 +1114,20 @@ TEST_F(PublisherInfoDatabaseTest, RemovePendingContributions) {
*/
ledger::PendingContributionInfoList select_list;
publisher_info_database_->GetPendingContributions(&select_list);
EXPECT_EQ(select_list.at(0).publisher_key, "key1");
EXPECT_EQ(select_list.at(0)->publisher_key, "key1");
bool success = publisher_info_database_->RemovePendingContributions(
"key1",
"fsodfsdnf23r23rn",
select_list.at(0).added_date);
select_list.at(0)->added_date);
EXPECT_TRUE(success);

ledger::PendingContributionInfoList list;
publisher_info_database_->GetPendingContributions(&list);
EXPECT_EQ(static_cast<int>(list.size()), 3);

EXPECT_EQ(list.at(0).publisher_key, "key2");
EXPECT_EQ(list.at(1).publisher_key, "key3");
EXPECT_EQ(list.at(2).publisher_key, "key4");
EXPECT_EQ(list.at(0)->publisher_key, "key2");
EXPECT_EQ(list.at(1)->publisher_key, "key3");
EXPECT_EQ(list.at(2)->publisher_key, "key4");

/**
* Trying to delete not existing row
@@ -2751,13 +2751,13 @@ void RewardsServiceImpl::OnSavePendingContribution(ledger::Result result) {
}

void RewardsServiceImpl::SavePendingContribution(
const ledger::PendingContributionList& list) {
ledger::PendingContributionList list) {
base::PostTaskAndReplyWithResult(
file_task_runner_.get(),
FROM_HERE,
base::Bind(&SavePendingContributionOnFileTaskRunner,
publisher_info_backend_.get(),
list),
std::move(list)),
base::Bind(&RewardsServiceImpl::OnSavePendingContribution,
AsWeakPtr()));
}
@@ -3034,32 +3034,30 @@ ledger::PendingContributionInfoList PendingContributionsOnFileTaskRunner(
}

PendingContributionInfo PendingContributionLedgerToRewards(
const ledger::PendingContributionInfo& contribution) {
const ledger::PendingContributionInfoPtr contribution) {
PendingContributionInfo info;
info.publisher_key = contribution.publisher_key;
info.category = contribution.category;
info.verified = contribution.verified;
info.name = contribution.name;
info.url = contribution.url;
info.provider = contribution.provider;
info.favicon_url = contribution.favicon_url;
info.amount = contribution.amount;
info.added_date = contribution.added_date;
info.viewing_id = contribution.viewing_id;
info.expiration_date = contribution.expiration_date;
info.publisher_key = contribution->publisher_key;
info.category = contribution->category;
info.verified = contribution->verified;
info.name = contribution->name;
info.url = contribution->url;
info.provider = contribution->provider;
info.favicon_url = contribution->favicon_url;
info.amount = contribution->amount;
info.added_date = contribution->added_date;
info.viewing_id = contribution->viewing_id;
info.expiration_date = contribution->expiration_date;
return info;
}

void RewardsServiceImpl::OnGetPendingContributionsUI(
GetPendingContributionsCallback callback,
const std::vector<std::string>& json_list) {
ledger::PendingContributionInfoList list) {
This conversation was marked as resolved by tmancey

This comment has been minimized.

Copy link
@tmancey

tmancey May 28, 2019

Collaborator

list should be const

This comment has been minimized.

Copy link
@NejcZdovc

NejcZdovc May 28, 2019

Author Member

this one can't be const as then you get this error

../../brave/components/brave_rewards/browser/rewards_service_impl.cc:3060:44: error: call to deleted constructor of 'ledger::PendingContributionInfoPtr' (aka 'StructPtr<ledger::mojom::PendingContributionInfo>')
        PendingContributionLedgerToRewards(std::move(item));
                                           ^~~~~~~~~~~~~~~
../../mojo/public/cpp/bindings/struct_ptr.h:114:28: note: 'StructPtr' has been explicitly marked deleted here
  DISALLOW_COPY_AND_ASSIGN(StructPtr);
                           ^
../../brave/components/brave_rewards/browser/rewards_service_impl.cc:3037:46: note: passing argument to parameter 'contribution' here
    const ledger::PendingContributionInfoPtr contribution) {
                                             ^
1 error generated.

This comment has been minimized.

Copy link
@tmancey

tmancey May 28, 2019

Collaborator

Yeap apologies did not expand function

std::unique_ptr<brave_rewards::PendingContributionInfoList> new_list(
new brave_rewards::PendingContributionInfoList);
for (auto &json_contribution : json_list) {
ledger::PendingContributionInfo contribution;
contribution.loadFromJson(json_contribution);
for (auto &item : list) {
brave_rewards::PendingContributionInfo new_contribution =
PendingContributionLedgerToRewards(contribution);
PendingContributionLedgerToRewards(std::move(item));
new_list->push_back(new_contribution);
}

@@ -3076,12 +3074,12 @@ void RewardsServiceImpl::GetPendingContributionsUI(

void RewardsServiceImpl::OnGetPendingContributions(
const ledger::PendingContributionInfoListCallback& callback,
const ledger::PendingContributionInfoList& list) {
ledger::PendingContributionInfoList list) {
if (!Connected()) {
return;
}

callback(list);
callback(std::move(list));
}

void RewardsServiceImpl::GetPendingContributions(
@@ -359,11 +359,11 @@ class RewardsServiceImpl : public RewardsService,

void OnGetPendingContributionsUI(
GetPendingContributionsCallback callback,
const std::vector<std::string>& json_list);
ledger::PendingContributionInfoList list);

void OnGetPendingContributions(
const ledger::PendingContributionInfoListCallback& callback,
const ledger::PendingContributionInfoList& list);
ledger::PendingContributionInfoList list);

void OnGetExcludedPublishersNumberDB(
ledger::GetExcludedPublishersNumberDBCallback callback,
@@ -499,7 +499,7 @@ class RewardsServiceImpl : public RewardsService,
ledger::PublisherInfoPtr publisher_info);

void SavePendingContribution(
const ledger::PendingContributionList& list) override;
ledger::PendingContributionList list) override;

void OnSavePendingContribution(ledger::Result result);

@@ -568,11 +568,11 @@ std::string BatLedgerClientMojoProxy::URIEncode(const std::string& value) {
}

void BatLedgerClientMojoProxy::SavePendingContribution(
const ledger::PendingContributionList& list) {
ledger::PendingContributionList list) {
if (!Connected())
return;

bat_ledger_client_->SavePendingContribution(list.ToJson());
bat_ledger_client_->SavePendingContribution(std::move(list));
}

void OnLoadActivityInfo(
@@ -730,22 +730,14 @@ void BatLedgerClientMojoProxy::GetExcludedPublishersNumberDB(

void OnGetPendingContributions(
const ledger::PendingContributionInfoListCallback& callback,
const std::vector<std::string>& info_list) {
ledger::PendingContributionInfoList list;

for (const auto& info : info_list) {
ledger::PendingContributionInfo new_info;
new_info.loadFromJson(info);
list.push_back(new_info);
}

callback(list);
ledger::PendingContributionInfoList list) {
callback(std::move(list));
}

void BatLedgerClientMojoProxy::GetPendingContributions(
const ledger::PendingContributionInfoListCallback& callback) {
if (!Connected()) {
callback(std::vector<ledger::PendingContributionInfo>());
callback(ledger::PendingContributionInfoList());
return;
}

@@ -107,7 +107,7 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,
std::string URIEncode(const std::string& value) override;

void SavePendingContribution(
const ledger::PendingContributionList& list) override;
ledger::PendingContributionList list) override;

void LoadActivityInfo(ledger::ActivityInfoFilter filter,
ledger::PublisherInfoCallback callback) override;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.