Skip to content

Commit

Permalink
Merge pull request #5518 from brave/recover-payout-1.8
Browse files Browse the repository at this point in the history
Adds recovery path for may payout problem (uplift to 1.8.x)
  • Loading branch information
kjozwiak authored and bsclifton committed May 12, 2020
1 parent 8afc9c9 commit f574085
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 15 deletions.
2 changes: 1 addition & 1 deletion components/brave_rewards/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const char kUseRewardsStagingServer[] = "brave.rewards.use_staging_server";
const char kStatePromotionLastFetchStamp[] =
"brave.rewards.promotion_last_fetch_stamp";
const char kStatePromotionCorruptedMigrated[] =
"brave.rewards.promotion_corrupted_migrated";
"brave.rewards.promotion_corrupted_migrated2";
const char kStateAnonTransferChecked[] = "brave.rewards.anon_transfer_checked";
} // namespace prefs
} // namespace brave_rewards
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ enum PromotionStatus {
ACTIVE = 0,
ATTESTED = 1,
FINISHED = 4,
OVER = 5
OVER = 5,
CORRUPTED = 6
};

struct Promotion {
Expand Down Expand Up @@ -440,7 +441,8 @@ enum CredsBatchStatus {
BLINDED = 1,
CLAIMED = 2,
SIGNED = 3,
FINISHED = 4
FINISHED = 4,
CORRUPTED = 5
};

struct CredsBatch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ void CredentialsPromotion::OnStart(
callback(ledger::Result::LEDGER_OK);
break;
}
case ledger::CredsBatchStatus::CORRUPTED: {
callback(ledger::Result::LEDGER_ERROR);
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ void Database::UpdateCredsBatchStatus(
creds_batch_->UpdateStatus(trigger_id, trigger_type, status, callback);
}

void Database::UpdateCredsBatchesStatus(
const std::vector<std::string>& trigger_ids,
const ledger::CredsBatchType trigger_type,
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback) {
creds_batch_->UpdateRecordsStatus(
trigger_ids,
trigger_type,
status,
callback);
}

/**
* MEDIA PUBLISHER INFO
*/
Expand Down Expand Up @@ -296,6 +308,13 @@ void Database::UpdatePromotionStatus(
promotion_->UpdateStatus(promotion_id, status, callback);
}

void Database::UpdatePromotionsStatus(
const std::vector<std::string>& promotion_ids,
const ledger::PromotionStatus status,
ledger::ResultCallback callback) {
promotion_->UpdateRecordsStatus(promotion_ids, status, callback);
}

void Database::PromotionCredentialCompleted(
const std::string& promotion_id,
ledger::ResultCallback callback) {
Expand All @@ -314,6 +333,12 @@ void Database::GetPromotionListByType(
promotion_->GetRecordsByType(types, callback);
}

void Database::UpdatePromotionsBlankPublicKey(
const std::vector<std::string>& ids,
ledger::ResultCallback callback) {
promotion_->UpdateRecordsBlankPublicKey(ids, callback);
}

/**
* PUBLISHER INFO
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ class Database {
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback);

void UpdateCredsBatchesStatus(
const std::vector<std::string>& trigger_ids,
const ledger::CredsBatchType trigger_type,
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback);

/**
* MEDIA PUBLISHER INFO
*/
Expand Down Expand Up @@ -207,6 +213,11 @@ class Database {
const ledger::PromotionStatus status,
ledger::ResultCallback callback);

void UpdatePromotionsStatus(
const std::vector<std::string>& promotion_ids,
const ledger::PromotionStatus status,
ledger::ResultCallback callback);

void PromotionCredentialCompleted(
const std::string& promotion_id,
ledger::ResultCallback callback);
Expand All @@ -219,6 +230,10 @@ class Database {
const std::vector<ledger::PromotionType>& types,
ledger::GetPromotionListCallback callback);

void UpdatePromotionsBlankPublicKey(
const std::vector<std::string>& ids,
ledger::ResultCallback callback);

/**
* PUBLISHER INFO
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,37 @@ void DatabaseCredsBatch::UpdateStatus(
ledger_->RunDBTransaction(std::move(transaction), transaction_callback);
}

void DatabaseCredsBatch::UpdateRecordsStatus(
const std::vector<std::string>& trigger_ids,
const ledger::CredsBatchType trigger_type,
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback) {
if (trigger_ids.empty()) {
callback(ledger::Result::LEDGER_ERROR);
return;
}

auto transaction = ledger::DBTransaction::New();

const std::string query = base::StringPrintf(
"UPDATE %s SET status = ? WHERE trigger_id IN (%s) AND trigger_type = ?",
kTableName,
GenerateStringInCase(trigger_ids).c_str());

auto command = ledger::DBCommand::New();
command->type = ledger::DBCommand::Type::RUN;
command->command = query;

BindInt(command.get(), 0, static_cast<int>(status));
BindInt(command.get(), 1, static_cast<int>(trigger_type));

transaction->commands.push_back(std::move(command));

auto transaction_callback = std::bind(&OnResultCallback,
_1,
callback);

ledger_->RunDBTransaction(std::move(transaction), transaction_callback);
}

} // namespace braveledger_database
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class DatabaseCredsBatch: public DatabaseTable {
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback);

void UpdateRecordsStatus(
const std::vector<std::string>& trigger_ids,
const ledger::CredsBatchType trigger_type,
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback);

private:
bool CreateTableV18(ledger::DBTransaction* transaction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,36 @@ void DatabasePromotion::UpdateStatus(
ledger_->RunDBTransaction(std::move(transaction), transaction_callback);
}

void DatabasePromotion::UpdateRecordsStatus(
const std::vector<std::string>& ids,
const ledger::PromotionStatus status,
ledger::ResultCallback callback) {
if (ids.empty()) {
callback(ledger::Result::LEDGER_ERROR);
return;
}

const std::string query = base::StringPrintf(
"UPDATE %s SET status = ? WHERE promotion_id IN (%s)",
kTableName,
GenerateStringInCase(ids).c_str());

auto transaction = ledger::DBTransaction::New();
auto command = ledger::DBCommand::New();
command->type = ledger::DBCommand::Type::RUN;
command->command = query;

BindInt(command.get(), 0, static_cast<int>(status));

transaction->commands.push_back(std::move(command));

auto transaction_callback = std::bind(&OnResultCallback,
_1,
callback);

ledger_->RunDBTransaction(std::move(transaction), transaction_callback);
}

void DatabasePromotion::CredentialCompleted(
const std::string& promotion_id,
ledger::ResultCallback callback) {
Expand Down Expand Up @@ -623,4 +653,27 @@ void DatabasePromotion::GetRecordsByType(
ledger_->RunDBTransaction(std::move(transaction), transaction_callback);
}

void DatabasePromotion::UpdateRecordsBlankPublicKey(
const std::vector<std::string>& ids,
ledger::ResultCallback callback) {
const std::string query = base::StringPrintf(
"UPDATE %s as p SET public_keys = "
"(SELECT PRINTF('[\"%%s\"]', public_key) FROM creds_batch as cb "
"WHERE cb.trigger_id = p.promotion_id) WHERE p.promotion_id IN (%s)",
kTableName,
GenerateStringInCase(ids).c_str());

auto transaction = ledger::DBTransaction::New();
auto command = ledger::DBCommand::New();
command->type = ledger::DBCommand::Type::EXECUTE;
command->command = query;
transaction->commands.push_back(std::move(command));

auto transaction_callback = std::bind(&OnResultCallback,
_1,
callback);

ledger_->RunDBTransaction(std::move(transaction), transaction_callback);
}

} // namespace braveledger_database
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class DatabasePromotion: public DatabaseTable {
const ledger::PromotionStatus status,
ledger::ResultCallback callback);

void UpdateRecordsStatus(
const std::vector<std::string>& ids,
const ledger::PromotionStatus status,
ledger::ResultCallback callback);

void CredentialCompleted(
const std::string& promotion_id,
ledger::ResultCallback callback);
Expand All @@ -59,6 +64,10 @@ class DatabasePromotion: public DatabaseTable {
const std::vector<ledger::PromotionType>& types,
ledger::GetPromotionListCallback callback);

void UpdateRecordsBlankPublicKey(
const std::vector<std::string>& ids,
ledger::ResultCallback callback);

private:
bool CreateTableV10(ledger::DBTransaction* transaction);

Expand Down
25 changes: 25 additions & 0 deletions vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,13 @@ void LedgerImpl::UpdatePromotionStatus(
bat_database_->UpdatePromotionStatus(promotion_id, status, callback);
}

void LedgerImpl::UpdatePromotionsStatus(
const std::vector<std::string>& promotion_ids,
const ledger::PromotionStatus status,
ledger::ResultCallback callback) {
bat_database_->UpdatePromotionsStatus(promotion_ids, status, callback);
}

void LedgerImpl::PromotionCredentialCompleted(
const std::string& promotion_id,
ledger::ResultCallback callback) {
Expand Down Expand Up @@ -1752,4 +1759,22 @@ void LedgerImpl::UpdateCredsBatchStatus(
callback);
}

void LedgerImpl::UpdateCredsBatchesStatus(
const std::vector<std::string>& trigger_ids,
const ledger::CredsBatchType trigger_type,
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback) {
bat_database_->UpdateCredsBatchesStatus(
trigger_ids,
trigger_type,
status,
callback);
}

void LedgerImpl::UpdatePromotionsBlankPublicKey(
const std::vector<std::string>& ids,
ledger::ResultCallback callback) {
bat_database_->UpdatePromotionsBlankPublicKey(ids, callback);
}

} // namespace bat_ledger
15 changes: 15 additions & 0 deletions vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@ class LedgerImpl : public ledger::Ledger {
const ledger::PromotionStatus status,
ledger::ResultCallback callback);

void UpdatePromotionsStatus(
const std::vector<std::string>& promotion_ids,
const ledger::PromotionStatus status,
ledger::ResultCallback callback);

void PromotionCredentialCompleted(
const std::string& promotion_id,
ledger::ResultCallback callback);
Expand All @@ -735,6 +740,16 @@ class LedgerImpl : public ledger::Ledger {
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback);

void UpdateCredsBatchesStatus(
const std::vector<std::string>& trigger_ids,
const ledger::CredsBatchType trigger_type,
const ledger::CredsBatchStatus status,
ledger::ResultCallback callback);

void UpdatePromotionsBlankPublicKey(
const std::vector<std::string>& ids,
ledger::ResultCallback callback);

private:
void InitializeConfirmations(
const bool execute_create_script,
Expand Down
Loading

0 comments on commit f574085

Please sign in to comment.