-
Notifications
You must be signed in to change notification settings - Fork 35
/
createaccountcontroller.h
118 lines (101 loc) · 3.34 KB
/
createaccountcontroller.h
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
#ifndef GREEN_CREATEACCOUNTCONTROLLER_H
#define GREEN_CREATEACCOUNTCONTROLLER_H
#include <QQmlEngine>
#include <QValidator>
#include "controller.h"
class Account;
class MnemonicGenerator : public QObject
{
Q_OBJECT
Q_PROPERTY(int size READ size WRITE setSize NOTIFY sizeChanged)
Q_PROPERTY(QStringList mnemonic READ mnemonic NOTIFY mnemonicChanged)
QML_ELEMENT
public:
MnemonicGenerator(QObject* parent = nullptr);
int size() const { return m_size; }
void setSize(int size);
QStringList mnemonic() const { return m_mnemonic; }
public slots:
void generate();
signals:
void sizeChanged();
void mnemonicChanged();
private:
int m_size{12};
QStringList m_mnemonic;
};
class CreateAccountController : public Controller
{
Q_OBJECT
Q_PROPERTY(Asset* asset READ asset WRITE setAsset NOTIFY assetChanged)
Q_PROPERTY(Network* network READ network WRITE setNetwork NOTIFY networkChanged)
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(QStringList recoveryMnemonic READ recoveryMnemonic WRITE setRecoveryMnemonic NOTIFY recoveryMnemonicChanged)
Q_PROPERTY(QString recoveryXpub READ recoveryXpub WRITE setRecoveryXpub NOTIFY recoveryXpubChanged)
QML_ELEMENT
public:
explicit CreateAccountController(QObject *parent = nullptr);
Asset* asset() const { return m_asset; }
void setAsset(Asset* asset);
Network* network() const { return m_network; }
void setNetwork(Network* network);
QString type() const { return m_type; }
void setType(const QString& type);
QStringList recoveryMnemonic() const { return m_recovery_mnemonic; }
void setRecoveryMnemonic(const QStringList& recovery_mnemonic);
QString recoveryXpub() const { return m_recovery_xpub; }
void setRecoveryXpub(const QString& recovery_xpub);
Q_INVOKABLE QStringList generateMnemonic(int size) const;
signals:
void assetChanged();
void networkChanged();
void typeChanged();
void created(Account* account);
void recoveryMnemonicChanged();
void recoveryXpubChanged();
void failed(const QString& error);
public slots:
void create();
private slots:
void ensureSession();
void ensureAccount();
private:
Asset* m_asset{nullptr};
Network* m_network{nullptr};
QString m_type;
QString m_error;
QStringList m_recovery_mnemonic;
QString m_recovery_xpub;
Account* m_account{nullptr};
};
class XPubValidator : public QValidator
{
Q_OBJECT
Q_PROPERTY(Network* network READ network WRITE setNetwork NOTIFY networkChanged)
QML_ELEMENT
public:
XPubValidator(QObject* parent = nullptr);
Network* network() const { return m_network; }
void setNetwork(Network* network);
QValidator::State validate(QString& input, int& pos) const override;
signals:
void networkChanged();
private:
Network* m_network{nullptr};
};
class DescriptorValidator : public QValidator
{
Q_OBJECT
Q_PROPERTY(Network* network READ network WRITE setNetwork NOTIFY networkChanged)
QML_ELEMENT
public:
DescriptorValidator(QObject* parent = nullptr);
Network* network() const { return m_network; }
void setNetwork(Network* network);
QValidator::State validate(QString& input, int& pos) const override;
signals:
void networkChanged();
private:
Network* m_network{nullptr};
};
#endif // GREEN_CREATEACCOUNTCONTROLLER_H