Skip to content

Commit 7d39a2f

Browse files
committed
fix token show problem when switch from 0.30.6 version
1 parent 7e651c8 commit 7d39a2f

File tree

1 file changed

+57
-61
lines changed

1 file changed

+57
-61
lines changed

src/ripple/protocol/impl/UintTypes.cpp

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -27,78 +27,74 @@ namespace ripple {
2727

2828
std::string to_string(Currency const& currency)
2929
{
30-
// Characters we are willing to allow in the ASCII representation of a
31-
// three-letter currency code.
32-
static std::string const allowed_characters =
33-
"abcdefghijklmnopqrstuvwxyz"
34-
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
35-
"0123456789"
36-
"<>(){}[]|?!@#$%^&*";
37-
38-
if (currency == zero)
39-
return systemCurrencyCode();
40-
41-
if (currency == noCurrency())
42-
return "1";
43-
44-
static Currency const sIsoBits(
45-
from_hex_text<Currency>("FFFFFFFFFFFFFFFFFF0000000000000000000000"));
46-
47-
if ((currency & sIsoBits).isZero())
48-
{
49-
// The offset of the 3 character ISO code in the currency descriptor
50-
int const isoOffset = 10;
51-
int const startOffset = 9;
52-
53-
char length = currency.data()[startOffset];
54-
55-
std::string const iso(
56-
currency.data() + isoOffset,
57-
currency.data() + isoOffset + length);
58-
59-
// Specifying the system currency code using ISO-style representation
60-
// is not allowed.
61-
if ((iso != systemCurrencyCode()) &&
62-
(iso.find_first_not_of(allowed_characters) == std::string::npos))
63-
{
64-
return iso;
65-
}
66-
}
67-
68-
return strHex(currency.begin(), currency.size());
30+
// Characters we are willing to allow in the ASCII representation of a
31+
// three-letter currency code.
32+
static std::string const allowed_characters =
33+
"abcdefghijklmnopqrstuvwxyz"
34+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
35+
"0123456789"
36+
"<>(){}[]|?!@#$%^&*";
37+
38+
if (currency == zero)
39+
return systemCurrencyCode();
40+
41+
if (currency == noCurrency())
42+
return "1";
43+
44+
static Currency const sIsoBits (
45+
from_hex_text<Currency>("FFFFFFFFFFFFFFFFFFFFFFFF000000FFFFFFFFFF"));
46+
47+
if ((currency & sIsoBits).isZero ())
48+
{
49+
// The offset of the 3 character ISO code in the currency descriptor
50+
int const isoOffset = 12;
51+
52+
std::string const iso(
53+
currency.data () + isoOffset,
54+
currency.data () + isoOffset + 3);
55+
56+
// Specifying the system currency code using ISO-style representation
57+
// is not allowed.
58+
if ((iso != systemCurrencyCode()) &&
59+
(iso.find_first_not_of (allowed_characters) == std::string::npos))
60+
{
61+
return iso;
62+
}
63+
}
64+
65+
return strHex (currency.begin (), currency.size ());
6966
}
7067

7168
bool to_currency(Currency& currency, std::string const& code)
7269
{
73-
if (code.empty() || !code.compare(systemCurrencyCode()))
74-
{
75-
currency = zero;
76-
return true;
77-
}
70+
if (code.empty () || !code.compare (systemCurrencyCode()))
71+
{
72+
currency = zero;
73+
return true;
74+
}
7875

79-
static const int CURRENCY_CODE_LENGTH = 3;
80-
static const int CURRENCY_CODE_MAXLENGTH = 10;
81-
if (code.size() >= CURRENCY_CODE_LENGTH && code.size() <= CURRENCY_CODE_MAXLENGTH)
82-
{
83-
Blob codeBlob(code.size());
76+
static const int CURRENCY_CODE_LENGTH = 3;
77+
if (code.size () == CURRENCY_CODE_LENGTH)
78+
{
79+
Blob codeBlob (CURRENCY_CODE_LENGTH);
8480

85-
std::transform(code.begin(), code.end(), codeBlob.begin(), ::toupper);
81+
std::transform (code.begin (), code.end (), codeBlob.begin (), ::toupper);
8682

87-
Serializer s;
83+
Serializer s;
8884

89-
s.addZeros(72 / 8);
90-
s.add8(code.size());
91-
s.addRaw(codeBlob);
92-
s.addZeros(20 - 10 - code.size());
85+
s.addZeros (96 / 8);
86+
s.addRaw (codeBlob);
87+
s.addZeros (16 / 8);
88+
s.addZeros (24 / 8);
9389

94-
s.get160(currency, 0);
95-
return true;
96-
}
90+
s.get160 (currency, 0);
91+
return true;
92+
}
9793

98-
if (40 == code.size())
99-
return currency.SetHex(code);
94+
if (40 == code.size ())
95+
return currency.SetHex (code);
10096

101-
return false;
97+
return false;
10298
}
10399

104100
Currency to_currency(std::string const& code)

0 commit comments

Comments
 (0)