-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRippleAddress.h
127 lines (103 loc) · 2.89 KB
/
RippleAddress.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
126
127
#ifndef _RIPPLE_ADDRESS_H_
#define _RIPPLE_ADDRESS_H_
#include "base58.h"
#include "uint256.h"
#include "key.h"
#include "uchar_vector.h"
#include <boost/thread/mutex.hpp>
#include <boost/unordered_map.hpp>
typedef enum {
VER_NONE = 1,
VER_NODE_PUBLIC = 28,
VER_NODE_PRIVATE = 32,
VER_ACCOUNT_ID = 0,
VER_ACCOUNT_PUBLIC = 35,
VER_ACCOUNT_PRIVATE = 34,
VER_FAMILY_GENERATOR = 41,
VER_FAMILY_SEED = 33,
} VersionEncoding;
class RippleAddress : public CBase58Data
{
public:
void setSeed(uint128 hash);
uint128 getSeed() const;
const std::vector<unsigned char>& getAccountPublic() const;
void setAccountPublic(const uchar_vector& generator, int seq);
uint160 getAccountID() const;
void setAccountID(const uint160& hash160);
std::string humanAccountID() const;
std::string humanSeed() const;
};
void RippleAddress::setSeed(uint128 hash)
{
SetData(VER_FAMILY_SEED, hash.begin(), 16);
}
uint128 RippleAddress::getSeed() const
{
return uint128(vchData);
}
static RippleAddress createGeneratorPublic(const RippleAddress& naSeed)
{
CKey ckSeed(naSeed.getSeed());
RippleAddress naNew;
naNew.SetData(VER_FAMILY_GENERATOR, ckSeed.GetPubKey());
return naNew;
}
const std::vector<unsigned char>& RippleAddress::getAccountPublic() const
{
return vchData;
}
void RippleAddress::setAccountPublic(const uchar_vector& generator, int seq)
{
CKey pubkey(generator, seq);
SetData(VER_ACCOUNT_PUBLIC, pubkey.GetPubKey());
}
uint160 RippleAddress::getAccountID() const
{
switch (nVersion) {
case VER_NONE:
throw std::runtime_error("unset source - getAccountID");
case VER_ACCOUNT_ID:
return uint160(vchData);
case VER_ACCOUNT_PUBLIC:
// Note, we are encoding the left.
return Hash160(vchData);
default:
throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion)));
}
}
void RippleAddress::setAccountID(const uint160& hash160)
{
SetData(VER_ACCOUNT_ID, hash160.begin(), 20);
}
std::string RippleAddress::humanAccountID() const
{
switch (nVersion) {
case VER_NONE:
throw std::runtime_error("unset source - humanAccountID");
case VER_ACCOUNT_ID:
{
return ToString();
}
case VER_ACCOUNT_PUBLIC:
{
RippleAddress accountID;
(void) accountID.setAccountID(getAccountID());
return accountID.ToString();
}
default:
throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion)));
}
}
std::string RippleAddress::humanSeed() const
{
switch (nVersion) {
case VER_NONE:
throw std::runtime_error("unset source - humanSeed");
case VER_FAMILY_SEED:
return ToString();
default:
throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion)));
}
}
#endif