Skip to content

Commit 55222dc

Browse files
recvinniefalco
authored andcommitted
New types Account, Currency, Directory:
* New tagged uint types. * Extract to_string functions from header to hide dependencies. * Include what you use and C++11 for cleanups.
1 parent adce6ae commit 55222dc

File tree

118 files changed

+2357
-3169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+2357
-3169
lines changed

Builds/VisualStudio2013/RippleD.vcxproj

+5-29
Original file line numberDiff line numberDiff line change
@@ -1983,9 +1983,6 @@
19831983
<ClCompile Include="..\..\src\ripple\module\app\book\impl\Taker.cpp">
19841984
<ExcludedFromBuild>True</ExcludedFromBuild>
19851985
</ClCompile>
1986-
<ClCompile Include="..\..\src\ripple\module\app\book\impl\Types.cpp">
1987-
<ExcludedFromBuild>True</ExcludedFromBuild>
1988-
</ClCompile>
19891986
<ClCompile Include="..\..\src\ripple\module\app\book\tests\OfferStream.test.cpp">
19901987
<ExcludedFromBuild>True</ExcludedFromBuild>
19911988
</ClCompile>
@@ -2002,26 +1999,6 @@
20021999
</ClCompile>
20032000
<ClInclude Include="..\..\src\ripple\module\app\consensus\LedgerConsensus.h">
20042001
</ClInclude>
2005-
<ClCompile Include="..\..\src\ripple\module\app\contracts\Contract.cpp">
2006-
<ExcludedFromBuild>True</ExcludedFromBuild>
2007-
</ClCompile>
2008-
<ClInclude Include="..\..\src\ripple\module\app\contracts\Contract.h">
2009-
</ClInclude>
2010-
<ClCompile Include="..\..\src\ripple\module\app\contracts\Interpreter.cpp">
2011-
<ExcludedFromBuild>True</ExcludedFromBuild>
2012-
</ClCompile>
2013-
<ClInclude Include="..\..\src\ripple\module\app\contracts\Interpreter.h">
2014-
</ClInclude>
2015-
<ClCompile Include="..\..\src\ripple\module\app\contracts\Operation.cpp">
2016-
<ExcludedFromBuild>True</ExcludedFromBuild>
2017-
</ClCompile>
2018-
<ClInclude Include="..\..\src\ripple\module\app\contracts\Operation.h">
2019-
</ClInclude>
2020-
<ClCompile Include="..\..\src\ripple\module\app\contracts\ScriptData.cpp">
2021-
<ExcludedFromBuild>True</ExcludedFromBuild>
2022-
</ClCompile>
2023-
<ClInclude Include="..\..\src\ripple\module\app\contracts\ScriptData.h">
2024-
</ClInclude>
20252002
<ClCompile Include="..\..\src\ripple\module\app\data\DBInit.cpp">
20262003
<ExcludedFromBuild>True</ExcludedFromBuild>
20272004
</ClCompile>
@@ -2333,9 +2310,6 @@
23332310
</ClInclude>
23342311
<ClInclude Include="..\..\src\ripple\module\app\paths\Tuning.h">
23352312
</ClInclude>
2336-
<ClCompile Include="..\..\src\ripple\module\app\paths\Types.cpp">
2337-
<ExcludedFromBuild>True</ExcludedFromBuild>
2338-
</ClCompile>
23392313
<ClInclude Include="..\..\src\ripple\module\app\paths\Types.h">
23402314
</ClInclude>
23412315
<ClInclude Include="..\..\src\ripple\module\app\peers\ClusterNodeStatus.h">
@@ -2378,10 +2352,10 @@
23782352
</ClCompile>
23792353
<ClInclude Include="..\..\src\ripple\module\app\shamap\SHAMapMissingNode.h">
23802354
</ClInclude>
2381-
<ClCompile Include="..\..\src\ripple\module\app\shamap\SHAMapNode.cpp">
2355+
<ClCompile Include="..\..\src\ripple\module\app\shamap\SHAMapNodeID.cpp">
23822356
<ExcludedFromBuild>True</ExcludedFromBuild>
23832357
</ClCompile>
2384-
<ClInclude Include="..\..\src\ripple\module\app\shamap\SHAMapNode.h">
2358+
<ClInclude Include="..\..\src\ripple\module\app\shamap\SHAMapNodeID.h">
23852359
</ClInclude>
23862360
<ClCompile Include="..\..\src\ripple\module\app\shamap\SHAMapSync.cpp">
23872361
<ExcludedFromBuild>True</ExcludedFromBuild>
@@ -3383,6 +3357,8 @@
33833357
</ClInclude>
33843358
<ClInclude Include="..\..\src\ripple\types\api\UInt160.h">
33853359
</ClInclude>
3360+
<ClInclude Include="..\..\src\ripple\types\api\UintTypes.h">
3361+
</ClInclude>
33863362
<ClInclude Include="..\..\src\ripple\types\api\base_uint.h">
33873363
</ClInclude>
33883364
<ClInclude Include="..\..\src\ripple\types\api\strHex.h">
@@ -3402,7 +3378,7 @@
34023378
<ClCompile Include="..\..\src\ripple\types\impl\RippleIdentifierTests.cpp">
34033379
<ExcludedFromBuild>True</ExcludedFromBuild>
34043380
</ClCompile>
3405-
<ClCompile Include="..\..\src\ripple\types\impl\UInt160.cpp">
3381+
<ClCompile Include="..\..\src\ripple\types\impl\UintTypes.cpp">
34063382
<ExcludedFromBuild>True</ExcludedFromBuild>
34073383
</ClCompile>
34083384
<ClCompile Include="..\..\src\ripple\types\impl\base_uint.cpp">

