mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:41:20 +02:00
working, with soft reset
This commit is contained in:
parent
3d0e3a3901
commit
300f611c47
7 changed files with 33 additions and 10 deletions
|
@ -176,6 +176,7 @@ Rectangle {
|
||||||
id: walletChoice;
|
id: walletChoice;
|
||||||
proceedFunction: function (isReset) {
|
proceedFunction: function (isReset) {
|
||||||
console.log(isReset ? "Reset wallet." : "Trying again with new wallet.");
|
console.log(isReset ? "Reset wallet." : "Trying again with new wallet.");
|
||||||
|
Commerce.setSoftReset();
|
||||||
if (isReset) {
|
if (isReset) {
|
||||||
walletResetSetup();
|
walletResetSetup();
|
||||||
} else {
|
} else {
|
||||||
|
@ -795,7 +796,7 @@ Rectangle {
|
||||||
var timestamp = new Date();
|
var timestamp = new Date();
|
||||||
walletSetup.startingTimestamp = timestamp;
|
walletSetup.startingTimestamp = timestamp;
|
||||||
walletSetup.setupAttemptID = generateUUID();
|
walletSetup.setupAttemptID = generateUUID();
|
||||||
UserActivityLogger.commerceWalletSetupStarted(timestamp, setupAttemptID, walletSetup.setupFlowVersion, walletSetup.referrer ? walletSetup.referrer : "wallet app",
|
UserActivityLogger.commerceWalletSetupStarted(timestamp, walletSetup.setupAttemptID, walletSetup.setupFlowVersion, walletSetup.referrer ? walletSetup.referrer : "wallet app",
|
||||||
(AddressManager.placename || AddressManager.hostname || '') + (AddressManager.pathname ? AddressManager.pathname.match(/\/[^\/]+/)[0] : ''));
|
(AddressManager.placename || AddressManager.hostname || '') + (AddressManager.pathname ? AddressManager.pathname.match(/\/[^\/]+/)[0] : ''));
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
|
@ -101,7 +101,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ledger::receiveAt(const QString& hfc_key, const QString& old_key) {
|
bool Ledger::receiveAt(const QString& hfc_key, const QString& signing_key) {
|
||||||
auto accountManager = DependencyManager::get<AccountManager>();
|
auto accountManager = DependencyManager::get<AccountManager>();
|
||||||
if (!accountManager->isLoggedIn()) {
|
if (!accountManager->isLoggedIn()) {
|
||||||
qCWarning(commerce) << "Cannot set receiveAt when not logged in.";
|
qCWarning(commerce) << "Cannot set receiveAt when not logged in.";
|
||||||
|
@ -110,7 +110,7 @@ bool Ledger::receiveAt(const QString& hfc_key, const QString& old_key) {
|
||||||
return false; // We know right away that we will fail, so tell the caller.
|
return false; // We know right away that we will fail, so tell the caller.
|
||||||
}
|
}
|
||||||
|
|
||||||
signedSend("public_key", hfc_key.toUtf8(), old_key, "receive_at", "receiveAtSuccess", "receiveAtFailure");
|
signedSend("public_key", hfc_key.toUtf8(), signing_key, "receive_at", "receiveAtSuccess", "receiveAtFailure");
|
||||||
return true; // Note that there may still be an asynchronous signal of failure that callers might be interested in.
|
return true; // Note that there may still be an asynchronous signal of failure that callers might be interested in.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +248,7 @@ void Ledger::accountSuccess(QNetworkReply& reply) {
|
||||||
auto iv = QByteArray::fromBase64(data["iv"].toString().toUtf8());
|
auto iv = QByteArray::fromBase64(data["iv"].toString().toUtf8());
|
||||||
auto ckey = QByteArray::fromBase64(data["ckey"].toString().toUtf8());
|
auto ckey = QByteArray::fromBase64(data["ckey"].toString().toUtf8());
|
||||||
QString remotePublicKey = data["public_key"].toString();
|
QString remotePublicKey = data["public_key"].toString();
|
||||||
|
bool isOverride = wallet->wasSoftReset();
|
||||||
|
|
||||||
wallet->setSalt(salt);
|
wallet->setSalt(salt);
|
||||||
wallet->setIv(iv);
|
wallet->setIv(iv);
|
||||||
|
@ -255,9 +256,13 @@ void Ledger::accountSuccess(QNetworkReply& reply) {
|
||||||
|
|
||||||
QString keyStatus = "ok";
|
QString keyStatus = "ok";
|
||||||
QStringList localPublicKeys = wallet->listPublicKeys();
|
QStringList localPublicKeys = wallet->listPublicKeys();
|
||||||
if (remotePublicKey.isEmpty()) {
|
qDebug() << "FIXME isOverride:" << isOverride;
|
||||||
|
qDebug() << "remote:" << remotePublicKey;
|
||||||
|
qDebug() << " local:" << (localPublicKeys.isEmpty() ? "" : localPublicKeys.first());
|
||||||
|
if (remotePublicKey.isEmpty() || isOverride) {
|
||||||
if (!localPublicKeys.isEmpty()) {
|
if (!localPublicKeys.isEmpty()) {
|
||||||
receiveAt(localPublicKeys.first(), "");
|
QString key = localPublicKeys.first();
|
||||||
|
receiveAt(key, key);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (localPublicKeys.isEmpty()) {
|
if (localPublicKeys.isEmpty()) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Ledger : public QObject, public Dependency {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void buy(const QString& hfc_key, int cost, const QString& asset_id, const QString& inventory_key, const bool controlled_failure = false);
|
void buy(const QString& hfc_key, int cost, const QString& asset_id, const QString& inventory_key, const bool controlled_failure = false);
|
||||||
bool receiveAt(const QString& hfc_key, const QString& old_key);
|
bool receiveAt(const QString& hfc_key, const QString& signing_key);
|
||||||
void balance(const QStringList& keys);
|
void balance(const QStringList& keys);
|
||||||
void inventory(const QStringList& keys);
|
void inventory(const QStringList& keys);
|
||||||
void history(const QStringList& keys, const int& pageNumber);
|
void history(const QStringList& keys, const int& pageNumber);
|
||||||
|
|
|
@ -127,6 +127,11 @@ void QmlCommerce::changePassphrase(const QString& oldPassphrase, const QString&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlCommerce::setSoftReset() {
|
||||||
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
|
wallet->setSoftReset();
|
||||||
|
}
|
||||||
|
|
||||||
void QmlCommerce::setPassphrase(const QString& passphrase) {
|
void QmlCommerce::setPassphrase(const QString& passphrase) {
|
||||||
auto wallet = DependencyManager::get<Wallet>();
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
wallet->setPassphrase(passphrase);
|
wallet->setPassphrase(passphrase);
|
||||||
|
|
|
@ -63,6 +63,7 @@ protected:
|
||||||
Q_INVOKABLE void chooseSecurityImage(const QString& imageFile);
|
Q_INVOKABLE void chooseSecurityImage(const QString& imageFile);
|
||||||
Q_INVOKABLE void setPassphrase(const QString& passphrase);
|
Q_INVOKABLE void setPassphrase(const QString& passphrase);
|
||||||
Q_INVOKABLE void changePassphrase(const QString& oldPassphrase, const QString& newPassphrase);
|
Q_INVOKABLE void changePassphrase(const QString& oldPassphrase, const QString& newPassphrase);
|
||||||
|
Q_INVOKABLE void setSoftReset();
|
||||||
|
|
||||||
Q_INVOKABLE void buy(const QString& assetId, int cost, const bool controlledFailure = false);
|
Q_INVOKABLE void buy(const QString& assetId, int cost, const bool controlledFailure = false);
|
||||||
Q_INVOKABLE void balance();
|
Q_INVOKABLE void balance();
|
||||||
|
|
|
@ -61,13 +61,20 @@ QString keyFilePath() {
|
||||||
}
|
}
|
||||||
bool Wallet::copyKeyFileFrom(const QString& pathname) {
|
bool Wallet::copyKeyFileFrom(const QString& pathname) {
|
||||||
QString existing = getKeyFilePath();
|
QString existing = getKeyFilePath();
|
||||||
|
qCDebug(commerce) << "Old keyfile" << existing;
|
||||||
if (!existing.isEmpty()) {
|
if (!existing.isEmpty()) {
|
||||||
if (!QFile::rename(existing, existing + ".backup" + QDateTime::currentDateTime().toString(Qt::ISODate))) {
|
QString backup = QString(existing).insert(existing.indexOf(KEY_FILE) - 1,
|
||||||
qCCritical(commerce) << "Unable to backup" << existing;
|
QDateTime::currentDateTime().toString(Qt::ISODate).replace(":", ""));
|
||||||
|
qCDebug(commerce) << "Renaming old keyfile to" << backup;
|
||||||
|
if (!QFile::rename(existing, backup)) {
|
||||||
|
qCCritical(commerce) << "Unable to backup" << existing << "to" << backup;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QFile::copy(pathname, keyFilePath());
|
QString destination = keyFilePath();
|
||||||
|
bool result = QFile::copy(pathname, destination);
|
||||||
|
qCDebug(commerce) << "copy" << pathname << "to" << destination << "=>" << result;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the cached _passphrase if it exists, otherwise we need to prompt
|
// use the cached _passphrase if it exists, otherwise we need to prompt
|
||||||
|
@ -544,13 +551,14 @@ bool Wallet::generateKeyPair() {
|
||||||
QString key = keyPair.first->toBase64();
|
QString key = keyPair.first->toBase64();
|
||||||
_publicKeys.push_back(key);
|
_publicKeys.push_back(key);
|
||||||
qCDebug(commerce) << "public key:" << key;
|
qCDebug(commerce) << "public key:" << key;
|
||||||
|
_isOverridingServer = false;
|
||||||
|
|
||||||
// It's arguable whether we want to change the receiveAt every time, but:
|
// 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.
|
// 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.
|
// 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.
|
// 3. It maximally exercises all the machinery, so we are most likely to surface issues now.
|
||||||
auto ledger = DependencyManager::get<Ledger>();
|
auto ledger = DependencyManager::get<Ledger>();
|
||||||
return ledger->receiveAt(key, "");
|
return ledger->receiveAt(key, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Wallet::listPublicKeys() {
|
QStringList Wallet::listPublicKeys() {
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
bool getPassphraseIsCached() { return !(_passphrase->isEmpty()); }
|
bool getPassphraseIsCached() { return !(_passphrase->isEmpty()); }
|
||||||
bool walletIsAuthenticatedWithPassphrase();
|
bool walletIsAuthenticatedWithPassphrase();
|
||||||
bool changePassphrase(const QString& newPassphrase);
|
bool changePassphrase(const QString& newPassphrase);
|
||||||
|
void setSoftReset() { _isOverridingServer = true; }
|
||||||
|
bool wasSoftReset() { bool was = _isOverridingServer; _isOverridingServer = false; return was; }
|
||||||
|
|
||||||
void getWalletStatus();
|
void getWalletStatus();
|
||||||
enum WalletStatus {
|
enum WalletStatus {
|
||||||
|
@ -76,6 +78,7 @@ private:
|
||||||
QByteArray _iv;
|
QByteArray _iv;
|
||||||
QByteArray _ckey;
|
QByteArray _ckey;
|
||||||
QString* _passphrase { new QString("") };
|
QString* _passphrase { new QString("") };
|
||||||
|
bool _isOverridingServer { false };
|
||||||
|
|
||||||
bool writeWallet(const QString& newPassphrase = QString(""));
|
bool writeWallet(const QString& newPassphrase = QString(""));
|
||||||
void updateImageProvider();
|
void updateImageProvider();
|
||||||
|
|
Loading…
Reference in a new issue