Could it be this simple?

This commit is contained in:
Zach Fox 2017-11-07 12:12:27 -08:00
parent f248eb5518
commit 8f54c106f6
3 changed files with 26 additions and 4 deletions

View file

@ -90,6 +90,15 @@ void Ledger::buy(const QString& hfc_key, int cost, const QString& asset_id, cons
signedSend("transaction", transactionString, hfc_key, "buy", "buySuccess", "buyFailure", controlled_failure); signedSend("transaction", transactionString, hfc_key, "buy", "buySuccess", "buyFailure", controlled_failure);
} }
void Ledger::receiveAtSuccess(QNetworkReply& reply) {
auto wallet = DependencyManager::get<Wallet>();
QByteArray response = reply.readAll();
QJsonObject data = QJsonDocument::fromJson(response).object();
if (data["status"] == "fail") { // Not on "The List" for receiving HFC
wallet->setMustRegenerateKeypair(true);
}
}
bool Ledger::receiveAt(const QString& hfc_key, const QString& old_key, const QString& machine_fingerprint) { bool Ledger::receiveAt(const QString& hfc_key, const QString& old_key, const QString& machine_fingerprint) {
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
if (!accountManager->isLoggedIn()) { if (!accountManager->isLoggedIn()) {

View file

@ -327,6 +327,12 @@ Wallet::Wallet() {
auto walletScriptingInterface = DependencyManager::get<WalletScriptingInterface>(); auto walletScriptingInterface = DependencyManager::get<WalletScriptingInterface>();
uint status; uint status;
if (_mustRegenerateKeypair) {
_mustRegenerateKeypair = false;
resetKeysOnly();
generateKeyPair();
}
if (wallet->getKeyFilePath() == "" || !wallet->getSecurityImage()) { if (wallet->getKeyFilePath() == "" || !wallet->getSecurityImage()) {
status = (uint)WalletStatus::WALLET_STATUS_NOT_SET_UP; status = (uint)WalletStatus::WALLET_STATUS_NOT_SET_UP;
} else if (!wallet->walletIsAuthenticatedWithPassphrase()) { } else if (!wallet->walletIsAuthenticatedWithPassphrase()) {
@ -661,9 +667,13 @@ QString Wallet::getKeyFilePath() {
} }
} }
void Wallet::reset() { void Wallet::resetKeysOnly() {
_publicKeys.clear(); _publicKeys.clear();
QFile keyFile(keyFilePath());
keyFile.remove();
}
void Wallet::reset() {
delete _securityImage; delete _securityImage;
_securityImage = nullptr; _securityImage = nullptr;
@ -671,9 +681,7 @@ void Wallet::reset() {
updateImageProvider(); updateImageProvider();
_passphrase->clear(); _passphrase->clear();
resetKeysOnly();
QFile keyFile(keyFilePath());
keyFile.remove();
} }
bool Wallet::writeWallet(const QString& newPassphrase) { bool Wallet::writeWallet(const QString& newPassphrase) {
RSA* keys = readKeys(keyFilePath().toStdString().c_str()); RSA* keys = readKeys(keyFilePath().toStdString().c_str());

View file

@ -49,6 +49,7 @@ public:
bool walletIsAuthenticatedWithPassphrase(); bool walletIsAuthenticatedWithPassphrase();
bool changePassphrase(const QString& newPassphrase); bool changePassphrase(const QString& newPassphrase);
void resetKeysOnly();
void reset(); void reset();
void getWalletStatus(); void getWalletStatus();
@ -59,6 +60,8 @@ public:
WALLET_STATUS_READY WALLET_STATUS_READY
}; };
void setMustRegenerateKeypair(const bool& val) { _mustRegenerateKeypair = val; }
signals: signals:
void securityImageResult(bool exists); void securityImageResult(bool exists);
void keyFilePathIfExistsResult(const QString& path); void keyFilePathIfExistsResult(const QString& path);
@ -83,6 +86,8 @@ private:
bool writeBackupInstructions(); bool writeBackupInstructions();
void account(); void account();
bool _mustRegenerateKeypair { false };
}; };
#endif // hifi_Wallet_h #endif // hifi_Wallet_h