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

Fixes corrupt wallet #1866

Merged
merged 1 commit into from
Mar 7, 2019
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
20 changes: 18 additions & 2 deletions vendor/bat-native-ledger/src/bat_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void BatClient::requestCredentialsCallback(

ledger_->SetUserId(user_id);

std::string registrar_vk = ledger_->GetRegistrarVK();
std::string registrar_vk;
if (!braveledger_bat_helper::getJSONValue(REGISTRARVK_FIELDNAME,
response,
&registrar_vk)) {
Expand All @@ -87,7 +87,7 @@ void BatClient::requestCredentialsCallback(
return;
}

braveledger_bat_helper::WALLET_INFO_ST wallet_info = ledger_->GetWalletInfo();
braveledger_bat_helper::WALLET_INFO_ST wallet_info;
std::vector<uint8_t> key_info_seed = braveledger_bat_helper::generateSeed();

wallet_info.keyInfoSeed_ = key_info_seed;
Expand Down Expand Up @@ -638,6 +638,22 @@ void BatClient::GetAddressesForPaymentIdCallback(
ledger_->SetAddresses(addresses);
}

void BatClient::CreateWalletIfNecessary() {
const auto payment_id = ledger_->GetPaymentId();
const auto stamp = ledger_->GetBootStamp();
const auto persona_id = ledger_->GetPersonaId();

if (!payment_id.empty() && stamp != 0 && !persona_id.empty()) {
ledger_->OnWalletInitialized(ledger::Result::WALLET_CREATED);
return;
}

BLOG(ledger_, ledger::LogLevel::LOG_ERROR) <<
"Wallet creation didn't finish or corrupted. " <<
"We need to clear persona Id and start again";
ledger_->SetPersonaId("");

registerPersona();
}

} // namespace braveledger_bat_client
2 changes: 2 additions & 0 deletions vendor/bat-native-ledger/src/bat_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class BatClient {

void GetAddressesForPaymentId(ledger::WalletAddressesCallback callback);

void CreateWalletIfNecessary();

private:
void getGrantCaptchaCallback(
bool result,
Expand Down
9 changes: 3 additions & 6 deletions vendor/bat-native-ledger/src/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ void LedgerImpl::Initialize() {
}

bool LedgerImpl::CreateWallet() {
if (initializing_)
if (initializing_) {
return false;
}

initializing_ = true;
if (initialized_) {
OnWalletInitialized(ledger::Result::LEDGER_ERROR);
return false;
}
bat_client_->registerPersona();
bat_client_->CreateWalletIfNecessary();
return true;
}

Expand Down