Builds/VisualStudio2013/RippleD.vcxproj.filters

+6-36
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@
367367
<Filter Include="ripple\module\app\consensus">
368368
<UniqueIdentifier>{28E35C4D-F39A-6C32-60CB-B29F44A08B72}</UniqueIdentifier>
369369
</Filter>
370-
<Filter Include="ripple\module\app\contracts">
371-
<UniqueIdentifier>{4EC681B8-69F8-73E2-8E0E-FD12EEC5AD2C}</UniqueIdentifier>
372-
</Filter>
373370
<Filter Include="ripple\module\app\data">
374371
<UniqueIdentifier>{22718803-3748-7147-16F9-822D9BBFA8DC}</UniqueIdentifier>
375372
</Filter>
@@ -2970,9 +2967,6 @@
29702967
<ClCompile Include="..\..\src\ripple\module\app\book\impl\Taker.cpp">
29712968
<Filter>ripple\module\app\book\impl</Filter>
29722969
</ClCompile>
2973-
<ClCompile Include="..\..\src\ripple\module\app\book\impl\Types.cpp">
2974-
<Filter>ripple\module\app\book\impl</Filter>
2975-
</ClCompile>
29762970
<ClCompile Include="..\..\src\ripple\module\app\book\tests\OfferStream.test.cpp">
29772971
<Filter>ripple\module\app\book\tests</Filter>
29782972
</ClCompile>
@@ -2991,30 +2985,6 @@
29912985
<ClInclude Include="..\..\src\ripple\module\app\consensus\LedgerConsensus.h">
29922986
<Filter>ripple\module\app\consensus</Filter>
29932987
</ClInclude>
2994-
<ClCompile Include="..\..\src\ripple\module\app\contracts\Contract.cpp">
2995-
<Filter>ripple\module\app\contracts</Filter>
2996-
</ClCompile>
2997-
<ClInclude Include="..\..\src\ripple\module\app\contracts\Contract.h">
2998-
<Filter>ripple\module\app\contracts</Filter>
2999-
</ClInclude>
3000-
<ClCompile Include="..\..\src\ripple\module\app\contracts\Interpreter.cpp">
3001-
<Filter>ripple\module\app\contracts</Filter>
3002-
</ClCompile>
3003-
<ClInclude Include="..\..\src\ripple\module\app\contracts\Interpreter.h">
3004-
<Filter>ripple\module\app\contracts</Filter>
3005-
</ClInclude>
3006-
<ClCompile Include="..\..\src\ripple\module\app\contracts\Operation.cpp">
3007-
<Filter>ripple\module\app\contracts</Filter>
3008-
</ClCompile>
3009-
<ClInclude Include="..\..\src\ripple\module\app\contracts\Operation.h">
3010-
<Filter>ripple\module\app\contracts</Filter>
3011-
</ClInclude>
3012-
<ClCompile Include="..\..\src\ripple\module\app\contracts\ScriptData.cpp">
3013-
<Filter>ripple\module\app\contracts</Filter>
3014-
</ClCompile>
3015-
<ClInclude Include="..\..\src\ripple\module\app\contracts\ScriptData.h">
3016-
<Filter>ripple\module\app\contracts</Filter>
3017-
</ClInclude>
30182988
<ClCompile Include="..\..\src\ripple\module\app\data\DBInit.cpp">
30192989
<Filter>ripple\module\app\data</Filter>
30202990
</ClCompile>
@@ -3387,9 +3357,6 @@
33873357
<ClInclude Include="..\..\src\ripple\module\app\paths\Tuning.h">
33883358
<Filter>ripple\module\app\paths</Filter>
33893359
</ClInclude>
3390-
<ClCompile Include="..\..\src\ripple\module\app\paths\Types.cpp">
3391-
<Filter>ripple\module\app\paths</Filter>
3392-
</ClCompile>
33933360
<ClInclude Include="..\..\src\ripple\module\app\paths\Types.h">
33943361
<Filter>ripple\module\app\paths</Filter>
33953362
</ClInclude>
@@ -3441,10 +3408,10 @@
34413408
<ClInclude Include="..\..\src\ripple\module\app\shamap\SHAMapMissingNode.h">
34423409
<Filter>ripple\module\app\shamap</Filter>
34433410
</ClInclude>
3444-
<ClCompile Include="..\..\src\ripple\module\app\shamap\SHAMapNode.cpp">
3411+
<ClCompile Include="..\..\src\ripple\module\app\shamap\SHAMapNodeID.cpp">
34453412
<Filter>ripple\module\app\shamap</Filter>
34463413
</ClCompile>
3447-
<ClInclude Include="..\..\src\ripple\module\app\shamap\SHAMapNode.h">
3414+
<ClInclude Include="..\..\src\ripple\module\app\shamap\SHAMapNodeID.h">
34483415
<Filter>ripple\module\app\shamap</Filter>
34493416
</ClInclude>
34503417
<ClCompile Include="..\..\src\ripple\module\app\shamap\SHAMapSync.cpp">
@@ -4650,6 +4617,9 @@
46504617
<ClInclude Include="..\..\src\ripple\types\api\UInt160.h">
46514618
<Filter>ripple\types\api</Filter>
46524619
</ClInclude>
4620+
<ClInclude Include="..\..\src\ripple\types\api\UintTypes.h">
4621+
<Filter>ripple\types\api</Filter>
4622+
</ClInclude>
46534623
<ClInclude Include="..\..\src\ripple\types\api\base_uint.h">
46544624
<Filter>ripple\types\api</Filter>
46554625
</ClInclude>
@@ -4671,7 +4641,7 @@
46714641
<ClCompile Include="..\..\src\ripple\types\impl\RippleIdentifierTests.cpp">
46724642
<Filter>ripple\types\impl</Filter>
46734643
</ClCompile>
4674-
<ClCompile Include="..\..\src\ripple\types\impl\UInt160.cpp">
4644+
<ClCompile Include="..\..\src\ripple\types\impl\UintTypes.cpp">
46754645
<Filter>ripple\types\impl</Filter>
46764646
</ClCompile>
46774647
<ClCompile Include="..\..\src\ripple\types\impl\base_uint.cpp">

