a585f8d8d6fbcc40ed6878100757e969fa3217c6
[novacoin.git] / src / qt / walletmodel.h
1 #ifndef WALLETMODEL_H
2 #define WALLETMODEL_H
3
4 #include <QObject>
5
6 class OptionsModel;
7 class AddressTableModel;
8 class TransactionTableModel;
9 class CWallet;
10
11 struct SendCoinsRecipient
12 {
13     QString address;
14     QString label;
15     qint64 amount;
16 };
17
18 // Interface to Bitcoin wallet from Qt view code
19 class WalletModel : public QObject
20 {
21     Q_OBJECT
22 public:
23     explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
24
25     enum StatusCode
26     {
27         OK,
28         InvalidAmount,
29         InvalidAddress,
30         AmountExceedsBalance,
31         AmountWithFeeExceedsBalance,
32         DuplicateAddress,
33         TransactionCreationFailed,
34         TransactionCommitFailed,
35         Aborted,
36         MiscError
37     };
38
39     enum EncryptionStatus
40     {
41         Unencrypted,  // !wallet->IsCrypted()
42         Locked,       // wallet->IsCrypted() && wallet->IsLocked()
43         Unlocked      // wallet->IsCrypted() && !wallet->IsLocked()
44     };
45
46     OptionsModel *getOptionsModel();
47     AddressTableModel *getAddressTableModel();
48     TransactionTableModel *getTransactionTableModel();
49
50     qint64 getBalance() const;
51     qint64 getUnconfirmedBalance() const;
52     int getNumTransactions() const;
53     EncryptionStatus getEncryptionStatus() const;
54
55     bool isEncrypted() const;
56
57     // Check address for validity
58     bool validateAddress(const QString &address);
59
60     // Return status record for SendCoins, contains error id + information
61     struct SendCoinsReturn
62     {
63         SendCoinsReturn(StatusCode status,
64                          qint64 fee=0,
65                          QString hex=QString()):
66             status(status), fee(fee), hex(hex) {}
67         StatusCode status;
68         qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
69         QString hex; // is filled with the transaction hash if status is "OK"
70     };
71
72     // Send coins to a list of recipients
73     SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
74 private:
75     CWallet *wallet;
76
77     // Wallet has an options model for wallet-specific options
78     // (transaction fee, for example)
79     OptionsModel *optionsModel;
80
81     AddressTableModel *addressTableModel;
82     TransactionTableModel *transactionTableModel;
83
84     qint64 cachedBalance;
85     qint64 cachedUnconfirmedBalance;
86     qint64 cachedNumTransactions;
87     EncryptionStatus cachedEncryptionStatus;
88
89 signals:
90     void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
91     void numTransactionsChanged(int count);
92     void encryptionStatusChanged(int status);
93
94     // Asynchronous error notification
95     void error(const QString &title, const QString &message);
96
97 public slots:
98
99 private slots:
100     void update();
101 };
102
103
104 #endif // WALLETMODEL_H