diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/oshelper.cpp | 33 | ||||
| -rw-r--r-- | src/main/oshelper.h | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/main/oshelper.cpp b/src/main/oshelper.cpp index c9b1e269..8294dd3c 100644 --- a/src/main/oshelper.cpp +++ b/src/main/oshelper.cpp @@ -63,6 +63,7 @@ #include "QR-Code-scanner/Decoder.h" #include "qt/ScopeGuard.h" +#include "NetworkType.h" namespace { @@ -280,3 +281,35 @@ bool OSHelper::installed() const return false; #endif } + +std::pair<quint8, QString> OSHelper::getNetworkTypeAndAddressFromFile(const QString &wallet) +{ + quint8 networkType = NetworkType::MAINNET; + QString address = QString(""); + // attempt to retreive wallet address + if(QFile::exists(wallet + ".address.txt")){ + QFile file(wallet + ".address.txt"); + file.open(QFile::ReadOnly | QFile::Text); + QString _address = QString(file.readAll()); + if(!_address.isEmpty()){ + address = _address; + if(address.startsWith("5") || address.startsWith("7")){ + networkType = NetworkType::STAGENET; + } else if(address.startsWith("9") || address.startsWith("B")){ + networkType = NetworkType::TESTNET; + } + } + + file.close(); + } + return std::make_pair(networkType, address); +} + +quint8 OSHelper::getNetworkTypeFromFile(const QString &keysPath) const +{ + QString walletPath = keysPath; + if(keysPath.endsWith(".keys")){ + walletPath = keysPath.mid(0,keysPath.length()-5); + } + return getNetworkTypeAndAddressFromFile(walletPath).first; +} diff --git a/src/main/oshelper.h b/src/main/oshelper.h index f4168071..eca1f2c7 100644 --- a/src/main/oshelper.h +++ b/src/main/oshelper.h @@ -52,7 +52,9 @@ public: Q_INVOKABLE QString temporaryPath() const; Q_INVOKABLE bool removeTemporaryWallet(const QString &walletName) const; Q_INVOKABLE bool isCapsLock() const; + Q_INVOKABLE quint8 getNetworkTypeFromFile(const QString &keysPath) const; + static std::pair<quint8, QString> getNetworkTypeAndAddressFromFile(const QString &wallet); private: bool installed() const; |
