aboutsummaryrefslogtreecommitdiff
path: root/src/libwalletqt/WalletManager.h
blob: 8e63050a9352ca7619620647af0f085706cd98f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef WALLETMANAGER_H
#define WALLETMANAGER_H

#include <QObject>
#include <QUrl>
#include <wallet/wallet2_api.h>

class Wallet;
namespace Bitmonero {
    class WalletManager;
}

class WalletManager : public QObject
{
    Q_OBJECT

public:
    enum LogLevel {
        LogLevel_Silent = Bitmonero::WalletManagerFactory::LogLevel_Silent,
        LogLevel_0 = Bitmonero::WalletManagerFactory::LogLevel_0,
        LogLevel_1 = Bitmonero::WalletManagerFactory::LogLevel_1,
        LogLevel_2 = Bitmonero::WalletManagerFactory::LogLevel_2,
        LogLevel_3 = Bitmonero::WalletManagerFactory::LogLevel_3,
        LogLevel_4 = Bitmonero::WalletManagerFactory::LogLevel_4,
        LogLevel_Min = Bitmonero::WalletManagerFactory::LogLevel_Min,
        LogLevel_Max = Bitmonero::WalletManagerFactory::LogLevel_Max,
    };

    static WalletManager * instance();
    // wizard: createWallet path;
    Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password,
                                      const QString &language, bool testnet = false);

    /*!
     * \brief openWallet - opens wallet by given path
     * \param path       - wallet filename
     * \param password   - wallet password. Empty string in wallet isn't password protected
     * \param testnet    - determines if we running testnet
     * \return wallet object pointer
     */
    Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, bool testnet = false);

    /*!
     * \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal
     *                          emitted when wallet opened;
     */
    Q_INVOKABLE void openWalletAsync(const QString &path, const QString &password, bool testnet = false);

    // wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = ""
    Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo,
                                       bool testnet = false, quint64 restoreHeight = 0);

    /*!
     * \brief closeWallet - closes wallet and frees memory
     * \param wallet
     * \return wallet address
     */
    Q_INVOKABLE QString closeWallet(Wallet * wallet);

    /*!
     * \brief closeWalletAsync - asynchronous version of "closeWallet"
     * \param wallet - wallet pointer;
     */
    Q_INVOKABLE void closeWalletAsync(Wallet * wallet);

    //! checks is given filename is a wallet;
    Q_INVOKABLE bool walletExists(const QString &path) const;

    //! returns list with wallet's filenames, if found by given path
    Q_INVOKABLE QStringList findWallets(const QString &path);

    //! returns error description in human language
    Q_INVOKABLE QString errorString() const;


    // wizard: both "create" and "recovery" paths.
    // TODO: probably move it to "Wallet" interface
    Q_INVOKABLE bool moveWallet(const QString &src, const QString &dst);
    //! returns libwallet language name for given locale
    Q_INVOKABLE QString walletLanguage(const QString &locale);


    //! since we can't call static method from QML, move it to this class
    Q_INVOKABLE QString displayAmount(quint64 amount) const;
    Q_INVOKABLE quint64 amountFromString(const QString &amount) const;
    Q_INVOKABLE quint64 amountFromDouble(double amount) const;
    Q_INVOKABLE quint64 maximumAllowedAmount() const;

    // QML JS engine doesn't support unsigned integers
    Q_INVOKABLE QString maximumAllowedAmountAsSting() const;

    Q_INVOKABLE bool paymentIdValid(const QString &payment_id) const;
    Q_INVOKABLE bool addressValid(const QString &address, bool testnet) const;
    Q_INVOKABLE QString paymentIdFromAddress(const QString &address, bool testnet) const;

    Q_INVOKABLE QString checkPayment(const QString &address, const QString &txid, const QString &txkey, const QString &daemon_address) const;

    // QML missing such functionality, implementing these helpers here
    Q_INVOKABLE QString urlToLocalPath(const QUrl &url) const;
    Q_INVOKABLE QUrl localPathToUrl(const QString &path) const;

    void setLogLevel(int logLevel);

    Q_INVOKABLE quint64 add(quint64 x, quint64 y) const { return x + y; }
    Q_INVOKABLE quint64 sub(quint64 x, quint64 y) const { return x - y; }
    Q_INVOKABLE qint64 addi(qint64 x, qint64 y) const { return x + y; }
    Q_INVOKABLE qint64 subi(qint64 x, qint64 y) const { return x - y; }

signals:

    void walletOpened(Wallet * wallet);
    void walletClosed(const QString &walletAddress);

public slots:
private:

    explicit WalletManager(QObject *parent = 0);
    static WalletManager * m_instance;
    Bitmonero::WalletManager * m_pimpl;

};

#endif // WALLETMANAGER_H