forked from zeroreserve/ZeroReserve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zrtypes.h
125 lines (104 loc) · 3.33 KB
/
zrtypes.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
119
120
121
122
123
124
125
/*
This file is part of the Zero Reserve Plugin for Retroshare.
Zero Reserve is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zero Reserve 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Zero Reserve. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ZRTYPES_H
#define ZRTYPES_H
#include <boost/rational.hpp>
#include <string>
#include <QString>
#include <sstream>
#include <math.h>
#include <stdint.h>
namespace ZR {
class ZR_Number : public boost::rational< int64_t >
{
public:
ZR_Number() : boost::rational< int64_t >::rational( 0 ){}
ZR_Number( int64_t numerator, int64_t denumerator = 1):
boost::rational< int64_t >::rational( numerator, denumerator){}
ZR_Number( const boost::rational< int64_t > & a ) :
boost::rational< int64_t >::rational( a.numerator(), a.denominator() ){}
double toDouble() const
{
return boost::rational_cast<double>( *this );
}
static ZR_Number fromFractionString( const std::string & s_num )
{
boost::rational< int64_t > num;
std::istringstream sNum( s_num );
sNum >> num;
return num;
}
static ZR_Number fromDecimalString( const std::string & s_num )
{
const char delim = ( s_num.find( ',' ) != std::string::npos ) ? ',' : '.';
std::istringstream iss( s_num );
std::string sIntPart;
std::string sFracPart;
std::getline(iss, sIntPart, delim);
std::getline(iss, sFracPart, delim);
int factor = (int)pow(10, sFracPart.length() );
int intPart = strtol( sIntPart.c_str(), NULL, 10 );
int fracPart = strtol( sFracPart.c_str(), NULL, 10 );
if( intPart < 0 ) fracPart = -fracPart;
ZR_Number zrnum( intPart * factor + fracPart, factor );
return zrnum;
}
static ZR_Number fromDecimalString( QString s_num )
{
return fromDecimalString( s_num.toStdString() );
}
std::string toStdString() const
{
std::ostringstream o;
o << *this;
return o.str();
}
int length()
{
return toStdString().length();
}
QString toQString()
{
return QString::fromStdString( toStdString() );
}
std::string toDecimalStdString() const
{
std::ostringstream o;
o << toDouble();
return o.str();
}
QString toDecimalQString() const
{
return QString::fromStdString( toDecimalStdString() );
}
};
enum RetVal {
ZR_FAILURE = 0,
ZR_SUCCESS,
ZR_FINISH
};
/**
* @brief serves as the virtual address of a Turtle style tunnel and also as a TX id for remote payments
*/
typedef std::string VirtualAddress;
/**
* @brief Transaction ID for local payments
*/
typedef std::string TransactionId;
typedef std::string PeerAddress;
typedef std::string WalletSeed;
typedef std::string WalletSecret;
typedef std::string BitcoinAddress;
}
#endif // ZRTYPES_H