aboutsummaryrefslogtreecommitdiff
path: root/src/main/oshelper.cpp
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2023-01-11 12:16:55 -0500
committerluigi1111 <luigi1111w@gmail.com>2023-01-11 12:16:55 -0500
commit4487471ada3c1bb72283452a8bef3764b927ec1a (patch)
tree48c489f314288ed4c2499a5ff62c60555ab4ef5c /src/main/oshelper.cpp
parent55a0bc46e42d550b49708ad4f5481c1e2441d844 (diff)
parenta01dc06a54c5f30bb2bf49b0e28d8853c95df7af (diff)
downloadmonzero-gui-4487471ada3c1bb72283452a8bef3764b927ec1a.tar.gz
monzero-gui-4487471ada3c1bb72283452a8bef3764b927ec1a.tar.xz
monzero-gui-4487471ada3c1bb72283452a8bef3764b927ec1a.zip
Merge pull request #4088
a01dc06 open-wallet: set network type when using file browser (plowsof)
Diffstat (limited to 'src/main/oshelper.cpp')
-rw-r--r--src/main/oshelper.cpp33
1 files changed, 33 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;
+}