mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Avoid the getValue confusion. Use getNValue for native, getMantissa otherwise
This commit is contained in:
@@ -721,9 +721,9 @@ uint64 getRate(const STAmount& offerOut, const STAmount& offerIn)
|
|||||||
if (offerOut.isZero()) throw std::runtime_error("Worthless offer");
|
if (offerOut.isZero()) throw std::runtime_error("Worthless offer");
|
||||||
|
|
||||||
STAmount r = divide(offerIn, offerOut, uint160(1));
|
STAmount r = divide(offerIn, offerOut, uint160(1));
|
||||||
assert((r.getOffset() >= -100) && (r.getOffset() <= 155));
|
assert((r.getExponent() >= -100) && (r.getExponent() <= 155));
|
||||||
uint64 ret = r.getOffset() + 100;
|
uint64 ret = r.getExponent() + 100;
|
||||||
return (ret << (64 - 8)) | r.getValue();
|
return (ret << (64 - 8)) | r.getMantissa();
|
||||||
}
|
}
|
||||||
|
|
||||||
STAmount getClaimed(STAmount& offerOut, STAmount& offerIn, STAmount& paid)
|
STAmount getClaimed(STAmount& offerOut, STAmount& offerIn, STAmount& paid)
|
||||||
@@ -786,8 +786,7 @@ static uint64_t muldiv(uint64_t a, uint64_t b, uint64_t c)
|
|||||||
|
|
||||||
uint64 convertToDisplayAmount(const STAmount& internalAmount, uint64_t totalNow, uint64_t totalInit)
|
uint64 convertToDisplayAmount(const STAmount& internalAmount, uint64_t totalNow, uint64_t totalInit)
|
||||||
{ // Convert an internal ledger/account quantity of native currency to a display amount
|
{ // Convert an internal ledger/account quantity of native currency to a display amount
|
||||||
if (internalAmount.isNative()) throw std::runtime_error("not native curency");
|
return muldiv(internalAmount.getNValue(), totalInit, totalNow);
|
||||||
return muldiv(internalAmount.getValue(), totalInit, totalNow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STAmount convertToInternalAmount(uint64_t displayAmount, uint64_t totalNow, uint64_t totalInit,
|
STAmount convertToInternalAmount(uint64_t displayAmount, uint64_t totalNow, uint64_t totalInit,
|
||||||
|
|||||||
@@ -164,14 +164,14 @@ STAmount SerializedTransaction::getTransactionFee() const
|
|||||||
{
|
{
|
||||||
const STAmount* v = dynamic_cast<const STAmount*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
|
const STAmount* v = dynamic_cast<const STAmount*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
|
||||||
if (!v) throw std::runtime_error("corrupt transaction");
|
if (!v) throw std::runtime_error("corrupt transaction");
|
||||||
return v->getValue();
|
return v->getNValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializedTransaction::setTransactionFee(STAmount saFee)
|
void SerializedTransaction::setTransactionFee(STAmount saFee)
|
||||||
{
|
{
|
||||||
STAmount* v = dynamic_cast<STAmount*>(mMiddleTxn.getPIndex(TransactionIFee));
|
STAmount* v = dynamic_cast<STAmount*>(mMiddleTxn.getPIndex(TransactionIFee));
|
||||||
if (!v) throw std::runtime_error("corrupt transaction");
|
if (!v) throw std::runtime_error("corrupt transaction");
|
||||||
v->setValue(saFee);
|
v->setNValue(saFee);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 SerializedTransaction::getSequence() const
|
uint32 SerializedTransaction::getSequence() const
|
||||||
|
|||||||
@@ -253,9 +253,12 @@ public:
|
|||||||
std::string getRaw() const;
|
std::string getRaw() const;
|
||||||
void add(Serializer& s) const;
|
void add(Serializer& s) const;
|
||||||
|
|
||||||
int getOffset() const { return mOffset; }
|
int getExponent() const { return mOffset; }
|
||||||
uint64 getValue() const { return mValue; }
|
uint64 getMantissa() const { return mValue; }
|
||||||
void setValue(const STAmount& v) { mValue=v; }
|
|
||||||
|
uint64 getNValue() const { if (!mIsNative) throw std::runtime_error("not native"); return mValue; }
|
||||||
|
void setNValue(uint64_t v) { if (!mIsNative) throw std::runtime_error("not native"); mValue = v; }
|
||||||
|
|
||||||
std::string getCurrencyHuman();
|
std::string getCurrencyHuman();
|
||||||
|
|
||||||
bool isNative() const { return mIsNative; }
|
bool isNative() const { return mIsNative; }
|
||||||
|
|||||||
Reference in New Issue
Block a user