/* * This file is part of the Flowee project * Copyright (C) 2020 Tom Zander * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef FLOWEEPAY_H #define FLOWEEPAY_H #include #include #include #include #include class Wallet; class FloweePay : public QObject, WorkerThreads { Q_OBJECT Q_PROPERTY(QString unitName READ unitName NOTIFY unitChanged) Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged) Q_PROPERTY(int windowHeight READ windowHeight WRITE setWindowHeight NOTIFY windowHeightChanged) Q_PROPERTY(int unitAllowedDecimals READ unitAllowedDecimals NOTIFY unitChanged) Q_ENUMS(UnitsOfBitcoin StringType) public: enum StringType { Unknown = 0, PrivateKey, CashPKH, CashSH, LegacyPKH, LegacySH }; enum UnitOfBitcoin { BCH, MilliBCH, MicroBCH, Bits, Satoshis }; FloweePay(); ~FloweePay(); static FloweePay *instance(); QList wallets() const; DownloadManager* p2pNet(); /// return the app data location QString basedir() const; /// for a price, in satoshis, return a formatted string in unitName(). Q_INVOKABLE inline QString priceToString(double price) const { return priceToString(static_cast(price)); } /// for a price, in satoshis, return a formatted string in unitName(). QString priceToString(qint64 price) const; /// create a new wallet with an optional name. Q_INVOKABLE void createNewWallet(const QString &walletName = QString()); /// swipe a paper wallet with an optional name Q_INVOKABLE void createImportedWallet(const QString &privateKey, const QString &walletName); /// take a bitcoin-address and identify the type. Q_INVOKABLE StringType identifyString(const QString &string) const; /// returns the unit of our prices. BCH, for instance. QString unitName() const; /// returns the amount of digits allowed behind the decimal-separator. int unitAllowedDecimals() const; int windowWidth() const; void setWindowWidth(int windowWidth); int windowHeight() const; void setWindowHeight(int windowHeight); signals: void loadComplete(); /// \internal void loadComplete_priv(); void unitChanged(); void walletsChanged(); void windowWidthChanged(); void windowHeightChanged(); private: void init(); void saveData(); void saveAll(); Wallet *createWallet(const QString &name); UnitOfBitcoin m_unit = BCH; QString m_basedir; std::unique_ptr m_downloadManager; QList m_wallets; }; #endif