From 92292a178b5f015882cdf3c9e655e6a9047e2ceb Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 11 Feb 2013 22:19:21 -0800 Subject: [PATCH] Bring some sanity to integer->STAmount constructors. --- src/cpp/ripple/LedgerEntrySet.cpp | 2 +- src/cpp/ripple/Pathfinder.cpp | 2 +- src/cpp/ripple/RippleCalc.cpp | 2 +- src/cpp/ripple/SerializedTypes.h | 38 +++++++++++++++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/cpp/ripple/LedgerEntrySet.cpp b/src/cpp/ripple/LedgerEntrySet.cpp index 15461e52e..b5dda8849 100644 --- a/src/cpp/ripple/LedgerEntrySet.cpp +++ b/src/cpp/ripple/LedgerEntrySet.cpp @@ -1135,7 +1135,7 @@ STAmount LedgerEntrySet::rippleTransferFee(const uint160& uSenderID, const uint1 if (QUALITY_ONE != uTransitRate) { - STAmount saTransitRate(CURRENCY_ONE, ACCOUNT_ONE, uTransitRate, -9); + STAmount saTransitRate(CURRENCY_ONE, ACCOUNT_ONE, static_cast(uTransitRate), -9); STAmount saTransferTotal = STAmount::multiply(saAmount, saTransitRate, saAmount.getCurrency(), saAmount.getIssuer()); STAmount saTransferFee = saTransferTotal-saAmount; diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index f3654366b..6ea459be1 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -135,7 +135,7 @@ Pathfinder::Pathfinder(const RippleAddress& uSrcAccountID, const RippleAddress& mSrcIssuerID(uSrcIssuerID) { mLedger = theApp->getLedgerMaster().getCurrentLedger(); - mSrcAmount = STAmount(uSrcCurrencyID, uSrcIssuerID, 1, 0, true); // -1/uSrcIssuerID/uSrcIssuerID + mSrcAmount = STAmount(uSrcCurrencyID, uSrcIssuerID, 1, 0); // -1/uSrcIssuerID/uSrcIssuerID theApp->getOrderBookDB().setup( theApp->getLedgerMaster().getCurrentLedger()); // TODO: have the orderbook update itself rather than rebuild it from scratch each time diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index 0b1ece0d3..39673c924 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -1681,7 +1681,7 @@ TER RippleCalc::calcNodeAccountRev(const unsigned int uNode, PathState& psCur, c STAmount& saPrvIssueAct = pnPrv.saRevIssue; // For !bPrvAccount - const STAmount saPrvDeliverReq = STAmount::saFromSigned(uCurrencyID, uCurAccountID, -1); // Unlimited. + const STAmount saPrvDeliverReq = STAmount(uCurrencyID, uCurAccountID, -1); // Unlimited. STAmount& saPrvDeliverAct = pnPrv.saRevDeliver; // For bNxtAccount diff --git a/src/cpp/ripple/SerializedTypes.h b/src/cpp/ripple/SerializedTypes.h index 89b687c9a..d501ab4aa 100644 --- a/src/cpp/ripple/SerializedTypes.h +++ b/src/cpp/ripple/SerializedTypes.h @@ -233,7 +233,21 @@ protected: : SerializedType(name), mCurrency(cur), mIssuer(iss), mValue(val), mOffset(off), mIsNative(isNat), mIsNegative(isNeg) { ; } - void set(int64_t v) + void set(int64 v) + { + if (v < 0) + { + mIsNegative = true; + mValue = static_cast(-v); + } + else + { + mIsNegative = false; + mValue = static_cast(v); + } + } + + void set(int v) { if (v < 0) { @@ -271,6 +285,11 @@ public: : mCurrency(uCurrencyID), mIssuer(uIssuerID), mValue(uV), mOffset(iOff), mIsNegative(bNegative) { canonicalize(); } + STAmount(const uint160& uCurrencyID, const uint160& uIssuerID, + uint32 uV, int iOff = 0, bool bNegative = false) + : mCurrency(uCurrencyID), mIssuer(uIssuerID), mValue(uV), mOffset(iOff), mIsNegative(bNegative) + { canonicalize(); } + STAmount(SField::ref n, const uint160& currency, const uint160& issuer, uint64 v = 0, int off = 0, bool isNeg = false) : SerializedType(n), mCurrency(currency), mIssuer(issuer), mValue(v), mOffset(off), mIsNegative(isNeg) @@ -290,6 +309,20 @@ public: canonicalize(); } + STAmount(const uint160& uCurrencyID, const uint160& uIssuerID, int v, int iOff = 0) + : mCurrency(uCurrencyID), mIssuer(uIssuerID), mOffset(iOff) + { + set(v); + canonicalize(); + } + + STAmount(SField::ref n, const uint160& currency, const uint160& issuer, int v, int off = 0) + : SerializedType(n), mCurrency(currency), mIssuer(issuer), mOffset(off) + { + set(v); + canonicalize(); + } + STAmount(SField::ref, const Json::Value&); static STAmount createFromInt64(SField::ref n, int64 v); @@ -302,9 +335,6 @@ public: static STAmount saFromRate(uint64 uRate = 0) { return STAmount(CURRENCY_ONE, ACCOUNT_ONE, uRate, -9, false); } - static STAmount saFromSigned(const uint160& uCurrencyID, const uint160& uIssuerID, int64 iV = 0, int iOff = 0) - { return STAmount(uCurrencyID, uIssuerID, iV < 0 ? -iV : iV, iOff, iV < 0); } - SerializedTypeID getSType() const { return STI_AMOUNT; } std::string getText() const; std::string getRaw() const;