Bring some sanity to integer->STAmount constructors.

This commit is contained in:
JoelKatz
2013-02-11 22:19:21 -08:00
parent 33154e4ef5
commit 92292a178b
4 changed files with 37 additions and 7 deletions

View File

@@ -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<uint64>(uTransitRate), -9);
STAmount saTransferTotal = STAmount::multiply(saAmount, saTransitRate, saAmount.getCurrency(), saAmount.getIssuer());
STAmount saTransferFee = saTransferTotal-saAmount;

View File

@@ -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

View File

@@ -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

View File

@@ -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<uint64>(-v);
}
else
{
mIsNegative = false;
mValue = static_cast<uint64>(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;