src/ripple/module/app/book/Taker.h

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class Taker
7070
// The amounts still left over for us to try and take.
7171
Amounts m_remain;
7272

73-
private:
7473
Amounts
7574
flow (Amounts amount, Offer const& offer, Account const& taker);
7675

src/ripple/module/app/book/Types.h

-38
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,6 @@
3030
namespace ripple {
3131
namespace core {
3232

33-
namespace detail {
34-
35-
class AccountTag {};
36-
class CurrencyTag {};
37-
38-
} // detail
39-
40-
typedef base_uint<160, detail::AccountTag> Account;
41-
typedef base_uint<160, detail::CurrencyTag> Currency;
42-
43-
inline std::string to_string(Currency const& c)
44-
{
45-
return STAmount::createHumanCurrency(c);
46-
}
47-
48-
inline std::string to_string(Account const& a)
49-
{
50-
return RippleAddress::createHumanAccountID(a);
51-
}
52-
53-
inline std::ostream& operator<< (std::ostream& os, Account const& x)
54-
{
55-
os << to_string (x);
56-
return os;
57-
}
58-
59-
inline std::ostream& operator<< (std::ostream& os, Currency const& x)
60-
{
61-
os << to_string (x);
62-
return os;
63-
}
64-
6533
/** A mutable view that overlays an immutable ledger to track changes. */
6634
typedef LedgerEntrySet LedgerView;
6735

@@ -85,12 +53,6 @@ class Clock // : public abstract_clock <std::chrono::seconds>
8553
};
8654

8755
} // core
88-
89-
inline bool isXRP(core::Currency const& c)
90-
{
91-
return c == zero;
92-
}
93-
9456
} // ripple
9557

9658
#endif

src/ripple/module/app/book/impl/Types.cpp

-29
This file was deleted.

src/ripple/module/app/book/tests/Quality.test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Quality_test : public beast::unit_test::suite
3232
Amount
3333
static raw (std::uint64_t mantissa, int exponent)
3434
{
35-
return Amount (uint160(3), uint160(3), mantissa, exponent);
35+
return Amount (Currency(3), Account(3), mantissa, exponent);
3636
}
3737

3838
template <class Integer>

src/ripple/module/app/consensus/DisputedTx.cpp

