mirror of
https://github.com/overte-org/overte.git
synced 2025-04-18 01:26:31 +02:00
...simplify your life
This commit is contained in:
parent
7995f50fab
commit
38fde43009
6 changed files with 22 additions and 67 deletions
|
@ -43,10 +43,6 @@ Item {
|
|||
|
||||
calculatePendingAndInvalidated();
|
||||
}
|
||||
|
||||
if (transactionHistoryModel.count === 0) {
|
||||
commerce.setMustRegenerateKeypair(true);
|
||||
}
|
||||
refreshTimer.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ QJsonObject Ledger::failResponse(const QString& label, QNetworkReply& reply) {
|
|||
#define FailHandler(NAME) void Ledger::NAME##Failure(QNetworkReply& reply) { emit NAME##Result(failResponse(#NAME, reply)); }
|
||||
#define Handler(NAME) ApiHandler(NAME) FailHandler(NAME)
|
||||
Handler(buy)
|
||||
Handler(receiveAt)
|
||||
Handler(balance)
|
||||
Handler(inventory)
|
||||
|
||||
|
@ -89,18 +90,6 @@ void Ledger::buy(const QString& hfc_key, int cost, const QString& asset_id, cons
|
|||
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();
|
||||
|
||||
// ZRF FIXME! Change to something like `data["status"] == fail`
|
||||
// Not on "The List" for receiving HFC
|
||||
if (true) {
|
||||
wallet->setMustRegenerateKeypair(true);
|
||||
}
|
||||
}
|
||||
void Ledger::receiveAtFailure(QNetworkReply& reply) { failResponse("receiveAt", reply); }
|
||||
bool Ledger::receiveAt(const QString& hfc_key, const QString& old_key, const QString& machine_fingerprint) {
|
||||
auto accountManager = DependencyManager::get<AccountManager>();
|
||||
if (!accountManager->isLoggedIn()) {
|
||||
|
|
|
@ -57,11 +57,6 @@ void QmlCommerce::getWalletAuthenticatedStatus() {
|
|||
emit walletAuthenticatedStatusResult(wallet->walletIsAuthenticatedWithPassphrase());
|
||||
}
|
||||
|
||||
void QmlCommerce::setMustRegenerateKeypair(const bool& val) {
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
wallet->setMustRegenerateKeypair(val);
|
||||
}
|
||||
|
||||
void QmlCommerce::getSecurityImage() {
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
wallet->getSecurityImage();
|
||||
|
|
|
@ -54,7 +54,6 @@ protected:
|
|||
Q_INVOKABLE void getKeyFilePathIfExists();
|
||||
Q_INVOKABLE void getSecurityImage();
|
||||
Q_INVOKABLE void getWalletAuthenticatedStatus();
|
||||
Q_INVOKABLE void setMustRegenerateKeypair(const bool& val);
|
||||
|
||||
Q_INVOKABLE void chooseSecurityImage(const QString& imageFile);
|
||||
Q_INVOKABLE void setPassphrase(const QString& passphrase);
|
||||
|
|
|
@ -324,19 +324,9 @@ Wallet::Wallet() {
|
|||
|
||||
connect(ledger.data(), &Ledger::accountResult, this, [&]() {
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
auto ledger = DependencyManager::get<Ledger>();
|
||||
auto walletScriptingInterface = DependencyManager::get<WalletScriptingInterface>();
|
||||
uint status;
|
||||
|
||||
if (_mustRegenerateKeypair || getKeyFilePath() == "") {
|
||||
qCDebug(commerce) << "Regenerating keys and resetting user_hfc_account. _mustRegenerateKeypair:"
|
||||
<< _mustRegenerateKeypair << "keyFilePath:" << getKeyFilePath();
|
||||
_mustRegenerateKeypair = false;
|
||||
resetKeysOnly();
|
||||
ledger->reset(); // Hits `reset_user_hfc_account` endpoint
|
||||
generateKeyPair(); // Hits `receive_at` endpoint
|
||||
}
|
||||
|
||||
if (wallet->getKeyFilePath() == "" || !wallet->getSecurityImage()) {
|
||||
status = (uint)WalletStatus::WALLET_STATUS_NOT_SET_UP;
|
||||
} else if (!wallet->walletIsAuthenticatedWithPassphrase()) {
|
||||
|
@ -535,32 +525,25 @@ bool Wallet::generateKeyPair() {
|
|||
// FIXME: initialize OpenSSL elsewhere soon
|
||||
initialize();
|
||||
|
||||
qCInfo(commerce) << "Generating keypair...";
|
||||
QPair<QByteArray*, QByteArray*> keyPair = generateRSAKeypair();
|
||||
qCInfo(commerce) << "Generating keypair.";
|
||||
auto keyPair = generateRSAKeypair();
|
||||
|
||||
writeBackupInstructions();
|
||||
|
||||
// TODO: redo this soon -- need error checking and so on
|
||||
writeSecurityImage(_securityImage, keyFilePath());
|
||||
QString oldKey = _publicKeys.count() == 0 ? "" : _publicKeys.last();
|
||||
if (keyPair.first) {
|
||||
writeBackupInstructions();
|
||||
QString key = keyPair.first->toBase64();
|
||||
_publicKeys.push_back(key);
|
||||
qCDebug(commerce) << "public key:" << key;
|
||||
|
||||
// TODO: redo this soon -- need error checking and so on
|
||||
if (_securityImage) {
|
||||
writeSecurityImage(_securityImage, keyFilePath());
|
||||
}
|
||||
|
||||
QString key = keyPair.first->toBase64();
|
||||
_publicKeys.push_back(key);
|
||||
qCDebug(commerce) << "public key:" << key;
|
||||
|
||||
// It's arguable whether we want to change the receiveAt every time, but:
|
||||
// 1. It's certainly needed the first time, when createIfNeeded answers true.
|
||||
// 2. It is maximally private, and we can step back from that later if desired.
|
||||
// 3. It maximally exercises all the machinery, so we are most likely to surface issues now.
|
||||
auto ledger = DependencyManager::get<Ledger>();
|
||||
QString machineFingerprint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint());
|
||||
return ledger->receiveAt(key, oldKey, machineFingerprint);
|
||||
} else {
|
||||
qCDebug(commerce) << "Failure generating keys!";
|
||||
return false;
|
||||
}
|
||||
// It's arguable whether we want to change the receiveAt every time, but:
|
||||
// 1. It's certainly needed the first time, when createIfNeeded answers true.
|
||||
// 2. It is maximally private, and we can step back from that later if desired.
|
||||
// 3. It maximally exercises all the machinery, so we are most likely to surface issues now.
|
||||
auto ledger = DependencyManager::get<Ledger>();
|
||||
QString machineFingerprint = uuidStringWithoutCurlyBraces(FingerprintUtils::getMachineFingerprint());
|
||||
return ledger->receiveAt(key, oldKey, machineFingerprint);
|
||||
}
|
||||
|
||||
QStringList Wallet::listPublicKeys() {
|
||||
|
@ -678,13 +661,9 @@ QString Wallet::getKeyFilePath() {
|
|||
}
|
||||
}
|
||||
|
||||
void Wallet::resetKeysOnly() {
|
||||
void Wallet::reset() {
|
||||
_publicKeys.clear();
|
||||
|
||||
QFile keyFile(keyFilePath());
|
||||
keyFile.remove();
|
||||
}
|
||||
void Wallet::reset() {
|
||||
delete _securityImage;
|
||||
_securityImage = nullptr;
|
||||
|
||||
|
@ -692,7 +671,9 @@ void Wallet::reset() {
|
|||
updateImageProvider();
|
||||
_passphrase->clear();
|
||||
|
||||
resetKeysOnly();
|
||||
|
||||
QFile keyFile(keyFilePath());
|
||||
keyFile.remove();
|
||||
}
|
||||
bool Wallet::writeWallet(const QString& newPassphrase) {
|
||||
RSA* keys = readKeys(keyFilePath().toStdString().c_str());
|
||||
|
|
|
@ -49,7 +49,6 @@ public:
|
|||
bool walletIsAuthenticatedWithPassphrase();
|
||||
bool changePassphrase(const QString& newPassphrase);
|
||||
|
||||
void resetKeysOnly();
|
||||
void reset();
|
||||
|
||||
void getWalletStatus();
|
||||
|
@ -60,8 +59,6 @@ public:
|
|||
WALLET_STATUS_READY
|
||||
};
|
||||
|
||||
void setMustRegenerateKeypair(const bool& val) { _mustRegenerateKeypair = val; }
|
||||
|
||||
signals:
|
||||
void securityImageResult(bool exists);
|
||||
void keyFilePathIfExistsResult(const QString& path);
|
||||
|
@ -86,8 +83,6 @@ private:
|
|||
bool writeBackupInstructions();
|
||||
|
||||
void account();
|
||||
|
||||
bool _mustRegenerateKeypair { false };
|
||||
};
|
||||
|
||||
#endif // hifi_Wallet_h
|
||||
|
|
Loading…
Reference in a new issue