Skip to content

Commit

Permalink
Merge pull request #2738 from /issues/4794-0.67.x
Browse files Browse the repository at this point in the history
Fix wallet is in a persisted bad state until wallet recovery is complete - 0.67.x
  • Loading branch information
bsclifton committed Jun 25, 2019
2 parents f53fb04 + 5cad022 commit 74aa020
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
26 changes: 14 additions & 12 deletions vendor/bat-native-ledger/src/bat/ledger/internal/bat_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,6 @@ void BatClient::continueRecover(int result,
return;
}


braveledger_bat_helper::WALLET_INFO_ST wallet_info = ledger_->GetWalletInfo();
wallet_info.keyInfoSeed_ = newSeed;
ledger_->SetWalletInfo(wallet_info);

std::vector<uint8_t> secretKey = braveledger_bat_helper::getHKDF(newSeed);
std::vector<uint8_t> publicKey;
std::vector<uint8_t> newSecretKey;
Expand All @@ -408,7 +403,8 @@ void BatClient::continueRecover(int result,
this,
_1,
_2,
_3);
_3,
newSeed);
ledger_->LoadURL(braveledger_bat_helper::buildURL(
(std::string)RECOVER_WALLET_PUBLIC_KEY + publicKeyHex, PREFIX_V2),
std::vector<std::string>(), "", "",
Expand All @@ -418,7 +414,8 @@ void BatClient::continueRecover(int result,
void BatClient::recoverWalletPublicKeyCallback(
int response_status_code,
const std::string& response,
const std::map<std::string, std::string>& headers) {
const std::map<std::string, std::string>& headers,
const std::vector<uint8_t>& new_seed) {
ledger_->LogResponse(__func__, response_status_code, response, headers);

if (response_status_code != net::HTTP_OK) {
Expand All @@ -434,7 +431,8 @@ void BatClient::recoverWalletPublicKeyCallback(
_1,
_2,
_3,
recoveryId);
recoveryId,
new_seed);
ledger_->LoadURL(braveledger_bat_helper::buildURL(
(std::string)WALLET_PROPERTIES + recoveryId, PREFIX_V2),
std::vector<std::string>(), "", "", ledger::URL_METHOD::GET, callback);
Expand All @@ -444,8 +442,9 @@ void BatClient::recoverWalletCallback(
int response_status_code,
const std::string& response,
const std::map<std::string, std::string>& headers,
const std::string& recoveryId) {
ledger_->LogResponse(__func__, response_status_code, response, headers);
const std::string& recoveryId,
const std::vector<uint8_t>& new_seed) {
ledger_->LogResponse(__func__, response_status_code, response, headers);
if (response_status_code != net::HTTP_OK) {
std::vector<braveledger_bat_helper::GRANT> empty;
ledger_->OnRecoverWallet(ledger::Result::LEDGER_ERROR, 0, empty);
Expand All @@ -467,14 +466,17 @@ ledger_->LogResponse(__func__, response_status_code, response, headers);
&properties.balance_,
&properties.probi_,
&properties.grants_);
ledger_->SetWalletInfo(wallet_info);
ledger_->SetCurrency(currency);
if (!ledger_->GetUserChangedContribution()) {
ledger_->SetContributionAmount(fee_amount);
}
ledger_->SetDays(days);
ledger_->SetWalletProperties(&properties);
ledger_->SetPaymentId(recoveryId);

wallet_info.paymentId_ = recoveryId;
wallet_info.keyInfoSeed_ = new_seed;
ledger_->SetWalletInfo(wallet_info);

ledger_->OnRecoverWallet(ledger::Result::LEDGER_OK,
properties.balance_,
properties.grants_);
Expand Down
6 changes: 4 additions & 2 deletions vendor/bat-native-ledger/src/bat/ledger/internal/bat_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ class BatClient {
void recoverWalletPublicKeyCallback(
int response_status_code,
const std::string& response,
const std::map<std::string, std::string>& headers);
const std::map<std::string, std::string>& headers,
const std::vector<uint8_t>& new_seed);

void recoverWalletCallback(
int response_status_code,
const std::string& response,
const std::map<std::string, std::string>& headers,
const std::string& paymentId);
const std::string& recoveryId,
const std::vector<uint8_t>& new_seed);

std::string getAnonizeProof(const std::string& registrarVK,
const std::string& id,
Expand Down
5 changes: 0 additions & 5 deletions vendor/bat-native-ledger/src/bat/ledger/internal/bat_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ const std::string& BatState::GetPaymentId() const {
return state_->walletInfo_.paymentId_;
}

void BatState::SetPaymentId(const std::string& payment_id) {
state_->walletInfo_.paymentId_ = payment_id;
SaveState();
}

const braveledger_bat_helper::Grants& BatState::GetGrants() const {
return state_->grants_;
}
Expand Down
2 changes: 0 additions & 2 deletions vendor/bat-native-ledger/src/bat/ledger/internal/bat_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class BatState {

const std::string& GetPaymentId() const;

void SetPaymentId(const std::string& payment_id);

const braveledger_bat_helper::Grants& GetGrants() const;

void SetGrants(braveledger_bat_helper::Grants grants);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,10 +1197,6 @@ const std::string& LedgerImpl::GetPaymentId() const {
return bat_state_->GetPaymentId();
}

void LedgerImpl::SetPaymentId(const std::string& payment_id) {
bat_state_->SetPaymentId(payment_id);
}

const braveledger_bat_helper::Grants& LedgerImpl::GetGrants() const {
return bat_state_->GetGrants();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ class LedgerImpl : public ledger::Ledger,

const std::string& GetPaymentId() const;

void SetPaymentId(const std::string& payment_id);

const braveledger_bat_helper::Grants& GetGrants() const;

void SetGrants(braveledger_bat_helper::Grants grants);
Expand Down

0 comments on commit 74aa020

Please sign in to comment.