+23-19
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,50 @@ namespace ripple {
2222
// #define TRUST_NETWORK
2323

2424
// Track a peer's yes/no vote on a particular disputed transaction
25-
void DisputedTx::setVote (const uint160& peer, bool votesYes)
25+
void DisputedTx::setVote (NodeID const& peer, bool votesYes)
2626
{
27-
// VFALCO TODO Simplify this declaration. It doesn't exactly roll off the tongue!
28-
std::pair <ripple::unordered_map <uint160, bool>::iterator, bool> res =
29-
mVotes.insert (std::make_pair (peer, votesYes));
27+
auto res = mVotes.insert (std::make_pair (peer, votesYes));
3028

3129
// new vote
3230
if (res.second)
3331
{
3432
if (votesYes)
3533
{
36-
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " votes YES on " << mTransactionID;
34+
WriteLog (lsDEBUG, LedgerConsensus)
35+
<< "Peer " << peer << " votes YES on " << mTransactionID;
3736
++mYays;
3837
}
3938
else
4039
{
41-
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " votes NO on " << mTransactionID;
40+
WriteLog (lsDEBUG, LedgerConsensus)
41+
<< "Peer " << peer << " votes NO on " << mTransactionID;
4242
++mNays;
4343
}
4444
}
4545
// changes vote to yes
4646
else if (votesYes && !res.first->second)
4747
{
48-
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " now votes YES on " << mTransactionID;
48+
WriteLog (lsDEBUG, LedgerConsensus)
49+
<< "Peer " << peer << " now votes YES on " << mTransactionID;
4950
--mNays;
5051
++mYays;
5152
res.first->second = true;
5253
}
5354
// changes vote to no
5455
else if (!votesYes && res.first->second)
5556
{
56-
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " now votes NO on " << mTransactionID;
57+
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer
58+
<< " now votes NO on " << mTransactionID;
5759
++mNays;
5860
--mYays;
5961
res.first->second = false;
6062
}
6163
}
6264

6365
// Remove a peer's vote on this disputed transasction
64-
void DisputedTx::unVote (const uint160& peer)
66+
void DisputedTx::unVote (NodeID const& peer)
6567
{
66-
ripple::unordered_map<uint160, bool>::iterator it = mVotes.find (peer);
68+
auto it = mVotes.find (peer);
6769

6870
if (it != mVotes.end ())
6971
{
@@ -95,10 +97,12 @@ bool DisputedTx::updateVote (int percentTime, bool proposing)
9597
// This is basically the percentage of nodes voting 'yes' (including us)
9698
weight = (mYays * 100 + (mOurVote ? 100 : 0)) / (mNays + mYays + 1);
9799

98-
// VFALCO TODO Rename these macros and turn them into language constructs.
99-
// consolidate them into a class that collects all these related values.
100+
// VFALCO TODO Rename these macros and turn them into language
101+
// constructs. consolidate them into a class that collects
102+
// all these related values.
100103
//
101-
// To prevent avalanche stalls, we increase the needed weight slightly over time
104+
// To prevent avalanche stalls, we increase the needed weight slightly
105+
// over time.
102106
if (percentTime < AV_MID_CONSENSUS_TIME)
103107
newPosition = weight > AV_INIT_CONSENSUS_PCT;
104108
else if (percentTime < AV_LATE_CONSENSUS_TIME)
@@ -116,14 +120,17 @@ bool DisputedTx::updateVote (int percentTime, bool proposing)
116120

117121
if (newPosition == mOurVote)
118122
{
119-
WriteLog (lsINFO, LedgerConsensus) <<
120-
"No change (" << (mOurVote ? "YES" : "NO") << ") : weight " << weight << ", percent " << percentTime;
123+
WriteLog (lsINFO, LedgerConsensus)
124+
<< "No change (" << (mOurVote ? "YES" : "NO") << ") : weight "
125+
<< weight << ", percent " << percentTime;
121126
WriteLog (lsDEBUG, LedgerConsensus) << getJson ();
122127
return false;
123128
}
124129

125130
mOurVote = newPosition;
126-
WriteLog (lsDEBUG, LedgerConsensus) << "We now vote " << (mOurVote ? "YES" : "NO") << " on " << mTransactionID;
131+
WriteLog (lsDEBUG, LedgerConsensus)
132+
<< "We now vote " << (mOurVote ? "YES" : "NO")
133+
<< " on " << mTransactionID;
127134
WriteLog (lsDEBUG, LedgerConsensus) << getJson ();
128135
return true;
129136
}
@@ -140,14 +147,11 @@ Json::Value DisputedTx::getJson ()
140147
{
141148
Json::Value votesj (Json::objectValue);
142149
for (auto& vote : mVotes)
143-
{
144150
votesj[to_string (vote.first)] = vote.second;
145-
}
146151
ret["votes"] = votesj;
147152
}
148153

149154
return ret;
150155
}
151156

152157
} // ripple
153-

0 commit comments

Comments
 (0)