From d322f1c015064329d59f5193a7135fd81b448f1e Mon Sep 17 00:00:00 2001 From: Nejc Zdovc Date: Wed, 6 Mar 2019 06:55:29 +0100 Subject: [PATCH] Merge pull request #1839 from brave/try-again-wallet Fixes corrupt wallet --- vendor/bat-native-ledger/src/bat_client.cc | 20 ++++++++++++++++++-- vendor/bat-native-ledger/src/bat_client.h | 2 ++ vendor/bat-native-ledger/src/ledger_impl.cc | 9 +++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/vendor/bat-native-ledger/src/bat_client.cc b/vendor/bat-native-ledger/src/bat_client.cc index 306d90e79516..0736861352c0 100644 --- a/vendor/bat-native-ledger/src/bat_client.cc +++ b/vendor/bat-native-ledger/src/bat_client.cc @@ -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, ®istrar_vk)) { @@ -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 key_info_seed = braveledger_bat_helper::generateSeed(); wallet_info.keyInfoSeed_ = key_info_seed; @@ -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 diff --git a/vendor/bat-native-ledger/src/bat_client.h b/vendor/bat-native-ledger/src/bat_client.h index bb7bccdbd08a..bf8853f90262 100644 --- a/vendor/bat-native-ledger/src/bat_client.h +++ b/vendor/bat-native-ledger/src/bat_client.h @@ -67,6 +67,8 @@ class BatClient { void GetAddressesForPaymentId(ledger::WalletAddressesCallback callback); + void CreateWalletIfNecessary(); + private: void getGrantCaptchaCallback( bool result, diff --git a/vendor/bat-native-ledger/src/ledger_impl.cc b/vendor/bat-native-ledger/src/ledger_impl.cc index ccd0d2eed9bd..eabca2473530 100644 --- a/vendor/bat-native-ledger/src/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/ledger_impl.cc @@ -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; }