bb1c6e85d368d58537bd45f94ddba64585b64b49
[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     OptionsModel *getOptionsModel();
40     AddressTableModel *getAddressTableModel();
41     TransactionTableModel *getTransactionTableModel();
42
43     qint64 getBalance() const;
44     qint64 getUnconfirmedBalance() const;
45     int getNumTransactions() const;
46
47     // Check address for validity
48     bool validateAddress(const QString &address);
49
50     // Return status record for SendCoins, contains error id + information
51     struct SendCoinsReturn
52     {
53         SendCoinsReturn(StatusCode status,
54                          qint64 fee=0,
55                          QString hex=QString()):
56             status(status), fee(fee), hex(hex) {}
57         StatusCode status;
58         qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
59         QString hex; // is filled with the transaction hash if status is "OK"
60     };
61
62     // Send coins to a list of recipients
63     SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
64 private:
65     CWallet *wallet;
66
67     // Wallet has an options model for wallet-specific options
68     // (transaction fee, for example)
69     OptionsModel *optionsModel;
70
71     AddressTableModel *addressTableModel;
72     TransactionTableModel *transactionTableModel;
73
74     qint64 cachedBalance;
75     qint64 cachedUnconfirmedBalance;
76     qint64 cachedNumTransactions;
77
78 signals:
79     void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
80     void numTransactionsChanged(int count);
81
82     // Asynchronous error notification
83     void error(const QString &title, const QString &message);
84
85 public slots:
86
87 private slots:
88     void update();
89 };
90
91
92 #endif // WALLETMODEL_H