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

Fix wallet is in a persisted bad state until wallet recovery is complete #2655

Merged
merged 1 commit into from
Jun 11, 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
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 @@ -92,13 +92,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 @@ -1189,10 +1189,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 @@ -322,8 +322,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