forked from carver/mix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QEther.h
92 lines (78 loc) · 2.34 KB
/
QEther.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
/*
This file is part of cpp-ethereum.
cpp-ethereum 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.
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file QEther.h
* @author Yann [email protected]
* @date 2014
* Represent an amount of Ether in QML (mapped to u256 in c++).
*/
#pragma once
#include <QObject>
#include <libethcore/Common.h>
#include "QBigInt.h"
namespace dev
{
namespace mix
{
class QEther: public QBigInt
{
Q_OBJECT
Q_ENUMS(EtherUnit)
Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(EtherUnit unit READ unit WRITE setUnit NOTIFY unitChanged)
public:
enum EtherUnit
{
Uether,
Vether,
Dether,
Nether,
Yether,
Zether,
Eether,
Pether,
Tether,
Gether,
Mether,
Grand,
Ether,
Finney,
Szabo,
Gwei,
Mwei,
Kwei,
Wei
};
QEther(QObject* _parent = 0): QBigInt(dev::u256(0), _parent), m_currentUnit(EtherUnit::Wei) {}
QEther(dev::u256 _value, EtherUnit _unit, QObject* _parent = 0): QBigInt(_value, _parent), m_currentUnit(_unit) {}
~QEther() {}
/// @returns user-friendly string representation of the amount of ether. Invokable from QML.
Q_INVOKABLE QString format() const;
/// @returns the current amount of Ether in Wei. Invokable from QML.
Q_INVOKABLE QBigInt* toWei() const;
/// @returns the current unit used. Invokable from QML.
Q_INVOKABLE EtherUnit unit() const { return m_currentUnit; }
/// Set the unit to be used. Invokable from QML.
Q_INVOKABLE void setUnit(EtherUnit const& _unit) { m_currentUnit = _unit; }
/// Set the unit to be used. Invokable from QML.
Q_INVOKABLE void setUnit(QString const& _unit);
/// @returns the u256 value of the current amount of Ether in Wei.
dev::u256 toU256Wei() { return boost::get<dev::u256>(toWei()->internalValue()); }
private:
EtherUnit m_currentUnit;
signals:
void valueChanged();
void unitChanged();
};
}
}